List of usage examples for com.vaadin.ui Button setIcon
@Override public void setIcon(Resource icon)
From source file:me.uni.emuseo.view.common.form.FormWithButtonsLayout.java
License:Open Source License
protected HorizontalLayout buildButtons() { final Button saveButton = new Button(); final Button cancelButton = new Button(); ClickListener clickListener = new ClickListener() { private static final long serialVersionUID = 5320702365033343873L; @Override/*from ww w . j a v a 2 s. c o m*/ public void buttonClick(ClickEvent event) { Button button = event.getButton(); if (button.equals(saveButton)) { onPreSave(); } else if (button.equals(cancelButton)) { onCancel(); } } }; HorizontalLayout buttonLayout = new HorizontalLayout(); saveButton.addStyleName("primary"); saveButton.setIcon(FontAwesome.SAVE); saveButton.addClickListener(clickListener); cancelButton.addStyleName("primary"); cancelButton.setIcon(FontAwesome.UNDO); cancelButton.addClickListener(clickListener); buttonLayout.addComponent(saveButton); buttonLayout.addComponent(cancelButton); buttonLayout.setSpacing(true); buttonLayout.addStyleName("form-buttons"); return buttonLayout; }
From source file:me.uni.emuseo.view.common.form.SearchFormLayout.java
License:Open Source License
private CssLayout createButtonsLayout() { CssLayout buttonsLayout = new CssLayout(); Button searchButton = new Button(); searchButton.addStyleName("primary"); searchButton.setIcon(FontAwesome.SEARCH); searchButton.addClickListener(new Button.ClickListener() { /**//from w w w. ja v a2 s . co m * */ private static final long serialVersionUID = -8034803606737706285L; @Override public void buttonClick(ClickEvent event) { try { formBuilder.commit(); eventPropagator.fireChangeEvent(formBuilder.getBean()); } catch (CommitException e) { e.printStackTrace(); } } }); Button clearButton = new Button(); clearButton.addStyleName("primary"); clearButton.setIcon(FontAwesome.ERASER); clearButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = -8684340029871714722L; @Override public void buttonClick(ClickEvent event) { T bean = getBean(); formBuilder.setBean(bean); eventPropagator.fireClearEvent(formBuilder.getBean()); } }); buttonsLayout.addComponents(clearButton, searchButton); buttonsLayout.setSizeFull(); buttonsLayout.addStyleName("buttons-layout"); return buttonsLayout; }
From source file:me.uni.emuseo.view.menu.MenuView.java
License:Open Source License
private CssLayout buildMenu() { // Add items/*from www .j a v a 2 s . co m*/ if (authManager.isAuthorizedTo(Permissions.MENU_USERS_VIEW)) { menuItems.put(Permissions.MENU_USERS_VIEW, "Uytkownicy"); } if (authManager.isAuthorizedTo(Permissions.MENU_EXHIBIT_VIEW)) { menuItems.put(Permissions.MENU_EXHIBIT_VIEW, "Katalog eksponatw"); } if (authManager.isAuthorizedTo(Permissions.MENU_CATEGORIES_VIEW)) { menuItems.put(Permissions.MENU_CATEGORIES_VIEW, "Kategorie"); } if (authManager.isAuthorizedTo(Permissions.MENU_RESOURCES_VIEW)) { menuItems.put(Permissions.MENU_RESOURCES_VIEW, "Zasoby"); } final HorizontalLayout top = new HorizontalLayout(); top.setWidth("100%"); top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); top.addStyleName("valo-menu-title"); menu.addComponent(top); final Button showMenu = new Button("Menu", new ClickListener() { private static final long serialVersionUID = -719702284721453362L; @Override public void buttonClick(final ClickEvent event) { if (menu.getStyleName().contains("valo-menu-visible")) { menu.removeStyleName("valo-menu-visible"); } else { menu.addStyleName("valo-menu-visible"); } } }); showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY); showMenu.addStyleName(ValoTheme.BUTTON_SMALL); showMenu.addStyleName("valo-menu-toggle"); showMenu.setIcon(FontAwesome.LIST); menu.addComponent(showMenu); final Label title = new Label("<h3>e<strong>Museo</strong></h3>", ContentMode.HTML); title.setSizeUndefined(); top.addComponent(title); top.setExpandRatio(title, 1); final MenuBar settings = new MenuBar(); settings.addStyleName("user-menu"); settingsItem = settings.addItem("Jan Kowalski", defaultIcon, null); if (authManager.isAuthorizedTo(Permissions.MENU_MY_ACCOUNT_VIEW)) { settingsItem.addItem("Moje konto", new MenuBar.Command() { private static final long serialVersionUID = 7015035735144235104L; @Override public void menuSelected(MenuItem selectedItem) { navigator.navigateTo(Permissions.MENU_MY_ACCOUNT_VIEW); } }); } if (authManager.isAuthorizedTo(Permissions.MENU_SETTINGS_VIEW)) { settingsItem.addItem("Ustawienia", new MenuBar.Command() { private static final long serialVersionUID = 7015035735144235105L; @Override public void menuSelected(MenuItem selectedItem) { navigator.navigateTo(Permissions.MENU_SETTINGS_VIEW); } }); } settingsItem.addSeparator(); settingsItem.addItem("Wyloguj", new MenuBar.Command() { private static final long serialVersionUID = 1333473616079310225L; @Override public void menuSelected(MenuItem selectedItem) { final AuthManager authManager = EMuseoUtil.getAppContext().getBean(AuthManager.class); authManager.logout(); } }); menu.addComponent(settings); menuItemsLayout.setPrimaryStyleName("valo-menuitems"); menu.addComponent(menuItemsLayout); for (final Entry<String, String> item : menuItems.entrySet()) { FontIcon icon = null; if (item.getKey().equals(Permissions.MENU_USERS_VIEW)) { icon = FontAwesome.USERS; } else if (item.getKey().endsWith(Permissions.MENU_EXHIBIT_VIEW)) { icon = FontAwesome.UNIVERSITY; } else if (item.getKey().endsWith(Permissions.MENU_CATEGORIES_VIEW)) { icon = FontAwesome.ARCHIVE; } else if (item.getKey().endsWith(Permissions.MENU_RESOURCES_VIEW)) { icon = FontAwesome.IMAGE; } final Button b = new Button(item.getValue(), new ClickListener() { private static final long serialVersionUID = -7089398070311521853L; @Override public void buttonClick(final ClickEvent event) { navigator.navigateTo(item.getKey()); } }); b.setHtmlContentAllowed(true); b.setPrimaryStyleName("valo-menu-item"); if (icon != null) { b.setIcon(icon); } menuItemsLayout.addComponent(b); } return menu; }
From source file:me.uni.emuseo.view.settings.MyAccountView.java
License:Open Source License
public MyAccountView() { authManager = EMuseoUtil.getAppContext().getBean(AuthManager.class); userService = EMuseoUtil.getAppContext().getBean(UserService.class); final Long userId = authManager.getLoggedUserId(); UserDTO user = userService.getUser(userId); FormWithButtonsLayout<UserDTO> formLayout = new FormWithButtonsLayout<UserDTO>(user) { private static final long serialVersionUID = -1826989504302110056L; @Override/* ww w .j av a2s.c o m*/ protected void onSave(UserDTO bean) { userService.editUser(bean); } @Override protected FormBuilder<UserDTO> buildForm(UserDTO bean) { return new MyAccountFormLayout(bean); } }; ExpandingPanel myAccountPanel = new ExpandingPanel(); myAccountPanel.setCaption("Moje dane"); myAccountPanel.setContent(formLayout); myAccountPanel.setExpanded(true); Button addButton = new Button("Zmie haso"); addButton.setIcon(FontAwesome.LOCK); addButton.addStyleName("emuseo-button-icon"); addButton.addStyleName("emuseo-button-margin"); addButton.setWidth(100, Unit.PERCENTAGE); addComponent(myAccountPanel); addComponent(addButton); // setComponentAlignment(formLayout, Alignment.MIDDLE_CENTER); addButton.addClickListener(new ClickListener() { private static final long serialVersionUID = -263205007196895260L; @Override public void buttonClick(ClickEvent event) { PasswordPopUpWindow exhibitPopUpWidow = new PasswordPopUpWindow("Zmie haso") { private static final long serialVersionUID = 3776311059670953583L; @Override protected boolean onSave(PasswordDTO bean) throws InvalidBeanException { try { userService.changePassword(userId, bean); return true; } catch (PasswordChangeException e) { new Notification("Bd", e.getReason(), Type.ERROR_MESSAGE, true) .show(Page.getCurrent()); } return false; } }; UI.getCurrent().addWindow(exhibitPopUpWidow); } }); }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
private void initView() { setCompositionRoot(root);/* ww w . j ava2 s . co m*/ root.setSizeFull(); root.setSplitPosition(15); root.setStyleName("small previews"); previewArea.setWidth("100%"); previewTabs = new VerticalLayout(); previewTabs.setSizeFull(); previewTabs.setHeight(null); compoundTabs = new VerticalLayout(); compoundTabs.setSizeFull(); compoundTabs.setHeight(null); bennuStylesTabs = new VerticalLayout(); bennuStylesTabs.setSizeFull(); bennuStylesTabs.setHeight(null); VerticalLayout menu = new VerticalLayout(); menu.setSizeFull(); menu.setStyleName("sidebar-menu"); Button syncThemes = new Button("Sync Themes", new ClickListener() { @Override public void buttonClick(ClickEvent event) { syncThemes(); } }); menu.addComponent(syncThemes); menu.addComponent(new Label("Single Components")); menu.addComponent(previewTabs); menu.addComponent(new Label("Compound Styles")); menu.addComponent(compoundTabs); menu.addComponent(new Label("Bennu Styles")); menu.addComponent(bennuStylesTabs); root.setFirstComponent(menu); CssLayout toolbar = new CssLayout(); toolbar.setWidth("100%"); toolbar.setStyleName("toolbar"); toolbar.addComponent(editorToggle); final Window downloadWindow = new Window("Download Theme"); GridLayout l = new GridLayout(3, 2); l.setSizeUndefined(); l.setMargin(true); l.setSpacing(true); downloadWindow.setContent(l); downloadWindow.setModal(true); downloadWindow.setResizable(false); downloadWindow.setCloseShortcut(KeyCode.ESCAPE, null); downloadWindow.addStyleName("opaque"); Label caption = new Label("Theme Name"); l.addComponent(caption); l.setComponentAlignment(caption, Alignment.MIDDLE_CENTER); final TextField name = new TextField(); name.setValue("my-chameleon"); name.addValidator(new RegexpValidator("[a-zA-Z0-9\\-_\\.]+", "Only alpha-numeric characters allowed")); name.setRequired(true); name.setRequiredError("Please give a name for the theme"); downloadWindow.addComponent(name); Label info = new Label( "This is the name you will use to set the theme in your application code, i.e. <code>setTheme(\"my-cameleon\")</code>.", Label.CONTENT_XHTML); info.addStyleName("tiny"); info.setWidth("200px"); l.addComponent(info, 1, 1, 2, 1); Button download = new Button(null, new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { getApplication().getMainWindow().addWindow(downloadWindow); name.focus(); } }); download.setDescription("Donwload the current theme"); download.setIcon(new ThemeResource("download.png")); download.setStyleName("icon-only"); toolbar.addComponent(download); menu.addComponent(toolbar); menu.setExpandRatio(toolbar, 1); menu.setComponentAlignment(toolbar, Alignment.BOTTOM_CENTER); }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
private Layout getButtonPreviews() { Layout grid = getPreviewLayout("Buttons"); Button button = new Button("Button"); grid.addComponent(button);//from w w w .j av a 2 s . c o m button = new Button("Default"); button.setStyleName("default"); grid.addComponent(button); button = new Button("Small"); button.setStyleName("small"); grid.addComponent(button); button = new Button("Small Default"); button.setStyleName("small default"); grid.addComponent(button); button = new Button("Big"); button.setStyleName("big"); grid.addComponent(button); button = new Button("Big Default"); button.setStyleName("big default"); grid.addComponent(button); button = new Button("Disabled"); button.setEnabled(false); grid.addComponent(button); button = new Button("Disabled default"); button.setEnabled(false); button.setStyleName("default"); grid.addComponent(button); button = new Button("Link style"); button.setStyleName(BaseTheme.BUTTON_LINK); grid.addComponent(button); button = new Button("Disabled link"); button.setStyleName(BaseTheme.BUTTON_LINK); button.setEnabled(false); grid.addComponent(button); button = new Button("120px overflows out of the button"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); button.setWidth("120px"); grid.addComponent(button); button = new Button("Small"); button.setStyleName("small"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Big"); button.setStyleName("big"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Big Default"); button.setStyleName("big default"); button.setIcon(new ThemeResource("../runo/icons/32/document-txt.png")); grid.addComponent(button); button = new Button("Big link"); button.setStyleName(BaseTheme.BUTTON_LINK + " big"); button.setIcon(new ThemeResource("../runo/icons/32/document.png")); grid.addComponent(button); button = new Button("Borderless"); button.setStyleName("borderless"); button.setIcon(new ThemeResource("../runo/icons/32/note.png")); grid.addComponent(button); button = new Button("Borderless icon on top"); button.setStyleName("borderless icon-on-top"); button.setIcon(new ThemeResource("../runo/icons/32/note.png")); grid.addComponent(button); button = new Button("Icon on top"); button.setStyleName("icon-on-top"); button.setIcon(new ThemeResource("../runo/icons/32/users.png")); grid.addComponent(button); button = new Button("Wide Default"); button.setStyleName("wide default"); grid.addComponent(button); button = new Button("Wide"); button.setStyleName("wide"); grid.addComponent(button); button = new Button("Tall"); button.setStyleName("tall"); grid.addComponent(button); button = new Button("Wide, Tall & Big"); button.setStyleName("wide tall big"); grid.addComponent(button); button = new Button("Icon on right"); button.setStyleName("icon-on-right"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Big icon"); button.setStyleName("icon-on-right big"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Toggle (down)"); button.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (event.getButton().getStyleName().endsWith("down")) { event.getButton().removeStyleName("down"); } else { event.getButton().addStyleName("down"); } } }); button.addStyleName("down"); grid.addComponent(button); button.setDescription( button.getDescription() + "<br><strong>Stylename switching logic must be done separately</strong>"); button = new Button(); button.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (event.getButton().getStyleName().endsWith("down")) { event.getButton().removeStyleName("down"); } else { event.getButton().addStyleName("down"); } } }); button.addStyleName("icon-only"); button.addStyleName("down"); button.setIcon(new ThemeResource("../runo/icons/16/user.png")); grid.addComponent(button); button.setDescription( button.getDescription() + "<br><strong>Stylename switching logic must be done separately</strong>"); Link l = new Link("Link: vaadin.com", new ExternalResource("http://vaadin.com")); grid.addComponent(l); l = new Link("Link: vaadin.com", new ExternalResource("http://vaadin.com")); l.setIcon(new ThemeResource("../runo/icons/32/globe.png")); grid.addComponent(l); return grid; }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
Layout getCompoundButtons() { Layout grid = getPreviewLayout("Compound Buttons"); Label title = new Label("Segment"); title.setStyleName("h1"); grid.addComponent(title);//from w w w . j a va 2 s . c o m ((GridLayout) grid).newLine(); Label segments = new Label( "The segment control is just a set of buttons inside a HorizontalLayout. Use the structure shown on the right, <strong>and remember that you need to implement all logic yourself</strong>. This theme just provides suitable stylenames for you to use.", Label.CONTENT_XHTML); grid.addComponent(segments); segments = new Label( "HorizontalLayout.setStyleName(\"segment\") and .addStyleName(\"segment-alternate\")\n + Button.addStyleName(\"first\") and .addStyleName(\"down\")\n + Button\n\t...\n + Button.addStyleName(\"last\")", Label.CONTENT_PREFORMATTED); ((GridLayout) grid).addComponent(segments, 1, 1, 2, 1); Segment segment = new Segment(); segment.setCaption("Segment"); Button b = new Button("One"); b.setStyleName("down"); b.setIcon(new ThemeResource("../runo/icons/16/document-txt.png")); segment.addButton(b).addButton(new Button("Two")).addButton(new Button("Three")) .addButton(new Button("Four")); grid.addComponent(segment); segment = new Segment(); segment.addStyleName("segment-alternate"); segment.setCaption("Segment (alternate)"); b = new Button("One"); b.setStyleName("down"); b.setIcon(new ThemeResource("../runo/icons/16/document-txt.png")); segment.addButton(b).addButton(new Button("Two")).addButton(new Button("Three")) .addButton(new Button("Four")); grid.addComponent(segment); segment = new Segment(); segment.setCaption("Small segment"); b = new Button("Apples"); b.setStyleName("small"); b.addStyleName("down"); segment.addButton(b); b = new Button("Oranges"); b.setStyleName("small"); segment.addButton(b); b = new Button("Bananas"); b.setStyleName("small"); segment.addButton(b); b = new Button("Grapes"); b.setStyleName("small"); segment.addButton(b); grid.addComponent(segment); return grid; }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
Layout getCompoundMenus() { Layout grid = getPreviewLayout("Compound Menus"); Label title = new Label("Sidebar Menu"); title.setStyleName("h1"); grid.addComponent(title);//from w w w . j av a 2s .c om ((GridLayout) grid).newLine(); Label menus = new Label( "<strong>The sidebar menu</strong> control is just a set of labels and buttons inside a CssLayout or a VerticalLayout. Use the structure shown on the right, <strong>and remember that you need to implement all logic yourself</strong>. This theme just provides suitable stylenames for you to use.<br><br>You can also use the <a href=\"http://vaadin.com/forum/-/message_boards/message/119172\">DetachedTabs add-on</a> inside the sidebar-menu, it will style automatically.<br><br><strong>Note: only NativeButtons are styled inside the menu, normal buttons are left untouched.</strong>", Label.CONTENT_XHTML); grid.addComponent(menus); menus = new Label( "CssLayout.setStyleName(\"sidebar-menu\")\n + Label\n + NativeButton\n + NativeButton\n\t...\n + Label\n + DetachedTabs\n\t...", Label.CONTENT_PREFORMATTED); grid.addComponent(menus); SidebarMenu sidebar = new SidebarMenu(); sidebar.setWidth("200px"); sidebar.addComponent(new Label("Fruits")); NativeButton b = new NativeButton("Apples"); b.setIcon(new ThemeResource("../runo/icons/16/note.png")); sidebar.addButton(b); sidebar.setSelected(b); sidebar.addButton(new NativeButton("Oranges")); sidebar.addButton(new NativeButton("Bananas")); sidebar.addButton(new NativeButton("Grapes")); sidebar.addComponent(new Label("Vegetables")); sidebar.addButton(new NativeButton("Tomatoes")); sidebar.addButton(new NativeButton("Cabbages")); sidebar.addButton(new NativeButton("Potatoes")); sidebar.addButton(new NativeButton("Carrots")); grid.addComponent(sidebar); ((GridLayout) grid).setColumnExpandRatio(0, 1); ((GridLayout) grid).setColumnExpandRatio(1, 1); title = new Label("Toolbar"); title.setStyleName("h1"); grid.addComponent(title); ((GridLayout) grid).newLine(); CssLayout toolbars = new CssLayout(); menus = new Label( "<strong>Toolbar</strong> is a simple CssLayout with a stylename. It provides the background and a little padding for its contents. Normally you will want to put buttons inside it, but segment controls fit in nicely as well.", Label.CONTENT_XHTML); grid.addComponent(menus); menus = new Label("CssLayout.setStyleName(\"toolbar\")", Label.CONTENT_PREFORMATTED); grid.addComponent(menus); CssLayout toolbar = new CssLayout(); toolbar.setStyleName("toolbar"); toolbar.setWidth("300px"); Button b2 = new Button("Action"); b2.setStyleName("small"); toolbar.addComponent(b2); Segment segment = new Segment(); segment.addStyleName("segment-alternate"); b2 = new Button("Apples"); b2.setStyleName("small"); b2.addStyleName("down"); segment.addButton(b2); b2 = new Button("Oranges"); b2.setStyleName("small"); segment.addButton(b2); toolbar.addComponent(segment); b2 = new Button("Notes"); b2.setStyleName("small borderless"); b2.setIcon(new ThemeResource("../runo/icons/16/note.png")); toolbar.addComponent(b2); toolbars.addComponent(toolbar); toolbar = new CssLayout(); toolbar.setStyleName("toolbar"); toolbar.setWidth("300px"); b2 = new Button("Action"); b2.setIcon(new ThemeResource("../runo/icons/32/document.png")); b2.setStyleName("borderless"); toolbar.addComponent(b2); b2 = new Button("Action 2"); b2.setStyleName("borderless"); b2.setIcon(new ThemeResource("../runo/icons/32/user.png")); toolbar.addComponent(b2); b2 = new Button("Action 3"); b2.setStyleName("borderless"); b2.setIcon(new ThemeResource("../runo/icons/32/note.png")); toolbar.addComponent(b2); toolbars.addComponent(toolbar); grid.addComponent(toolbars); return grid; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.DataEntryPropertyComponent.java
License:Apache License
@Override protected Component initContent() { Panel p = new Panel(); FormLayout l = new FormLayout(); getInternalValue().forEach(prop -> { if (!prop.getPropertyName().equals("property.expected.result")) { HorizontalLayout hl = new HorizontalLayout(); TextField tf = new TextField(TRANSLATOR.translate(prop.getPropertyName()), prop.getPropertyValue()); hl.addComponent(tf);//from w ww. j av a2 s . co m if (edit) { //Add button for deleting this property. Button delete = new Button(); delete.setIcon(VaadinIcons.MINUS); delete.addClickListener(listener -> { getInternalValue().remove(prop); l.removeComponent(hl); }); hl.addComponent(delete); } l.addComponent(hl); } }); p.setContent(l); return p; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.execution.ExecutionWizardStep.java
License:Apache License
@Override public Component getContent() { Panel form = new Panel(TRANSLATOR.translate("step.detail")); if (getExecutionStep().getExecutionStart() == null) { //Set the start date. getExecutionStep().setExecutionStart(new Date()); }// ww w .ja v a 2 s.com FormLayout layout = new FormLayout(); form.setContent(layout); form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(getExecutionStep().getStep().getClass()); binder.setItemDataSource(getExecutionStep().getStep()); TextArea text = new TextArea(TRANSLATOR.translate("general.text")); text.setConverter(new ByteToStringConverter()); binder.bind(text, "text"); text.setSizeFull(); layout.addComponent(text); Field notes = binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes", TextArea.class); notes.setSizeFull(); layout.addComponent(notes); if (getExecutionStep().getExecutionStart() != null) { start = new DateField(TRANSLATOR.translate("start.date")); start.setResolution(Resolution.SECOND); start.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal()); start.setValue(getExecutionStep().getExecutionStart()); start.setReadOnly(true); layout.addComponent(start); } if (getExecutionStep().getExecutionEnd() != null) { end = new DateField(TRANSLATOR.translate("end.date")); end.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal()); end.setResolution(Resolution.SECOND); end.setValue(getExecutionStep().getExecutionEnd()); end.setReadOnly(true); layout.addComponent(end); } binder.setReadOnly(true); //Space to record result if (getExecutionStep().getResultId() != null) { result.setValue(getExecutionStep().getResultId().getResultName()); } layout.addComponent(result); if (reviewer) {//Space to record review if (getExecutionStep().getReviewResultId() != null) { review.setValue(getExecutionStep().getReviewResultId().getReviewName()); } layout.addComponent(review); } //Add Reviewer name if (getExecutionStep().getReviewer() != null) { TextField reviewerField = new TextField(TRANSLATOR.translate("general.reviewer")); reviewerField.setValue(getExecutionStep().getReviewer().getFirstName() + " " + getExecutionStep().getReviewer().getLastName()); reviewerField.setReadOnly(true); layout.addComponent(reviewerField); } if (getExecutionStep().getReviewDate() != null) { reviewDate = new DateField(TRANSLATOR.translate("review.date")); reviewDate.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal()); reviewDate.setResolution(Resolution.SECOND); reviewDate.setValue(getExecutionStep().getReviewDate()); reviewDate.setReadOnly(true); layout.addComponent(reviewDate); } if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { TextArea expectedResult = new TextArea(TRANSLATOR.translate("expected.result")); expectedResult.setConverter(new ByteToStringConverter()); binder.bind(expectedResult, "expectedResult"); expectedResult.setSizeFull(); layout.addComponent(expectedResult); } //Add the fields fields.clear(); getExecutionStep().getStep().getDataEntryList().forEach(de -> { switch (de.getDataEntryType().getId()) { case 1://String TextField tf = new TextField(TRANSLATOR.translate(de.getEntryName())); tf.setRequired(true); tf.setData(de.getEntryName()); if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { //Add expected result DataEntryProperty stringCase = DataEntryServer.getProperty(de, "property.match.case"); DataEntryProperty r = DataEntryServer.getProperty(de, "property.expected.result"); if (r != null && !r.getPropertyValue().equals("null")) { String error = TRANSLATOR.translate("expected.result") + ": " + r.getPropertyValue(); tf.setRequiredError(error); tf.setRequired(DataEntryServer.getProperty(de, "property.required").getPropertyValue() .equals("true")); tf.addValidator((Object val) -> { //We have an expected result and a match case requirement if (stringCase != null && stringCase.getPropertyValue().equals("true") ? !((String) val).equals(r.getPropertyValue()) : !((String) val).equalsIgnoreCase(r.getPropertyValue())) { throw new InvalidValueException(error); } }); } } fields.add(tf); //Set value if already recorded updateValue(tf); layout.addComponent(tf); break; case 2://Numeric NumberField field = new NumberField(TRANSLATOR.translate(de.getEntryName())); field.setSigned(true); field.setUseGrouping(true); field.setGroupingSeparator(','); field.setDecimalSeparator('.'); field.setConverter(new StringToDoubleConverter()); field.setRequired( DataEntryServer.getProperty(de, "property.required").getPropertyValue().equals("true")); field.setData(de.getEntryName()); Double min = null, max = null; for (DataEntryProperty prop : de.getDataEntryPropertyList()) { String value = prop.getPropertyValue(); if (prop.getPropertyName().equals("property.max")) { try { max = Double.parseDouble(value); } catch (NumberFormatException ex) { //Leave as null } } else if (prop.getPropertyName().equals("property.min")) { try { min = Double.parseDouble(value); } catch (NumberFormatException ex) { //Leave as null } } } //Add expected result if (VMSettingServer.getSetting("show.expected.result").getBoolVal() && (min != null || max != null)) { String error = TRANSLATOR.translate("error.out.of.range") + " " + (min == null ? " " : (TRANSLATOR.translate("property.min") + ": " + min)) + " " + (max == null ? "" : (TRANSLATOR.translate("property.max") + ": " + max)); field.setRequiredError(error); field.addValidator(new DoubleRangeValidator(error, min, max)); } fields.add(field); //Set value if already recorded updateValue(field); layout.addComponent(field); break; case 3://Boolean CheckBox cb = new CheckBox(TRANSLATOR.translate(de.getEntryName())); cb.setData(de.getEntryName()); cb.setRequired( DataEntryServer.getProperty(de, "property.required").getPropertyValue().equals("true")); if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { DataEntryProperty r = DataEntryServer.getProperty(de, "property.expected.result"); if (r != null) { //Add expected result String error = TRANSLATOR.translate("expected.result") + ": " + r.getPropertyValue(); cb.addValidator((Object val) -> { if (!val.toString().equals(r.getPropertyValue())) { throw new InvalidValueException(error); } }); } } fields.add(cb); //Set value if already recorded updateValue(cb); layout.addComponent(cb); break; case 4://Attachment Label l = new Label(TRANSLATOR.translate(de.getEntryName())); layout.addComponent(l); break; default: LOG.log(Level.SEVERE, "Unexpected field type: {0}", de.getDataEntryType().getId()); } }); //Add the Attachments HorizontalLayout attachments = new HorizontalLayout(); attachments.setCaption(TRANSLATOR.translate("general.attachment")); HorizontalLayout comments = new HorizontalLayout(); comments.setCaption(TRANSLATOR.translate("general.comments")); HorizontalLayout issues = new HorizontalLayout(); issues.setCaption(TRANSLATOR.translate("general.issue")); int commentCounter = 0; int issueCounter = 0; for (ExecutionStepHasIssue ei : getExecutionStep().getExecutionStepHasIssueList()) { issueCounter++; Button a = new Button("Issue #" + issueCounter); a.setIcon(VaadinIcons.BUG); a.addClickListener((Button.ClickEvent event) -> { displayIssue(new IssueServer(ei.getIssue())); }); a.setEnabled(!step.getLocked()); issues.addComponent(a); } for (ExecutionStepHasAttachment attachment : getExecutionStep().getExecutionStepHasAttachmentList()) { switch (attachment.getAttachment().getAttachmentType().getType()) { case "comment": { //Comments go in a different section commentCounter++; Button a = new Button("Comment #" + commentCounter); a.setIcon(VaadinIcons.CLIPBOARD_TEXT); a.addClickListener((Button.ClickEvent event) -> { if (!step.getLocked()) { //Prompt if user wants this removed MessageBox mb = getDeletionPrompt(attachment); mb.open(); } else { displayComment(new AttachmentServer(attachment.getAttachment().getAttachmentPK())); } }); a.setEnabled(!step.getLocked()); comments.addComponent(a); break; } default: { Button a = new Button(attachment.getAttachment().getFileName()); a.setEnabled(!step.getLocked()); a.setIcon(VaadinIcons.PAPERCLIP); a.addClickListener((Button.ClickEvent event) -> { if (!step.getLocked()) { //Prompt if user wants this removed MessageBox mb = getDeletionPrompt(attachment); mb.open(); } else { displayAttachment(new AttachmentServer(attachment.getAttachment().getAttachmentPK())); } }); attachments.addComponent(a); break; } } } if (attachments.getComponentCount() > 0) { layout.addComponent(attachments); } if (comments.getComponentCount() > 0) { layout.addComponent(comments); } if (issues.getComponentCount() > 0) { layout.addComponent(issues); } //Add the menu HorizontalLayout hl = new HorizontalLayout(); attach = new Button(TRANSLATOR.translate("add.attachment")); attach.setIcon(VaadinIcons.PAPERCLIP); attach.addClickListener((Button.ClickEvent event) -> { //Show dialog to upload file. Window dialog = new VMWindow(TRANSLATOR.translate("attach.file")); VerticalLayout vl = new VerticalLayout(); MultiFileUpload multiFileUpload = new MultiFileUpload() { @Override protected void handleFile(File file, String fileName, String mimeType, long length) { try { LOG.log(Level.FINE, "Received file {1} at: {0}", new Object[] { file.getAbsolutePath(), fileName }); //Process the file //Create the attachment AttachmentServer a = new AttachmentServer(); a.addFile(file, fileName); //Overwrite the default file name set in addFile. It'll be a temporary file name a.setFileName(fileName); a.write2DB(); //Now add it to this Execution Step if (getExecutionStep().getExecutionStepHasAttachmentList() == null) { getExecutionStep().setExecutionStepHasAttachmentList(new ArrayList<>()); } getExecutionStep().addAttachment(a); getExecutionStep().write2DB(); w.updateCurrentStep(); } catch (Exception ex) { LOG.log(Level.SEVERE, "Error creating attachment!", ex); } } }; multiFileUpload.setCaption(TRANSLATOR.translate("select.files.attach")); vl.addComponent(multiFileUpload); dialog.setContent(vl); dialog.setHeight(25, Sizeable.Unit.PERCENTAGE); dialog.setWidth(25, Sizeable.Unit.PERCENTAGE); ValidationManagerUI.getInstance().addWindow(dialog); }); hl.addComponent(attach); bug = new Button(TRANSLATOR.translate("create.issue")); bug.setIcon(VaadinIcons.BUG); bug.addClickListener((Button.ClickEvent event) -> { displayIssue(new IssueServer()); }); hl.addComponent(bug); comment = new Button(TRANSLATOR.translate("add.comment")); comment.setIcon(VaadinIcons.CLIPBOARD_TEXT); comment.addClickListener((Button.ClickEvent event) -> { AttachmentServer as = new AttachmentServer(); //Get comment type AttachmentType type = AttachmentTypeServer.getTypeForExtension("comment"); as.setAttachmentType(type); displayComment(as); }); hl.addComponent(comment); step.update(); attach.setEnabled(!step.getLocked()); bug.setEnabled(!step.getLocked()); comment.setEnabled(!step.getLocked()); result.setEnabled(!step.getLocked()); layout.addComponent(hl); return layout; }