Example usage for com.vaadin.ui GridLayout setRowExpandRatio

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

Introduction

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

Prototype

public void setRowExpandRatio(int rowIndex, float ratio) 

Source Link

Document

Sets the expand ratio of given row.

Usage

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  a 2 s  .c om
    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(/*ww  w.j  av a  2 s  .  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   w  w  w . j  a  va2 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 www . j av a  2  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();/* w ww  .ja v a 2s.  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.groom.translation.model.EntriesFlowlet.java

License:Apache License

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

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

    filterDefinitions.add(new FilterDescriptor("basename", "basename", "Basename", new TextField(), 200, "like",
            String.class, ""));

    filterDefinitions.add(new FilterDescriptor("language", "language", "Language", new TextField(), 30, "=",
            String.class, ""));

    filterDefinitions.add(//from w w  w  .  j a  va2s .  c  om
            new FilterDescriptor("country", "country", "Country", new TextField(), 30, "=", String.class, ""));

    filterDefinitions
            .add(new FilterDescriptor("key", "key", "Key", new TextField(), 200, "like", String.class, ""));

    filterDefinitions.add(
            new FilterDescriptor("value", "value", "Value", new TextField(), 200, "like", String.class, ""));

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new LazyEntityContainer<Entry>(entityManager, true, true, false, Entry.class, 1000,
            new String[] { "basename", "key", "language", "country" }, new boolean[] { true, true, true, true },
            "entryId");

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final GridLayout gridLayout = new GridLayout(1, 3);
    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, 1);

    final Table table = new FormattingTable();
    grid = new Grid(table, container);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);

    table.setColumnCollapsed("entryId", true);
    table.setColumnCollapsed("path", true);
    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    grid.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 350, Unit.PIXELS);

    gridLayout.addComponent(grid, 0, 2);

    /*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 Entry entry = new Entry();
        entry.setCreated(new Date());
        entry.setModified(entry.getCreated());
        entry.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
        final EntryFlowlet entryView = getFlow().forward(EntryFlowlet.class);
        entryView.edit(entry, 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 Entry entity = container.getEntity(grid.getSelectedItemId());
            final EntryFlowlet entryView = getFlow().forward(EntryFlowlet.class);
            entryView.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) {
            final Entry entity = container.getEntity(grid.getSelectedItemId());
            entity.setDeleted(new Date());
            entity.setAuthor(getSite().getSecurityProvider().getUser());
            entityManager.getTransaction().begin();
            try {
                entityManager.persist(entityManager.merge(entity));
                entityManager.getTransaction().commit();
            } catch (final Exception e) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException(e);
            }
            container.refresh();
        }
    });

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

        @Override
        public void buttonClick(final ClickEvent event) {
            final Entry entity = container.getEntity(grid.getSelectedItemId());
            entity.setDeleted(null);
            entity.setAuthor(getSite().getSecurityProvider().getUser());
            entityManager.getTransaction().begin();
            try {
                entityManager.persist(entityManager.merge(entity));
                entityManager.getTransaction().commit();
            } catch (final Exception e) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException(e);
            }
            container.refresh();
        }
    });
    /*
            final Button permanentRemoveButton = getSite().getButton("permanent-remove");
            buttonLayout.addComponent(permanentRemoveButton);
            permanentRemoveButton.addClickListener(new ClickListener() {
    private static final long serialVersionUID = 1L;
            
    @Override
    public void buttonClick(final ClickEvent event) {
        final Entry entity = container.getEntity(grid.getSelectedItemId());
        entity.setDeleted(null);
        entityManager.getTransaction().begin();
        try {
            entityManager.remove(entityManager.merge(entity));
            entityManager.getTransaction().commit();
        } catch (final Exception e) {
            if (entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().rollback();
            }
            throw new RuntimeException(e);
        }
        container.refresh();
    }
            });
    */

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

        @Override
        public void buttonClick(final ClickEvent event) {
            TranslationSynchronizer.startSynchronize();
            Notification.show(getSite().localize("message-synchronization-started"));
        }
    });

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

    repositoryField = new ComboBox(getSite().localize("field-repository"));
    repositoryField.setNullSelectionAllowed(false);
    repositoryField.setTextInputAllowed(true);
    repositoryField.setNewItemsAllowed(false);
    repositoryField.setInvalidAllowed(false);
    repositoryField.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            container.removeDefaultFilters();
            container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId()));
            final Repository repository = (Repository) repositoryField.getValue();
            if (repository != null) {
                container.addDefaultFilter(
                        new Compare.Equal("repository.repositoryId", repository.getRepositoryId()));
            }
        }
    });
    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);
        }
    }
    final VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setMargin(new MarginInfo(false, false, true, false));
    verticalLayout.addComponent(repositoryField);
    gridLayout.addComponent(verticalLayout, 0, 0);
}

