List of usage examples for com.vaadin.ui Button setWidth
@Override public void setWidth(float width, Unit unit)
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// w ww .java2s .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:net.sourceforge.javydreamercsw.validation.manager.web.workflow.WorkflowViewer.java
License:Apache License
private Component getControls() { VerticalLayout controls = new VerticalLayout(); Button addStep = new Button(TRANSLATOR.translate("general.add.step")); VerticalLayout vl = new VerticalLayout(); TextField name = new TextField(TRANSLATOR.translate("general.name")); vl.addComponent(name);// ww w.j a v a2s.c om addStep.addClickListener(listener -> { MessageBox prompt = MessageBox.createQuestion().withCaption(TRANSLATOR.translate("general.add.step")) .withMessage(vl).withYesButton(() -> { if (name.getValue() != null && !name.getValue().isEmpty()) { Graph.Node node = new Graph.Node(TRANSLATOR.translate(name.getValue())); nodes.put(--count, node); node.setParam(KEY, "" + count); node.setParam(ITEM_NAME, TRANSLATOR.translate(name.getValue())); added.add(node); refreshWorkflow(); } }, ButtonOption.focus(), ButtonOption.icon(VaadinIcons.CHECK)) .withNoButton(ButtonOption.icon(VaadinIcons.CLOSE)); prompt.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); prompt.open(); }); addStep.setWidth(100, Unit.PERCENTAGE); addStep.setEnabled(workflows.getValue() != null); controls.addComponent(addStep); Button addTransition = new Button(TRANSLATOR.translate("general.add.transition")); VerticalLayout vl2 = new VerticalLayout(); TextField transitionName = new TextField(TRANSLATOR.translate("general.name")); ListSelect nodeList = new ListSelect(TRANSLATOR.translate("general.step")); BeanItemContainer<Graph.Node> container = new BeanItemContainer<>(Graph.Node.class, nodes.values()); nodeList.setContainerDataSource(container); nodeList.getItemIds().forEach(id -> { Graph.Node temp = ((Graph.Node) id); nodeList.setItemCaption(id, temp.getId()); }); nodeList.setNullSelectionAllowed(false); vl2.addComponent(transitionName); vl2.addComponent(nodeList); addTransition.addClickListener(listener -> { MessageBox prompt = MessageBox.createQuestion() .withCaption(TRANSLATOR.translate("general.add.transition")).withMessage(vl2) .withYesButton(() -> { if (transitionName.getValue() != null && !transitionName.getValue().isEmpty() && selected instanceof Subgraph.Node) { Subgraph.Edge edge = new Subgraph.Edge(); edge.setDest((Subgraph.Node) nodeList.getValue()); edges.put(transitionName.getValue(), new AbstractMap.SimpleEntry<>((Subgraph.Node) selected, edge)); edge.setParam(KEY, "" + --count); added.add(edge); refreshWorkflow(); } }, ButtonOption.focus(), ButtonOption.icon(VaadinIcons.CHECK)) .withNoButton(ButtonOption.icon(VaadinIcons.CLOSE)); prompt.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); prompt.open(); }); addTransition.setWidth(100, Unit.PERCENTAGE); addTransition.setEnabled(selected instanceof Subgraph.Node); controls.addComponent(addTransition); Button delete = new Button(TRANSLATOR.translate("general.delete")); delete.setEnabled(selected != null); delete.setWidth(100, Unit.PERCENTAGE); delete.addClickListener(listener -> { MessageBox prompt = MessageBox.createQuestion().withCaption(TRANSLATOR.translate("general.delete")) .withMessage(TRANSLATOR.translate("general.delete.confirmation")).withYesButton(() -> { if (selected instanceof Subgraph.Edge) { Subgraph.Edge edge = (Subgraph.Edge) selected; edges.remove(edge.getParam("label")); addToDelete(edge); } else { Graph.Node node = (Graph.Node) selected; addToDelete(node); } refreshWorkflow(); }, ButtonOption.focus(), ButtonOption.icon(VaadinIcons.CHECK)) .withNoButton(ButtonOption.icon(VaadinIcons.CLOSE)); prompt.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); prompt.open(); }); controls.addComponent(delete); Button rename = new Button(TRANSLATOR.translate("general.rename")); rename.setWidth(100, Unit.PERCENTAGE); rename.setEnabled(selected != null); rename.addClickListener(listener -> { Window w = new VMWindow(TRANSLATOR.translate("general.rename")); w.setWidth(25, Unit.PERCENTAGE); w.setHeight(25, Unit.PERCENTAGE); UI.getCurrent().addWindow(w); }); controls.addComponent(rename); Button save = new Button(TRANSLATOR.translate("general.save")); save.setWidth(100, Unit.PERCENTAGE); save.setEnabled(!added.isEmpty() || !deleted.isEmpty()); save.addClickListener(listener -> { List<Graph.Node> nodesToAdd = new ArrayList<>(); List<Subgraph.Edge> edgesToAdd = new ArrayList<>(); WorkflowServer ws = new WorkflowServer(((Workflow) workflows.getValue()).getId()); added.forEach(a -> { if (a instanceof Graph.Node) { nodesToAdd.add((Graph.Node) a); } else if (a instanceof Subgraph.Edge) { edgesToAdd.add((Subgraph.Edge) a); } }); deleted.forEach(a -> { LOG.log(Level.INFO, "Deleted: {0}", a); }); nodesToAdd.forEach(node -> { try { ws.addStep(node.getParam(ITEM_NAME)); } catch (VMException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage(), ex); } }); displayWorkflow(ws.getEntity()); }); controls.addComponent(save); Button cancel = new Button(TRANSLATOR.translate("general.cancel")); cancel.setWidth(100, Unit.PERCENTAGE); cancel.setEnabled(selected != null); cancel.addClickListener(listener -> { Workflow w = (Workflow) workflows.getValue(); if (w != null) { displayWorkflow(w); } deleted.clear(); added.clear(); }); controls.addComponent(cancel); return controls; }
From source file:org.activiti.explorer.ui.mainlayout.MainMenuBar.java
License:Apache License
protected Button addMenuButton(String type, String label, Resource icon, boolean active, float width) { Button button = new Button(label); button.addStyleName(type);// w w w . ja va2s. c o m button.addStyleName(ExplorerLayout.STYLE_MAIN_MENU_BUTTON); button.addStyleName(Reindeer.BUTTON_LINK); button.setHeight(54, UNITS_PIXELS); button.setIcon(icon); button.setWidth(width, UNITS_PIXELS); addComponent(button); setComponentAlignment(button, Alignment.TOP_CENTER); return button; }
From source file:org.activiti.kickstart.ui.MainMenuBar.java
License:Apache License
protected Button addMenuButton(String label, Resource icon, boolean active, float width) { Button button = new Button(label); button.addStyleName(STYLE_MAIN_MENU_BUTTON); button.addStyleName(Reindeer.BUTTON_LINK); button.setHeight(54, UNITS_PIXELS);// w w w. j a va 2 s. co m button.setIcon(icon); button.setWidth(width, UNITS_PIXELS); addComponent(button); setComponentAlignment(button, Alignment.TOP_CENTER); return button; }
From source file:org.inakirj.imagerulette.screens.DicePlayView.java
License:Open Source License
/** * Sets the layout.// www .j a v a 2s .c o m */ private void setLayout() { mainLayout = new VerticalLayout(); mainLayout.setWidth(100, Unit.PERCENTAGE); FileResource resource = new FileResource(new File( VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "/WEB-INF/image/nope.png")); Image none = new Image("", resource); randomImgToBeReplaced = none; randomImgToBeReplaced.setWidth(78, Unit.PIXELS); randomImgToBeReplaced.setHeight(81, Unit.PIXELS); randomImgToBeReplaced.addStyleName("random-image"); imageLayout = new HorizontalLayout(); imageLayout.addComponent(randomImgToBeReplaced); imageLayout.setWidth(100, Unit.PERCENTAGE); imageLayout.setComponentAlignment(randomImgToBeReplaced, Alignment.TOP_CENTER); Button rollBtn = new Button(); rollBtn.addClickListener(e -> onPickABallClick()); rollBtn.setWidth(25, Unit.PERCENTAGE); rollBtn.setHeight(50, Unit.PIXELS); rollBtn.setIcon(FontAwesome.CUBE); rollBtn.addStyleName("dice-button-roll"); mainLayout.addComponent(imageLayout); mainLayout.addComponent(rollBtn); mainLayout.setComponentAlignment(rollBtn, Alignment.BOTTOM_CENTER); calculateStats(); addComponent(mainLayout); }
From source file:org.lucidj.ui.gauss.GaussUI.java
License:Apache License
private void add_smart_tab(VerticalLayout container, String caption, Component contents) { String style_expanded = "ui-panel-caption-expanded"; // Every panel is a glorified button disguised as accordion tab... final Button caption_button = new Button(caption); caption_button.setWidth(100, Unit.PERCENTAGE); container.addComponent(caption_button); caption_button.addStyleName("ui-panel-caption"); caption_button.addStyleName(style_expanded); // ... with a panel for the contents and selective hide/show final Panel content_panel = new Panel(); content_panel.setWidth(100, Unit.PERCENTAGE); content_panel.setContent(contents);//from w w w. j av a 2 s . c o m content_panel.addStyleName("ui-panel-contents"); content_panel.addStyleName(ValoTheme.PANEL_BORDERLESS); container.addComponent(content_panel); caption_button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { if (content_panel.isVisible()) { content_panel.setVisible(false); caption_button.removeStyleName(style_expanded); } else { content_panel.setVisible(true); caption_button.addStyleName(style_expanded); } } }); }
From source file:org.lucidj.ui.gauss.GaussUI.java
License:Apache License
private void initToolbarArea() { hToolbarArea.setStyleName("ui-toolbar-area"); hToolbarArea.setSizeUndefined();//from w w w . j a v a2 s . c o m hToolbarArea.setWidth("100%"); CssLayout home_buttons = new CssLayout(); home_buttons.setStyleName("ui-toolbar-area-home"); home_buttons.setWidth(get_default_left_panel_width(), Sizeable.Unit.PIXELS); home_buttons.setId("_home_buttons"); final Button toggle_menu = new Button(); toggle_menu.setWidth(3, Unit.EM); toggle_menu.setIcon(FontAwesome.CHEVRON_DOWN); toggle_menu.addStyleName("tiny"); toggle_menu.addStyleName("link"); toggle_menu.addStyleName("ui-toolbar-spacer"); toggle_menu.addStyleName("ui-toggle-button"); toggle_menu.setId("_toggle_menu"); home_buttons.addComponent(toggle_menu); toggle_menu.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { if (!hsMenuContents.isLocked()) { default_left_panel_width_px = (int) hsMenuContents.getSplitPosition(); acMenu.setVisible(false); hsMenuContents.setMinSplitPosition(0, Unit.PIXELS); hsMenuContents.setSplitPosition(0, Sizeable.Unit.PIXELS); toggle_menu.setIcon(FontAwesome.CHEVRON_RIGHT); hsMenuContents.setLocked(true); } else { hsMenuContents.setLocked(false); acMenu.setVisible(true); hsMenuContents.setMinSplitPosition(MIN_LEFT_PANEL_WIDTH_PX, Unit.PIXELS); hsMenuContents.setSplitPosition(get_default_left_panel_width(), Unit.PIXELS); toggle_menu.setIcon(FontAwesome.CHEVRON_DOWN); } } }); final Button home = new Button("Home"); home.setIcon(FontAwesome.HOME); home.addStyleName("tiny"); home.addStyleName("ui-toolbar-spacer"); home.addStyleName("ui-toggle-button"); home.setId("_home"); home_buttons.addComponent(home); home.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { navigator.navigateTo("home"); } }); final Button new_button = new Button("New"); new_button.setIcon(FontAwesome.EDIT); new_button.addStyleName("tiny"); new_button.addStyleName("primary"); new_button.addStyleName("ui-toggle-button"); new_button.setId("_new"); home_buttons.addComponent(new_button); new_button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { navigator.navigateTo("new"); } }); hToolbarArea.addComponent(home_buttons); hToolbarPlaceholder = new CssLayout(); hToolbarPlaceholder.setSizeFull(); hToolbarArea.addComponent(hToolbarPlaceholder); hToolbarArea.setExpandRatio(hToolbarPlaceholder, 1.0f); final Button eject_view = new Button(); eject_view.setIcon(FontAwesome.EXTERNAL_LINK); eject_view.addStyleName("tiny"); eject_view.addStyleName("link"); eject_view.addStyleName("ui-toggle-button"); eject_view.setId("_eject_view"); hToolbarArea.addComponent(eject_view); eject_view.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { Notification.show("Not implemented", Notification.Type.HUMANIZED_MESSAGE); } }); toggle_sidebar = new Button(); toggle_sidebar.setWidth(3, Unit.EM); toggle_sidebar.addStyleName("tiny"); toggle_sidebar.addStyleName("link"); toggle_sidebar.addStyleName("ui-toolbar-spacer"); toggle_sidebar.addStyleName("ui-toggle-button"); toggle_sidebar.setId("_toggle_sidebar"); hToolbarArea.addComponent(toggle_sidebar); toggle_sidebar.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { show_sidebar(!sidebar_visible()); } }); }
From source file:org.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceEditWindow.java
License:Open Source License
/** * Constructor/* w w w. ja va 2 s .co m*/ * * @param businessService the Business Service DTO instance to be configured */ @SuppressWarnings("unchecked") public BusinessServiceEditWindow(BusinessService businessService, BusinessServiceManager businessServiceManager) { /** * set window title... */ super("Business Service Edit"); m_businessService = businessService; /** * ...and basic properties */ setModal(true); setClosable(false); setResizable(false); setWidth(650, Unit.PIXELS); setHeight(550, Unit.PIXELS); /** * create set for Business Service names */ m_businessServiceNames = businessServiceManager.getAllBusinessServices().stream() .map(BusinessService::getName).collect(Collectors.toSet()); if (m_businessService.getName() != null) { m_businessServiceNames.remove(m_businessService.getName()); } /** * construct the main layout */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull(); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); /** * add saveBusinessService button */ Button saveButton = new Button("Save"); saveButton.setId("saveButton"); saveButton.addClickListener( UIHelper.getCurrent(TransactionAwareUI.class).wrapInTransactionProxy(new Button.ClickListener() { private static final long serialVersionUID = -5985304347211214365L; @Override public void buttonClick(Button.ClickEvent event) { if (!m_thresholdTextField.isValid() || !m_nameTextField.isValid()) { return; } final ReductionFunction reductionFunction = getReduceFunction(); businessService.setName(m_nameTextField.getValue().trim()); businessService.setReduceFunction(reductionFunction); businessService.save(); close(); } private ReductionFunction getReduceFunction() { try { final ReductionFunction reductionFunction = ((Class<? extends ReductionFunction>) m_reduceFunctionNativeSelect .getValue()).newInstance(); reductionFunction.accept(new ReduceFunctionVisitor<Void>() { @Override public Void visit(HighestSeverity highestSeverity) { return null; } @Override public Void visit(HighestSeverityAbove highestSeverityAbove) { highestSeverityAbove.setThreshold((Status) m_thresholdStatusSelect.getValue()); return null; } @Override public Void visit(Threshold threshold) { threshold.setThreshold(Float.parseFloat(m_thresholdTextField.getValue())); return null; } }); return reductionFunction; } catch (final InstantiationException | IllegalAccessException e) { throw Throwables.propagate(e); } } })); /** * add the cancel button */ Button cancelButton = new Button("Cancel"); cancelButton.setId("cancelButton"); cancelButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 5306168797758047745L; @Override public void buttonClick(Button.ClickEvent event) { close(); } }); /** * add the buttons to a HorizontalLayout */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.addComponent(saveButton); buttonLayout.addComponent(cancelButton); /** * instantiate the input fields */ m_nameTextField = new TextField("Business Service Name"); m_nameTextField.setId("nameField"); m_nameTextField.setNullRepresentation(""); m_nameTextField.setNullSettingAllowed(true); m_nameTextField.setValue(businessService.getName()); m_nameTextField.setWidth(100, Unit.PERCENTAGE); m_nameTextField.setRequired(true); m_nameTextField.focus(); m_nameTextField.addValidator(new AbstractStringValidator("Name must be unique") { private static final long serialVersionUID = 1L; @Override protected boolean isValidValue(String value) { return value != null && !m_businessServiceNames.contains(value); } }); verticalLayout.addComponent(m_nameTextField); /** * create the reduce function component */ m_reduceFunctionNativeSelect = new NativeSelect("Reduce Function", ImmutableList.builder() .add(HighestSeverity.class).add(Threshold.class).add(HighestSeverityAbove.class).build()); m_reduceFunctionNativeSelect.setId("reduceFunctionNativeSelect"); m_reduceFunctionNativeSelect.setWidth(100.0f, Unit.PERCENTAGE); m_reduceFunctionNativeSelect.setNullSelectionAllowed(false); m_reduceFunctionNativeSelect.setMultiSelect(false); m_reduceFunctionNativeSelect.setImmediate(true); m_reduceFunctionNativeSelect.setNewItemsAllowed(false); /** * setting the captions for items */ m_reduceFunctionNativeSelect.getItemIds().forEach( itemId -> m_reduceFunctionNativeSelect.setItemCaption(itemId, ((Class<?>) itemId).getSimpleName())); verticalLayout.addComponent(m_reduceFunctionNativeSelect); m_thresholdTextField = new TextField("Threshold"); m_thresholdTextField.setId("thresholdTextField"); m_thresholdTextField.setRequired(false); m_thresholdTextField.setEnabled(false); m_thresholdTextField.setImmediate(true); m_thresholdTextField.setWidth(100.0f, Unit.PERCENTAGE); m_thresholdTextField.setValue("0.0"); m_thresholdTextField.addValidator(v -> { if (m_thresholdTextField.isEnabled()) { try { final float value = Float.parseFloat(m_thresholdTextField.getValue()); if (0.0f >= value || value > 1.0) { throw new NumberFormatException(); } } catch (final NumberFormatException e) { throw new Validator.InvalidValueException("Threshold must be a positive number"); } } }); verticalLayout.addComponent(m_thresholdTextField); /** * Status selection for "Highest Severity Above" */ m_thresholdStatusSelect = new NativeSelect("Threshold"); m_thresholdStatusSelect.setId("thresholdStatusSelect"); m_thresholdStatusSelect.setRequired(false); m_thresholdStatusSelect.setEnabled(false); m_thresholdStatusSelect.setImmediate(true); m_thresholdStatusSelect.setWidth(100.0f, Unit.PERCENTAGE); m_thresholdStatusSelect.setMultiSelect(false); m_thresholdStatusSelect.setNewItemsAllowed(false); m_thresholdStatusSelect.setNullSelectionAllowed(false); for (Status eachStatus : Status.values()) { m_thresholdStatusSelect.addItem(eachStatus); } m_thresholdStatusSelect.setValue(Status.INDETERMINATE); m_thresholdStatusSelect.getItemIds() .forEach(itemId -> m_thresholdStatusSelect.setItemCaption(itemId, ((Status) itemId).getLabel())); verticalLayout.addComponent(m_thresholdStatusSelect); m_reduceFunctionNativeSelect.addValueChangeListener(ev -> { boolean thresholdFunction = m_reduceFunctionNativeSelect.getValue() == Threshold.class; boolean highestSeverityAboveFunction = m_reduceFunctionNativeSelect .getValue() == HighestSeverityAbove.class; setVisible(m_thresholdTextField, thresholdFunction); setVisible(m_thresholdStatusSelect, highestSeverityAboveFunction); }); if (Objects.isNull(businessService.getReduceFunction())) { m_reduceFunctionNativeSelect.setValue(HighestSeverity.class); } else { m_reduceFunctionNativeSelect.setValue(businessService.getReduceFunction().getClass()); businessService.getReduceFunction().accept(new ReduceFunctionVisitor<Void>() { @Override public Void visit(HighestSeverity highestSeverity) { return null; } @Override public Void visit(HighestSeverityAbove highestSeverityAbove) { m_thresholdStatusSelect.setValue(highestSeverityAbove.getThreshold()); return null; } @Override public Void visit(Threshold threshold) { m_thresholdTextField.setValue(String.valueOf(threshold.getThreshold())); return null; } }); } /** * create the edges list box */ m_edgesListSelect = new ListSelect("Edges"); m_edgesListSelect.setId("edgeList"); m_edgesListSelect.setWidth(100.0f, Unit.PERCENTAGE); m_edgesListSelect.setRows(10); m_edgesListSelect.setNullSelectionAllowed(false); m_edgesListSelect.setMultiSelect(false); refreshEdges(); HorizontalLayout edgesListAndButtonLayout = new HorizontalLayout(); edgesListAndButtonLayout.setWidth(100.0f, Unit.PERCENTAGE); VerticalLayout edgesButtonLayout = new VerticalLayout(); edgesButtonLayout.setWidth(110.0f, Unit.PIXELS); edgesButtonLayout.setSpacing(true); Button addEdgeButton = new Button("Add Edge"); addEdgeButton.setId("addEdgeButton"); addEdgeButton.setWidth(110.0f, Unit.PIXELS); addEdgeButton.addStyleName("small"); edgesButtonLayout.addComponent(addEdgeButton); addEdgeButton.addClickListener((Button.ClickListener) event -> { final BusinessServiceEdgeEditWindow window = new BusinessServiceEdgeEditWindow(businessService, businessServiceManager, null); window.addCloseListener(e -> refreshEdges()); this.getUI().addWindow(window); }); Button editEdgeButton = new Button("Edit Edge"); editEdgeButton.setId("editEdgeButton"); editEdgeButton.setEnabled(false); editEdgeButton.setWidth(110.0f, Unit.PIXELS); editEdgeButton.addStyleName("small"); edgesButtonLayout.addComponent(editEdgeButton); editEdgeButton.addClickListener((Button.ClickListener) event -> { final BusinessServiceEdgeEditWindow window = new BusinessServiceEdgeEditWindow(businessService, businessServiceManager, (Edge) m_edgesListSelect.getValue()); window.addCloseListener(e -> refreshEdges()); this.getUI().addWindow(window); }); final Button removeEdgeButton = new Button("Remove Edge"); removeEdgeButton.setId("removeEdgeButton"); removeEdgeButton.setEnabled(false); removeEdgeButton.setWidth(110.0f, Unit.PIXELS); removeEdgeButton.addStyleName("small"); edgesButtonLayout.addComponent(removeEdgeButton); m_edgesListSelect.addValueChangeListener((Property.ValueChangeListener) event -> { removeEdgeButton.setEnabled(event.getProperty().getValue() != null); editEdgeButton.setEnabled(event.getProperty().getValue() != null); }); removeEdgeButton.addClickListener((Button.ClickListener) event -> { if (m_edgesListSelect.getValue() != null) { removeEdgeButton.setEnabled(false); ((Edge) m_edgesListSelect.getValue()).delete(); refreshEdges(); } }); edgesListAndButtonLayout.setSpacing(true); edgesListAndButtonLayout.addComponent(m_edgesListSelect); edgesListAndButtonLayout.setExpandRatio(m_edgesListSelect, 1.0f); edgesListAndButtonLayout.addComponent(edgesButtonLayout); edgesListAndButtonLayout.setComponentAlignment(edgesButtonLayout, Alignment.BOTTOM_CENTER); verticalLayout.addComponent(edgesListAndButtonLayout); /** * create the attributes list box */ m_attributesListSelect = new ListSelect("Attributes"); m_attributesListSelect.setId("attributeList"); m_attributesListSelect.setWidth(100.0f, Unit.PERCENTAGE); m_attributesListSelect.setRows(10); m_attributesListSelect.setNullSelectionAllowed(false); m_attributesListSelect.setMultiSelect(false); refreshAttributes(); HorizontalLayout attributesListAndButtonLayout = new HorizontalLayout(); attributesListAndButtonLayout.setWidth(100.0f, Unit.PERCENTAGE); VerticalLayout attributesButtonLayout = new VerticalLayout(); attributesButtonLayout.setWidth(110.0f, Unit.PIXELS); attributesButtonLayout.setSpacing(true); Button addAttributeButton = new Button("Add Attribute"); addAttributeButton.setId("addAttributeButton"); addAttributeButton.setWidth(110.0f, Unit.PIXELS); addAttributeButton.addStyleName("small"); attributesButtonLayout.addComponent(addAttributeButton); addAttributeButton.addClickListener((Button.ClickListener) event -> { KeyValueInputDialogWindow keyValueInputDialogWindow = new KeyValueInputDialogWindow() .withKeyFieldName("Key").withValueFieldName("Value").withCaption("Attribute").withKey("") .withValue("").withOkAction(new KeyValueInputDialogWindow.Action() { @Override public void execute(KeyValueInputDialogWindow window) { m_businessService.getAttributes().put(window.getKey(), window.getValue()); refreshAttributes(); } }).withKeyValidator(new AbstractStringValidator("Key must not be empty") { private static final long serialVersionUID = 1L; @Override protected boolean isValidValue(String value) { return !Strings.isNullOrEmpty(value); } }).withKeyValidator(new AbstractStringValidator("Key must be unique") { private static final long serialVersionUID = 1L; @Override protected boolean isValidValue(String value) { return !m_businessService.getAttributes().containsKey(value); } }).focusKey(); this.getUI().addWindow(keyValueInputDialogWindow); keyValueInputDialogWindow.focus(); }); Button editAttributeButton = new Button("Edit Attribute"); editAttributeButton.setId("editAttributeButton"); editAttributeButton.setEnabled(false); editAttributeButton.setWidth(110.0f, Unit.PIXELS); editAttributeButton.addStyleName("small"); attributesButtonLayout.addComponent(editAttributeButton); editAttributeButton.addClickListener((Button.ClickListener) event -> { Map.Entry<String, String> entry = (Map.Entry<String, String>) m_attributesListSelect.getValue(); KeyValueInputDialogWindow keyValueInputDialogWindow = new KeyValueInputDialogWindow() .withKeyFieldName("Key").withValueFieldName("Value").withCaption("Attribute") .withKey(entry.getKey()).disableKey().withValue(entry.getValue()) .withOkAction(new KeyValueInputDialogWindow.Action() { @Override public void execute(KeyValueInputDialogWindow window) { m_businessService.getAttributes().put(window.getKey(), window.getValue()); refreshAttributes(); } }).focusValue(); this.getUI().addWindow(keyValueInputDialogWindow); keyValueInputDialogWindow.focus(); }); final Button removeAttributeButton = new Button("Remove Attribute"); removeAttributeButton.setId("removeAttributeButton"); removeAttributeButton.setEnabled(false); removeAttributeButton.setWidth(110.0f, Unit.PIXELS); removeAttributeButton.addStyleName("small"); attributesButtonLayout.addComponent(removeAttributeButton); m_attributesListSelect.addValueChangeListener((Property.ValueChangeListener) event -> { removeAttributeButton.setEnabled(event.getProperty().getValue() != null); editAttributeButton.setEnabled(event.getProperty().getValue() != null); }); removeAttributeButton.addClickListener((Button.ClickListener) event -> { if (m_attributesListSelect.getValue() != null) { removeAttributeButton.setEnabled(false); m_businessService.getAttributes() .remove(((Map.Entry<String, String>) m_attributesListSelect.getValue()).getKey()); refreshAttributes(); } }); attributesListAndButtonLayout.setSpacing(true); attributesListAndButtonLayout.addComponent(m_attributesListSelect); attributesListAndButtonLayout.setExpandRatio(m_attributesListSelect, 1.0f); attributesListAndButtonLayout.addComponent(attributesButtonLayout); attributesListAndButtonLayout.setComponentAlignment(attributesButtonLayout, Alignment.BOTTOM_CENTER); verticalLayout.addComponent(attributesListAndButtonLayout); /** * now add the button layout to the main layout */ verticalLayout.addComponent(buttonLayout); verticalLayout.setExpandRatio(buttonLayout, 1.0f); verticalLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT); /** * set the window's content */ setContent(verticalLayout); }
From source file:org.sensorhub.ui.AdminUI.java
License:Mozilla Public License
protected Component buildToolbar() { HorizontalLayout toolbar = new HorizontalLayout(); toolbar.setWidth(100.0f, Unit.PERCENTAGE); // apply changes button Button saveButton = new Button("Save Config"); saveButton.setDescription("Save Config"); saveButton.setIcon(UIConstants.APPLY_ICON); saveButton.addStyleName(UIConstants.STYLE_SMALL); saveButton.setWidth(100.0f, Unit.PERCENTAGE); // apply button action saveButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { try { SensorHub.getInstance().getModuleRegistry().saveModulesConfiguration(); } catch (Exception e) { AdminUI.log.error("Error while saving SensorHub configuration", e); Notification.show("Error", e.getMessage(), Notification.Type.ERROR_MESSAGE); }//from w ww . j a v a 2s. c om } }); toolbar.addComponent(saveButton); return toolbar; }
From source file:org.vaadin.addons.sitekit.viewlet.administrator.company.CompaniesFlowlet.java
License:Apache License
@Override public void initialize() { entityManager = getSite().getSiteContext().getObject(EntityManager.class); gridLayout = new GridLayout(1, 2); gridLayout.setSizeFull();//from w w w . j a v a 2 s. co m gridLayout.setMargin(false); gridLayout.setSpacing(true); gridLayout.setRowExpandRatio(1, 1f); setViewContent(gridLayout); final List<FieldDescriptor> fieldDefinitions = SiteFields.getFieldDescriptors(Company.class); final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>(); filterDefinitions.add(new FilterDescriptor("companyName", "companyName", "Company Name", new TextField(), 101, "=", String.class, "")); entityContainer = new EntityContainer<Company>(entityManager, true, false, false, Company.class, 1000, new String[] { "companyName" }, new boolean[] { false }, "companyId"); for (final FieldDescriptor fieldDefinition : fieldDefinitions) { entityContainer.addContainerProperty(fieldDefinition.getId(), fieldDefinition.getValueType(), fieldDefinition.getDefaultValue(), fieldDefinition.isReadOnly(), fieldDefinition.isSortable()); } final Table table = new Table(); entityGrid = new Grid(table, entityContainer); entityGrid.setFields(fieldDefinitions); entityGrid.setFilters(filterDefinitions); table.setColumnCollapsed("created", true); table.setColumnCollapsed("modified", true); table.setColumnCollapsed("company", true); table.setColumnCollapsed("emailPasswordReset", true); table.setColumnCollapsed("openIdLogin", true); table.setColumnCollapsed("maxFailedLoginCount", true); table.setColumnCollapsed("salesEmailAddress", true); table.setColumnCollapsed("supportEmailAddress", true); table.setColumnCollapsed("invoicingEmailAddress", true); gridLayout.addComponent(entityGrid, 0, 1); final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.setSizeUndefined(); gridLayout.addComponent(buttonLayout, 0, 0); final Button addButton = new Button("Add"); addButton.setIcon(getSite().getIcon("button-icon-add")); addButton.setWidth(100, UNITS_PIXELS); buttonLayout.addComponent(addButton); addButton.addListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { final Company company = new Company(); company.setCreated(new Date()); company.setModified(company.getCreated()); company.setInvoicingAddress(new PostalAddress()); company.setDeliveryAddress(new PostalAddress()); final CompanyFlowlet companyView = getFlow().forward(CompanyFlowlet.class); companyView.edit(company, true); } }); final Button editButton = new Button("Edit"); editButton.setIcon(getSite().getIcon("button-icon-edit")); editButton.setWidth(100, UNITS_PIXELS); buttonLayout.addComponent(editButton); editButton.addListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { final Company entity = entityContainer.getEntity(entityGrid.getSelectedItemId()); final CompanyFlowlet companyView = getFlow().forward(CompanyFlowlet.class); companyView.edit(entity, false); } }); final Button removeButton = new Button("Remove"); removeButton.setIcon(getSite().getIcon("button-icon-remove")); removeButton.setWidth(100, UNITS_PIXELS); buttonLayout.addComponent(removeButton); removeButton.addListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { entityContainer.removeItem(entityGrid.getSelectedItemId()); entityContainer.commit(); } }); }