Example usage for com.vaadin.ui GridLayout setSpacing

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

Introduction

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

Prototype

@Override
    public void setSpacing(boolean spacing) 

Source Link

Usage

From source file:org.eclipse.hawkbit.ui.rollout.rollout.AddUpdateRolloutWindowLayout.java

License:Open Source License

private GridLayout createSimpleGroupDefinitionTab() {
    final GridLayout layout = new GridLayout();
    layout.setSpacing(true);
    layout.setColumns(3);/*from  www. j  a v a 2s .co m*/
    layout.setRows(4);
    layout.setStyleName("marginTop");

    layout.addComponent(getLabel("caption.rollout.generate.groups"), 0, 0, 2, 0);

    layout.addComponent(getMandatoryLabel("prompt.number.of.groups"), 0, 1);
    layout.addComponent(noOfGroups, 1, 1);
    noOfGroups.addValidator(nullValidator);
    layout.addComponent(groupSizeLabel, 2, 1);

    layout.addComponent(getMandatoryLabel("prompt.tigger.threshold"), 0, 2);
    layout.addComponent(triggerThreshold, 1, 2);
    triggerThreshold.addValidator(nullValidator);
    layout.addComponent(getPercentHintLabel(), 2, 2);

    layout.addComponent(getMandatoryLabel("prompt.error.threshold"), 0, 3);
    layout.addComponent(errorThreshold, 1, 3);
    errorThreshold.addValidator(nullValidator);
    layout.addComponent(errorThresholdOptionGroup, 2, 3);

    return layout;
}

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 w  w  w . ja v a 2  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();//ww  w.  j a v a  2s .  com

    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.RepositoriesFlowlet.java

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDescriptors = ReviewFields.getFieldDescriptors(Repository.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new LazyEntityContainer<Repository>(entityManager, true, true, false, Repository.class, 1000,
            new String[] { "path" }, new boolean[] { true }, "repositoryId");

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

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

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

    final Table table = new FormattingTable();
    grid = new Grid(table, container);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);
    grid.setWidth(100, Unit.PERCENTAGE);
    grid.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 285, Unit.PIXELS);

    table.setColumnCollapsed("repositoryId", true);
    gridLayout.addComponent(grid, 0, 1);

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

        @Override
        public void buttonClick(final ClickEvent event) {
            final Repository repository = new Repository();
            repository.setCreated(new Date());
            repository.setModified(repository.getCreated());
            repository.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final RepositoryFlowlet repositoryView = getFlow().forward(RepositoryFlowlet.class);
            repositoryView.edit(repository, true);
        }
    });

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

        @Override
        public void buttonClick(final ClickEvent event) {
            final Repository entity = container.getEntity(grid.getSelectedItemId());
            final RepositoryFlowlet repositoryView = getFlow().forward(RepositoryFlowlet.class);
            repositoryView.edit(entity, false);
        }
    });

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

        @Override
        public void buttonClick(final ClickEvent event) {
            container.removeItem(grid.getSelectedItemId());
            container.commit();
        }
    });

    final Button cloneButton = new Button("Clone");
    buttonLayout.addComponent(cloneButton);
    cloneButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Repository entity = container.getEntity(grid.getSelectedItemId());
            Notification.show(
                    Shell.execute("git clone --mirror " + entity.getUrl() + " " + entity.getPath(), ""),
                    Notification.Type.TRAY_NOTIFICATION);
        }
    });

    final Company company = getSite().getSiteContext().getObject(Company.class);
    container.removeDefaultFilters();
    container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId()));
    grid.refresh();
}

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