From source file:org.groom.translation.model.EntryFlowlet.java

License:Apache License

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

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

    entryEditor = new ValidatingEditor(TranslationFields.getFieldDescriptors(Entry.class));
    entryEditor.setCaption("Entry");
    entryEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(entryEditor, 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) {
            entryEditor.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);
                entryEditor.discard();
                container.refresh();
            } 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) {
            entryEditor.discard();
        }
    });

    final List<FieldDescriptor> fieldDescriptors = TranslationFields.getFieldDescriptors(Entry.class);

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

    container = new LazyEntityContainer<Entry>(entityManager, true, true, false, Entry.class, 1000,
            new String[] { "basename", "key", "language", "country" }, new boolean[] { true, true, true, true },
            "entryId");
    container.getQueryView().getQueryDefinition().setMaxQuerySize(1);

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final Table table = new FormattingTable();
    final Grid grid = new Grid(table, container);
    grid.setCaption("All Translations");
    grid.setSizeFull();
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);

    table.setColumnCollapsed("entryId", true);
    table.setColumnCollapsed("path", true);
    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    gridLayout.addComponent(grid, 0, 2);

}

From source file:org.hoot.EntriesFlowlet.java

License:Apache License

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

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

    filterDefinitions.add(new FilterDescriptor("basename", "basename", "Basename", new TextField(), 200, "like",
            String.class, ""));

    filterDefinitions.add(new FilterDescriptor("language", "language", "Language", new TextField(), 30, "=",
            String.class, ""));

    filterDefinitions.add(/*from  w ww .  j  a v a  2  s  .  co m*/
            new FilterDescriptor("country", "country", "Country", new TextField(), 30, "=", String.class, ""));

    filterDefinitions
            .add(new FilterDescriptor("key", "key", "Key", new TextField(), 200, "like", String.class, ""));

    filterDefinitions.add(
            new FilterDescriptor("value", "value", "Value", new TextField(), 200, "like", String.class, ""));

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new LazyEntityContainer<Entry>(entityManager, true, true, false, Entry.class, 1000,
            new String[] { "basename", "key", "language", "country" }, new boolean[] { true, true, true, true },
            "entryId");

    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 Grid(table, container);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);

    table.setColumnCollapsed("entryId", true);
    table.setColumnCollapsed("path", true);
    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    grid.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 250, Unit.PIXELS);

    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 Entry entry = new Entry();
            entry.setCreated(new Date());
            entry.setModified(entry.getCreated());
            entry.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final EntryFlowlet entryView = getFlow().forward(EntryFlowlet.class);
            entryView.edit(entry, 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 Entry entity = container.getEntity(grid.getSelectedItemId());
            final EntryFlowlet entryView = getFlow().forward(EntryFlowlet.class);
            entryView.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) {
            final Entry entity = container.getEntity(grid.getSelectedItemId());
            entity.setDeleted(new Date());
            entity.setAuthor(getSite().getSecurityProvider().getUser());
            entityManager.getTransaction().begin();
            try {
                entityManager.persist(entityManager.merge(entity));
                entityManager.getTransaction().commit();
            } catch (final Exception e) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException(e);
            }
            container.refresh();
        }
    });

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

        @Override
        public void buttonClick(final ClickEvent event) {
            final Entry entity = container.getEntity(grid.getSelectedItemId());
            entity.setDeleted(null);
            entity.setAuthor(getSite().getSecurityProvider().getUser());
            entityManager.getTransaction().begin();
            try {
                entityManager.persist(entityManager.merge(entity));
                entityManager.getTransaction().commit();
            } catch (final Exception e) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException(e);
            }
            container.refresh();
        }
    });
    /*
            final Button permanentRemoveButton = getSite().getButton("permanent-remove");
            buttonLayout.addComponent(permanentRemoveButton);
            permanentRemoveButton.addClickListener(new ClickListener() {
    private static final long serialVersionUID = 1L;
            
    @Override
    public void buttonClick(final ClickEvent event) {
        final Entry entity = container.getEntity(grid.getSelectedItemId());
        entity.setDeleted(null);
        entityManager.getTransaction().begin();
        try {
            entityManager.remove(entityManager.merge(entity));
            entityManager.getTransaction().commit();
        } catch (final Exception e) {
            if (entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().rollback();
            }
            throw new RuntimeException(e);
        }
        container.refresh();
    }
            });
    */

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

        @Override
        public void buttonClick(final ClickEvent event) {
            HootSynchronizer.startSynchronize();
        }
    });

    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.hoot.EntryFlowlet.java

