List of usage examples for com.vaadin.ui Button setId
@Override public void setId(String id)
From source file:org.lucidj.ui.gauss.GaussUI.java
License:Apache License
private void initToolbarArea() { hToolbarArea.setStyleName("ui-toolbar-area"); hToolbarArea.setSizeUndefined();//from www . j av a 2 s. c om 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.opencms.ui.components.codemirror.CmsCodeMirror.java
License:Open Source License
/** * Registers the given buttons as the search and replace buttons.<p> * * @param search the search button/* w ww .ja v a 2 s .c o m*/ * @param replace the replace button */ public void registerSearchReplace(Button search, Button replace) { if (getState().m_enableSearchReplace) { throw new RuntimeException("Search/replace already registered."); } search.setId(HTML_ID_PREFIX + m_componentId + "-search"); replace.setId(HTML_ID_PREFIX + m_componentId + "-replace"); getState().m_enableSearchReplace = true; markAsDirty(); }
From source file:org.opencms.ui.components.codemirror.CmsCodeMirror.java
License:Open Source License
/** * Registers the given buttons as undo redo buttons.<p> * * @param undo the undo button/*from w w w . j a v a 2 s . c om*/ * @param redo the redo button */ public void registerUndoRedo(Button undo, Button redo) { if (getState().m_enableUndoRedo) { throw new RuntimeException("Undo/redo already registered."); } undo.setId(HTML_ID_PREFIX + m_componentId + "-undo"); redo.setId(HTML_ID_PREFIX + m_componentId + "-redo"); getState().m_enableUndoRedo = true; markAsDirty(); }
From source file:org.opennms.features.topology.app.internal.ui.ToolbarPanel.java
License:Open Source License
public ToolbarPanel(final ToolbarPanelController controller) { addStyleName(Styles.TOOLBAR);//from w w w . j ava2 s . c om this.layoutManager = controller.getLayoutManager(); final Property<Double> scale = controller.getScaleProperty(); final Boolean[] eyeClosed = new Boolean[] { false }; final Button showFocusVerticesBtn = new Button(); showFocusVerticesBtn.setIcon(FontAwesome.EYE); showFocusVerticesBtn.setDescription("Toggle Highlight Focus Nodes"); showFocusVerticesBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (eyeClosed[0]) { showFocusVerticesBtn.setIcon(FontAwesome.EYE); } else { showFocusVerticesBtn.setIcon(FontAwesome.EYE_SLASH); } eyeClosed[0] = !eyeClosed[0]; // toggle controller.toggleHighlightFocus(); } }); final Button magnifyBtn = new Button(); magnifyBtn.setIcon(FontAwesome.PLUS); magnifyBtn.setDescription("Magnify"); magnifyBtn.addClickListener( (Button.ClickListener) event -> scale.setValue(Math.min(1, scale.getValue() + 0.25))); final Button demagnifyBtn = new Button(); demagnifyBtn.setIcon(FontAwesome.MINUS); demagnifyBtn.setDescription("Demagnify"); demagnifyBtn.addClickListener( (Button.ClickListener) event -> scale.setValue(Math.max(0, scale.getValue() - 0.25))); m_szlOutBtn = new Button(); m_szlOutBtn.setId("szlOutBtn"); m_szlOutBtn.setIcon(FontAwesome.ANGLE_DOWN); m_szlOutBtn.setDescription("Decrease Semantic Zoom Level"); m_szlOutBtn.setEnabled(controller.getSemanticZoomLevel() > 0); m_szlOutBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { int szl = controller.getSemanticZoomLevel(); if (szl > 0) { setSemanticZoomLevel(controller, szl - 1); controller.saveHistory(); } } }); final Button szlInBtn = new Button(); szlInBtn.setId("szlInBtn"); szlInBtn.setIcon(FontAwesome.ANGLE_UP); szlInBtn.setDescription("Increase Semantic Zoom Level"); szlInBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { setSemanticZoomLevel(controller, controller.getSemanticZoomLevel() + 1); controller.saveHistory(); } }); m_zoomLevelLabel.setId("szlInputLabel"); m_panBtn = new Button(); m_panBtn.setIcon(FontAwesome.ARROWS); m_panBtn.setDescription("Pan Tool"); m_panBtn.addStyleName(Styles.SELECTED); m_selectBtn = new Button(); m_selectBtn.setIcon(IonicIcons.ANDROID_EXPAND); m_selectBtn.setDescription("Selection Tool"); m_selectBtn.setStyleName("toolbar-button"); m_selectBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { m_selectBtn.addStyleName(Styles.SELECTED); m_panBtn.removeStyleName(Styles.SELECTED); controller.setActiveTool(ActiveTool.select); } }); m_panBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { m_panBtn.addStyleName(Styles.SELECTED); m_selectBtn.removeStyleName(Styles.SELECTED); controller.setActiveTool(ActiveTool.pan); } }); Button showAllMapBtn = new Button(); showAllMapBtn.setId("showEntireMapBtn"); showAllMapBtn.setIcon(FontAwesome.GLOBE); showAllMapBtn.setDescription("Show Entire Map"); showAllMapBtn.addClickListener((Button.ClickListener) event -> controller.showAllMap()); Button centerSelectionBtn = new Button(); centerSelectionBtn.setIcon(FontAwesome.LOCATION_ARROW); centerSelectionBtn.setDescription("Center On Selection"); centerSelectionBtn.addClickListener((Button.ClickListener) event -> controller.centerMapOnSelection()); Button shareButton = new Button("", FontAwesome.SHARE_SQUARE_O); shareButton.setDescription("Share"); shareButton.addClickListener((x) -> { // Create the share link String fragment = getUI().getPage().getLocation().getFragment(); String url = getUI().getPage().getLocation().toString().replace("#" + fragment, ""); String shareLink = String.format("%s?%s=%s", url, PARAMETER_HISTORY_FRAGMENT, fragment); // Create the Window Window shareWindow = new Window(); shareWindow.setCaption("Share Link"); shareWindow.setModal(true); shareWindow.setClosable(true); shareWindow.setResizable(false); shareWindow.setWidth(400, Sizeable.Unit.PIXELS); TextArea shareLinkField = new TextArea(); shareLinkField.setValue(shareLink); shareLinkField.setReadOnly(true); shareLinkField.setRows(3); shareLinkField.setWidth(100, Sizeable.Unit.PERCENTAGE); // Close Button Button close = new Button("Close"); close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); close.addClickListener(event -> shareWindow.close()); // Layout for Buttons HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); buttonLayout.addComponent(close); buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT); // Content Layout VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.setSpacing(true); verticalLayout.addComponent( new Label("Please use the following link to share the current view with others.")); verticalLayout.addComponent(shareLinkField); verticalLayout.addComponent(buttonLayout); shareWindow.setContent(verticalLayout); getUI().addWindow(shareWindow); }); // Refresh Button Button refreshButton = new Button(); refreshButton.setId("refreshNow"); refreshButton.setIcon(FontAwesome.REFRESH); refreshButton.setDescription("Refresh Now"); refreshButton.addClickListener((event) -> controller.refreshUI()); // Layer Layout layerLayout = new VerticalLayout(); layerLayout.setId("layerComponent"); layerLayout.setSpacing(true); layerLayout.setMargin(true); // Layer Button layerButton = new Button(); layerButton.setId("layerToggleButton"); layerButton.setIcon(FontAwesome.BARS); layerButton.setDescription("Layers"); layerButton.addClickListener((event) -> { boolean isCollapsed = layerButton.getStyleName().contains(Styles.EXPANDED); setLayerLayoutVisible(!isCollapsed); }); // Save button layerSaveButton = new Button(); layerSaveButton.setId("saveLayerButton"); layerSaveButton.setIcon(FontAwesome.FLOPPY_O); layerSaveButton.addClickListener((event) -> controller.saveLayout()); // Actual Layout for the Toolbar CssLayout contentLayout = new CssLayout(); contentLayout.addStyleName("toolbar-component"); contentLayout.addComponent(createGroup(szlInBtn, m_zoomLevelLabel, m_szlOutBtn)); contentLayout.addComponent( createGroup(refreshButton, centerSelectionBtn, showAllMapBtn, layerButton, showFocusVerticesBtn)); contentLayout.addComponent(createGroup(m_panBtn, m_selectBtn)); contentLayout.addComponent(createGroup(magnifyBtn, demagnifyBtn)); contentLayout.addComponent(createGroup(shareButton)); contentLayout.addComponent(createGroup(layerSaveButton)); // Toolbar addComponent(contentLayout); }
From source file:org.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceEdgeEditWindow.java
License:Open Source License
/** * Constructor/*from w w w . j a v a2 s .c o m*/ * * @param businessService the Business Service DTO instance to be configured * @param businessServiceManager the Business Service Manager */ @SuppressWarnings("unchecked") public BusinessServiceEdgeEditWindow(final BusinessService businessService, final BusinessServiceManager businessServiceManager, final Edge edge) { super("Business Service Edge Edit"); /** * Basic window setup */ setModal(true); setClosable(false); setResizable(false); setWidth(650, Unit.PIXELS); setHeight(325, Unit.PIXELS); /** * Creating the root layout... */ final VerticalLayout rootLayout = new VerticalLayout(); rootLayout.setSpacing(true); rootLayout.setMargin(false); /** * ...and the nested layout */ final FormLayout formLayout = new FormLayout(); formLayout.setSpacing(true); formLayout.setMargin(true); /** * type selector box */ m_typeSelect = new NativeSelect("Type"); m_typeSelect.setId("edgeTypeSelector"); m_typeSelect.setMultiSelect(false); m_typeSelect.setNewItemsAllowed(false); m_typeSelect.setNullSelectionAllowed(false); m_typeSelect.setRequired(true); m_typeSelect.addItem(EdgeType.CHILD_SERVICE); m_typeSelect.setItemCaption(EdgeType.CHILD_SERVICE, "Child Service"); m_typeSelect.addItem(EdgeType.IP_SERVICE); m_typeSelect.setItemCaption(EdgeType.IP_SERVICE, "IP Service"); m_typeSelect.addItem(EdgeType.REDUCTION_KEY); m_typeSelect.setItemCaption(EdgeType.REDUCTION_KEY, "Reduction Key"); m_typeSelect.setWidth(100.0f, Unit.PERCENTAGE); formLayout.addComponent(m_typeSelect); // List of child services m_childServiceComponent = new ComboBox("Child Service"); m_childServiceComponent.setId("childServiceList"); m_childServiceComponent.setInputPrompt("No child service selected"); m_childServiceComponent.setNewItemsAllowed(false); m_childServiceComponent.setNullSelectionAllowed(false); m_childServiceComponent.setWidth(100.0f, Unit.PERCENTAGE); m_childServiceComponent.setVisible(false); m_childServiceComponent.setImmediate(true); m_childServiceComponent.setValidationVisible(true); m_childServiceComponent.setFilteringMode(FilteringMode.CONTAINS); m_childServiceComponent.addItems(businessServiceManager.getFeasibleChildServices(businessService).stream() .sorted(Ordering.natural().onResultOf(s -> BusinessServiceEditWindow.describeBusinessService(s))) .collect(Collectors.toList())); m_childServiceComponent.getItemIds().forEach(item -> m_childServiceComponent.setItemCaption(item, BusinessServiceEditWindow.describeBusinessService((BusinessService) item))); formLayout.addComponent(m_childServiceComponent); // List of IP services m_ipServiceComponent = new ComboBox("IP Service"); m_ipServiceComponent.setId("ipServiceList"); m_ipServiceComponent.setInputPrompt("No IP service selected"); m_ipServiceComponent.setNewItemsAllowed(false); m_ipServiceComponent.setNullSelectionAllowed(false); m_ipServiceComponent.setWidth(100.0f, Unit.PERCENTAGE); m_ipServiceComponent.setVisible(false); m_ipServiceComponent.setImmediate(true); m_ipServiceComponent.setValidationVisible(true); m_ipServiceComponent.setFilteringMode(FilteringMode.CONTAINS); m_ipServiceComponent.addItems(businessServiceManager.getAllIpServices().stream() .sorted(Ordering.natural().onResultOf(s -> BusinessServiceEditWindow.describeIpService(s))) .collect(Collectors.toList())); m_ipServiceComponent.getItemIds().forEach(item -> m_ipServiceComponent.setItemCaption(item, BusinessServiceEditWindow.describeIpService((IpService) item))); formLayout.addComponent(m_ipServiceComponent); /** * reduction key input field */ m_reductionKeyComponent = new TextField("Reduction Key"); m_reductionKeyComponent.setId("reductionKeyField"); m_reductionKeyComponent.setWidth(100.0f, Unit.PERCENTAGE); m_reductionKeyComponent.setVisible(false); m_reductionKeyComponent.setImmediate(true); m_reductionKeyComponent.setValidationVisible(true); formLayout.addComponent(m_reductionKeyComponent); /** * the friendly name */ m_friendlyNameField = new TextField("Friendly Name"); m_friendlyNameField.setId("friendlyNameField"); m_friendlyNameField.setWidth(100.0f, Unit.PERCENTAGE); m_friendlyNameField.setVisible(false); m_friendlyNameField.setImmediate(true); m_friendlyNameField.setValidationVisible(true); m_friendlyNameField.setNullSettingAllowed(true); m_friendlyNameField.setNullRepresentation(""); m_friendlyNameField.setMaxLength(FRIENDLY_NAME_MAXLENGTH); formLayout.addComponent(m_friendlyNameField); /** * show and hide components */ m_typeSelect.addValueChangeListener(event -> { m_childServiceComponent.setVisible(m_typeSelect.getValue() == EdgeType.CHILD_SERVICE); m_childServiceComponent.setRequired(m_typeSelect.getValue() == EdgeType.CHILD_SERVICE); m_ipServiceComponent.setVisible(m_typeSelect.getValue() == EdgeType.IP_SERVICE); m_ipServiceComponent.setRequired(m_typeSelect.getValue() == EdgeType.IP_SERVICE); m_reductionKeyComponent.setVisible(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY); m_reductionKeyComponent.setRequired(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY); m_friendlyNameField.setVisible(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY || m_typeSelect.getValue() == EdgeType.IP_SERVICE); }); /** * map function field */ m_mapFunctionSelect = new NativeSelect("Map Function", ImmutableList.builder().add(Decrease.class) .add(Identity.class).add(Ignore.class).add(Increase.class).add(SetTo.class).build()); m_mapFunctionSelect.setId("mapFunctionSelector"); m_mapFunctionSelect.setNullSelectionAllowed(false); m_mapFunctionSelect.setMultiSelect(false); m_mapFunctionSelect.setNewItemsAllowed(false); m_mapFunctionSelect.setRequired(true); m_mapFunctionSelect.setWidth(100.0f, Unit.PERCENTAGE); /** * setting the captions for items */ m_mapFunctionSelect.getItemIds() .forEach(itemId -> m_mapFunctionSelect.setItemCaption(itemId, ((Class<?>) itemId).getSimpleName())); formLayout.addComponent(m_mapFunctionSelect); /** * severity selection field */ m_mapFunctionSeveritySelect = new NativeSelect("Severity"); m_mapFunctionSeveritySelect.setMultiSelect(false); m_mapFunctionSeveritySelect.setNewItemsAllowed(false); m_mapFunctionSeveritySelect.setNullSelectionAllowed(false); m_mapFunctionSeveritySelect.setRequired(false); m_mapFunctionSeveritySelect.addItem(Status.CRITICAL); m_mapFunctionSeveritySelect.setItemCaption(Status.CRITICAL, "Critical"); m_mapFunctionSeveritySelect.addItem(Status.MAJOR); m_mapFunctionSeveritySelect.setItemCaption(Status.MAJOR, "Major"); m_mapFunctionSeveritySelect.addItem(Status.MINOR); m_mapFunctionSeveritySelect.setItemCaption(Status.MINOR, "Minor"); m_mapFunctionSeveritySelect.addItem(Status.WARNING); m_mapFunctionSeveritySelect.setItemCaption(Status.WARNING, "Warning"); m_mapFunctionSeveritySelect.addItem(Status.NORMAL); m_mapFunctionSeveritySelect.setItemCaption(Status.NORMAL, "Normal"); m_mapFunctionSeveritySelect.addItem(Status.INDETERMINATE); m_mapFunctionSeveritySelect.setItemCaption(Status.INDETERMINATE, "Indeterminate"); m_mapFunctionSeveritySelect.setWidth(100.0f, Unit.PERCENTAGE); m_mapFunctionSeveritySelect.setEnabled(false); m_mapFunctionSeveritySelect.setImmediate(true); m_mapFunctionSeveritySelect.setValidationVisible(true); formLayout.addComponent(m_mapFunctionSeveritySelect); /** * hide or show additional severity input field */ m_mapFunctionSelect.addValueChangeListener(event -> { m_mapFunctionSeveritySelect.setEnabled(SetTo.class.equals(m_mapFunctionSelect.getValue())); m_mapFunctionSeveritySelect.setRequired(SetTo.class.equals(m_mapFunctionSelect.getValue())); }); /** * the weight input field */ m_weightField = new TextField("Weight"); m_weightField.setId("weightField"); m_weightField.setRequired(true); m_weightField.setWidth(100.0f, Unit.PERCENTAGE); m_weightField.addValidator(value -> { try { int intValue = Integer.parseInt((String) value); if (intValue <= 0) { throw new Validator.InvalidValueException("Weight must be > 0"); } } catch (final NumberFormatException e) { throw new Validator.InvalidValueException("Weight must be a number"); } }); m_weightField.setImmediate(true); m_weightField.setValidationVisible(true); formLayout.addComponent(m_weightField); /** * setting the defaults */ m_typeSelect.setValue(EdgeType.CHILD_SERVICE); m_mapFunctionSelect.setValue(Identity.class); m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); m_weightField.setValue(Integer.toString(Edge.DEFAULT_WEIGHT)); /** * add the button layout... */ final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.setMargin(true); /** * ...and the save button */ final Button saveButton = new Button(edge == null ? "Add Edge" : "Update Edge"); saveButton.setId("saveEdgeButton"); saveButton.addClickListener(UIHelper.getCurrent(TransactionAwareUI.class) .wrapInTransactionProxy((Button.ClickListener) event -> { if (!m_weightField.isValid()) return; if (!m_ipServiceComponent.isValid()) return; if (!m_childServiceComponent.isValid()) return; if (!m_reductionKeyComponent.isValid()) return; final MapFunction mapFunction = getMapFunction(); final int weight = Integer.parseInt(m_weightField.getValue()); /** * in the case edge is not null, remove the old object... */ if (edge != null) { businessService.removeEdge(edge); } /** * ...and add the new edge */ switch ((EdgeType) m_typeSelect.getValue()) { case CHILD_SERVICE: businessService.addChildEdge((BusinessService) m_childServiceComponent.getValue(), mapFunction, weight); break; case IP_SERVICE: businessService.addIpServiceEdge((IpService) m_ipServiceComponent.getValue(), mapFunction, weight, m_friendlyNameField.getValue()); break; case REDUCTION_KEY: businessService.addReductionKeyEdge(m_reductionKeyComponent.getValue(), mapFunction, weight, m_friendlyNameField.getValue()); break; } close(); })); buttonLayout.addComponent(saveButton); /** * ...and a cancel button */ final Button cancelButton = new Button("Cancel"); cancelButton.setId("cancelEdgeButton"); cancelButton.addClickListener((Button.ClickListener) event -> close()); buttonLayout.addComponent(cancelButton); /** * when edge is not null, fill the components with values */ if (edge != null) { edge.accept(new EdgeVisitor<Void>() { @Override public Void visit(IpServiceEdge edge) { m_typeSelect.setValue(EdgeType.IP_SERVICE); for (IpService ipService : (Collection<IpService>) m_ipServiceComponent.getItemIds()) { if (ipService.getId() == edge.getIpService().getId()) { m_ipServiceComponent.setValue(ipService); break; } } m_friendlyNameField.setValue(edge.getFriendlyName()); m_ipServiceComponent.setEnabled(false); return null; } @Override public Void visit(ReductionKeyEdge edge) { m_typeSelect.setValue(EdgeType.REDUCTION_KEY); m_reductionKeyComponent.setValue(edge.getReductionKey()); m_friendlyNameField.setValue(edge.getFriendlyName()); m_reductionKeyComponent.setEnabled(false); return null; } @Override public Void visit(ChildEdge edge) { m_typeSelect.setValue(EdgeType.CHILD_SERVICE); m_childServiceComponent.setValue(edge.getChild()); m_childServiceComponent.setEnabled(false); return null; } }); m_typeSelect.setEnabled(false); m_mapFunctionSelect.setValue(edge.getMapFunction().getClass()); edge.getMapFunction().accept(new MapFunctionVisitor<Void>() { @Override public Void visit(Decrease decrease) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(Identity identity) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(Ignore ignore) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(Increase increase) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(SetTo setTo) { m_mapFunctionSeveritySelect.setValue(((SetTo) edge.getMapFunction()).getStatus()); return null; } }); m_weightField.setValue(String.valueOf(edge.getWeight())); } /** * now set the root layout */ rootLayout.addComponent(formLayout); rootLayout.addComponent(buttonLayout); rootLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT); setContent(rootLayout); }
From source file:org.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceEditWindow.java
License:Open Source License
/** * Constructor/*from w w w . ja v a 2s.c om*/ * * @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.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceMainLayout.java
License:Open Source License
public BusinessServiceMainLayout(BusinessServiceManager businessServiceManager) { m_businessServiceManager = Objects.requireNonNull(businessServiceManager); m_table = new BusinessServiceTreeTable(businessServiceManager); setSizeFull();/*from w ww .ja v a 2 s . c o m*/ // Create button final Button createButton = UIHelper.createButton("New Business Service", null, FontAwesome.PLUS_SQUARE, (Button.ClickListener) event -> { final BusinessService businessService = m_businessServiceManager.createBusinessService(); final BusinessServiceEditWindow window = new BusinessServiceEditWindow(businessService, m_businessServiceManager); window.addCloseListener(e -> m_table.refresh()); getUI().addWindow(window); }); createButton.setId("createButton"); // Collapse all final Button collapseButton = UIHelper.createButton("Collapse All", null, FontAwesome.FOLDER, (Button.ClickListener) event -> { m_table.getContainerDataSource().getItemIds().forEach(id -> m_table.setCollapsed(id, true)); }); collapseButton.setId("collapseButton"); // Expand all final Button expandButton = UIHelper.createButton("Expand All", null, FontAwesome.FOLDER_OPEN, (Button.ClickListener) event -> { m_table.getContainerDataSource().getItemIds().forEach(id -> m_table.setCollapsed(id, false)); }); expandButton.setId("expandButton"); // Refresh final Button refreshButton = UIHelper.createButton("Refresh Table", null, FontAwesome.REFRESH, (Button.ClickListener) event -> { m_table.refresh(); }); refreshButton.setId("refreshButton"); // Reload daemon final Button reloadButton = UIHelper.createButton("Reload Daemon", "Reloads the Business Service State Machine", FontAwesome.RETWEET, (Button.ClickListener) event -> { m_businessServiceManager.triggerDaemonReload(); }); reloadButton.setId("reloadButton"); // Group the create and collapse buttons on the left HorizontalLayout leftButtonGroup = new HorizontalLayout(); leftButtonGroup.setSpacing(true); leftButtonGroup.addComponent(createButton); leftButtonGroup.addComponent(collapseButton); leftButtonGroup.addComponent(expandButton); leftButtonGroup.setDefaultComponentAlignment(Alignment.TOP_LEFT); // Group the refresh and reload buttons to the right HorizontalLayout rightButtonGroup = new HorizontalLayout(); rightButtonGroup.setSpacing(true); rightButtonGroup.addComponent(refreshButton); rightButtonGroup.addComponent(reloadButton); rightButtonGroup.setDefaultComponentAlignment(Alignment.TOP_RIGHT); // Build the upper layout HorizontalLayout upperLayout = new HorizontalLayout(); upperLayout.setSpacing(true); upperLayout.addComponent(leftButtonGroup); upperLayout.addComponent(rightButtonGroup); upperLayout.setComponentAlignment(leftButtonGroup, Alignment.TOP_LEFT); upperLayout.setComponentAlignment(rightButtonGroup, Alignment.TOP_RIGHT); upperLayout.setWidth(100, Unit.PERCENTAGE); addComponent(upperLayout); // Add some space between the upper layout and the table Label sz = new Label(""); sz.setWidth(null); sz.setHeight(5, Unit.PIXELS); addComponent(sz); /** * add the table to the layout */ addComponent(m_table); setExpandRatio(m_table, 1.0f); /** * initial refresh of table */ m_table.refresh(); }
From source file:org.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceTreeTable.java
License:Open Source License
public BusinessServiceTreeTable(BusinessServiceManager businessServiceManager) { this.businessServiceManager = Objects.requireNonNull(businessServiceManager); setSizeFull();// w w w. j av a2s . c om setContainerDataSource(new BusinessServiceContainer()); // Add the "LINKS" columns addGeneratedColumn("links", new Table.ColumnGenerator() { private static final long serialVersionUID = 7113848887128656685L; @Override public Object generateCell(Table source, Object itemId, Object columnId) { final HorizontalLayout layout = new HorizontalLayout(); final BusinessServiceStateMachine stateMachine = businessServiceManager.getStateMachine(); final BusinessService businessService = getItem(itemId).getBean().getBusinessService(); final Status status = stateMachine.getOperationalStatus(businessService); if (status != null) { // Build the query string final List<BasicNameValuePair> urlParms = Lists.newArrayList( new BasicNameValuePair("focus-vertices", businessService.getId().toString()), new BasicNameValuePair("szl", "1"), new BasicNameValuePair("layout", "Hierarchy Layout"), new BasicNameValuePair("provider", "Business Services")); final String queryString = URLEncodedUtils.format(urlParms, Charset.forName("UTF-8")); // Generate the link final Link link = new Link("View in Topology UI", new ExternalResource(String.format("/opennms/topology?%s", queryString))); link.setIcon(FontAwesome.EXTERNAL_LINK_SQUARE); // This app is typically access in an iframe, so we open the URL in a new window/tab link.setTargetName("_blank"); layout.addComponent(link); layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER); } else { Label label = new Label("N/A"); label.setDescription("Try reloading the daemon and refreshing the table."); label.setWidth(null); layout.addComponent(label); } return layout; } }); // add edit and delete buttons addGeneratedColumn("edit / delete", new Table.ColumnGenerator() { private static final long serialVersionUID = 7113848887128656685L; @Override public Object generateCell(Table source, Object itemId, Object columnId) { HorizontalLayout layout = new HorizontalLayout(); layout.setSpacing(true); Button editButton = new Button("Edit", FontAwesome.PENCIL_SQUARE_O); editButton.setId("editButton-" + getItem(itemId).getBean().getName()); editButton.addClickListener(UIHelper.getCurrent(TransactionAwareUI.class) .wrapInTransactionProxy((Button.ClickListener) event -> { final Long businessServiceId = getItem(itemId).getBean().getBusinessService().getId(); BusinessService businessService = businessServiceManager .getBusinessServiceById(businessServiceId); final BusinessServiceEditWindow window = new BusinessServiceEditWindow(businessService, businessServiceManager); window.addCloseListener(e -> refresh()); getUI().addWindow(window); })); layout.addComponent(editButton); Button deleteButton = new Button("Delete", FontAwesome.TRASH_O); deleteButton.setId("deleteButton-" + getItem(itemId).getBean().getName()); deleteButton.addClickListener((Button.ClickListener) event -> { final Long businessServiceId = getItem(itemId).getBean().getBusinessService().getId(); BusinessService businessService = businessServiceManager .getBusinessServiceById(businessServiceId); if (businessService.getParentServices().isEmpty() && businessService.getChildEdges().isEmpty()) { UIHelper.getCurrent(TransactionAwareUI.class).runInTransaction(() -> { businessServiceManager.getBusinessServiceById(businessServiceId).delete(); refresh(); }); } else { new org.opennms.netmgt.vaadin.core.ConfirmationDialog() .withOkAction((org.opennms.netmgt.vaadin.core.ConfirmationDialog.Action) UIHelper .getCurrent(TransactionAwareUI.class).wrapInTransactionProxy( new org.opennms.netmgt.vaadin.core.ConfirmationDialog.Action() { @Override public void execute( org.opennms.netmgt.vaadin.core.ConfirmationDialog window) { businessServiceManager .getBusinessServiceById(businessServiceId).delete(); refresh(); } })) .withOkLabel("Delete anyway").withCancelLabel("Cancel").withCaption("Warning") .withDescription( "This entry is referencing or is referenced by other Business Services! Do you really want to delete this entry?") .open(); } }); layout.addComponent(deleteButton); return layout; } }); setColumnExpandRatio("name", 5); setColumnExpandRatio("links", 1); setColumnExpandRatio("edit / delete", 1); }
From source file:probe.com.view.body.QuantCompareDataLayout.java
private VerticalLayout initProteinsDataCapture(int width) { VerticalLayout proteinsDataCapturingMainLayout = new VerticalLayout(); proteinsDataCapturingMainLayout.setSpacing(true); proteinsDataCapturingMainLayout.setMargin(true); String containerWidth = ((width * 2) + 10) + "px"; proteinsDataCapturingMainLayout.setWidth(containerWidth); proteinsDataCapturingMainLayout.setSpacing(true); Label titleLabel = new Label("2. Insert UniProt Proteins Accessions"); titleLabel.setContentMode(ContentMode.HTML); titleLabel.setStyleName("normalheader"); titleLabel.setHeight("20px"); proteinsDataCapturingMainLayout.addComponent(titleLabel); proteinsDataCapturingMainLayout.setComponentAlignment(titleLabel, Alignment.TOP_LEFT); GridLayout insertProteinsLayout = new GridLayout(3, 3); proteinsDataCapturingMainLayout.addComponent(insertProteinsLayout); insertProteinsLayout.setSpacing(true); insertProteinsLayout.setMargin(new MarginInfo(false, false, false, false)); insertProteinsLayout.setWidth(containerWidth); HorizontalLayout hlo1 = new HorizontalLayout(); hlo1.setWidth("100%"); hlo1.setMargin(new MarginInfo(false, true, false, false)); Label highLabel = new Label("<font color='#cc0000'> High</font>"); highLabel.setWidth("40px"); highLabel.setContentMode(ContentMode.HTML); hlo1.addComponent(highLabel);/*from w w w. j a v a 2 s . c o m*/ HorizontalLayout hlo2 = new HorizontalLayout(); hlo2.setWidth("100%"); hlo2.setMargin(new MarginInfo(false, true, false, false)); Label stableLabel = new Label("<font color='#018df4'> Stable</font>"); stableLabel.setWidth("50px"); stableLabel.setContentMode(ContentMode.HTML); hlo2.addComponent(stableLabel); HorizontalLayout hlo3 = new HorizontalLayout(); hlo3.setWidth("100%"); hlo3.setMargin(new MarginInfo(false, true, false, false)); Label lowLabel = new Label("<font color='#009900'> Low</font>"); lowLabel.setWidth("40px"); lowLabel.setContentMode(ContentMode.HTML); hlo3.addComponent(lowLabel); insertProteinsLayout.addComponent(hlo1, 0, 0); insertProteinsLayout.setComponentAlignment(hlo1, Alignment.MIDDLE_CENTER); insertProteinsLayout.addComponent(hlo2, 1, 0); insertProteinsLayout.setComponentAlignment(hlo2, Alignment.MIDDLE_CENTER); insertProteinsLayout.addComponent(hlo3, 2, 0); insertProteinsLayout.setComponentAlignment(hlo3, Alignment.MIDDLE_CENTER); highTextArea.setWidth("100%"); highTextArea.setHeight("200px"); insertProteinsLayout.addComponent(highTextArea, 0, 1); insertProteinsLayout.setComponentAlignment(highTextArea, Alignment.MIDDLE_CENTER); stableTextArea.setWidth("100%"); stableTextArea.setHeight("200px"); insertProteinsLayout.addComponent(stableTextArea, 1, 1); insertProteinsLayout.setComponentAlignment(stableTextArea, Alignment.MIDDLE_CENTER); lowTextArea.setWidth("100%"); lowTextArea.setHeight("200px"); insertProteinsLayout.addComponent(lowTextArea, 2, 1); insertProteinsLayout.setComponentAlignment(lowTextArea, Alignment.MIDDLE_CENTER); VerticalLayout clear1 = new VerticalLayout(); hlo1.addComponent(clear1); clear1.setDescription("Clear field"); clear1.setStyleName("clearfieldbtn"); clear1.setWidth("20px"); clear1.setHeight("20px"); // insertProteinsLayout.addComponent(clear1, 0, 2); hlo1.setComponentAlignment(clear1, Alignment.MIDDLE_RIGHT); clear1.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { @Override public void layoutClick(LayoutEvents.LayoutClickEvent event) { highTextArea.clear(); } }); VerticalLayout clear2 = new VerticalLayout(); hlo2.addComponent(clear2); clear2.setDescription("Clear field"); clear2.setStyleName("clearfieldbtn"); clear2.setWidth("20px"); clear2.setHeight("20px"); clear2.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { @Override public void layoutClick(LayoutEvents.LayoutClickEvent event) { stableTextArea.clear(); } }); hlo2.setComponentAlignment(clear2, Alignment.MIDDLE_RIGHT); VerticalLayout clear3 = new VerticalLayout(); hlo3.addComponent(clear3); clear3.setDescription("Clear field"); clear3.setStyleName("clearfieldbtn"); clear3.setWidth("20px"); clear3.setHeight("20px"); clear3.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { @Override public void layoutClick(LayoutEvents.LayoutClickEvent event) { lowTextArea.clear(); } }); hlo3.setComponentAlignment(clear3, Alignment.MIDDLE_RIGHT); Label errorLabel = new Label(); proteinsDataCapturingMainLayout.addComponent(errorLabel); HorizontalLayout btnsLayout = new HorizontalLayout(); btnsLayout.setSpacing(true); btnsLayout.setMargin(new MarginInfo(true, false, false, false)); proteinsDataCapturingMainLayout.addComponent(btnsLayout); proteinsDataCapturingMainLayout.setComponentAlignment(btnsLayout, Alignment.MIDDLE_RIGHT); Button sampleBtn = new Button("Sample"); sampleBtn.setStyleName(Reindeer.BUTTON_SMALL); btnsLayout.addComponent(sampleBtn); sampleBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { reset(); highTextArea.setValue(highAcc); lowTextArea.setValue(lowAcc); stableTextArea.setValue(stableAcc); diseaseGroupsListA.select("Group A"); diseaseGroupsListB.select("Group B"); compareBtn.focus(); } }); Button resetBtn = new Button("Reset"); resetBtn.setStyleName(Reindeer.BUTTON_SMALL); btnsLayout.addComponent(resetBtn); resetBtn.setId("resetBtn"); resetBtn.addClickListener(this); compareBtn = new Button("Compare"); compareBtn.setStyleName(Reindeer.BUTTON_SMALL); btnsLayout.addComponent(compareBtn); compareBtn.setId("compareBtn"); compareBtn.addClickListener(this); // highTextArea.setValue(highAcc); // lowTextArea.setValue(lowAcc); // stableTextArea.setValue(stableAcc); return proteinsDataCapturingMainLayout; }
From source file:uk.q3c.krail.core.user.opt.DefaultOptionPopup.java
License:Apache License
@Override public void popup(@Nonnull OptionContext context, I18NKey windowCaption) { // changing context, so we need to clear the context fields if (context != activeContext) { contextFields = null;/* ww w .j a va 2 s . c o m*/ if (window != null) { window.close(); } } Option option = context.getOption(); window = new Window(); window.setCaption(windowCaption(windowCaption)); Map<OptionKey, Class<?>> keys = contextKeys(context); GridLayout baseLayout = new GridLayout(2, keys.size()); baseLayout.setSizeUndefined(); if (keys.size() == 0) { Label label = new Label(translate.from(LabelKey.No_Options_to_Show)); baseLayout.addComponent(label, 0, 0); } else { calculateWindowSize(window, keys.size()); int row = 0; for (OptionKey key : keys.keySet()) { Object value = option.get(key); AbstractField uiField = dataTypeToUI.componentFor(value); uiField.setCaption(translate.from(key.getKey())); uiField.setDescription(translate.from(key.getDescriptionKey())); uiField.setId(ID.getId(Optional.of(((Enum) key.getKey()).name()), this, uiField)); log.debug("Component id for '{}' set to: '{}'", uiField.getCaption(), uiField.getId()); //noinspection unchecked uiField.setValue(value); uiField.addValueChangeListener(event -> { option.set(uiField.getValue(), key); context.optionValueChanged(event); }); Button defaultsButton = new Button(translate.from(LabelKey.Reset_to_Default)); defaultsButton.setId(ID.getId(Optional.of(((Enum) key.getKey()).name()), this, defaultsButton)); defaultsButton.addClickListener((event -> { option.delete(0, key); //we create an event to represent the field which whose value will be affected by this change AbstractField.ValueChangeEvent changeEvent = new AbstractField.ValueChangeEvent(uiField); context.optionValueChanged(changeEvent); //update the value of the field - it may have changed uiField.setValue(option.get(key)); })); baseLayout.addComponent(new FormLayout(uiField), 0, row); baseLayout.addComponent(new FormLayout(defaultsButton), 1, row); row++; } } window.setId(ID.getId(Optional.empty(), context, this, window)); window.setClosable(true); window.setContent(baseLayout); window.center(); UI.getCurrent().addWindow(window); this.activeContext = context; }