Example usage for com.vaadin.ui GridLayout setColumnExpandRatio

List of usage examples for com.vaadin.ui GridLayout setColumnExpandRatio

Introduction

In this page you can find the example usage for com.vaadin.ui GridLayout setColumnExpandRatio.

Prototype

public void setColumnExpandRatio(int columnIndex, float ratio) 

Source Link

Document

Sets the expand ratio of given column.

Usage

From source file:org.apache.ace.webui.vaadin.component.ConfirmationDialog.java

License:Apache License

/**
 * Adds all components to this dialog.//from  w w w . j  a  v  a 2s  . c  om
 * 
 * @param message
 *            the optional message to display, can be <code>null</code>;
 * @param buttonNames
 *            the names of the buttons to add, never <code>null</code> or empty.
 */
protected void addComponents(String message, String defaultButton, String... buttonNames) {
    if (message != null) {
        addComponent(new Label(message));
    }

    GridLayout gl = new GridLayout(buttonNames.length + 1, 1);
    gl.setSpacing(true);
    gl.setWidth("100%");

    gl.addComponent(new Label(" "));
    gl.setColumnExpandRatio(0, 1.0f);

    for (String buttonName : buttonNames) {
        Button button = new Button(buttonName, this);
        button.setData(buttonName);
        if (defaultButton != null && defaultButton.equals(buttonName)) {
            button.setStyleName(Reindeer.BUTTON_DEFAULT);
            button.setClickShortcut(KeyCode.ENTER);
            // Request focus in this window...
            button.focus();
        }
        gl.addComponent(button);
    }

    addComponent(gl);
}

From source file:org.bubblecloud.ilves.comment.CommentListComponent.java

License:Open Source License

public void refresh() {

    final String contextPath = VaadinService.getCurrentRequest().getContextPath();
    final Site site = Site.getCurrent();

    final Company company = site.getSiteContext().getObject(Company.class);
    final EntityManager entityManager = site.getSiteContext().getObject(EntityManager.class);

    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<Comment> commentCriteriaQuery = builder.createQuery(Comment.class);
    final Root<Comment> commentRoot = commentCriteriaQuery.from(Comment.class);
    commentCriteriaQuery.where(builder.and(builder.equal(commentRoot.get("owner"), company),
            builder.equal(commentRoot.get("dataId"), contextPath)));
    commentCriteriaQuery.orderBy(builder.asc(commentRoot.get("created")));

    final TypedQuery<Comment> commentTypedQuery = entityManager.createQuery(commentCriteriaQuery);
    final List<Comment> commentList = commentTypedQuery.getResultList();

    final Panel panel = new Panel(site.localize("panel-comments"));
    setCompositionRoot(panel);//www  .ja  v  a2s .  c  o m

    final GridLayout gridLayout = new GridLayout(3, commentList.size() + 1);
    panel.setContent(gridLayout);
    gridLayout.setSpacing(true);
    gridLayout.setMargin(true);
    gridLayout.setColumnExpandRatio(0, 0.0f);
    gridLayout.setColumnExpandRatio(1, 0.1f);
    gridLayout.setColumnExpandRatio(2, 0.9f);

    final Label authorHeaderLabel = new Label();
    authorHeaderLabel.setStyleName(ValoTheme.LABEL_BOLD);
    authorHeaderLabel.setValue(site.localize("column-header-author"));
    gridLayout.addComponent(authorHeaderLabel, 0, 0, 1, 0);

    final Label commentHeaderLabel = new Label();
    commentHeaderLabel.setStyleName(ValoTheme.LABEL_BOLD);
    commentHeaderLabel.setValue(site.localize("column-header-comment"));
    gridLayout.addComponent(commentHeaderLabel, 2, 0);

    for (int i = 0; i < commentList.size(); i++) {
        final Comment comment = commentList.get(i);

        final Link authorImageLink = GravatarUtil.getGravatarImageLink(comment.getAuthor().getEmailAddress());
        gridLayout.addComponent(authorImageLink, 0, i + 1);

        final Label authorLabel = new Label();
        final String authorName = comment.getAuthor().getFirstName();
        authorLabel.setValue(authorName);
        gridLayout.addComponent(authorLabel, 1, i + 1);

        final Label messageLabel = new Label();
        messageLabel.setValue(comment.getMessage());
        gridLayout.addComponent(messageLabel, 2, i + 1);
    }

}

