List of usage examples for com.vaadin.ui GridLayout addComponent
public void addComponent(Component component, int column, int row) throws OverlapsException, OutOfBoundsException
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 . jav a 2s . 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 ww w . jav a 2s . c o m*/ new FilterDescriptor("title", "title", "Title", new TextField(), 200, "like", String.class, "")); final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class); container = new LazyEntityContainer<Review>(entityManager, true, false, false, Review.class, 0, new String[] { "created" }, new boolean[] { true }, "reviewId"); ContainerUtil.addContainerProperties(container, fieldDescriptors); final GridLayout gridLayout = new GridLayout(1, 2); gridLayout.setSizeFull(); gridLayout.setMargin(false); gridLayout.setSpacing(true); gridLayout.setRowExpandRatio(1, 1f); setViewContent(gridLayout); final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.setSizeUndefined(); gridLayout.addComponent(buttonLayout, 0, 0); final Table table = new FormattingTable(); grid = new org.bubblecloud.ilves.component.grid.Grid(table, container); //grid.setWidth(550, Unit.PIXELS); grid.setFields(fieldDescriptors); grid.setFilters(filterDefinitions); grid.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 250, Unit.PIXELS); table.setNullSelectionAllowed(false); table.setColumnCollapsed("modified", true); table.setColumnCollapsed("reviewId", true); table.setColumnCollapsed("path", true); //table.setColumnCollapsed("sinceHash", true); //table.setColumnCollapsed("untilHash", true); table.setColumnCollapsed("completed", true); //table.setColumnCollapsed("reviewGroup", true); gridLayout.addComponent(grid, 0, 1); /*table.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (grid.getSelectedItemId() != null) { final Review entity = container.getEntity(grid.getSelectedItemId()); final ReviewFlowlet reviewView = getViewSheet().getFlowlet(ReviewFlowlet.class); reviewView.edit(entity, false); getViewSheet().forward(ReviewFlowlet.class); table.setValue(null); } } });*/ table.addItemClickListener(new ItemClickEvent.ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { final Review entity = container.getEntity(event.getItemId()); final ReviewFlowlet reviewView = getFlow().getFlowlet(ReviewFlowlet.class); reviewView.edit(entity, false); getFlow().forward(ReviewFlowlet.class); //table.setValue(null); } }); final Company company = getSite().getSiteContext().getObject(Company.class); final User user = ((SecurityProviderSessionImpl) getSite().getSecurityProvider()).getUserFromSession(); container.removeDefaultFilters(); container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId())); container.addDefaultFilter(new Compare.Equal("completed", false)); final List<Group> groups = UserDao.getUserGroups(entityManager, company, user); Container.Filter groupsFilter = null; for (final Group group : groups) { final Container.Filter groupFilter = new Compare.Equal("reviewGroup", group); if (groupsFilter == null) { groupsFilter = groupFilter; } else { groupsFilter = new Or(groupsFilter, groupFilter); } } if (groupsFilter != null) { container.addDefaultFilter(groupsFilter); } grid.refresh(); }
From source file:org.groom.review.ui.flows.reviewer.ReviewFlowlet.java
License:Apache License
@Override public void initialize() { entityManager = getSite().getSiteContext().getObject(EntityManager.class); final GridLayout gridLayout = new GridLayout(2, 4); gridLayout.setSizeFull();//from w w w .j av a 2 s. c om gridLayout.setMargin(false); gridLayout.setSpacing(true); //gridLayout.setRowExpandRatio(0, 0.5f); gridLayout.setRowExpandRatio(1, 1f); gridLayout.setColumnExpandRatio(1, 1f); setViewContent(gridLayout); reviewEditor = new ValidatingEditor(ReviewFields.getFieldDescriptors(Review.class)); reviewEditor.setCaption("Review"); reviewEditor.addListener((ValidatingEditorStateListener) this); reviewEditor.setWidth(450, Unit.PIXELS); reviewEditor.setReadOnly(true); gridLayout.addComponent(reviewEditor, 0, 0); final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); gridLayout.addComponent(buttonLayout, 0, 3); beanQueryFactory = new BeanQueryFactory<FileDiffBeanQuery>(FileDiffBeanQuery.class); queryConfiguration = new HashMap<String, Object>(); beanQueryFactory.setQueryConfiguration(queryConfiguration); container = new LazyQueryContainer(beanQueryFactory, "path", 20, false); container.addContainerProperty("status", Character.class, null, true, false); container.addContainerProperty("reviewed", String.class, null, true, false); container.addContainerProperty("path", String.class, null, true, false); final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); fileDiffTable = new Table() { @Override protected String formatPropertyValue(Object rowId, Object colId, Property property) { Object v = property.getValue(); if (v instanceof Date) { Date dateValue = (Date) v; return format.format(v); } return super.formatPropertyValue(rowId, colId, property); } }; fileDiffTable.setNullSelectionAllowed(false); fileDiffTable.setSizeFull(); fileDiffTable.setContainerDataSource(container); fileDiffTable.setVisibleColumns(new Object[] { "reviewed", "path" }); //table.setColumnWidth("path", 500); fileDiffTable.setColumnWidth("status", 40); fileDiffTable.setColumnWidth("reviewed", 40); fileDiffTable.setColumnHeaders(new String[] { "", getSite().localize("field-path") }); fileDiffTable.setColumnCollapsingAllowed(false); fileDiffTable.setSelectable(true); fileDiffTable.setMultiSelect(false); fileDiffTable.setImmediate(true); fileDiffTable.addItemClickListener(new ItemClickEvent.ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { final String selectedPath = (String) event.getItemId(); if (selectedPath != null) { reviewFileDiff(selectedPath); } } }); fileDiffTable.setCellStyleGenerator(new Table.CellStyleGenerator() { @Override public String getStyle(Table source, Object itemId, Object propertyId) { if (propertyId != null && propertyId.equals("status")) { final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) source.getItem(itemId)).getBean(); switch (fileDiff.getStatus()) { case 'A': return "added"; case 'D': return "deleted"; case 'M': return "modified"; default: return ""; } } else if (propertyId != null && propertyId.equals("path")) { final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) source.getItem(itemId)).getBean(); switch (fileDiff.getStatus()) { case 'A': return "path-added"; case 'D': return "path-deleted"; case 'M': return "path-modified"; default: return ""; } } else if (propertyId != null && propertyId.equals("reviewed")) { final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) source.getItem(itemId)).getBean(); if (fileDiff.isReviewed()) { return "ok"; } else { return ""; } } else { return ""; } } }); fileDiffTable.setConverter("status", new Converter<String, Character>() { @Override public Character convertToModel(String value, Class<? extends Character> targetType, Locale locale) throws ConversionException { throw new UnsupportedOperationException(); } @Override public String convertToPresentation(Character value, Class<? extends String> targetType, Locale locale) throws ConversionException { return ""; } @Override public Class<Character> getModelType() { return Character.class; } @Override public Class<String> getPresentationType() { return String.class; } }); fileDiffTable.setConverter("reviewed", new Converter<String, Boolean>() { @Override public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale) throws ConversionException { throw new UnsupportedOperationException(); } @Override public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale) throws ConversionException { return ""; } @Override public Class<Boolean> getModelType() { return Boolean.class; } @Override public Class<String> getPresentationType() { return String.class; } }); Panel fileDiffPanel = new Panel("Diffs"); fileDiffPanel.setStyleName(ValoTheme.PANEL_BORDERLESS); fileDiffPanel.setSizeFull(); fileDiffPanel.setContent(fileDiffTable); gridLayout.addComponent(fileDiffPanel, 1, 0, 1, 1); reviewStatusContainer = new LazyEntityContainer<ReviewStatus>(entityManager, true, false, false, ReviewStatus.class, 0, new String[] { "reviewer.emailAddress" }, new boolean[] { true }, "reviewStatusId"); final List<FieldDescriptor> fieldDescriptors = ReviewFields.getFieldDescriptors(ReviewStatus.class); ContainerUtil.addContainerProperties(reviewStatusContainer, fieldDescriptors); final Table reviewerStatusesTable = new FormattingTable(); org.bubblecloud.ilves.component.grid.Grid grid = new org.bubblecloud.ilves.component.grid.Grid( reviewerStatusesTable, reviewStatusContainer); grid.setFields(fieldDescriptors); reviewerStatusesTable.setColumnCollapsed("reviewStatusId", true); reviewerStatusesTable.setColumnCollapsed("created", true); reviewerStatusesTable.setColumnCollapsed("modified", true); reviewerStatusesTable.setSelectable(false); reviewerStatusesTable.setCellStyleGenerator(new Table.CellStyleGenerator() { @Override public String getStyle(Table source, Object itemId, Object propertyId) { if (propertyId != null && propertyId.equals("completed")) { final ReviewStatus reviewStatus = ((NestingBeanItem<ReviewStatus>) source.getItem(itemId)) .getBean(); if (reviewStatus.isCompleted()) { return "ok"; } else { return ""; } } else { return ""; } } }); reviewerStatusesTable.setConverter("completed", new Converter<String, Boolean>() { @Override public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale) throws ConversionException { throw new UnsupportedOperationException(); } @Override public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale) throws ConversionException { return ""; } @Override public Class<Boolean> getModelType() { return Boolean.class; } @Override public Class<String> getPresentationType() { return String.class; } }); Panel reviewerPanel = new Panel("Reviewers"); reviewerPanel.setStyleName(ValoTheme.PANEL_BORDERLESS); reviewerPanel.setHeight(300, Unit.PIXELS); reviewerPanel.setContent(grid); gridLayout.addComponent(reviewerPanel, 0, 2); commentContainer = new LazyEntityContainer<Comment>(entityManager, true, false, false, Comment.class, 0, new String[] { "path", "line" }, new boolean[] { true, true }, "reviewCommentId"); final List<FieldDescriptor> commentFieldDescriptors = ReviewFields.getFieldDescriptors(Comment.class); ContainerUtil.addContainerProperties(commentContainer, commentFieldDescriptors); final Table commentTable = new FormattingTable(); org.bubblecloud.ilves.component.grid.Grid commentGrid = new org.bubblecloud.ilves.component.grid.Grid( commentTable, commentContainer); commentTable.setNullSelectionAllowed(false); commentGrid.setSizeFull(); commentGrid.setFields(commentFieldDescriptors); commentTable.setImmediate(true); commentTable.setColumnCollapsed("reviewCommentId", true); commentTable.setColumnCollapsed("created", true); commentTable.setColumnCollapsed("modified", true); commentTable.setColumnCollapsed("committer", true); commentTable.setColumnCollapsed("path", true); commentTable.setColumnCollapsed("line", true); commentTable.setColumnCollapsed("hash", true); commentTable.setCellStyleGenerator(new Table.CellStyleGenerator() { @Override public String getStyle(Table source, Object itemId, Object propertyId) { if (propertyId != null && propertyId.equals("severity")) { final Comment comment = ((NestingBeanItem<Comment>) source.getItem(itemId)).getBean(); switch (comment.getSeverity()) { case 1: return "kudo"; case -1: return "warning"; case -2: return "red-flag"; default: return ""; } } else { return ""; } } }); commentTable.setConverter("severity", new Converter<String, Integer>() { @Override public Integer convertToModel(String value, Class<? extends Integer> targetType, Locale locale) throws ConversionException { throw new UnsupportedOperationException(); } @Override public String convertToPresentation(Integer value, Class<? extends String> targetType, Locale locale) throws ConversionException { return ""; } @Override public Class<Integer> getModelType() { return Integer.class; } @Override public Class<String> getPresentationType() { return String.class; } }); Panel commentPanel = new Panel("Review Comments"); commentPanel.setStyleName(ValoTheme.PANEL_BORDERLESS); commentPanel.setHeight(300, Unit.PIXELS); commentPanel.setContent(commentGrid); gridLayout.addComponent(commentPanel, 1, 2, 1, 2); commentTable.addItemClickListener(new ItemClickEvent.ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { final String commentId = (String) event.getItemId(); if (commentId != null) { final Comment comment = ((NestingBeanItem<Comment>) commentTable.getItem(commentId)).getBean(); final String path = comment.getPath(); final FileDiff fileDiff = ((NestingBeanItem<FileDiff>) fileDiffTable.getItem(path)).getBean(); fileDiff.setReviewed(true); ReviewDao.saveReviewStatus(entityManager, reviewStatus); final char status = fileDiff.getStatus(); if (status == 'A' || status == 'M') { final ReviewFileDiffFlowlet view = getFlow().forward(ReviewFileDiffFlowlet.class); view.setFileDiff(review, fileDiff, comment.getDiffLine()); } } } }); completeButton = new Button(getSite().localize("button-complete")); completeButton.setImmediate(true); buttonLayout.addComponent(completeButton); completeButton.addListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { final ReviewCommentDialog commentDialog = new ReviewCommentDialog( new ReviewCommentDialog.DialogListener() { @Override public void onOk(final String message) { reviewStatus.setReviewComment(message); reviewStatus.setCompleted(true); ReviewDao.saveReviewStatus(entityManager, reviewStatus); enter(); } @Override public void onCancel() { } }); commentDialog.setCaption("Please enter final comment."); UI.getCurrent().addWindow(commentDialog); commentDialog.getTextArea().focus(); } }); reopenButton = new Button(getSite().localize("button-reopen")); reopenButton.setImmediate(true); buttonLayout.addComponent(reopenButton); reopenButton.addListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { reviewStatus.setCompleted(false); ReviewDao.saveReviewStatus(entityManager, reviewStatus); enter(); } }); }
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 ww w. j ava 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, 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();//from w w w. j a va 2 s . 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.hip.vif.web.util.RatingsTable.java
License:Open Source License
private Component createRatingsTable(final RatingsHelper inRatings) { final GridLayout outLayout = new GridLayout(4, 6); outLayout.setWidth(400, Unit.PIXELS); outLayout.setStyleName("vif-ratings"); //$NON-NLS-1$ final IMessages lMessages = Activator.getMessages(); // first row: table header final Label lSpacer = new Label(""); //$NON-NLS-1$ lSpacer.setWidth(70, Unit.PIXELS);/* w ww . jav a2 s . co m*/ outLayout.addComponent(lSpacer, 0, 0); outLayout.addComponent(createLabel(lMessages.getMessage("ratings.table.column.correctness")), 1, 0); //$NON-NLS-1$ outLayout.addComponent(createLabel(lMessages.getMessage("ratings.table.column.responsiveness")), 2, 0); //$NON-NLS-1$ outLayout.addComponent(createLabel(lMessages.getMessage("ratings.table.column.etiquette")), 3, 0); //$NON-NLS-1$ // first content: good addComponent(outLayout, RatingValue.GOOD.render(), 0, 1, Alignment.MIDDLE_CENTER); //$NON-NLS-1$ addComponent(outLayout, createLabel(inRatings.getCorrectnessA()), 1, 1, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEfficiencyA()), 2, 1, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEtiquetteA()), 3, 1, Alignment.MIDDLE_CENTER); // second content: average addComponent(outLayout, RatingValue.AVERAGE.render(), 0, 2, Alignment.MIDDLE_CENTER); //$NON-NLS-1$ addComponent(outLayout, createLabel(inRatings.getCorrectnessB()), 1, 2, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEfficiencyB()), 2, 2, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEtiquetteB()), 3, 2, Alignment.MIDDLE_CENTER); // third content: bad addComponent(outLayout, RatingValue.BAD.render(), 0, 3, Alignment.MIDDLE_CENTER); //$NON-NLS-1$ addComponent(outLayout, createLabel(inRatings.getCorrectnessC()), 1, 3, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEfficiencyC()), 2, 3, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEtiquetteC()), 3, 3, Alignment.MIDDLE_CENTER); // total addComponent(outLayout, new Label(lMessages.getMessage("ratings.table.label.total")), 0, 4, //$NON-NLS-1$ Alignment.MIDDLE_LEFT); addComponent(outLayout, createLabel(inRatings.getTotal1()), 1, 4, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getTotal2()), 2, 4, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getTotal3()), 3, 4, Alignment.MIDDLE_CENTER); // average addComponent(outLayout, new Label(lMessages.getMessage("ratings.table.label.mean")), 0, 5, //$NON-NLS-1$ Alignment.MIDDLE_LEFT); addComponent(outLayout, createLabel(inRatings.getMean1()), 1, 5, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getMean2()), 2, 5, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getMean3()), 3, 5, Alignment.MIDDLE_CENTER); return outLayout; }
From source file:org.hip.vif.web.util.RatingsTable.java
License:Open Source License
private void addComponent(final GridLayout inLayout, final Component inComponen, final int inColumn, final int inRow, final Alignment inAlignment) { inLayout.addComponent(inComponen, inColumn, inRow); inLayout.setComponentAlignment(inComponen, inAlignment); }
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 w w . jav a2s .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();/*from ww w . j a v a 2 s .c om*/ 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 w w w . jav a 2 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); }