License:Apache License

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

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

    entryEditor = new ValidatingEditor(HootFields.getFieldDescriptors(Entry.class));
    entryEditor.setCaption("Entry");
    entryEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(entryEditor, 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) {
            entryEditor.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);
                entryEditor.discard();
                container.refresh();
            } 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) {
            entryEditor.discard();
        }
    });

    final List<FieldDescriptor> fieldDescriptors = HootFields.getFieldDescriptors(Entry.class);

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

    container = new LazyEntityContainer<Entry>(entityManager, true, true, false, Entry.class, 1000,
            new String[] { "basename", "key", "language", "country" }, new boolean[] { true, true, true, true },
            "entryId");
    container.getQueryView().getQueryDefinition().setMaxQuerySize(1);

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final Table table = new FormattingTable();
    final Grid grid = new Grid(table, container);
    grid.setCaption("All Translations");
    grid.setSizeFull();
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);

    table.setColumnCollapsed("entryId", true);
    table.setColumnCollapsed("path", true);
    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    gridLayout.addComponent(grid, 0, 2);

}

From source file:org.hoot.HootView.java

License:Apache License

/**
 * {@inheritDoc}/*from ww  w.  java2  s .c o m*/
 */
@Override
protected void initializeComponents() {
    final int columnCount = 5;
    final int rowCount = 3;

    final GridLayout layout = this;
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setColumns(columnCount);
    layout.setRows(rowCount);
    //layout.setColumnExpandRatio(0, MARGIN_COLUMN_EXPAND_RATIO);
    //layout.setColumnExpandRatio(MARGIN_COLUMN_RIGTH_INDEX, MARGIN_COLUMN_EXPAND_RATIO);
    layout.setRowExpandRatio(1, 1.0f);
    layout.setColumnExpandRatio(2, 1.0f);
    layout.setSizeFull();

    final AbstractComponent logoComponent = getComponent("logo");
    logoComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS);
    layout.addComponent(logoComponent, 1, 0);

    final AbstractComponent navigationComponent = getComponent("navigation");
    navigationComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS);
    navigationComponent.setHeight(NAVIGATION_HEIGHT, Unit.PIXELS);
    layout.addComponent(navigationComponent, 1, 1);

    //final AbstractComponent headerComponent = getComponent("header");
    //headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    //headerComponent.setSizeFull();
    //layout.addComponent(headerComponent, 2, 0);

    final AbstractComponent contentComponent = getComponent("content");
    //contentComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    contentComponent.setSizeFull();
    layout.addComponent(contentComponent, 2, 0, 2, 2);

    //final AbstractComponent footerComponent = getComponent("footer");
    //headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    //layout.addComponent(footerComponent, 2, 2);
}