From source file:org.bubblecloud.ilves.ui.administrator.user.UserFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout layout = new GridLayout(2, 3);
    layout.setSizeFull();//w  w w.  j  a  v a2 s. com
    layout.setMargin(false);
    layout.setSpacing(true);
    layout.setRowExpandRatio(1, 1f);
    layout.setColumnExpandRatio(1, 1f);
    setViewContent(layout);

    editor = new ValidatingEditor(SiteFields.getFieldDescriptors(User.class));
    editor.setCaption("User");
    editor.addListener((ValidatingEditorStateListener) this);
    editor.setWidth("480px");
    layout.addComponent(editor, 0, 1);

    final List<FieldDescriptor> childFieldDescriptors = SiteFields.getFieldDescriptors(GroupMember.class);
    final List<FilterDescriptor> childFilterDescriptors = new ArrayList<FilterDescriptor>();
    childContainer = new EntityContainer<GroupMember>(entityManager, GroupMember.class, "groupMemberId", 1000,
            true, false, false);
    childContainer.getQueryView().getQueryDefinition().setDefaultSortState(
            new String[] { "user.firstName", "user.lastName" }, new boolean[] { true, true });

    ContainerUtil.addContainerProperties(childContainer, childFieldDescriptors);

    final Table childTable = new FormattingTable();
    childGrid = new Grid(childTable, childContainer);
    childGrid.setFields(childFieldDescriptors);
    childGrid.setFilters(childFilterDescriptors);

    childTable.setColumnCollapsed("created", true);

    layout.addComponent(childGrid, 1, 1);

    final HorizontalLayout editorButtonLayout = new HorizontalLayout();
    editorButtonLayout.setSpacing(true);
    layout.addComponent(editorButtonLayout, 0, 2);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    editorButtonLayout.addComponent(saveButton);
    saveButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.commit();
            try {
                final boolean toBeAdded = user.getUserId() == null;
                if (user.getPasswordHash() != null) {
                    final int hashSize = 64;
                    if (user.getPasswordHash().length() != hashSize) {
                        try {
                            PasswordLoginUtil.setUserPasswordHash(user.getOwner(), user,
                                    user.getPasswordHash());
                        } catch (NoSuchAlgorithmException e) {
                            e.printStackTrace();
                        }
                    }
                }
                // UserLogic.updateUser(user,
                // UserDao.getGroupMembers(entityManager, user));
                if (toBeAdded) {
                    SecurityService.addUser(getSite().getSiteContext(), user,
                            UserDao.getGroup(entityManager, user.getOwner(), DefaultRoles.USER));
                    childGrid.refresh();
                } else {
                    SecurityService.updateUser(getSite().getSiteContext(), user);
                }

                editor.setItem(new BeanItem<User>(user), false);
                //entityManager.detach(user);
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + user, t);
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    editorButtonLayout.addComponent(discardButton);
    discardButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.discard();
        }
    });

    childListButtonLayout = new HorizontalLayout();
    childListButtonLayout.setSpacing(true);
    childListButtonLayout.setSizeUndefined();
    layout.addComponent(childListButtonLayout, 1, 0);

    final Button addButton = getSite().getButton("add");
    childListButtonLayout.addComponent(addButton);
    addButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final GroupMember userElement = new GroupMember();
            userElement.setUser(user);
            userElement.setCreated(new Date());
            final UserGroupMemberFlowlet userGroupMemberFlowlet = getFlow()
                    .forward(UserGroupMemberFlowlet.class);
            userGroupMemberFlowlet.edit(userElement, true);
        }
    });

    final Button removeButton = getSite().getButton("remove");
    childListButtonLayout.addComponent(removeButton);
    removeButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            if (childGrid.getSelectedItemId() == null) {
                return;
            }
            childContainer.removeItem(childGrid.getSelectedItemId());
            childContainer.commit();
        }
    });

}

From source file:org.bubblecloud.ilves.ui.user.UserAccountFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout layout = new GridLayout(1, 3);
    layout.setSizeFull();/*from   w  w w  . j a  v  a  2s . co m*/
    layout.setMargin(false);
    layout.setSpacing(true);
    layout.setRowExpandRatio(1, 1f);
    layout.setColumnExpandRatio(1, 1f);
    setViewContent(layout);

    editor = new ValidatingEditor(SiteFields.getFieldDescriptors(User.class));
    editor.setCaption("User");
    editor.addListener((ValidatingEditorStateListener) this);
    editor.setWidth("380px");
    layout.addComponent(editor, 0, 1);

    final HorizontalLayout editorButtonLayout = new HorizontalLayout();
    editorButtonLayout.setSpacing(true);
    layout.addComponent(editorButtonLayout, 0, 2);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    editorButtonLayout.addComponent(saveButton);
    saveButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.commit();
            try {

                if (user.getPasswordHash() != null) {
                    final int hashSize = 64;
                    if (user.getPasswordHash().length() != hashSize) {
                        try {
                            PasswordLoginUtil.setUserPasswordHash(user.getOwner(), user,
                                    user.getPasswordHash());
                        } catch (NoSuchAlgorithmException e) {
                            e.printStackTrace();
                        }
                    }
                }
                // UserLogic.updateUser(user,
                // UserDao.getGroupMembers(entityManager, user));
                user = entityManager.merge(user);
                SecurityService.updateUser(getSite().getSiteContext(), user);
                editor.setItem(new BeanItem<User>(user), false);
                entityManager.detach(user);
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + user, t);
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    editorButtonLayout.addComponent(discardButton);
    discardButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.discard();
        }
    });

}

From source file:org.diretto.web.richwebclient.view.windows.UploadSettingsWindow.java

/**
 * Constructs an {@link UploadSettingsWindow}.
 * /*w w  w .  jav a  2s.c  o  m*/
 * @param mainWindow The corresponding {@code MainWindow}
 * @param uploadSection The corresponding {@code UploadSection}
 * @param fileInfo The {@code FileInfo} object
 * @param mediaType The {@code MediaType} of the file
 * @param uploadSettings The corresponding {@code UploadSettings}
 * @param otherFiles The names of the other upload files
 */
