List of usage examples for com.vaadin.ui GridLayout GridLayout
public GridLayout(int columns, int rows)
From source file:org.esn.esobase.view.tab.SearchInCatalogsTab.java
public SearchInCatalogsTab(DBService service_, DictionaryService dictionaryService_) { this.dictionaryService = dictionaryService_; this.service = service_; this.setSizeFull(); GridLayout hl = new GridLayout(2, 1); hl.setHeight(100, Unit.PIXELS);//from w w w. j av a2s . c om searchField = new TextField(); searchField.setWidth(500, Unit.PIXELS); searchField .addShortcutListener(new ShortcutListener("Search shortcut", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { search(); } }); hl.addComponent(searchField, 0, 0); searchButton = new Button("?"); searchButton.addClickListener(new ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { search(); } }); hl.addComponent(searchButton, 1, 0); this.addComponent(hl); resultTable = new Table(""); resultTable.setSizeFull(); Styles styles = Page.getCurrent().getStyles(); styles.add(".v-table-cell-wrapper {\n" + " /* Do not specify any margins, paddings or borders here */\n" + " white-space: normal;\n" + " overflow: hidden;\n" + "}"); resultTable.addStyleName("v-table-cell-wrapper"); resultTable.setPageLength(0); hc.addContainerProperty("textEn", String.class, null); hc.addContainerProperty("textRu", String.class, null); hc.addContainerProperty("catalogType", String.class, null); hc.addContainerProperty("translator", String.class, null); hc.addContainerProperty("weight", Integer.class, null); resultTable.setContainerDataSource(hc); resultTable.setVisibleColumns(new Object[] { "textEn", "textRu", "catalogType", "translator" }); resultTable.setColumnHeaders( new String[] { "?", "?? ?", "", "" }); resultTable.setColumnExpandRatio("textEn", 4f); resultTable.setColumnExpandRatio("textRu", 4f); resultTable.setColumnExpandRatio("catalogType", 1f); resultTable.setColumnExpandRatio("translator", 1f); this.addComponent(resultTable); this.setExpandRatio(hl, 5); this.setExpandRatio(resultTable, 95); }
From source file:org.esn.esobase.view.tab.SearchInRawStringsTab.java
public SearchInRawStringsTab(DBService service_) { this.service = service_; this.setSizeFull(); GridLayout hl = new GridLayout(3, 1); hl.setHeight(100, Unit.PIXELS);// w w w .j av a 2 s . c om searchField = new TextField(); searchField.setWidth(500, Unit.PIXELS); searchField .addShortcutListener(new ShortcutListener("Search shortcut", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { search(); } }); hl.addComponent(searchField, 0, 0); isJp = new CheckBox("?"); isJp.setValue(Boolean.FALSE); isJp.addValueChangeListener(new HasValue.ValueChangeListener<Boolean>() { @Override public void valueChange(HasValue.ValueChangeEvent<Boolean> event) { setColumns(); } }); hl.addComponent(isJp, 1, 0); searchButton = new Button("?"); searchButton.addClickListener(new ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { search(); } }); hl.addComponent(searchButton, 2, 0); this.addComponent(hl); resultTable = new Table(""); resultTable.setSizeFull(); Styles styles = Page.getCurrent().getStyles(); styles.add(".v-table-cell-wrapper {\n" + " /* Do not specify any margins, paddings or borders here */\n" + " white-space: pre-line;\n" + " overflow: hidden;\n" + "}"); resultTable.addStyleName("v-table-cell-wrapper"); resultTable.setPageLength(0); hc.addContainerProperty("textEn", String.class, null); hc.addContainerProperty("textDe", String.class, null); hc.addContainerProperty("textFr", String.class, null); hc.addContainerProperty("textJp", String.class, null); resultTable.setContainerDataSource(hc); setColumns(); this.addComponent(resultTable); this.setExpandRatio(hl, 5); this.setExpandRatio(resultTable, 95); }
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();// w ww. j av a2 s . 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 av a 2 s . c o m 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();/* w w w . 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 v a 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 w w w. j ava 2 s .c om 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 w w .j av a 2 s .c om 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();/* www . j a 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.review.ui.flows.ReviewFileDiffFlowlet.java
License:Apache License
@Override public void initialize() { entityManager = getSite().getSiteContext().getObject(EntityManager.class); gridLayout = new GridLayout(1, 2); gridLayout.setSpacing(true);/* w w w .java2 s . c o m*/ gridLayout.setSizeFull(); gridLayout.setColumnExpandRatio(0, 1f); gridLayout.setRowExpandRatio(1, 1f); setViewContent(gridLayout); selectionChangeListener = new AceEditor.SelectionChangeListener() { @Override public void selectionChanged(AceEditor.SelectionChangeEvent e) { } }; //gridLayout.addComponent(editor, 0, 0); if (getFlow().getFlowlet(ReviewFlowlet.class) != null) { final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); gridLayout.addComponent(buttonLayout, 0, 0); final Button previousButton = new Button(getSite().localize("button-previous-diff")); previousButton.setClickShortcut(ShortcutAction.KeyCode.ARROW_LEFT); previousButton.setHtmlContentAllowed(true); buttonLayout.addComponent(previousButton); previousButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { final ReviewFlowlet view = getFlow().getFlowlet(ReviewFlowlet.class); view.previous(path); } }); final Button nextButton = new Button(getSite().localize("button-next-diff")); nextButton.setClickShortcut(ShortcutAction.KeyCode.ARROW_RIGHT); nextButton.setHtmlContentAllowed(true); buttonLayout.addComponent(nextButton); nextButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { final ReviewFlowlet view = getFlow().getFlowlet(ReviewFlowlet.class); view.next(path); } }); final Button scrollToPreviousChangeButton = new Button( getSite().localize("button-scroll-to-previous-change")); scrollToPreviousChangeButton.setClickShortcut(ShortcutAction.KeyCode.ARROW_UP); scrollToPreviousChangeButton.setHtmlContentAllowed(true); buttonLayout.addComponent(scrollToPreviousChangeButton); scrollToPreviousChangeButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { int cursorLine = getScrolledTowRow(); for (int i = cursorLine; i >= 0; i--) { cursorLine = i; if (blames.get(i).getType() == LineChangeType.NONE) { break; } } for (int i = cursorLine; i >= 0; i--) { cursorLine = i; if (i == 0 | blames.get(i).getType() != LineChangeType.NONE) { break; } } for (int i = cursorLine; i >= 0; i--) { if (i == 0) { final ReviewFlowlet view = getFlow().getFlowlet(ReviewFlowlet.class); //view.previous(path); scrollToRow(0); break; } if (blames.get(i).getType() == LineChangeType.NONE) { scrollToRow(i + 1); break; } } } }); final Button scrollToNextChangeButton = new Button(getSite().localize("button-scroll-to-next-change")); scrollToNextChangeButton.setClickShortcut(ShortcutAction.KeyCode.ARROW_DOWN); scrollToNextChangeButton.setHtmlContentAllowed(true); buttonLayout.addComponent(scrollToNextChangeButton); scrollToNextChangeButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { int cursorLine = getScrolledTowRow(); for (int i = cursorLine; i < blames.size(); i++) { cursorLine = i; if (blames.get(i).getType() == LineChangeType.NONE) { break; } } for (int i = cursorLine; i < blames.size(); i++) { if (i == blames.size() - 1) { final ReviewFlowlet view = getFlow().getFlowlet(ReviewFlowlet.class); //view.next(path); scrollToRow(i); break; } if (blames.get(i).getType() != LineChangeType.NONE) { scrollToRow(i); break; } } } }); final Button scrollToCursorButton = new Button("Scroll to Cursor"); scrollToCursorButton.setHtmlContentAllowed(true); buttonLayout.addComponent(scrollToCursorButton); scrollToCursorButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { if (editor.getSelection() == null || editor.getCursorPosition() < 0) { return; } int cursor = editor.getCursorPosition(); if (fileDiff.getReviewStatus() != null) { final int cursorLine = findLine(editor.getValue(), cursor); scrollToRow(cursorLine); } } }); groomButton = getSite().getButton("groom"); groomButton.setClickShortcut(ShortcutAction.KeyCode.ENTER); groomButton.setHtmlContentAllowed(true); buttonLayout.addComponent(groomButton); groomButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { if (editor.getSelection() == null || editor.getCursorPosition() < 0) { return; } int cursor = editor.getCursorPosition(); if (fileDiff.getReviewStatus() != null) { final int cursorLine = findLine(editor.getValue(), cursor); final BlameLine blame = blames.get(cursorLine); final CommentDialog commentDialog = new CommentDialog(new CommentDialog.DialogListener() { @Override public void onOk(final String message, final int severity) { final ReviewStatus reviewStatus = fileDiff.getReviewStatus(); final Review review = reviewStatus.getReview(); final Date date = new Date(); if (message.trim().length() > 0) { final Comment comment = new Comment(review, reviewStatus.getReviewer(), blame.getHash(), fileDiff.getPath(), blame.getFinalLine(), cursorLine, severity, message, blame.getAuthorName(), blame.getCommitterName(), date, date); ReviewDao.saveComment(entityManager, comment); addComment(comment); final Company company = getSite().getSiteContext().getObject(Company.class); final Thread emailThread = new Thread(new Runnable() { @Override public void run() { String severity; switch (comment.getSeverity()) { case 1: severity = "Kudo"; break; case -1: severity = "Warning"; break; case -2: severity = "Red Flag"; break; default: severity = Integer.toString(comment.getSeverity()); if (!severity.startsWith("-")) { severity = "+" + severity; } } EmailUtil.send(blame.getAuthorEmail(), reviewStatus.getReviewer().getEmailAddress(), severity + " from review '" + review.getTitle() + "'", "Reviewer: " + reviewStatus.getReviewer().getFirstName() + " " + reviewStatus.getReviewer().getLastName() + "\n" + "Commit: " + blame.getHash() + "\n" + "File: " + fileDiff.getPath() + "\n" + "Original Line: " + blame.getOriginalLine() + "\n" + "Diff line: " + cursorLine + "\n" + blame.getType() + ":" + blame.getLine() + "\n" + "Message: " + message); } }); emailThread.start(); } } public void onCancel() { //To change body of implemented methods use File | Settings | File Templates. } }); int cursorPosition = editor.getCursorPosition(); commentDialog.setCaption("Please enter groom text for " + blame.getAuthorName() + " at line: " + (cursorLine + 1)); UI.getCurrent().addWindow(commentDialog); commentDialog.getTextArea().focus(); } } }); } }