License:Apache License

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

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();//from   w  w w  .j a  va  2  s  .  c  om
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(2, 1f);
    setViewContent(gridLayout);

    repositoryEditor = new ValidatingEditor(ReviewFields.getFieldDescriptors(Repository.class));
    repositoryEditor.setCaption("Repository");
    repositoryEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(repositoryEditor, 0, 0);

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

    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) {
            repositoryEditor.commit();
            entityManager.getTransaction().begin();
            try {
                entity = entityManager.merge(entity);
                entity.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
                entity.setModified(new Date());
                entityManager.persist(entity);
                entityManager.getTransaction().commit();
                entityManager.detach(entity);
                repositoryEditor.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) {
            repositoryEditor.discard();
        }
    });

}

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  .  j a v a2 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.admin.ReviewsFlowlet.java

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDescriptors = ReviewFields.getFieldDescriptors(Review.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();

    filterDefinitions.add(//from  w w  w .ja va  2s.  c  o  m
            new FilterDescriptor("title", "title", "Title", new TextField(), 200, "like", String.class, ""));

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

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

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new LazyEntityContainer<Review>(entityManager, true, false, false, Review.class, 1000,
            new String[] { "created" }, new boolean[] { true }, "reviewId");

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final Table table = new FormattingTable();
    grid = new Grid(table, container);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);
    grid.setWidth(100, Unit.PERCENTAGE);
    grid.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 285, Unit.PIXELS);

    table.setColumnCollapsed("reviewId", true);

    gridLayout.addComponent(grid, 0, 1);

    /*final Button addButton = getSite().getButton("add");
    buttonLayout.addComponent(addButton);
    addButton.addClickListener(new ClickListener() {
    private static final long serialVersionUID = 1L;
            
    @Override
    public void buttonClick(final ClickEvent event) {
        final Review review = new Review();
        review.setCreated(new Date());
        review.setModified(review.getCreated());
        review.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
        final ReviewFlowlet reviewView = getViewSheet().forward(ReviewFlowlet.class);
        reviewView.edit(review, true);
    }
    });*/

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

        @Override
        public void buttonClick(final ClickEvent event) {
            final Review entity = container.getEntity(grid.getSelectedItemId());
            final ReviewFlowlet reviewView = getFlow().forward(ReviewFlowlet.class);
            reviewView.edit(entity, false);
        }
    });

    table.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            editButton.setEnabled(table.getValue() != null);
        }
    });

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

        @Override
        public void buttonClick(final ClickEvent event) {
            final Review entity = container.getEntity(grid.getSelectedItemId());
            final Company company = getSite().getSiteContext().getObject(Company.class);
            getUI().getPage().open(company.getUrl() + "/../report?reviewId=" + entity.getReviewId(), "_blank");
        }
    });

    /*final Button removeButton = getSite().getButton("remove");
    buttonLayout.addComponent(removeButton);
    removeButton.addClickListener(new ClickListener() {
    private static final long serialVersionUID = 1L;
            
    @Override
    public void buttonClick(final ClickEvent event) {
        container.removeItem(grid.getSelectedItemId());
        container.commit();
    }
    });*/

    final Company company = getSite().getSiteContext().getObject(Company.class);
    container.removeDefaultFilters();
    container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId()));
    grid.refresh();
}

From source file:org.groom.review.ui.flows.LogFlowlet.java