public UploadSettingsWindow(final MainWindow mainWindow, final UploadSection uploadSection, FileInfo fileInfo,
        MediaType mediaType, UploadSettings uploadSettings, List<String> otherFiles) {
    super("Upload Settings");

    this.mainWindow = mainWindow;

    setModal(true);
    setStyleName(Reindeer.WINDOW_BLACK);
    setWidth("940px");
    setHeight((((int) mainWindow.getHeight()) - 160) + "px");
    setResizable(false);
    setClosable(false);
    setDraggable(false);
    setPositionX((int) (mainWindow.getWidth() / 2.0f) - 470);
    setPositionY(126);

    wrapperLayout = new HorizontalLayout();
    wrapperLayout.setSizeFull();
    wrapperLayout.setMargin(true, true, true, true);
    addComponent(wrapperLayout);

    mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();
    mainLayout.setSpacing(true);

    HorizontalLayout titleLayout = new HorizontalLayout();
    titleLayout.setWidth("100%");
    mainLayout.addComponent(titleLayout);

    HorizontalLayout leftTitleLayout = new HorizontalLayout();
    titleLayout.addComponent(leftTitleLayout);
    titleLayout.setComponentAlignment(leftTitleLayout, Alignment.MIDDLE_LEFT);

    Label fileNameLabel = StyleUtils.getLabelH2(fileInfo.getName());
    leftTitleLayout.addComponent(fileNameLabel);
    leftTitleLayout.setComponentAlignment(fileNameLabel, Alignment.MIDDLE_LEFT);

    Label bullLabel = StyleUtils.getLabelHTML(
            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&bull;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    leftTitleLayout.addComponent(bullLabel);
    leftTitleLayout.setComponentAlignment(bullLabel, Alignment.MIDDLE_LEFT);

    Label titleLabel = StyleUtils.getLabelHTML("<b>Title</b>&nbsp;&nbsp;&nbsp;");
    leftTitleLayout.addComponent(titleLabel);
    leftTitleLayout.setComponentAlignment(titleLabel, Alignment.MIDDLE_LEFT);

    final TextField titleField = new TextField();
    titleField.setMaxLength(50);
    titleField.setWidth("100%");
    titleField.setImmediate(true);

    if (uploadSettings != null && uploadSettings.getTitle() != null) {
        titleField.setValue(uploadSettings.getTitle());
    }

    titleField.focus();
    titleField.setCursorPosition(((String) titleField.getValue()).length());

    titleLayout.addComponent(titleField);
    titleLayout.setComponentAlignment(titleField, Alignment.MIDDLE_RIGHT);

    titleLayout.setExpandRatio(leftTitleLayout, 0);
    titleLayout.setExpandRatio(titleField, 1);

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    GridLayout topGridLayout = new GridLayout(2, 3);
    topGridLayout.setColumnExpandRatio(0, 1.0f);
    topGridLayout.setColumnExpandRatio(1, 0.0f);
    topGridLayout.setWidth("100%");
    topGridLayout.setSpacing(true);
    mainLayout.addComponent(topGridLayout);

    Label descriptionLabel = StyleUtils.getLabelBold("Description");
    topGridLayout.addComponent(descriptionLabel, 0, 0);

    final TextArea descriptionArea = new TextArea();
    descriptionArea.setSizeFull();
    descriptionArea.setImmediate(true);

    if (uploadSettings != null && uploadSettings.getDescription() != null) {
        descriptionArea.setValue(uploadSettings.getDescription());
    }

    topGridLayout.addComponent(descriptionArea, 0, 1);

    VerticalLayout tagsWrapperLayout = new VerticalLayout();
    tagsWrapperLayout.setHeight("30px");
    tagsWrapperLayout.setSpacing(false);
    topGridLayout.addComponent(tagsWrapperLayout, 0, 2);

    HorizontalLayout tagsLayout = new HorizontalLayout();
    tagsLayout.setWidth("100%");
    tagsLayout.setSpacing(true);

    Label tagsLabel = StyleUtils.getLabelBoldHTML("Tags&nbsp;");
    tagsLabel.setSizeUndefined();
    tagsLayout.addComponent(tagsLabel);
    tagsLayout.setComponentAlignment(tagsLabel, Alignment.MIDDLE_LEFT);

    addTagField = new TextField();
    addTagField.setImmediate(true);
    addTagField.setInputPrompt("Enter new Tag");

    addTagField.addShortcutListener(new ShortcutListener(null, KeyCode.ENTER, new int[0]) {
        private static final long serialVersionUID = -4767515198819351723L;

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == addTagField) {
                addTag();
            }
        }
    });

    tagsLayout.addComponent(addTagField);
    tagsLayout.setComponentAlignment(addTagField, Alignment.MIDDLE_LEFT);

    tabSheet = new TabSheet();

    tabSheet.setStyleName(Reindeer.TABSHEET_SMALL);
    tabSheet.addStyleName("view");

    tabSheet.addListener(new ComponentDetachListener() {
        private static final long serialVersionUID = -657657505471281795L;

        @Override
        public void componentDetachedFromContainer(ComponentDetachEvent event) {
            tags.remove(tabSheet.getTab(event.getDetachedComponent()).getCaption());
        }
    });

    Button addTagButton = new Button("Add", new Button.ClickListener() {
        private static final long serialVersionUID = 5914473126402594623L;

        @Override
        public void buttonClick(ClickEvent event) {
            addTag();
        }
    });

    addTagButton.setStyleName(Reindeer.BUTTON_DEFAULT);

    tagsLayout.addComponent(addTagButton);
    tagsLayout.setComponentAlignment(addTagButton, Alignment.MIDDLE_LEFT);

    Label spaceLabel = StyleUtils.getLabelHTML("");
    spaceLabel.setSizeUndefined();
    tagsLayout.addComponent(spaceLabel);
    tagsLayout.setComponentAlignment(spaceLabel, Alignment.MIDDLE_LEFT);

    tagsLayout.addComponent(tabSheet);
    tagsLayout.setComponentAlignment(tabSheet, Alignment.MIDDLE_LEFT);
    tagsLayout.setExpandRatio(tabSheet, 1.0f);

    tagsWrapperLayout.addComponent(tagsLayout);
    tagsWrapperLayout.setComponentAlignment(tagsLayout, Alignment.TOP_LEFT);

    if (uploadSettings != null && uploadSettings.getTags() != null && uploadSettings.getTags().size() > 0) {
        for (String tag : uploadSettings.getTags()) {
            addTagField.setValue(tag);

            addTag();
        }
    }

    Label presettingLabel = StyleUtils.getLabelBold("Presetting");
    topGridLayout.addComponent(presettingLabel, 1, 0);

    final TwinColSelect twinColSelect;

    if (otherFiles != null && otherFiles.size() > 0) {
        twinColSelect = new TwinColSelect(null, otherFiles);
    } else {
        twinColSelect = new TwinColSelect();
    }

    twinColSelect.setWidth("400px");
    twinColSelect.setRows(10);
    topGridLayout.addComponent(twinColSelect, 1, 1);
    topGridLayout.setComponentAlignment(twinColSelect, Alignment.TOP_RIGHT);

    Label otherFilesLabel = StyleUtils
            .getLabelSmallHTML("Select the files which should get the settings of this file as presetting.");
    otherFilesLabel.setSizeUndefined();
    topGridLayout.addComponent(otherFilesLabel, 1, 2);
    topGridLayout.setComponentAlignment(otherFilesLabel, Alignment.MIDDLE_CENTER);

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    final UploadGoogleMap googleMap;

    if (uploadSettings != null && uploadSettings.getTopographicPoint() != null) {
        googleMap = new UploadGoogleMap(mediaType, 12, uploadSettings.getTopographicPoint().getLatitude(),
                uploadSettings.getTopographicPoint().getLongitude(), MapType.HYBRID);
    } else {
        googleMap = new UploadGoogleMap(mediaType, 12, 48.42255269321401d, 9.956477880477905d, MapType.HYBRID);
    }

    googleMap.setWidth("100%");
    googleMap.setHeight("300px");
    mainLayout.addComponent(googleMap);

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    GridLayout bottomGridLayout = new GridLayout(3, 3);
    bottomGridLayout.setSizeFull();
    bottomGridLayout.setSpacing(true);
    mainLayout.addComponent(bottomGridLayout);

    Label licenseLabel = StyleUtils.getLabelBold("License");
    bottomGridLayout.addComponent(licenseLabel, 0, 0);

    final TextArea licenseArea = new TextArea();
    licenseArea.setWidth("320px");
    licenseArea.setHeight("175px");
    licenseArea.setImmediate(true);

    if (uploadSettings != null && uploadSettings.getLicense() != null) {
        licenseArea.setValue(uploadSettings.getLicense());
    }

    bottomGridLayout.addComponent(licenseArea, 0, 1);

    final Label startTimeLabel = StyleUtils.getLabelBold("Earliest possible Start Date");
    startTimeLabel.setSizeUndefined();
    bottomGridLayout.setComponentAlignment(startTimeLabel, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(startTimeLabel, 1, 0);

    final InlineDateField startTimeField = new InlineDateField();
    startTimeField.setImmediate(true);
    startTimeField.setResolution(InlineDateField.RESOLUTION_SEC);

    boolean currentTimeAdjusted = false;

    if (uploadSettings != null && uploadSettings.getTimeRange() != null
            && uploadSettings.getTimeRange().getStartDateTime() != null) {
        startTimeField.setValue(uploadSettings.getTimeRange().getStartDateTime().toDate());
    } else {
        currentTimeAdjusted = true;

        startTimeField.setValue(new Date());
    }

    bottomGridLayout.setComponentAlignment(startTimeField, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(startTimeField, 1, 1);

    final CheckBox exactTimeCheckBox = new CheckBox("This is the exact point in time.");
    exactTimeCheckBox.setImmediate(true);
    bottomGridLayout.setComponentAlignment(exactTimeCheckBox, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(exactTimeCheckBox, 1, 2);

    final Label endTimeLabel = StyleUtils.getLabelBold("Latest possible Start Date");
    endTimeLabel.setSizeUndefined();
    bottomGridLayout.setComponentAlignment(endTimeLabel, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(endTimeLabel, 2, 0);

    final InlineDateField endTimeField = new InlineDateField();
    endTimeField.setImmediate(true);
    endTimeField.setResolution(InlineDateField.RESOLUTION_SEC);

    if (uploadSettings != null && uploadSettings.getTimeRange() != null
            && uploadSettings.getTimeRange().getEndDateTime() != null) {
        endTimeField.setValue(uploadSettings.getTimeRange().getEndDateTime().toDate());
    } else {
        endTimeField.setValue(startTimeField.getValue());
    }

    bottomGridLayout.setComponentAlignment(endTimeField, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(endTimeField, 2, 1);

    if (!currentTimeAdjusted && ((Date) startTimeField.getValue()).equals((Date) endTimeField.getValue())) {
        exactTimeCheckBox.setValue(true);

        endTimeLabel.setEnabled(false);
        endTimeField.setEnabled(false);
    }

    exactTimeCheckBox.addListener(new ValueChangeListener() {
        private static final long serialVersionUID = 7193545421803538364L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if ((Boolean) event.getProperty().getValue()) {
                endTimeLabel.setEnabled(false);
                endTimeField.setEnabled(false);
            } else {
                endTimeLabel.setEnabled(true);
                endTimeField.setEnabled(true);
            }
        }
    });

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setMargin(true, false, false, false);
    buttonLayout.setSpacing(false);

    HorizontalLayout uploadButtonLayout = new HorizontalLayout();
    uploadButtonLayout.setMargin(false, true, false, false);

    uploadButton = new Button("Upload File", new Button.ClickListener() {
        private static final long serialVersionUID = 8013811216568950479L;

        @Override
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            String titleValue = titleField.getValue().toString().trim();
            Date startTimeValue = (Date) startTimeField.getValue();
            Date endTimeValue = (Date) endTimeField.getValue();
            boolean exactTimeValue = (Boolean) exactTimeCheckBox.getValue();

            if (titleValue.equals("")) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Title Field",
                        StyleUtils.getLabelHTML("A title entry is required."));

                mainWindow.addWindow(confirmWindow);
            } else if (titleValue.length() < 5 || titleValue.length() > 50) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Title Field", StyleUtils
                        .getLabelHTML("The number of characters of the title has to be between 5 and 50."));

                mainWindow.addWindow(confirmWindow);
            } else if (!exactTimeValue && startTimeValue.after(endTimeValue)) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Date Entries",
                        StyleUtils.getLabelHTML("The second date has to be after the first date."));

                mainWindow.addWindow(confirmWindow);
            } else if (startTimeValue.after(new Date())
                    || (!exactTimeValue && endTimeValue.after(new Date()))) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Date Entries",
                        StyleUtils.getLabelHTML("The dates are not allowed to be in the future."));

                mainWindow.addWindow(confirmWindow);
            } else {
                disableButtons();

                String descriptionValue = descriptionArea.getValue().toString().trim();
                String licenseValue = licenseArea.getValue().toString().trim();
                TopographicPoint topographicPointValue = googleMap.getMarkerPosition();
                Collection<String> presettingValues = (Collection<String>) twinColSelect.getValue();

                if (exactTimeValue) {
                    endTimeValue = startTimeValue;
                }

                TimeRange timeRange = new TimeRange(new DateTime(startTimeValue), new DateTime(endTimeValue));

                UploadSettings uploadSettings = new UploadSettings(titleValue, descriptionValue, licenseValue,
                        new Vector<String>(tags), topographicPointValue, timeRange);

                mainWindow.removeWindow(event.getButton().getWindow());

                requestRepaint();

                uploadSection.upload(uploadSettings, new Vector<String>(presettingValues));
            }
        }
    });

    uploadButton.setStyleName(Reindeer.BUTTON_DEFAULT);
    uploadButtonLayout.addComponent(uploadButton);
    buttonLayout.addComponent(uploadButtonLayout);

    HorizontalLayout cancelButtonLayout = new HorizontalLayout();
    cancelButtonLayout.setMargin(false, true, false, false);

    cancelButton = new Button("Cancel", new Button.ClickListener() {
        private static final long serialVersionUID = -2565870159504952913L;

        @Override
        public void buttonClick(ClickEvent event) {
            disableButtons();

            mainWindow.removeWindow(event.getButton().getWindow());

            requestRepaint();

            uploadSection.cancelUpload();
        }
    });

    cancelButton.setStyleName(Reindeer.BUTTON_DEFAULT);
    cancelButtonLayout.addComponent(cancelButton);
    buttonLayout.addComponent(cancelButtonLayout);

    cancelAllButton = new Button("Cancel All", new Button.ClickListener() {
        private static final long serialVersionUID = -8578124709201789182L;

        @Override
        public void buttonClick(ClickEvent event) {
            disableButtons();

            mainWindow.removeWindow(event.getButton().getWindow());

            requestRepaint();

            uploadSection.cancelAllUploads();
        }
    });

    cancelAllButton.setStyleName(Reindeer.BUTTON_DEFAULT);
    buttonLayout.addComponent(cancelAllButton);

    mainLayout.addComponent(buttonLayout);
    mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_CENTER);

    wrapperLayout.addComponent(mainLayout);
}

