List of usage examples for com.vaadin.ui ComboBox ComboBox
protected ComboBox(DataCommunicator<T> dataCommunicator)
From source file:org.activiti.explorer.ui.form.ProcessDefinitionFormPropertyRenderer.java
License:Apache License
public Field getPropertyField(FormProperty formProperty) { ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty)); comboBox.setRequired(formProperty.isRequired()); comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty))); comboBox.setEnabled(formProperty.isWritable()); List<ProcessDefinition> processDefinitions = ProcessEngines.getDefaultProcessEngine().getRepositoryService() .createProcessDefinitionQuery().orderByProcessDefinitionName().asc() .orderByProcessDefinitionVersion().asc().list(); for (ProcessDefinition processDefinition : processDefinitions) { comboBox.addItem(processDefinition.getId()); String name = processDefinition.getName() + " (v" + processDefinition.getVersion() + ")"; comboBox.setItemCaption(processDefinition.getId(), name); }/* w w w . j a va 2 s .com*/ // Select first if (!processDefinitions.isEmpty()) { comboBox.setNullSelectionAllowed(false); comboBox.select(processDefinitions.get(0).getId()); } return comboBox; }
From source file:org.adho.dhconvalidator.ui.UserSwitchPanel.java
/** Setup UI. */ private void initComponents() { List<User> users = UserList.INSTANCE.getUsers(); userSwitchBox = new ComboBox(Messages.getString("UserSwitchPanel.boxCaption")); setUsers(users);//from www. ja va 2 s . c o m User current = (User) VaadinSession.getCurrent().getAttribute(SessionStorageKey.USER.name()); userSwitchBox.setValue(current); userSwitchBox.setDescription(Messages.getString("UserSwitchPanel.boxDescription")); userSwitchBox.setNewItemsAllowed(false); userSwitchBox.setNullSelectionAllowed(false); addComponent(userSwitchBox); btReload = new Button(Messages.getString("UserSwitchPanel.reloadCaption")); btReload.setStyleName(BaseTheme.BUTTON_LINK); btReload.addStyleName("plain-link"); addComponent(btReload); }
From source file:org.apache.usergrid.chop.webapp.view.util.UIUtil.java
License:Apache License
public static ComboBox createCombo(String caption, Object values[]) { ComboBox combo = new ComboBox(caption); combo.setTextInputAllowed(false);/*from w ww .j av a 2 s .c o m*/ combo.setNullSelectionAllowed(false); populateCombo(combo, values); return combo; }
From source file:org.apache.usergrid.chop.webapp.view.util.UIUtil.java
License:Apache License
public static ComboBox addCombo(AbsoluteLayout layout, String caption, String position, String width, Object values[]) {/*from w w w . j ava 2 s . com*/ ComboBox combo = new ComboBox(caption); combo.setTextInputAllowed(false); combo.setNullSelectionAllowed(false); combo.setWidth(width); layout.addComponent(combo, position); populateCombo(combo, values); return combo; }
From source file:org.eclipse.skalli.view.component.LinkWindow.java
License:Open Source License
/** * Render the window/*from w w w . ja va2 s.com*/ */ @SuppressWarnings("serial") private void createContents(String title) { setModal(true); setCaption(title); setWidth("400px"); //$NON-NLS-1$ setHeight("300px"); //$NON-NLS-1$ root = new VerticalLayout(); root.setMargin(true); root.setSpacing(true); final ComboBox cbLinkGroup = new ComboBox("Link Group"); cbLinkGroup.setInputPrompt("Enter a new group name or select from the list"); cbLinkGroup.setWidth("100%"); //$NON-NLS-1$ for (String groupName : knownGroups) { cbLinkGroup.addItem(groupName); } if (oldGroup != null && knownGroups.contains(oldGroup.getCaption())) { cbLinkGroup.select(oldGroup.getCaption()); } cbLinkGroup.setImmediate(true); cbLinkGroup.setNullSelectionAllowed(false); cbLinkGroup.setNewItemsAllowed(true); cbLinkGroup.setNewItemHandler(new NewItemHandler() { @Override public void addNewItem(String newGroupName) { cbLinkGroup.removeAllItems(); for (String groupName : knownGroups) { cbLinkGroup.addItem(groupName); } if (!cbLinkGroup.containsId(newGroupName)) { cbLinkGroup.addItem(newGroupName); } cbLinkGroup.select(newGroupName); } }); cbLinkGroup.setRequired(true); cbLinkGroup.addValidator(new StringValidator()); root.addComponent(cbLinkGroup); final TextField tfLinkCaption = new TextField("Page Title"); tfLinkCaption.setInputPrompt("Enter a descriptive name for the page"); tfLinkCaption.setWidth("100%"); //$NON-NLS-1$ tfLinkCaption.setImmediate(true); tfLinkCaption.setRequired(true); tfLinkCaption.addValidator(new StringValidator()); if (link != null) { tfLinkCaption.setValue(link.getLabel()); } root.addComponent(tfLinkCaption); final TextField tfLinkURL = new TextField("URL"); tfLinkURL.setInputPrompt("e.g. http://www.your-site.domain/path"); tfLinkURL.setWidth("100%"); //$NON-NLS-1$ tfLinkURL.setImmediate(true); tfLinkURL.setRequired(true); tfLinkURL.addValidator(new StringValidator()); tfLinkURL.addValidator(new URLValidator()); if (link != null) { tfLinkURL.setValue(link.getUrl()); } root.addComponent(tfLinkURL); final Button okAndCloseButton = new Button("OK & Close"); okAndCloseButton.setIcon(ICON_BUTTON_OK); okAndCloseButton.setDescription("Performs the action and closes the dialog."); okAndCloseButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { validateInput(cbLinkGroup); validateInput(tfLinkURL); validateInput(tfLinkCaption); if (cbLinkGroup.isValid() && tfLinkURL.isValid() && tfLinkCaption.isValid()) { String groupName = String.valueOf(cbLinkGroup.getValue()); String linkLabel = String.valueOf(tfLinkCaption.getValue()); String linkUrl = String.valueOf(tfLinkURL.getValue()); if (linkAddedHandler != null) { Link link = new Link(linkUrl, linkLabel); linkAddedHandler.onLinkAdded(groupName, link); close(); } if (linkModifiedHandler != null) { boolean linkModified = !link.getLabel().equals(linkLabel) || !link.getUrl().equals(linkUrl); link.setLabel(linkLabel); link.setUrl(linkUrl); linkModifiedHandler.onLinkModified(oldGroup, groupName, link, linkModified); close(); } } } }); root.addComponent(okAndCloseButton); root.setSizeFull(); setContent(root); }
From source file:org.esn.esobase.view.tab.BookTranslateTab.java
public BookTranslateTab(DBService service) { this.service = service; this.setSizeFull(); FilterChangeListener filterChangeListener = new FilterChangeListener(); bookListlayout = new HorizontalLayout(); bookListlayout.setWidth(100f, Unit.PERCENTAGE); bookTable = new ComboBox(""); bookTable.setPageLength(20);//from w w w .ja va 2 s .co m bookTable.setScrollToSelectedItem(true); bookTable.setDataProvider(new ListDataProvider<>(books)); bookTable.addValueChangeListener(new BookSelectListener()); bookTable.setWidth(100f, Unit.PERCENTAGE); locationTable = new ComboBox("?"); locationTable.setPageLength(15); locationTable.setScrollToSelectedItem(true); locationTable.setWidth(100f, Unit.PERCENTAGE); locationTable.setDataProvider(new ListDataProvider<>(locations)); locationTable.addValueChangeListener(filterChangeListener); subLocationTable = new ComboBox("?"); subLocationTable.setPageLength(15); subLocationTable.setScrollToSelectedItem(true); subLocationTable.addValueChangeListener(filterChangeListener); subLocationTable.setWidth(100f, Unit.PERCENTAGE); subLocationTable.setDataProvider(new ListDataProvider<>(subLocations)); FormLayout locationAndBook = new FormLayout(locationTable, subLocationTable, bookTable); locationAndBook.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); locationAndBook.setSizeFull(); bookListlayout.addComponent(locationAndBook); translateStatus = new ComboBoxMultiselect("? ", Arrays.asList(TRANSLATE_STATUS.values())); translateStatus.setClearButtonCaption("?"); translateStatus.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { LoadFilters(); } }); noTranslations = new CheckBox("? ?"); noTranslations.setValue(Boolean.FALSE); noTranslations.addValueChangeListener(filterChangeListener); emptyTranslations = new CheckBox("? "); emptyTranslations.setValue(Boolean.FALSE); emptyTranslations.addValueChangeListener(filterChangeListener); HorizontalLayout checkBoxlayout = new HorizontalLayout(noTranslations, emptyTranslations); translatorBox = new ComboBox(""); translatorBox.setPageLength(15); translatorBox.setScrollToSelectedItem(true); translatorBox.setDataProvider(new ListDataProvider(service.getSysAccounts())); translatorBox.addValueChangeListener(filterChangeListener); refreshButton = new Button(""); refreshButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { LoadFilters(); LoadBookContent(); } }); countLabel = new Label(); searchField = new TextField("?? ?"); searchField.setSizeFull(); searchField.setNullRepresentation(""); searchField.addValueChangeListener(filterChangeListener); FormLayout filtersLayout = new FormLayout(translateStatus, translatorBox, checkBoxlayout, searchField); filtersLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); filtersLayout.setSizeFull(); bookListlayout.addComponent(filtersLayout); bookListlayout.addComponent(refreshButton); bookListlayout.addComponent(countLabel); bookListlayout.setExpandRatio(locationAndBook, 0.4f); bookListlayout.setExpandRatio(filtersLayout, 0.4f); bookListlayout.setExpandRatio(refreshButton, 0.1f); bookListlayout.setExpandRatio(countLabel, 0.1f); bookListlayout.setHeight(105f, Unit.PIXELS); bookContentLayout = new TabSheet(); bookContentLayout.setSizeFull(); bookNameLayout = new HorizontalLayout(); bookNameLayout.setSizeFull(); bookNameOrigLayout = new VerticalLayout(); bookNameEn = new TextField("?"); bookNameEn.setWidth(500f, Unit.PIXELS); bookNameRu = new TextField(" ?"); bookNameRu.setWidth(500f, Unit.PIXELS); bookNameRu.setNullRepresentation(""); bookNameOrigLayout.addComponent(bookNameEn); bookNameOrigLayout.addComponent(bookNameRu); bookNameLayout.addComponent(bookNameOrigLayout); bookNameTranslationsLayout = new VerticalLayout(); bookNameTranslationsLayout.setSizeFull(); bookNameLayout.addComponent(bookNameTranslationsLayout); bookContentLayout.addTab(bookNameLayout, "?"); bookTextLayout = new HorizontalLayout(); bookTextLayout.setSizeFull(); bookTextOrigLayout = new HorizontalLayout(); bookTextOrigLayout.setSizeFull(); bookTextEn = new TextArea("?"); bookTextEn.setRows(20); bookTextEn.setSizeFull(); bookTextRu = new TextArea(" ?"); bookTextRu.setRows(20); bookTextRu.setSizeFull(); bookTextRu.setNullRepresentation(""); bookTextOrigLayout.addComponent(bookTextEn); bookTextOrigLayout.addComponent(bookTextRu); bookTextLayout.addComponent(bookTextOrigLayout); bookTextTranslationsLayout = new VerticalLayout(); bookTextTranslationsLayout.setSizeFull(); bookTextLayout.addComponent(bookTextTranslationsLayout); bookTextLayout.setExpandRatio(bookTextOrigLayout, 2f); bookTextLayout.setExpandRatio(bookTextTranslationsLayout, 1f); bookContentLayout.addTab(bookTextLayout, "?"); bookNameEn.setReadOnly(true); bookNameRu.setReadOnly(true); bookTextEn.setReadOnly(true); bookTextRu.setReadOnly(true); this.addComponent(bookListlayout); this.addComponent(bookContentLayout); this.bookListlayout.setHeight(105f, Unit.PIXELS); this.setExpandRatio(bookContentLayout, 1f); new NoAutcompleteComboBoxExtension(locationTable); new NoAutcompleteComboBoxExtension(subLocationTable); new NoAutcompleteComboBoxExtension(translatorBox); LoadFilters(); }
From source file:org.esn.esobase.view.tab.QuestTranslateTab.java
public QuestTranslateTab(DBService service_) { this.setSizeFull(); this.setSpacing(false); this.setMargin(false); this.service = service_; QuestChangeListener questChangeListener = new QuestChangeListener(); FilterChangeListener filterChangeListener = new FilterChangeListener(); questListlayout = new HorizontalLayout(); questListlayout.setWidth(100f, Unit.PERCENTAGE); questListlayout.setSpacing(false);/*from w ww . j a va 2 s. co m*/ questListlayout.setMargin(false); locationTable = new ComboBox("?"); locationTable.setPageLength(30); locationTable.setScrollToSelectedItem(true); locationTable.setWidth(100f, Unit.PERCENTAGE); locationTable.addValueChangeListener(filterChangeListener); locationTable.setDataProvider(new ListDataProvider<>(locations)); questTable = new ComboBox("?"); questTable.setWidth(100f, Unit.PERCENTAGE); questTable.setPageLength(15); questTable.setScrollToSelectedItem(true); questTable.setWidth(100f, Unit.PERCENTAGE); questTable.addValueChangeListener(questChangeListener); questTable.setDataProvider(new ListDataProvider<>(questList)); questListlayout.addComponent(questTable); FormLayout locationAndQuestLayout = new FormLayout(locationTable, questTable); locationAndQuestLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); locationAndQuestLayout.setSizeFull(); questListlayout.addComponent(locationAndQuestLayout); translateStatus = new ComboBoxMultiselect("? ", Arrays.asList(TRANSLATE_STATUS.values())); translateStatus.setClearButtonCaption("?"); translateStatus.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { LoadFilters(); LoadContent(); } }); noTranslations = new CheckBox("? ?"); noTranslations.setValue(Boolean.FALSE); noTranslations.addValueChangeListener(filterChangeListener); emptyTranslations = new CheckBox("? "); emptyTranslations.setValue(Boolean.FALSE); emptyTranslations.addValueChangeListener(filterChangeListener); HorizontalLayout checkBoxlayout = new HorizontalLayout(noTranslations, emptyTranslations); checkBoxlayout.setSpacing(false); checkBoxlayout.setMargin(false); translatorBox = new ComboBox(""); translatorBox.setPageLength(15); translatorBox.setScrollToSelectedItem(true); translatorBox.setDataProvider(new ListDataProvider<SysAccount>(service.getSysAccounts())); translatorBox.addValueChangeListener(filterChangeListener); refreshButton = new Button(""); refreshButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { LoadFilters(); LoadContent(); } }); countLabel = new Label(); searchField = new TextField("?? ?"); searchField.setSizeFull(); searchField.addValueChangeListener(filterChangeListener); FormLayout filtersLayout = new FormLayout(translateStatus, translatorBox, checkBoxlayout, searchField); filtersLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); filtersLayout.setSizeFull(); questListlayout.addComponent(filtersLayout); questListlayout.addComponent(refreshButton); questListlayout.addComponent(countLabel); questListlayout.setExpandRatio(locationAndQuestLayout, 0.4f); questListlayout.setExpandRatio(filtersLayout, 0.4f); questListlayout.setExpandRatio(refreshButton, 0.1f); questListlayout.setExpandRatio(countLabel, 0.1f); questListlayout.setHeight(105f, Unit.PIXELS); this.addComponent(questListlayout); infoLayout = new VerticalLayout(); infoLayout.setSizeFull(); infoLayout.setSpacing(false); infoLayout.setMargin(false); tabSheet = new TabSheet(); tabSheet.setSizeFull(); nameLayout = new VerticalLayout(); nameLayout.setSizeFull(); nameHLayout = new HorizontalLayout(); nameHLayout.setSizeFull(); nameHLayout.setSpacing(false); nameHLayout.setMargin(false); nameLayout = new VerticalLayout(); nameLayout.setSizeFull(); nameLayout.setSpacing(false); nameLayout.setMargin(false); questNameEnArea = new TextArea("?"); questNameEnArea.setSizeFull(); questNameEnArea.setRows(1); questNameEnArea.setReadOnly(true); questNameRuArea = new TextArea("? Ru"); questNameRuArea.setSizeFull(); questNameRuArea.setRows(1); questNameRuArea.setReadOnly(true); questNameRawEnArea = new TextArea("? "); questNameRawEnArea.setSizeFull(); questNameRawEnArea.setRows(1); questNameRawEnArea.setReadOnly(true); questNameRawRuArea = new TextArea("? Ru"); questNameRawRuArea.setSizeFull(); questNameRawRuArea.setRows(1); questNameRawRuArea.setReadOnly(true); nameLayout.addComponents(questNameEnArea, questNameRuArea, questNameRawEnArea, questNameRawRuArea); nameHLayout.addComponent(nameLayout); nameTranslateLayout = new VerticalLayout(); nameTranslateLayout.setSizeFull(); nameTranslateLayout.setSpacing(false); nameTranslateLayout.setMargin(false); nameHLayout.addComponent(nameTranslateLayout); infoLayout.addComponent(nameHLayout); descriptionLayout = new VerticalLayout(); descriptionLayout.setSizeFull(); descriptionHLayout = new HorizontalLayout(); descriptionHLayout.setSizeFull(); descriptionHLayout.setSpacing(false); descriptionHLayout.setMargin(false); descriptionLayout = new VerticalLayout(); descriptionLayout.setSizeFull(); descriptionLayout.setSpacing(false); descriptionLayout.setMargin(false); questDescriptionEnArea = new TextArea("?"); questDescriptionEnArea.setSizeFull(); questDescriptionEnArea.setRows(4); questDescriptionEnArea.setReadOnly(true); questDescriptionRuArea = new TextArea("? Ru"); questDescriptionRuArea.setSizeFull(); questDescriptionRuArea.setRows(4); questDescriptionRuArea.setReadOnly(true); questDescriptionRawEnArea = new TextArea("? "); questDescriptionRawEnArea.setSizeFull(); questDescriptionRawEnArea.setRows(4); questDescriptionRawEnArea.setReadOnly(true); questDescriptionRawRuArea = new TextArea("? Ru"); questDescriptionRawRuArea.setSizeFull(); questDescriptionRawRuArea.setRows(4); questDescriptionRawRuArea.setReadOnly(true); descriptionLayout.addComponents(questDescriptionEnArea, questDescriptionRuArea, questDescriptionRawEnArea, questDescriptionRawRuArea); descriptionHLayout.addComponent(descriptionLayout); descriptionTranslateLayout = new VerticalLayout(); descriptionTranslateLayout.setSizeFull(); descriptionTranslateLayout.setSpacing(false); descriptionTranslateLayout.setMargin(false); descriptionHLayout.addComponent(descriptionTranslateLayout); infoLayout.addComponent(descriptionHLayout); tabSheet.addTab(infoLayout, "?"); stepsLayout = new VerticalLayout(); stepsLayout.setSizeFull(); stepsLayout.setSpacing(false); stepsLayout.setMargin(false); stepsData = new TreeData(); stepsGrid = new TreeGrid(new TreeDataProvider(stepsData)); stepsGrid.setSelectionMode(Grid.SelectionMode.NONE); stepsGrid.setRowHeight(250); stepsGrid.setHeaderVisible(false); stepsGrid.setSizeFull(); stepsGrid.setItemCollapseAllowedProvider(new ItemCollapseAllowedProvider() { @Override public boolean test(Object item) { return false; } }); stepsGrid.addColumn(new ValueProvider() { @Override public Object apply(Object source) { if (source instanceof QuestStep) { return "?"; } if (source instanceof QuestDirection) { return " - " + ((QuestDirection) source).getDirectionType().name(); } return null; } }).setId("rowType").setCaption("").setWidth(132).setStyleGenerator(rowStyleGenerator); stepsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { VerticalLayout result = new VerticalLayout(); result.setSpacing(false); result.setMargin(false); if (source instanceof QuestStep) { QuestStep step = (QuestStep) source; if (step.getTextEn() != null && !step.getTextEn().isEmpty()) { TextArea textEnArea = new TextArea("? "); textEnArea.setValue(step.getTextEn()); textEnArea.setReadOnly(true); textEnArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textEnArea); } if (step.getTextRu() != null && !step.getTextRu().isEmpty()) { TextArea textRuArea = new TextArea(" "); textRuArea.setValue(step.getTextRu()); textRuArea.setReadOnly(true); textRuArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textRuArea); } } else if (source instanceof QuestDirection) { QuestDirection d = (QuestDirection) source; if (d.getTextEn() != null && !d.getTextEn().isEmpty()) { TextArea textEnArea = new TextArea("? "); textEnArea.setValue(d.getTextEn()); textEnArea.setRows(2); textEnArea.setReadOnly(true); textEnArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textEnArea); } if (d.getTextRu() != null && !d.getTextRu().isEmpty()) { TextArea textRuArea = new TextArea(" "); textRuArea.setValue(d.getTextRu()); textRuArea.setRows(2); textRuArea.setReadOnly(true); textRuArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textRuArea); } } return result; } }).setId("ingameText").setStyleGenerator(rowStyleGenerator); stepsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { VerticalLayout result = new VerticalLayout(); result.setSpacing(false); result.setMargin(false); if (source instanceof QuestStep) { QuestStep step = (QuestStep) source; if (step.getSheetsJournalEntry() != null) { TextArea textEnRawArea = new TextArea("? "); textEnRawArea.setValue(step.getSheetsJournalEntry().getTextEn()); textEnRawArea.setReadOnly(true); textEnRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textEnRawArea); if (step.getSheetsJournalEntry().getTextRu() != null && !step.getSheetsJournalEntry() .getTextRu().equals(step.getSheetsJournalEntry().getTextEn())) { TextArea textRuRawArea = new TextArea(" " + step.getSheetsJournalEntry().getTranslator()); textRuRawArea.setValue(step.getSheetsJournalEntry().getTextRu()); textRuRawArea.setReadOnly(true); textRuRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textRuRawArea);//, " " } } } else if (source instanceof QuestDirection) { QuestDirection d = (QuestDirection) source; if (d.getSheetsQuestDirection() != null) { TextArea textEnRawArea = new TextArea("? "); textEnRawArea.setValue(d.getSheetsQuestDirection().getTextEn()); textEnRawArea.setRows(2); textEnRawArea.setReadOnly(true); textEnRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textEnRawArea); if (d.getSheetsQuestDirection().getTextRu() != null && !d.getSheetsQuestDirection() .getTextRu().equals(d.getSheetsQuestDirection().getTextEn())) { TextArea textRuRawArea = new TextArea(" " + d.getSheetsQuestDirection().getTranslator()); textRuRawArea.setValue(d.getSheetsQuestDirection().getTextRu()); textRuRawArea.setRows(2); textRuRawArea.setReadOnly(true); textRuRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textRuRawArea); } } } return result; } }).setId("rawText").setStyleGenerator(rowStyleGenerator); stepsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { Panel panel = new Panel(); panel.addStyleName(ValoTheme.PANEL_BORDERLESS); panel.setWidth(100f, Unit.PERCENTAGE); panel.setHeight(245f, Unit.PIXELS); final VerticalLayout result = new VerticalLayout(); result.setSpacing(false); result.setMargin(false); if (source instanceof QuestStep) { Set<TranslatedText> list = new HashSet<>(); List<SysAccount> accounts = new ArrayList<>(); QuestStep step = (QuestStep) source; list.addAll(step.getSheetsJournalEntry().getTranslatedTexts()); if (list != null) { for (TranslatedText t : list) { result.addComponent(new TranslationCell(t)); accounts.add(t.getAuthor()); } } if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && step.getSheetsJournalEntry() != null && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) { final TranslatedText translatedText = new TranslatedText(); translatedText.setAuthor(SpringSecurityHelper.getSysAccount()); translatedText.setSpreadSheetsJournalEntry(step.getSheetsJournalEntry()); Button addTranslation = new Button(" ", FontAwesome.PLUS_SQUARE); addTranslation.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (translatedText.getSpreadSheetsJournalEntry() != null) { translatedText.getSpreadSheetsJournalEntry().getTranslatedTexts() .add(translatedText); } result.addComponent(new TranslationCell(translatedText)); event.getButton().setVisible(false); } }); result.addComponent(addTranslation); } } else if (source instanceof QuestDirection) { Set<TranslatedText> list = new HashSet<>(); List<SysAccount> accounts = new ArrayList<>(); QuestDirection d = (QuestDirection) source; list.addAll(d.getSheetsQuestDirection().getTranslatedTexts()); if (list != null) { for (TranslatedText t : list) { result.addComponent(new TranslationCell(t)); accounts.add(t.getAuthor()); } } if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && d.getSheetsQuestDirection() != null && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) { final TranslatedText translatedText = new TranslatedText(); translatedText.setAuthor(SpringSecurityHelper.getSysAccount()); translatedText.setSpreadSheetsQuestDirection(d.getSheetsQuestDirection()); Button addTranslation = new Button(" "); addTranslation.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (translatedText.getSpreadSheetsQuestDirection() != null) { translatedText.getSpreadSheetsQuestDirection().getTranslatedTexts() .add(translatedText); } result.addComponent(new TranslationCell(translatedText)); event.getButton().setVisible(false); } }); result.addComponent(addTranslation); } } panel.setContent(result); return panel; } }).setId("translation").setStyleGenerator(rowStyleGenerator); stepsGrid.setColumns("rowType", "ingameText", "rawText", "translation"); stepsLayout.addComponent(stepsGrid); tabSheet.addTab(stepsLayout, ""); itemsGrid = new Grid(new ListDataProvider(itemList)); itemsGrid.setSelectionMode(Grid.SelectionMode.NONE); itemsGrid.setRowHeight(250); itemsGrid.setHeaderVisible(false); itemsGrid.setSizeFull(); itemsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { VerticalLayout result = new VerticalLayout(); result.setSpacing(false); result.setMargin(false); if (source instanceof QuestItem) { QuestItem item = (QuestItem) source; if (item.getName() != null) { TextArea textEnRawArea = new TextArea("? "); textEnRawArea.setValue(item.getName().getTextEn()); textEnRawArea.setReadOnly(true); textEnRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textEnRawArea); if (item.getName().getTextRu() != null && !item.getName().getTextRu().equals(item.getName().getTextEn())) { TextArea textRuRawArea = new TextArea( " ? " + item.getName().getTranslator()); textRuRawArea.setValue(item.getName().getTextRu()); textRuRawArea.setReadOnly(true); textRuRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textRuRawArea);//, " " } } } return result; } }).setId("rawName"); itemsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { VerticalLayout result = new VerticalLayout(); result.setSpacing(false); result.setMargin(false); if (source instanceof QuestItem) { QuestItem item = (QuestItem) source; if (item.getDescription() != null) { TextArea textEnRawArea = new TextArea("? "); textEnRawArea.setValue(item.getDescription().getTextEn()); textEnRawArea.setReadOnly(true); textEnRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textEnRawArea); if (item.getDescription().getTextRu() != null && !item.getDescription().getTextRu().equals(item.getDescription().getTextEn())) { TextArea textRuRawArea = new TextArea( " ?? " + item.getDescription().getTranslator()); textRuRawArea.setValue(item.getDescription().getTextRu()); textRuRawArea.setReadOnly(true); textRuRawArea.setWidth(100f, Unit.PERCENTAGE); result.addComponent(textRuRawArea);//, " " } } } return result; } }).setId("rawDescription"); itemsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { Panel panel = new Panel(); panel.addStyleName(ValoTheme.PANEL_BORDERLESS); panel.setWidth(100f, Unit.PERCENTAGE); panel.setHeight(245f, Unit.PIXELS); final VerticalLayout result = new VerticalLayout(); result.setSpacing(false); result.setMargin(false); if (source instanceof QuestItem) { Set<TranslatedText> list = new HashSet<>(); List<SysAccount> accounts = new ArrayList<>(); QuestItem item = (QuestItem) source; if (item.getName() != null) { String text = item.getName().getTextEn(); list.addAll(item.getName().getTranslatedTexts()); if (list != null) { for (TranslatedText t : list) { result.addComponent(new TranslationCell(t)); accounts.add(t.getAuthor()); } } if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && text != null && !text.isEmpty() && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) { final TranslatedText translatedText = new TranslatedText(); translatedText.setAuthor(SpringSecurityHelper.getSysAccount()); translatedText.setSpreadSheetsItemName(item.getName()); Button addTranslation = new Button(" ", FontAwesome.PLUS_SQUARE); addTranslation.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (translatedText.getSpreadSheetsItemName() != null) { translatedText.getSpreadSheetsItemName().getTranslatedTexts() .add(translatedText); } result.addComponent(new TranslationCell(translatedText)); event.getButton().setVisible(false); } }); result.addComponent(addTranslation); } } } panel.setContent(result); return panel; } }).setId("nameTranslation"); itemsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { Panel panel = new Panel(); panel.addStyleName(ValoTheme.PANEL_BORDERLESS); panel.setWidth(100f, Unit.PERCENTAGE); panel.setHeight(245f, Unit.PIXELS); final VerticalLayout result = new VerticalLayout(); result.setSpacing(false); result.setMargin(false); if (source instanceof QuestItem) { Set<TranslatedText> list = new HashSet<>(); List<SysAccount> accounts = new ArrayList<>(); QuestItem item = (QuestItem) source; if (item.getDescription() != null) { String text = item.getDescription().getTextEn(); list.addAll(item.getDescription().getTranslatedTexts()); if (list != null) { for (TranslatedText t : list) { result.addComponent(new TranslationCell(t)); accounts.add(t.getAuthor()); } } if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && text != null && !text.isEmpty() && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) { final TranslatedText translatedText = new TranslatedText(); translatedText.setAuthor(SpringSecurityHelper.getSysAccount()); translatedText.setSpreadSheetsItemDescription(item.getDescription()); Button addTranslation = new Button(" ", FontAwesome.PLUS_SQUARE); addTranslation.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (translatedText.getSpreadSheetsItemDescription() != null) { translatedText.getSpreadSheetsItemDescription().getTranslatedTexts() .add(translatedText); } result.addComponent(new TranslationCell(translatedText)); event.getButton().setVisible(false); } }); result.addComponent(addTranslation); } } } panel.setContent(result); return panel; } }).setId("descriptionTranslation"); itemsGrid.addComponentColumn(new ValueProvider() { @Override public Object apply(Object source) { VerticalLayout result = new VerticalLayout(); result.setMargin(new MarginInfo(true, false, false, false)); result.setSpacing(false); if (source instanceof QuestItem) { GSpreadSheetsItemName name = ((QuestItem) source).getName(); if (name.getIcon() != null) { Image image = new Image(null, new ExternalResource( "https://elderscrolls.net" + name.getIcon().replaceAll(".dds", ".png"))); result.addComponent(image); return result; } } return result; } }).setId("icon").setWidth(95); itemsGrid.setColumns("icon", "rawName", "nameTranslation", "rawDescription", "descriptionTranslation"); tabSheet.addTab(itemsGrid, ""); this.addComponent(tabSheet); this.setExpandRatio(tabSheet, 1f); GridScrollExtension stepsScrollExtension = new GridScrollExtension(stepsGrid); GridScrollExtension itemsScrollExtension = new GridScrollExtension(itemsGrid); new NoAutcompleteComboBoxExtension(locationTable); new NoAutcompleteComboBoxExtension(questTable); new NoAutcompleteComboBoxExtension(translatorBox); LoadFilters(); }
From source file:org.esn.esobase.view.tab.TranslateTab.java
public void Init() { removeAllComponents();//from w ww. j a va2s .com TopicNpcColumnGenerator topicNpcColumnGenerator = new TopicNpcColumnGenerator(); TopicPlayerColumnGenerator topicPlayerColumnGenerator = new TopicPlayerColumnGenerator(); SubtitleColumnGenerator subtitleColumnGenerator = new SubtitleColumnGenerator(); TranslationColumnGenerator translationColumnGenerator = new TranslationColumnGenerator(); FilterChangeListener filterChangeListener = new FilterChangeListener(); this.setSizeFull(); this.setSpacing(false); this.setMargin(false); npcListlayout = new HorizontalLayout(); npcListlayout.setSpacing(false); npcListlayout.setMargin(false); npcListlayout.setSizeFull(); npcTable = new ComboBox("NPC"); npcTable.setPageLength(30); npcTable.setScrollToSelectedItem(true); npcTable.setWidth(100f, Unit.PERCENTAGE); npcTable.addValueChangeListener(new NpcSelectListener()); npcTable.setScrollToSelectedItem(true); npcTable.setEmptySelectionAllowed(true); locationTable = new ComboBox("?"); locationTable.setPageLength(30); locationTable.setScrollToSelectedItem(true); locationTable.setWidth(100f, Unit.PERCENTAGE); locationTable.addValueChangeListener(filterChangeListener); locationTable.setDataProvider(new ListDataProvider<>(locations)); locationTable.setEmptySelectionAllowed(true); subLocationTable = new ComboBox("?"); subLocationTable.setPageLength(30); subLocationTable.setScrollToSelectedItem(true); subLocationTable.setWidth(100f, Unit.PERCENTAGE); subLocationTable.addValueChangeListener(filterChangeListener); subLocationTable.setDataProvider(new ListDataProvider<>(subLocations)); subLocationTable.setEmptySelectionAllowed(true); questTable = new ComboBox("?"); questTable.setPageLength(30); questTable.setScrollToSelectedItem(true); questTable.setWidth(100f, Unit.PERCENTAGE); questTable.addValueChangeListener(filterChangeListener); questTable.setDataProvider(new ListDataProvider<>(questList)); npcTable.setDataProvider(new ListDataProvider<>(npcList)); FormLayout locationAndNpc = new FormLayout(questTable, locationTable, subLocationTable, npcTable); locationAndNpc.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); locationAndNpc.setSizeFull(); npcListlayout.addComponent(locationAndNpc); translateStatus = new ComboBoxMultiselect("? ", Arrays.asList(TRANSLATE_STATUS.values())); translateStatus.setClearButtonCaption("?"); translateStatus.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { LoadFilters(); LoadNpcContent(); } }); translateStatus.setPageLength(20); noTranslations = new CheckBox("? ?"); noTranslations.setValue(Boolean.FALSE); noTranslations.addValueChangeListener(new HasValue.ValueChangeListener<Boolean>() { @Override public void valueChange(HasValue.ValueChangeEvent<Boolean> event) { LoadFilters(); LoadNpcContent(); } }); emptyTranslations = new CheckBox("? "); emptyTranslations.setValue(Boolean.FALSE); emptyTranslations.addValueChangeListener(new HasValue.ValueChangeListener<Boolean>() { @Override public void valueChange(HasValue.ValueChangeEvent<Boolean> event) { LoadFilters(); LoadNpcContent(); } }); HorizontalLayout checkBoxlayout = new HorizontalLayout(noTranslations, emptyTranslations); translatorBox = new ComboBox(""); translatorBox.setPageLength(15); translatorBox.setScrollToSelectedItem(true); translatorBox.setDataProvider(new ListDataProvider(service.getSysAccounts())); translatorBox.addValueChangeListener(new HasValue.ValueChangeListener() { @Override public void valueChange(HasValue.ValueChangeEvent event) { LoadFilters(); LoadNpcContent(); } }); refreshButton = new Button(""); refreshButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { LoadFilters(); LoadNpcContent(); } }); countLabel = new Label(); searchField = new TextField("?? ?"); searchField.setSizeFull(); searchField.addValueChangeListener(new HasValue.ValueChangeListener<String>() { @Override public void valueChange(HasValue.ValueChangeEvent<String> event) { LoadFilters(); LoadNpcContent(); } }); FormLayout questAndWithNewTranslations = new FormLayout(translateStatus, translatorBox, checkBoxlayout, searchField); questAndWithNewTranslations.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); questAndWithNewTranslations.setSizeFull(); npcListlayout.addComponent(questAndWithNewTranslations); npcListlayout.addComponent(refreshButton); npcListlayout.addComponent(countLabel); npcListlayout.setExpandRatio(locationAndNpc, 0.4f); npcListlayout.setExpandRatio(questAndWithNewTranslations, 0.4f); npcListlayout.setExpandRatio(refreshButton, 0.1f); npcListlayout.setExpandRatio(countLabel, 0.1f); npcContentLayout = new VerticalLayout(); npcContentLayout.setSizeFull(); npcContentLayout.setSpacing(false); npcContentLayout.setMargin(false); npcTabSheet = new TabSheet(); npcTabSheet.setSizeFull(); npcTabLayout = new VerticalLayout(); locationName = new TextField("? "); npcTabLayout.addComponent(locationName); locationNameRu = new TextField(" ? "); npcTabLayout.addComponent(locationNameRu); npcName = new TextField("? NPC"); npcTabLayout.addComponent(npcName); npcNameRu = new TextField(" NPC"); npcTabLayout.addComponent(npcNameRu); npcTab = npcTabSheet.addTab(npcTabLayout, ""); npcTopicsTable = new Table(); npcTopicsTable.addStyleName(ValoTheme.TABLE_COMPACT); npcTopicsTable.setSizeFull(); npcTopicsTable.setPageLength(0); topicsContainer = new BeanItemContainer<>(Topic.class); npcTopicsTable.setContainerDataSource(topicsContainer); npcTopicsTable.addGeneratedColumn("npcTextG", topicNpcColumnGenerator); npcTopicsTable.addGeneratedColumn("playerTextG", topicPlayerColumnGenerator); npcTopicsTable.removeGeneratedColumn("playerTranslations"); npcTopicsTable.addGeneratedColumn("playerTranslations", translationColumnGenerator); npcTopicsTable.removeGeneratedColumn("npcTranslations"); npcTopicsTable.addGeneratedColumn("npcTranslations", translationColumnGenerator); npcTopicsTable.setVisibleColumns( new Object[] { "playerTextG", "playerTranslations", "npcTextG", "npcTranslations" }); npcTopicsTable.setColumnHeaders(new String[] { " ", "", " NPC", "" }); npcTopicsTable.setColumnExpandRatio("playerTextG", 1f); npcTopicsTable.setColumnExpandRatio("playerTranslations", 1.5f); npcTopicsTable.setColumnExpandRatio("npcTextG", 1.5f); npcTopicsTable.setColumnExpandRatio("npcTranslations", 1.5f); npcTopicsTable.setColumnWidth("actions", 150); npcSubtitlesTable = new Table(); npcSubtitlesTable.addStyleName(ValoTheme.TABLE_COMPACT); npcSubtitlesTable.setSizeFull(); npcSubtitlesTable.setPageLength(0); subtitlesContainer = new BeanItemContainer<>(Subtitle.class); npcSubtitlesTable.setContainerDataSource(subtitlesContainer); npcSubtitlesTable.addGeneratedColumn("textG", subtitleColumnGenerator); npcSubtitlesTable.removeGeneratedColumn("translations"); npcSubtitlesTable.addGeneratedColumn("translations", translationColumnGenerator); npcSubtitlesTable.setVisibleColumns(new Object[] { "textG", "translations" }); npcSubtitlesTable.setColumnHeaders(new String[] { "", "" }); npcSubtitlesTable.setColumnExpandRatio("textG", 1f); npcSubtitlesTable.setColumnExpandRatio("translations", 1f); npcSubtitlesTable.setColumnWidth("actions", 150); npcTopicsTab = npcTabSheet.addTab(npcTopicsTable, ""); npcSubtitlesTab = npcTabSheet.addTab(npcSubtitlesTable, ""); npcContentLayout.addComponent(npcTabSheet); this.addComponent(npcListlayout); this.addComponent(npcContentLayout); this.npcListlayout.setHeight(105f, Unit.PIXELS); this.setExpandRatio(npcContentLayout, 1f); LoadFilters(); new NoAutcompleteComboBoxExtension(questTable); new NoAutcompleteComboBoxExtension(locationTable); new NoAutcompleteComboBoxExtension(subLocationTable); new NoAutcompleteComboBoxExtension(npcTable); new NoAutcompleteComboBoxExtension(translatorBox); }
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();/*w w w . ja v a2s . 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.translation.model.EntriesFlowlet.java
License:Apache License
@Override public void initialize() { final List<FieldDescriptor> fieldDescriptors = TranslationFields.getFieldDescriptors(Entry.class); final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>(); filterDefinitions.add(new FilterDescriptor("basename", "basename", "Basename", new TextField(), 200, "like", String.class, "")); filterDefinitions.add(new FilterDescriptor("language", "language", "Language", new TextField(), 30, "=", String.class, "")); filterDefinitions.add(//from w w w .j av a 2 s. c o 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); }