License:Apache License

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

    final GridLayout gridLayout = new GridLayout(1, 3);
    gridLayout.setSizeFull();/*from  www .j  av  a  2  s  .c  o m*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(2, 1f);
    setViewContent(gridLayout);

    final HorizontalLayout filterLayout = new HorizontalLayout();
    filterLayout.setSpacing(true);
    filterLayout.setSizeUndefined();
    gridLayout.addComponent(filterLayout, 0, 0);

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

    final Validator validator = new Validator() {
        @Override
        public void validate(Object o) throws InvalidValueException {
            final String value = (String) o;
            if (value.indexOf("..") != -1) {
                throw new InvalidValueException("..");
            }
            for (int i = 0; i < value.length(); i++) {
                final char c = value.charAt(i);
                if (!(Character.isLetter(c) || Character.isDigit(c) || "-./".indexOf(c) != -1)) {
                    throw new InvalidValueException("" + c);
                }
            }
        }
    };

    repositoryField = new ComboBox(getSite().localize("field-repository"));
    repositoryField.setNullSelectionAllowed(false);
    repositoryField.setTextInputAllowed(true);
    repositoryField.setNewItemsAllowed(false);
    repositoryField.setInvalidAllowed(false);
    final List<Repository> repositories = ReviewDao.getRepositories(entityManager,
            (Company) getSite().getSiteContext().getObject(Company.class));

    for (final Repository repository : repositories) {
        repositoryField.addItem(repository);
        repositoryField.setItemCaption(repository, repository.getPath());
        if (repositoryField.getItemIds().size() == 1) {
            repositoryField.setValue(repository);
        }
    }
    filterLayout.addComponent(repositoryField);

    sinceField = new TextField(getSite().localize("field-since"));
    sinceField.setValue("master");
    sinceField.setValidationVisible(true);
    sinceField.addValidator(validator);
    filterLayout.addComponent(sinceField);

    untilField = new TextField(getSite().localize("field-until"));
    untilField.setValidationVisible(true);
    untilField.addValidator(validator);
    filterLayout.addComponent(untilField);

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

    final LazyQueryContainer container = new LazyQueryContainer(beanQueryFactory, "hash", 200, false);

    container.addContainerFilter(new Compare.Equal("branch", sinceField.getValue()));
    container.addContainerProperty("hash", String.class, null, true, false);
    container.addContainerProperty("committerDate", Date.class, null, true, false);
    container.addContainerProperty("committer", String.class, null, true, false);
    container.addContainerProperty("authorDate", Date.class, null, true, false);
    container.addContainerProperty("author", String.class, null, true, false);
    container.addContainerProperty("tags", String.class, null, true, false);
    container.addContainerProperty("subject", 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.setWidth(100, Unit.PERCENTAGE);
    table.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 350, Unit.PIXELS);
    table.setContainerDataSource(container);
    table.setVisibleColumns(
            new Object[] { "hash", "committerDate", "committer", "authorDate", "author", "tags", "subject" });

    table.setColumnWidth("hash", 50);
    table.setColumnWidth("committerDate", 120);
    table.setColumnWidth("committer", 100);
    table.setColumnWidth("authorDate", 120);
    table.setColumnWidth("author", 100);
    table.setColumnWidth("tags", 100);

    table.setColumnHeaders(new String[] { getSite().localize("field-hash"),
            getSite().localize("field-committer-date"), getSite().localize("field-committer"),
            getSite().localize("field-author-date"), getSite().localize("field-author"),
            getSite().localize("field-tags"), getSite().localize("field-subject") });

    table.setColumnCollapsingAllowed(true);
    table.setColumnCollapsed("authorDate", true);
    table.setColumnCollapsed("author", true);
    table.setSelectable(true);
    table.setMultiSelect(true);
    table.setImmediate(true);

    gridLayout.addComponent(table, 0, 2);

    final Button refreshButton = new Button(getSite().localize("button-refresh"));
    buttonLayout.addComponent(refreshButton);
    refreshButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    refreshButton.addStyleName("default");
    refreshButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            repository = (Repository) repositoryField.getValue();

            if (repository != null && sinceField.isValid() && untilField.isValid()) {
                queryConfiguration.put("repository", repository);
                final StringBuilder range = new StringBuilder(sinceField.getValue());
                if (untilField.getValue().length() > 0) {
                    range.append("..");
                    range.append(untilField);
                }
                container.removeAllContainerFilters();
                container.addContainerFilter(new Compare.Equal("range", range.toString()));
                container.refresh();
            }
        }
    });

    final Button fetchButton = new Button("Fetch");
    buttonLayout.addComponent(fetchButton);
    fetchButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Repository repository = (Repository) repositoryField.getValue();
            Notification.show("Executed fetch. " + Shell.execute("git fetch", repository.getPath()));
            refreshButton.click();
        }
    });

    final Button addReviewButton = getSite().getButton("add-review");
    addReviewButton.setEnabled(false);
    buttonLayout.addComponent(addReviewButton);
    addReviewButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Object[] selection = ((Set) table.getValue()).toArray();
            if (selection != null && selection.length == 2) {
                final String hashOne = (String) selection[0];
                final String hashTwo = (String) selection[1];
                final Commit commitOne = ((NestingBeanItem<Commit>) container.getItem(hashOne)).getBean();
                final Commit commitTwo = ((NestingBeanItem<Commit>) container.getItem(hashTwo)).getBean();

                final Commit sinceCommit;
                final Commit untilCommit;
                if (commitOne.getCommitterDate().getTime() > commitTwo.getCommitterDate().getTime()) {
                    sinceCommit = commitTwo;
                    untilCommit = commitOne;
                } else {
                    sinceCommit = commitOne;
                    untilCommit = commitTwo;
                }
                createReview(sinceCommit.getHash(), untilCommit.getHash());
            } else {
                final ReviewRangeDialog dialog = new ReviewRangeDialog(new ReviewRangeDialog.DialogListener() {
                    @Override
                    public void onOk(String sinceHash, String untilHash) {
                        if (sinceHash.length() > 0 && untilHash.length() > 0) {
                            createReview(sinceHash, untilHash);
                        }
                    }

                    @Override
                    public void onCancel() {
                    }
                }, ((selection != null && selection.length == 1) ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
                        : ""), ((selection != null && selection.length == 1) ? (String) selection[0] : ""));
                dialog.setCaption("Please enter final comment.");
                UI.getCurrent().addWindow(dialog);
                dialog.getSinceField().focus();
            }

        }
    });

    table.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            final Set selection = (Set) table.getValue();
            addReviewButton.setEnabled(selection != null && (selection.size() == 1 || selection.size() == 2));
        }
    });

}

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

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDescriptors = ReviewFields.getFieldDescriptors(Review.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();

    filterDefinitions.add(/*from   w  ww . j  ava2 s. co  m*/
            new FilterDescriptor("title", "title", "Title", new TextField(), 200, "like", String.class, ""));

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new LazyEntityContainer<Review>(entityManager, true, false, false, Review.class, 0,
            new String[] { "created" }, new boolean[] { true }, "reviewId");

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

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

    final Table table = new FormattingTable();
    grid = new org.bubblecloud.ilves.component.grid.Grid(table, container);
    //grid.setWidth(550, Unit.PIXELS);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);
    grid.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 250, Unit.PIXELS);

    table.setNullSelectionAllowed(false);
    table.setColumnCollapsed("modified", true);
    table.setColumnCollapsed("reviewId", true);
    table.setColumnCollapsed("path", true);
    //table.setColumnCollapsed("sinceHash", true);
    //table.setColumnCollapsed("untilHash", true);
    table.setColumnCollapsed("completed", true);
    //table.setColumnCollapsed("reviewGroup", true);

    gridLayout.addComponent(grid, 0, 1);

    /*table.addValueChangeListener(new Property.ValueChangeListener() {
    @Override
    public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
        if (grid.getSelectedItemId() != null) {
            final Review entity = container.getEntity(grid.getSelectedItemId());
            final ReviewFlowlet reviewView = getViewSheet().getFlowlet(ReviewFlowlet.class);
            reviewView.edit(entity, false);
            getViewSheet().forward(ReviewFlowlet.class);
            table.setValue(null);
        }
    }
    });*/

    table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            final Review entity = container.getEntity(event.getItemId());
            final ReviewFlowlet reviewView = getFlow().getFlowlet(ReviewFlowlet.class);
            reviewView.edit(entity, false);
            getFlow().forward(ReviewFlowlet.class);
            //table.setValue(null);
        }
    });

    final Company company = getSite().getSiteContext().getObject(Company.class);
    final User user = ((SecurityProviderSessionImpl) getSite().getSecurityProvider()).getUserFromSession();
    container.removeDefaultFilters();
    container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId()));
    container.addDefaultFilter(new Compare.Equal("completed", false));
    final List<Group> groups = UserDao.getUserGroups(entityManager, company, user);

    Container.Filter groupsFilter = null;
    for (final Group group : groups) {
        final Container.Filter groupFilter = new Compare.Equal("reviewGroup", group);
        if (groupsFilter == null) {
            groupsFilter = groupFilter;
        } else {
            groupsFilter = new Or(groupsFilter, groupFilter);
        }
    }
    if (groupsFilter != null) {
        container.addDefaultFilter(groupsFilter);
    }

    grid.refresh();
}

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 a  2  s.  c om
    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();
        }
    });
}