From source file:org.eclipse.hawkbit.ui.tenantconfiguration.AuthenticationConfigurationView.java

License:Open Source License

private void init() {

    final Panel rootPanel = new Panel();
    rootPanel.setSizeFull();//from ww  w .ja v  a2  s  .  c om

    rootPanel.addStyleName("config-panel");

    final VerticalLayout vLayout = new VerticalLayout();
    vLayout.setMargin(true);
    vLayout.setSizeFull();

    final Label header = new Label(i18n.getMessage("configuration.authentication.title"));
    header.addStyleName("config-panel-header");
    vLayout.addComponent(header);

    final GridLayout gridLayout = new GridLayout(3, 4);
    gridLayout.setSpacing(true);
    gridLayout.setImmediate(true);
    gridLayout.setSizeFull();
    gridLayout.setColumnExpandRatio(1, 1.0F);

    certificateAuthCheckbox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
    certificateAuthCheckbox.setValue(certificateAuthenticationConfigurationItem.isConfigEnabled());
    certificateAuthCheckbox.addValueChangeListener(this);
    certificateAuthenticationConfigurationItem.addChangeListener(this);
    gridLayout.addComponent(certificateAuthCheckbox, 0, 0);
    gridLayout.addComponent(certificateAuthenticationConfigurationItem, 1, 0);

    targetSecTokenCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
    targetSecTokenCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled());
    targetSecTokenCheckBox.addValueChangeListener(this);
    targetSecurityTokenAuthenticationConfigurationItem.addChangeListener(this);
    gridLayout.addComponent(targetSecTokenCheckBox, 0, 1);
    gridLayout.addComponent(targetSecurityTokenAuthenticationConfigurationItem, 1, 1);

    gatewaySecTokenCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
    gatewaySecTokenCheckBox.setId("gatewaysecuritycheckbox");
    gatewaySecTokenCheckBox.setValue(gatewaySecurityTokenAuthenticationConfigurationItem.isConfigEnabled());
    gatewaySecTokenCheckBox.addValueChangeListener(this);
    gatewaySecurityTokenAuthenticationConfigurationItem.addChangeListener(this);
    gridLayout.addComponent(gatewaySecTokenCheckBox, 0, 2);
    gridLayout.addComponent(gatewaySecurityTokenAuthenticationConfigurationItem, 1, 2);

    downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
    downloadAnonymousCheckBox.setId(UIComponentIdProvider.DOWNLOAD_ANONYMOUS_CHECKBOX);
    downloadAnonymousCheckBox.setValue(anonymousDownloadAuthenticationConfigurationItem.isConfigEnabled());
    downloadAnonymousCheckBox.addValueChangeListener(this);
    anonymousDownloadAuthenticationConfigurationItem.addChangeListener(this);
    gridLayout.addComponent(downloadAnonymousCheckBox, 0, 3);
    gridLayout.addComponent(anonymousDownloadAuthenticationConfigurationItem, 1, 3);

    final Link linkToSecurityHelp = SPUIComponentProvider.getHelpLink(i18n,
            uiProperties.getLinks().getDocumentation().getSecurity());
    gridLayout.addComponent(linkToSecurityHelp, 2, 3);
    gridLayout.setComponentAlignment(linkToSecurityHelp, Alignment.BOTTOM_RIGHT);

    vLayout.addComponent(gridLayout);
    rootPanel.setContent(vLayout);
    setCompositionRoot(rootPanel);
}

From source file:org.eclipse.hawkbit.ui.tenantconfiguration.RepositoryConfigurationView.java

License:Open Source License

private void init() {

    final Panel rootPanel = new Panel();
    rootPanel.setSizeFull();// w  w w.ja  va 2  s . co  m

    rootPanel.addStyleName("config-panel");

    final VerticalLayout vLayout = new VerticalLayout();
    vLayout.setMargin(true);
    vLayout.setSizeFull();

    final Label header = new Label(i18n.getMessage("configuration.repository.title"));
    header.addStyleName("config-panel-header");
    vLayout.addComponent(header);

    final GridLayout gridLayout = new GridLayout(2, 2);
    gridLayout.setSpacing(true);
    gridLayout.setImmediate(true);
    gridLayout.setColumnExpandRatio(1, 1.0F);
    gridLayout.setSizeFull();

    actionAutocloseCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
    actionAutocloseCheckBox.setId(UIComponentIdProvider.REPOSITORY_ACTIONS_AUTOCLOSE_CHECKBOX);
    actionAutocloseCheckBox.setValue(actionAutocloseConfigurationItem.isConfigEnabled());
    actionAutocloseCheckBox.addValueChangeListener(this);
    actionAutocloseConfigurationItem.addChangeListener(this);
    gridLayout.addComponent(actionAutocloseCheckBox, 0, 0);
    gridLayout.addComponent(actionAutocloseConfigurationItem, 1, 0);

    actionAutocleanupCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
    actionAutocleanupCheckBox.setId(UIComponentIdProvider.REPOSITORY_ACTIONS_AUTOCLEANUP_CHECKBOX);
    actionAutocleanupCheckBox.setValue(actionAutocleanupConfigurationItem.isConfigEnabled());
    actionAutocleanupCheckBox.addValueChangeListener(this);
    actionAutocleanupConfigurationItem.addChangeListener(this);
    gridLayout.addComponent(actionAutocleanupCheckBox, 0, 1);
    gridLayout.addComponent(actionAutocleanupConfigurationItem, 1, 1);

    vLayout.addComponent(gridLayout);
    rootPanel.setContent(vLayout);
    setCompositionRoot(rootPanel);
}

From source file:org.groom.review.ui.flows.admin.ReviewFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(2, 2);
    gridLayout.setSizeFull();//from w  ww .ja v  a  2  s.c o m
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(0, 1f);
    gridLayout.setColumnExpandRatio(1, 1f);
    setViewContent(gridLayout);

    reviewEditor = new ValidatingEditor(ReviewFields.getFieldDescriptors(Review.class));
    reviewEditor.setCaption("Review");
    reviewEditor.addListener((ValidatingEditorStateListener) this);
    reviewEditor.setWidth(400, Unit.PIXELS);
    gridLayout.addComponent(reviewEditor, 0, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    gridLayout.addComponent(buttonLayout, 0, 1);

    beanQueryFactory = new BeanQueryFactory<FileDiffBeanQuery>(FileDiffBeanQuery.class);
    queryConfiguration = new HashMap<String, Object>();
    beanQueryFactory.setQueryConfiguration(queryConfiguration);

    container = new LazyQueryContainer(beanQueryFactory, "path", 20, false);

    container.addContainerProperty("status", Character.class, null, true, false);
    container.addContainerProperty("path", String.class, null, true, false);

    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    final Table table = new Table() {
        @Override
        protected String formatPropertyValue(Object rowId, Object colId, Property property) {
            Object v = property.getValue();
            if (v instanceof Date) {
                Date dateValue = (Date) v;
                return format.format(v);
            }
            return super.formatPropertyValue(rowId, colId, property);
        }
    };

    table.setSizeFull();
    table.setContainerDataSource(container);
    table.setVisibleColumns(new Object[] { "status", "path" });

    table.setColumnWidth("status", 20);
    //table.setColumnWidth("path", 500);

    table.setColumnHeaders(
            new String[] { getSite().localize("field-status"), getSite().localize("field-path") });

    table.setColumnCollapsingAllowed(false);
    table.setSelectable(true);
    table.setMultiSelect(false);
    table.setImmediate(true);

    /*table.addValueChangeListener(new Property.ValueChangeListener() {
    @Override
    public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
        final String selectedPath = (String) table.getValue();
            
        if (selectedPath != null) {
            final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) table.getItem(selectedPath)).getBean();
            final char status = fileDiff.getStatus();
            if (status == 'A' || status == 'M') {
                final ReviewFileDiffFlowlet view = getViewSheet().forward(ReviewFileDiffFlowlet.class);
                view.setFileDiff(entity, fileDiff, 0);
            }
        }
    }
    });*/

    gridLayout.addComponent(table, 1, 0);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    buttonLayout.addComponent(saveButton);
    saveButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            reviewEditor.commit();
            entityManager.getTransaction().begin();
            try {
                entity = entityManager.merge(entity);
                //entity.setAuthor(getSite().getSecurityProvider().getUser());
                entity.setModified(new Date());
                entityManager.persist(entity);
                entityManager.getTransaction().commit();
                entityManager.detach(entity);
                reviewEditor.discard();
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + entity, t);
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    buttonLayout.addComponent(discardButton);
    discardButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            reviewEditor.discard();
        }
    });

}

From source file:org.groom.review.ui.flows.reviewer.ReviewFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(2, 4);
    gridLayout.setSizeFull();/*from www .  ja v  a2s .c  o  m*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    //gridLayout.setRowExpandRatio(0, 0.5f);
    gridLayout.setRowExpandRatio(1, 1f);
    gridLayout.setColumnExpandRatio(1, 1f);
    setViewContent(gridLayout);

    reviewEditor = new ValidatingEditor(ReviewFields.getFieldDescriptors(Review.class));
    reviewEditor.setCaption("Review");
    reviewEditor.addListener((ValidatingEditorStateListener) this);
    reviewEditor.setWidth(450, Unit.PIXELS);
    reviewEditor.setReadOnly(true);

    gridLayout.addComponent(reviewEditor, 0, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    gridLayout.addComponent(buttonLayout, 0, 3);

    beanQueryFactory = new BeanQueryFactory<FileDiffBeanQuery>(FileDiffBeanQuery.class);
    queryConfiguration = new HashMap<String, Object>();
    beanQueryFactory.setQueryConfiguration(queryConfiguration);

    container = new LazyQueryContainer(beanQueryFactory, "path", 20, false);

    container.addContainerProperty("status", Character.class, null, true, false);
    container.addContainerProperty("reviewed", String.class, null, true, false);
    container.addContainerProperty("path", String.class, null, true, false);

    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    fileDiffTable = new Table() {
        @Override
        protected String formatPropertyValue(Object rowId, Object colId, Property property) {
            Object v = property.getValue();
            if (v instanceof Date) {
                Date dateValue = (Date) v;
                return format.format(v);
            }
            return super.formatPropertyValue(rowId, colId, property);
        }
    };
    fileDiffTable.setNullSelectionAllowed(false);
    fileDiffTable.setSizeFull();
    fileDiffTable.setContainerDataSource(container);
    fileDiffTable.setVisibleColumns(new Object[] { "reviewed", "path" });

    //table.setColumnWidth("path", 500);
    fileDiffTable.setColumnWidth("status", 40);
    fileDiffTable.setColumnWidth("reviewed", 40);

    fileDiffTable.setColumnHeaders(new String[] { "", getSite().localize("field-path") });

    fileDiffTable.setColumnCollapsingAllowed(false);
    fileDiffTable.setSelectable(true);
    fileDiffTable.setMultiSelect(false);
    fileDiffTable.setImmediate(true);

    fileDiffTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            final String selectedPath = (String) event.getItemId();

            if (selectedPath != null) {
                reviewFileDiff(selectedPath);
            }
        }
    });

    fileDiffTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
        @Override
        public String getStyle(Table source, Object itemId, Object propertyId) {
            if (propertyId != null && propertyId.equals("status")) {
                final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) source.getItem(itemId)).getBean();
                switch (fileDiff.getStatus()) {
                case 'A':
                    return "added";
                case 'D':
                    return "deleted";
                case 'M':
                    return "modified";
                default:
                    return "";
                }
            } else if (propertyId != null && propertyId.equals("path")) {
                final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) source.getItem(itemId)).getBean();
                switch (fileDiff.getStatus()) {
                case 'A':
                    return "path-added";
                case 'D':
                    return "path-deleted";
                case 'M':
                    return "path-modified";
                default:
                    return "";
                }
            } else if (propertyId != null && propertyId.equals("reviewed")) {
                final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) source.getItem(itemId)).getBean();
                if (fileDiff.isReviewed()) {
                    return "ok";
                } else {
                    return "";
                }
            } else {
                return "";
            }
        }
    });

    fileDiffTable.setConverter("status", new Converter<String, Character>() {
        @Override
        public Character convertToModel(String value, Class<? extends Character> targetType, Locale locale)
                throws ConversionException {
            throw new UnsupportedOperationException();
        }

        @Override
        public String convertToPresentation(Character value, Class<? extends String> targetType, Locale locale)
                throws ConversionException {
            return "";
        }

        @Override
        public Class<Character> getModelType() {
            return Character.class;
        }

        @Override
        public Class<String> getPresentationType() {
            return String.class;
        }
    });

    fileDiffTable.setConverter("reviewed", new Converter<String, Boolean>() {
        @Override
        public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale)
                throws ConversionException {
            throw new UnsupportedOperationException();
        }

        @Override
        public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale)
                throws ConversionException {
            return "";
        }

        @Override
        public Class<Boolean> getModelType() {
            return Boolean.class;
        }

        @Override
        public Class<String> getPresentationType() {
            return String.class;
        }
    });

    Panel fileDiffPanel = new Panel("Diffs");
    fileDiffPanel.setStyleName(ValoTheme.PANEL_BORDERLESS);
    fileDiffPanel.setSizeFull();
    fileDiffPanel.setContent(fileDiffTable);

    gridLayout.addComponent(fileDiffPanel, 1, 0, 1, 1);

    reviewStatusContainer = new LazyEntityContainer<ReviewStatus>(entityManager, true, false, false,
            ReviewStatus.class, 0, new String[] { "reviewer.emailAddress" }, new boolean[] { true },
            "reviewStatusId");
    final List<FieldDescriptor> fieldDescriptors = ReviewFields.getFieldDescriptors(ReviewStatus.class);
    ContainerUtil.addContainerProperties(reviewStatusContainer, fieldDescriptors);
    final Table reviewerStatusesTable = new FormattingTable();
    org.bubblecloud.ilves.component.grid.Grid grid = new org.bubblecloud.ilves.component.grid.Grid(
            reviewerStatusesTable, reviewStatusContainer);
    grid.setFields(fieldDescriptors);
    reviewerStatusesTable.setColumnCollapsed("reviewStatusId", true);
    reviewerStatusesTable.setColumnCollapsed("created", true);
    reviewerStatusesTable.setColumnCollapsed("modified", true);
    reviewerStatusesTable.setSelectable(false);

    reviewerStatusesTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
        @Override
        public String getStyle(Table source, Object itemId, Object propertyId) {
            if (propertyId != null && propertyId.equals("completed")) {
                final ReviewStatus reviewStatus = ((NestingBeanItem<ReviewStatus>) source.getItem(itemId))
                        .getBean();
                if (reviewStatus.isCompleted()) {
                    return "ok";
                } else {
                    return "";
                }
            } else {
                return "";
            }
        }
    });

    reviewerStatusesTable.setConverter("completed", new Converter<String, Boolean>() {
        @Override
        public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale)
                throws ConversionException {
            throw new UnsupportedOperationException();
        }

        @Override
        public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale)
                throws ConversionException {
            return "";
        }

        @Override
        public Class<Boolean> getModelType() {
            return Boolean.class;
        }

        @Override
        public Class<String> getPresentationType() {
            return String.class;
        }
    });

    Panel reviewerPanel = new Panel("Reviewers");
    reviewerPanel.setStyleName(ValoTheme.PANEL_BORDERLESS);
    reviewerPanel.setHeight(300, Unit.PIXELS);
    reviewerPanel.setContent(grid);

    gridLayout.addComponent(reviewerPanel, 0, 2);

    commentContainer = new LazyEntityContainer<Comment>(entityManager, true, false, false, Comment.class, 0,
            new String[] { "path", "line" }, new boolean[] { true, true }, "reviewCommentId");
    final List<FieldDescriptor> commentFieldDescriptors = ReviewFields.getFieldDescriptors(Comment.class);
    ContainerUtil.addContainerProperties(commentContainer, commentFieldDescriptors);
    final Table commentTable = new FormattingTable();
    org.bubblecloud.ilves.component.grid.Grid commentGrid = new org.bubblecloud.ilves.component.grid.Grid(
            commentTable, commentContainer);
    commentTable.setNullSelectionAllowed(false);
    commentGrid.setSizeFull();
    commentGrid.setFields(commentFieldDescriptors);
    commentTable.setImmediate(true);
    commentTable.setColumnCollapsed("reviewCommentId", true);
    commentTable.setColumnCollapsed("created", true);
    commentTable.setColumnCollapsed("modified", true);
    commentTable.setColumnCollapsed("committer", true);
    commentTable.setColumnCollapsed("path", true);
    commentTable.setColumnCollapsed("line", true);
    commentTable.setColumnCollapsed("hash", true);

    commentTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
        @Override
        public String getStyle(Table source, Object itemId, Object propertyId) {
            if (propertyId != null && propertyId.equals("severity")) {
                final Comment comment = ((NestingBeanItem<Comment>) source.getItem(itemId)).getBean();
                switch (comment.getSeverity()) {
                case 1:
                    return "kudo";
                case -1:
                    return "warning";
                case -2:
                    return "red-flag";
                default:
                    return "";
                }
            } else {
                return "";
            }
        }
    });

    commentTable.setConverter("severity", new Converter<String, Integer>() {
        @Override
        public Integer convertToModel(String value, Class<? extends Integer> targetType, Locale locale)
                throws ConversionException {
            throw new UnsupportedOperationException();
        }

        @Override
        public String convertToPresentation(Integer value, Class<? extends String> targetType, Locale locale)
                throws ConversionException {
            return "";
        }

        @Override
        public Class<Integer> getModelType() {
            return Integer.class;
        }

        @Override
        public Class<String> getPresentationType() {
            return String.class;
        }
    });

    Panel commentPanel = new Panel("Review Comments");
    commentPanel.setStyleName(ValoTheme.PANEL_BORDERLESS);
    commentPanel.setHeight(300, Unit.PIXELS);
    commentPanel.setContent(commentGrid);

    gridLayout.addComponent(commentPanel, 1, 2, 1, 2);

    commentTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            final String commentId = (String) event.getItemId();

            if (commentId != null) {
                final Comment comment = ((NestingBeanItem<Comment>) commentTable.getItem(commentId)).getBean();
                final String path = comment.getPath();
                final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) fileDiffTable.getItem(path)).getBean();
                fileDiff.setReviewed(true);
                ReviewDao.saveReviewStatus(entityManager, reviewStatus);
                final char status = fileDiff.getStatus();
                if (status == 'A' || status == 'M') {
                    final ReviewFileDiffFlowlet view = getFlow().forward(ReviewFileDiffFlowlet.class);
                    view.setFileDiff(review, fileDiff, comment.getDiffLine());
                }

            }
        }
    });

    completeButton = new Button(getSite().localize("button-complete"));
    completeButton.setImmediate(true);
    buttonLayout.addComponent(completeButton);
    completeButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final ReviewCommentDialog commentDialog = new ReviewCommentDialog(
                    new ReviewCommentDialog.DialogListener() {
                        @Override
                        public void onOk(final String message) {
                            reviewStatus.setReviewComment(message);
                            reviewStatus.setCompleted(true);
                            ReviewDao.saveReviewStatus(entityManager, reviewStatus);
                            enter();
                        }

                        @Override
                        public void onCancel() {
                        }
                    });
            commentDialog.setCaption("Please enter final comment.");
            UI.getCurrent().addWindow(commentDialog);
            commentDialog.getTextArea().focus();
        }
    });

    reopenButton = new Button(getSite().localize("button-reopen"));
    reopenButton.setImmediate(true);
    buttonLayout.addComponent(reopenButton);
    reopenButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            reviewStatus.setCompleted(false);
            ReviewDao.saveReviewStatus(entityManager, reviewStatus);
            enter();
        }
    });
}

From source file:org.hip.vif.forum.usersettings.ui.ShowCompletedRatingView.java

License:Open Source License

/** Constructor for view to display the completed ratings given.
 *
 * @param inRatings {@link QueryResult} the participants involved in the review and rating process
 * @param inQuestions {@link QueryResult} the reviewed questions
 * @param inCompletions {@link QueryResult} the reviewed completions
 * @param inTexts {@link QueryResult} the reviewed texts
 * @param inTask {@link IPluggableWithLookup} the controlling task
 * @throws VException/*from w w  w. j a  v a  2s.c om*/
 * @throws SQLException */
public ShowCompletedRatingView(final QueryResult inRatings, final QueryResult inQuestions,
        final QueryResult inCompletions, final QueryResult inTexts, final IPluggableWithLookup inTask)
        throws VException, SQLException {
    final VerticalLayout lLayout = new VerticalLayout();
    setCompositionRoot(lLayout);

    final IMessages lMessages = Activator.getMessages();
    lLayout.setStyleName("vif-view"); //$NON-NLS-1$
    lLayout.addComponent(new Label(String.format(VIFViewHelper.TMPL_TITLE, "vif-title", //$NON-NLS-1$
            lMessages.getMessage("ratings.completed.title")), ContentMode.HTML)); //$NON-NLS-1$

    lLayout.addComponent(new Label(lMessages.getMessage("ui.rated.subtitle"), ContentMode.HTML)); //$NON-NLS-1$
    listContributions(inQuestions, inCompletions, inTexts, inTask, lLayout, lMessages);
    lLayout.addComponent(RiplaViewHelper.createSpacer());

    final GridLayout lRatings = new GridLayout(5, 3);
    lRatings.setStyleName("vif-rating"); //$NON-NLS-1$
    lRatings.setWidth("100%"); //$NON-NLS-1$
    lRatings.setColumnExpandRatio(4, 1);
    lLayout.addComponent(lRatings);

    // headers
    lRatings.addComponent(new Label("")); //$NON-NLS-1$
    addComponentSized(new Label(lMessages.getMessage("ui.rated.column.correctness"), ContentMode.HTML), //$NON-NLS-1$
            lRatings);
    addComponentSized(new Label(lMessages.getMessage("ui.rated.column.efficiency"), ContentMode.HTML), //$NON-NLS-1$
            lRatings);
    addComponentSized(new Label(lMessages.getMessage("ui.rated.column.etiquette"), ContentMode.HTML), lRatings); //$NON-NLS-1$
    Label lRemark = new Label(lMessages.getMessage("ui.rated.column.remark"), ContentMode.HTML); //$NON-NLS-1$
    lRemark.setStyleName("vif-colhead vif-padding-left"); //$NON-NLS-1$
    lRatings.addComponent(lRemark);
    lRatings.getComponent(0, 0).setWidth(350, Unit.PIXELS);

    // ratings
    final Map<Long, String> lParticipants = new HashMap<Long, String>();
    final List<Line> lLines = new Vector<ShowCompletedRatingView.Line>();
    while (inRatings.hasMoreElements()) {
        final GeneralDomainObject lRating = inRatings.nextAsDomainObject();
        setParticipant(lRating, lParticipants);
        lLines.add(new Line(lRating));
    }

    for (final Line lLine : lLines) {
        lRatings.addComponent(new Label(lLine.getInvolved(lParticipants, lMessages), ContentMode.HTML));
        addComponentAligened(lLine.getCorrectness(), lRatings);
        addComponentAligened(lLine.getEfficiency(), lRatings);
        addComponentAligened(lLine.getEtiquette(), lRatings);
        lRemark = new Label(lLine.getRemark(), ContentMode.HTML);
        lRemark.setStyleName("vif-padding-left"); //$NON-NLS-1$
        lRatings.addComponent(lRemark);
    }
}