List of usage examples for com.vaadin.ui FormLayout setMargin
@Override public void setMargin(boolean enabled)
From source file:org.opennms.features.topology.plugins.topo.bsm.info.SimulationModeReductionKeyInfoPanelItem.java
License:Open Source License
@Override public Component getComponent(VertexRef ref, GraphContainer container) { final ReductionKeyVertex vertex = (ReductionKeyVertex) ref; final FormLayout formLayout = new FormLayout(); formLayout.setSpacing(false);//w ww . j a va 2 s . c o m formLayout.setMargin(false); NativeSelect dropdown = new NativeSelect("Severity"); dropdown.setMultiSelect(false); dropdown.setNewItemsAllowed(false); dropdown.setNullSelectionAllowed(true); dropdown.setImmediate(true); dropdown.setRequired(true); dropdown.addItems(Arrays.asList(Status.values())); SetStatusToCriteria setStatusTo = findCriteria(container, vertex); if (setStatusTo != null) { dropdown.setValue(setStatusTo.getStatus()); } else { dropdown.setValue(null); } dropdown.addValueChangeListener(event -> { // The set of criteria may have changed since we last queried it above // do we issue try finding it again, instead of using the same existing object SetStatusToCriteria currentSetStatusTo = findCriteria(container, vertex); Status selectedStatus = (Status) dropdown.getValue(); if (currentSetStatusTo != null) { currentSetStatusTo.setStatus(selectedStatus); } else { currentSetStatusTo = new SetStatusToCriteria(vertex.getReductionKey(), selectedStatus); container.addCriteria(currentSetStatusTo); } // Remove the current selection before redrawing the layout in order // to avoid centering on the current vertex container.getSelectionManager().setSelectedVertexRefs(Collections.emptyList()); container.getSelectionManager().setSelectedEdgeRefs(Collections.emptyList()); container.redoLayout(); }); formLayout.addComponent(dropdown); return formLayout; }
From source file:org.opennms.features.topology.plugins.topo.bsm.info.SimulationModeReductionKeyInfoPanelItemProvider.java
License:Open Source License
private Component createComponent(ReductionKeyVertex vertex, GraphContainer container) { final FormLayout formLayout = new FormLayout(); formLayout.setSpacing(false);/*from w w w. j a v a 2 s . c o m*/ formLayout.setMargin(false); NativeSelect dropdown = new NativeSelect("Severity"); dropdown.setMultiSelect(false); dropdown.setNewItemsAllowed(false); dropdown.setNullSelectionAllowed(true); dropdown.setImmediate(true); dropdown.setRequired(true); dropdown.addItems(Arrays.asList(Status.values())); SetStatusToCriteria setStatusTo = findCriteria(container, vertex); if (setStatusTo != null) { dropdown.setValue(setStatusTo.getStatus()); } else { dropdown.setValue(null); } dropdown.addValueChangeListener(event -> { // The set of criteria may have changed since we last queried it above // do we issue try finding it again, instead of using the same existing object SetStatusToCriteria currentSetStatusTo = findCriteria(container, vertex); Status selectedStatus = (Status) dropdown.getValue(); if (currentSetStatusTo != null) { currentSetStatusTo.setStatus(selectedStatus); } else { currentSetStatusTo = new SetStatusToCriteria(vertex.getReductionKey(), selectedStatus); container.addCriteria(currentSetStatusTo); } // Remove the current selection before redrawing the layout in order // to avoid centering on the current vertex container.getSelectionManager().setSelectedVertexRefs(Collections.emptyList()); container.getSelectionManager().setSelectedEdgeRefs(Collections.emptyList()); container.redoLayout(); }); formLayout.addComponent(dropdown); return formLayout; }
From source file:org.opennms.features.vaadin.dashboard.config.ui.DashletSpecEditor.java
License:Open Source License
/** * Constructor for the DashletSpecEditor. * * @param wallboardEditor the {@link WallboardEditor} wallboard editor this editor belongs to * @param dashletSelector the {@link DashletSelector} used to query available {@link DashletFactory} instances * @param dashletSpec the associated {@link DashletSpec} instance *//*w w w .ja v a2s . c o m*/ public DashletSpecEditor(WallboardEditor wallboardEditor, DashletSelector dashletSelector, DashletSpec dashletSpec) { /** * Setting the member fields */ this.m_wallboardEditor = wallboardEditor; this.m_dashletSpec = dashletSpec; this.m_dashletSelector = dashletSelector; /** * Setting defaults */ DashletFactory dashletFactory = dashletSelector.getDashletFactoryForName(dashletSpec.getDashletName()); final Map<String, String> requiredParameters = dashletFactory.getRequiredParameters(); for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { if (!dashletSpec.getParameters().containsKey(entry.getKey())) { dashletSpec.getParameters().put(entry.getKey(), requiredParameters.get(entry.getKey())); } } /** * Setting up this component with size and layout */ setWidth(100.0f, Unit.PERCENTAGE); GridLayout gridLayout = new GridLayout(); gridLayout.setColumns(6); gridLayout.setRows(1); gridLayout.setMargin(true); /** * Priority field setup, layout and adding listener and validator */ final TextField priorityField = new TextField(); priorityField.setValue(String.valueOf(dashletSpec.getPriority())); priorityField.setImmediate(true); priorityField.setCaption("Priority"); priorityField.setDescription("Priority of this dashlet"); priorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); priorityField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (priorityField.isValid()) { m_dashletSpec.setPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority"); } } }); /** * Boost priority field setup, layout and adding listener and validator */ final TextField boostPriorityField = new TextField(); boostPriorityField.setValue(String.valueOf(dashletSpec.getBoostPriority())); boostPriorityField.setImmediate(true); boostPriorityField.setCaption("Boost-Priority"); boostPriorityField.setDescription("Boost priority of this dashlet"); boostPriorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); boostPriorityField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (boostPriorityField.isValid()) { m_dashletSpec .setBoostPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority"); } } }); /** * Duration field setup, layout and adding listener and validator */ final TextField durationField = new TextField(); durationField.setValue(String.valueOf(dashletSpec.getDuration())); durationField.setImmediate(true); durationField.setCaption("Duration"); durationField.setDescription("Duration for this dashlet"); durationField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); durationField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (durationField.isValid()) { m_dashletSpec.setDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration"); } } }); /** * Boost duration field setup, layout and adding listener and validator */ final TextField boostDurationField = new TextField(); boostDurationField.setValue(String.valueOf(dashletSpec.getBoostDuration())); boostDurationField.setImmediate(true); boostDurationField.setCaption("Boost-Duration"); boostDurationField.setDescription("Boost duration for this dashlet"); boostDurationField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); boostDurationField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (boostDurationField.isValid()) { m_dashletSpec .setBoostDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration"); } } }); boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .isBoostable(); boostPriorityField.setEnabled(boostable); boostDurationField.setEnabled(boostable); /** * Setting up the dashlet selection */ m_dashletSelect = new NativeSelect(); m_dashletSelect.setCaption("Dashlet"); updateDashletSelection(dashletSelector.getDashletFactoryList()); m_dashletSelect.setImmediate(true); m_dashletSelect.setNewItemsAllowed(false); m_dashletSelect.setNullSelectionItemId("Undefined"); m_dashletSelect.setNullSelectionAllowed(false); m_dashletSelect.select(dashletSpec.getDashletName()); m_dashletSelect.setDescription("Dashlet selection"); m_dashletSelect.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (m_savingDisabled) { return; } if (valueChangeEvent.getProperty().getValue() == null) { m_dashletSpec.setDashletName("Undefined"); } else { m_dashletSpec.setDashletName(valueChangeEvent.getProperty().getValue().toString()); m_dashletSelect.removeItem("Undefined"); } m_dashletSpec.getParameters().clear(); Map<String, String> requiredParameters = m_dashletSelector .getDashletFactoryForName(m_dashletSpec.getDashletName()).getRequiredParameters(); for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { m_dashletSpec.getParameters().put(entry.getKey(), entry.getValue()); } m_propertiesButton.setEnabled(requiredParameters.size() > 0); boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .isBoostable(); boostPriorityField.setEnabled(boostable); boostDurationField.setEnabled(boostable); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Dashlet"); } }); m_titleField = new TextField(); m_titleField.setValue(dashletSpec.getTitle()); m_titleField.setImmediate(true); m_titleField.setCaption("Title"); m_titleField.setDescription("Title for this dashlet instance"); m_titleField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { m_dashletSpec.setTitle((String) valueChangeEvent.getProperty().getValue()); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Title"); } }); FormLayout f1 = new FormLayout(); f1.addComponent(m_dashletSelect); f1.addComponent(m_titleField); /** * Adding the required input fields and buttons to several {@link FormLayout} instances for better layout. */ FormLayout f2 = new FormLayout(); f2.addComponent(priorityField); f2.addComponent(durationField); FormLayout f3 = new FormLayout(); f3.addComponent(boostPriorityField); f3.addComponent(boostDurationField); /** * Adding the properties button... */ m_propertiesButton = new Button("Properties"); m_propertiesButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { DashletConfigurationWindow configurationWindow = m_dashletSelector .getDashletFactoryForName(m_dashletSpec.getDashletName()) .configurationWindow(m_dashletSpec); getUI().addWindow(configurationWindow); } }); m_propertiesButton.setEnabled(m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .getRequiredParameters().size() > 0); m_propertiesButton.setStyleName("small"); m_propertiesButton.setDescription("Open properties dialog for this dashlet"); /** * ...and the remove button */ Button removeButton = new Button("Remove"); removeButton.setDescription("Remove this dashlet entry"); FormLayout f4 = new FormLayout(); f4.addComponent(m_propertiesButton); f4.addComponent(removeButton); removeButton.addClickListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.removeDashletSpecEditor(DashletSpecEditor.this); } }); removeButton.setStyleName("small"); Button upButton = new Button(); upButton.setStyleName("small"); upButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); upButton.setDescription("Move this a dashlet entry one position up"); Button downButton = new Button(); downButton.setStyleName("small"); downButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); downButton.setDescription("Move this a dashlet entry one position down"); FormLayout f5 = new FormLayout(); f5.addComponent(upButton); f5.addComponent(downButton); Button previewButton = new Button("Preview"); previewButton.setStyleName("small"); previewButton.setDescription("Preview this single dashlet entry"); Wallboard wallboard = new Wallboard(); wallboard.getDashletSpecs().add(m_dashletSpec); previewButton.addClickListener(new PreviewClickListener(this, wallboard)); FormLayout f6 = new FormLayout(); f6.addComponent(previewButton); upButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.swapDashletSpec(m_dashletSpec, -1); } }); downButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.swapDashletSpec(m_dashletSpec, +1); } }); /** * Adding the different {@link FormLayout} instances to a {@link GridLayout} */ f1.setMargin(true); f2.setMargin(true); f3.setMargin(true); f4.setMargin(true); f5.setMargin(true); f6.setMargin(true); gridLayout.addComponent(f1); gridLayout.addComponent(f2); gridLayout.addComponent(f3); gridLayout.addComponent(f4); gridLayout.addComponent(f5); gridLayout.addComponent(f6); setContent(gridLayout); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited *//*from w w w . ja va 2s. co m*/ public ChartsConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; /** * Setting up the base layouts */ setHeight(410, Unit.PIXELS); setWidth(40, Unit.PERCENTAGE); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setWidth(100, Unit.PERCENTAGE); horizontalLayout.setSpacing(true); horizontalLayout.setMargin(true); FormLayout formLayout = new FormLayout(); formLayout.setWidth(100, Unit.PERCENTAGE); formLayout.setSpacing(true); formLayout.setMargin(true); /** * Adding the checkboxes */ m_maximizeWidth = new CheckBox(); m_maximizeWidth.setCaption("Maximize width"); m_maximizeWidth.setDescription("Maximize width"); m_maximizeHeight = new CheckBox(); m_maximizeHeight.setCaption("Maximize height"); m_maximizeHeight.setDescription("Maximize height"); String maximizeWidthString = m_dashletSpec.getParameters().get("maximizeWidth"); String maximizeHeightString = m_dashletSpec.getParameters().get("maximizeHeight"); boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString) || "1".equals(maximizeHeightString)); boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString) || "1".equals(maximizeWidthString)); m_maximizeWidth.setValue(maximizeWidth); m_maximizeHeight.setValue(maximizeHeight); m_chartSelect = new NativeSelect(); m_chartSelect.setDescription("Select chart to be displayed"); m_chartSelect.setCaption("Chart"); m_chartSelect.setNullSelectionAllowed(false); m_chartSelect.setInvalidAllowed(false); m_chartSelect.setNewItemsAllowed(false); String firstChartName = null; try { Iterator<BarChart> it = ChartUtils.getChartCollectionIterator(); while (it.hasNext()) { BarChart chartConfig = (BarChart) it.next(); if (firstChartName == null) { firstChartName = chartConfig.getName(); } m_chartSelect.addItem(chartConfig.getName()); } } catch (Exception e) { e.printStackTrace(); } String chartName = m_dashletSpec.getParameters().get("chart"); if (chartName == null || "".equals(chartName)) { chartName = firstChartName; } final Panel panel = new Panel(); panel.setWidth(230, Unit.PIXELS); panel.setCaption("Preview"); formLayout.addComponent(m_chartSelect); Page.getCurrent().getStyles().add(".preview { width:225px; }"); m_chartSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { String newImage = "/opennms/charts?chart-name=" + valueChangeEvent.getProperty().getValue(); Image image = new Image(null, new ExternalResource(newImage)); image.setStyleName("preview"); panel.setContent(image); } }); m_chartSelect.setValue(chartName); m_chartSelect.setImmediate(true); formLayout.addComponent(m_maximizeWidth); formLayout.addComponent(m_maximizeHeight); horizontalLayout.addComponent(formLayout); horizontalLayout.addComponent(panel); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); buttonLayout.addComponent(cancel); buttonLayout.setExpandRatio(cancel, 1.0f); buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { m_dashletSpec.getParameters().put("maximizeWidth", (m_maximizeWidth.getValue() ? "true" : "false")); m_dashletSpec.getParameters().put("maximizeHeight", (m_maximizeHeight.getValue() ? "true" : "false")); m_dashletSpec.getParameters().put("chart", String.valueOf(m_chartSelect.getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties"); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonLayout.addComponent(ok); /** * Adding the layout and setting the content */ //verticalLayout.addComponent(buttonLayout); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(buttonLayout); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.KscDashletConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link org.opennms.features.vaadin.dashboard.model.DashletSpec} to be edited *//* ww w .j av a 2 s. c o m*/ public KscDashletConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; setHeight(210, Unit.PIXELS); setWidth(40, Unit.PERCENTAGE); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setWidth(100, Unit.PERCENTAGE); horizontalLayout.setSpacing(true); horizontalLayout.setMargin(true); FormLayout formLayout = new FormLayout(); formLayout.setWidth(100, Unit.PERCENTAGE); formLayout.setSpacing(true); formLayout.setMargin(true); m_kscSelect = new NativeSelect(); m_kscSelect.setDescription("Select KSC-report to be displayed"); m_kscSelect.setCaption("KSC-Report"); m_kscSelect.setImmediate(true); m_kscSelect.setNewItemsAllowed(false); m_kscSelect.setMultiSelect(false); m_kscSelect.setInvalidAllowed(false); m_kscSelect.setNullSelectionAllowed(false); m_kscSelect.setImmediate(true); final KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory.getInstance(); Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList(); for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) { m_kscSelect.addItem(entry.getKey()); m_kscSelect.setItemCaption(entry.getKey(), entry.getValue()); if (m_kscSelect.getValue() == null) { m_kscSelect.setValue(entry.getKey()); } } String chartName = m_dashletSpec.getParameters().get("kscReport"); if (chartName != null) { if (reportsMap.values().contains(chartName)) { m_kscSelect.setValue(chartName); } } formLayout.addComponent(m_kscSelect); m_kscSelect.setValue(chartName); m_kscSelect.setImmediate(true); horizontalLayout.addComponent(formLayout); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); buttonLayout.addComponent(cancel); buttonLayout.setExpandRatio(cancel, 1.0f); buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList(); m_dashletSpec.getParameters().put("kscReport", reportsMap.get(m_kscSelect.getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties"); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonLayout.addComponent(ok); if (reportsMap.size() == 0) { m_kscSelect.setEnabled(false); ok.setEnabled(false); } /** * Adding the layout and setting the content */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(buttonLayout); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewConfigurationCategoryWindow.java
License:Open Source License
/** * The constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used. * @param defs the column/row defs * @param def the def to be edited * @param saveActionListener the listener for the saving action *//*from www. j a va 2 s . c om*/ public SurveillanceViewConfigurationCategoryWindow(final SurveillanceViewService surveillanceViewService, final Collection<?> defs, final Def def, final SaveActionListener saveActionListener) { /** * calling the super constructor */ super("Window title"); /** * Check whether this dialog is for a column or row and alter the window title */ if (def instanceof RowDef) { super.setCaption("Row definition"); } else { super.setCaption("Column definition"); } /** * Setting the modal and size properties */ setModal(true); setClosable(false); setResizable(false); setWidth(30, Sizeable.Unit.PERCENTAGE); setHeight(400, Unit.PIXELS); /** * Title and refresh seconds */ final TextField labelField = new TextField(); labelField.setValue(def.getLabel()); labelField.setImmediate(true); labelField.setCaption("Label"); labelField.setDescription("Label of this category"); labelField.setWidth(100, Unit.PERCENTAGE); /** * Creating a simple validator for the title field */ labelField.addValidator( new AbstractStringValidator("Please use an unique name for this column/row definition") { @Override protected boolean isValidValue(String s) { if ("".equals(s.trim())) { return false; } /** * check if the name clashes with other defs */ for (Def defx : (Collection<Def>) defs) { if (defx.getLabel().equals(s)) { if (defx != def) { return false; } } } return true; } }); /** * Categories table */ final Table categoriesTable = new Table(); categoriesTable.setSizeFull(); categoriesTable.setHeight(250.0f, Unit.PIXELS); categoriesTable.setCaption("Categories"); categoriesTable.setSortEnabled(true); categoriesTable.addContainerProperty("name", String.class, ""); categoriesTable.setColumnHeader("name", "Category"); categoriesTable.setColumnExpandRatio("Category", 1.0f); categoriesTable.setSelectable(true); categoriesTable.setMultiSelect(true); final List<OnmsCategory> categories = surveillanceViewService.getOnmsCategories(); final Map<Integer, OnmsCategory> categoriesMap = new HashMap<>(); for (OnmsCategory onmsCategory : categories) { categoriesTable.addItem(new Object[] { onmsCategory.getName() }, onmsCategory.getId()); categoriesMap.put(onmsCategory.getId(), onmsCategory); if (def.containsCategory(onmsCategory.getName())) { categoriesTable.select(onmsCategory.getId()); } } /** * Create form layouts... */ FormLayout baseFormLayout = new FormLayout(); baseFormLayout.setSizeFull(); baseFormLayout.setMargin(true); baseFormLayout.addComponent(labelField); baseFormLayout.addComponent(categoriesTable); /** * Creating the vertical layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull(); verticalLayout.addComponent(baseFormLayout); verticalLayout.setExpandRatio(baseFormLayout, 1.0f); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth(100, Unit.PERCENTAGE); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing properties"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); horizontalLayout.addComponent(cancel); horizontalLayout.setExpandRatio(cancel, 1); horizontalLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Def finalDef = null; if (def instanceof RowDef) { finalDef = new RowDef(); } if (def instanceof ColumnDef) { finalDef = new ColumnDef(); } Set<Object> categories = (Set<Object>) categoriesTable.getValue(); if (!labelField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please use an unique label for this category", Notification.Type.ERROR_MESSAGE); return; } if (categories.isEmpty()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "You must choose at least one surveillance category", Notification.Type.ERROR_MESSAGE); return; } for (Object object : categories) { Category category = new Category(); category.setName(categoriesMap.get(object).getName()); finalDef.getCategories().add(category); } finalDef.setLabel(labelField.getValue()); saveActionListener.save(finalDef); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); horizontalLayout.addComponent(ok); verticalLayout.addComponent(horizontalLayout); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewConfigurationWindow.java
License:Open Source License
/** * The constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used * @param view the view to edit * @param saveActionListener the save action listener */// ww w . ja v a2 s .co m public SurveillanceViewConfigurationWindow(final SurveillanceViewService surveillanceViewService, final View view, final SaveActionListener saveActionListener) { /** * Setting the title */ super("Surveillance view configuration"); /** * Setting the modal and size properties */ setModal(true); setClosable(false); setResizable(false); setWidth(80, Sizeable.Unit.PERCENTAGE); setHeight(75, Sizeable.Unit.PERCENTAGE); /** * Title field */ final TextField titleField = new TextField(); titleField.setValue(view.getName()); titleField.setImmediate(true); titleField.setCaption("Title"); titleField.setDescription("Title of this surveillance view"); titleField.setWidth(25, Unit.PERCENTAGE); /** * Adding simple validator */ titleField.addValidator(new AbstractStringValidator("Please use an unique name for the surveillance view") { @Override protected boolean isValidValue(String string) { if ("".equals(string.trim())) { return false; } if (SurveillanceViewProvider.getInstance().containsView(string) && !view.getName().equals(string)) { return false; } return true; } }); /** * Refresh seconds field setup and validator */ final TextField refreshSecondsField = new TextField(); refreshSecondsField.setValue(String.valueOf(view.getRefreshSeconds())); refreshSecondsField.setImmediate(true); refreshSecondsField.setCaption("Refresh seconds"); refreshSecondsField.setDescription("Refresh duration in seconds"); refreshSecondsField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { int number; try { number = Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return (number >= 0); } }); /** * Columns table */ final Table columnsTable = new Table(); columnsTable.setSortEnabled(false); columnsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<ColumnDef> columns = new BeanItemContainer<ColumnDef>(ColumnDef.class, view.getColumns()); final Map<ColumnDef, Integer> columnOrder = new HashMap<>(); int c = 0; for (ColumnDef columnDef : view.getColumns()) { columnOrder.put(columnDef, c++); } columnsTable.setContainerDataSource(columns); columnsTable.setVisibleColumns("label"); columnsTable.setColumnHeader("label", "Columns"); columnsTable.setColumnExpandRatio("label", 1.0f); columnsTable.setSelectable(true); columnsTable.setMultiSelect(false); /** * Create custom sorter */ columns.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (columnOrder.get(o1).intValue() == columnOrder.get(o2).intValue()) { return 0; } else { if (columnOrder.get(o1).intValue() > columnOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button columnsAddButton = new Button("Add"); columnsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), new ColumnDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, columnOrder.size()); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); columnsAddButton.setEnabled(true); columnsAddButton.setStyleName("small"); columnsAddButton.setDescription("Add column"); columnsAddButton.setEnabled(true); final Button columnsEditButton = new Button("Edit"); columnsEditButton.setEnabled(true); columnsEditButton.setStyleName("small"); columnsEditButton.setDescription("Edit column"); columnsEditButton.setEnabled(false); columnsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), (ColumnDef) columnsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { ColumnDef columnToBeReplaced = (ColumnDef) columnsTable.getValue(); int index = columnOrder.get(columnToBeReplaced); columns.removeItem(columnToBeReplaced); columnOrder.remove(columnToBeReplaced); columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, index); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); final Button columnsRemoveButton = new Button("Remove"); columnsRemoveButton.setEnabled(true); columnsRemoveButton.setStyleName("small"); columnsRemoveButton.setDescription("Remove column"); columnsRemoveButton.setEnabled(false); columnsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { columnsTable.unselect(columnDef); columns.removeItem(columnDef); } columnsTable.refreshRowCache(); } }); final Button columnUpButton = new Button(); columnUpButton.setStyleName("small"); columnUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); columnUpButton.setDescription("Move this a column entry one position up"); columnUpButton.setEnabled(false); columnUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex - 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex - 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); final Button columnDownButton = new Button(); columnDownButton.setStyleName("small"); columnDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); columnDownButton.setDescription("Move this a column entry one position down"); columnDownButton.setEnabled(false); columnDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex + 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex + 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); columnsTable.setSizeFull(); columnUpButton.setSizeFull(); columnDownButton.setSizeFull(); columnsAddButton.setSizeFull(); columnsEditButton.setSizeFull(); columnsRemoveButton.setSizeFull(); columnsTable.setImmediate(true); /** * ...and a listener */ columnsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (columnsTable.getValue() != null); columnsRemoveButton.setEnabled(somethingSelected); columnsEditButton.setEnabled(somethingSelected); columnsAddButton.setEnabled(true); columnUpButton .setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() > 0); columnDownButton.setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() < columnOrder.size() - 1); } }); /** * Rows table */ final Table rowsTable = new Table(); rowsTable.setSortEnabled(false); rowsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<RowDef> rows = new BeanItemContainer<RowDef>(RowDef.class, view.getRows()); final Map<RowDef, Integer> rowOrder = new HashMap<>(); int r = 0; for (RowDef rowDef : view.getRows()) { rowOrder.put(rowDef, r++); } rowsTable.setContainerDataSource(rows); rowsTable.setVisibleColumns("label"); rowsTable.setColumnHeader("label", "Rows"); rowsTable.setColumnExpandRatio("label", 1.0f); rowsTable.setSelectable(true); rowsTable.setMultiSelect(false); /** * Create custom sorter */ rows.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (rowOrder.get(o1).intValue() == rowOrder.get(o2).intValue()) { return 0; } else { if (rowOrder.get(o1).intValue() > rowOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button rowsAddButton = new Button("Add"); rowsAddButton.setEnabled(true); rowsAddButton.setStyleName("small"); rowsAddButton.setDescription("Add row"); rowsAddButton.setEnabled(true); rowsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), new RowDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { rows.addItem((RowDef) def); rowOrder.put((RowDef) def, rowOrder.size()); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsEditButton = new Button("Edit"); rowsEditButton.setEnabled(true); rowsEditButton.setStyleName("small"); rowsEditButton.setDescription("Edit row"); rowsEditButton.setEnabled(false); rowsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), (RowDef) rowsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { RowDef rowToBeReplaced = (RowDef) rowsTable.getValue(); int index = rowOrder.get(rowToBeReplaced); rows.removeItem(rowToBeReplaced); rowOrder.remove(rowToBeReplaced); rows.addItem((RowDef) def); rowOrder.put((RowDef) def, index); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsRemoveButton = new Button("Remove"); rowsRemoveButton.setEnabled(true); rowsRemoveButton.setStyleName("small"); rowsRemoveButton.setDescription("Remove row"); rowsRemoveButton.setEnabled(false); rowsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { rowsTable.unselect(rowDef); rows.removeItem(rowDef); } rowsTable.refreshRowCache(); } }); final Button rowUpButton = new Button(); rowUpButton.setStyleName("small"); rowUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); rowUpButton.setDescription("Move this a row entry one position up"); rowUpButton.setEnabled(false); rowUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex - 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex - 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); final Button rowDownButton = new Button(); rowDownButton.setStyleName("small"); rowDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); rowDownButton.setDescription("Move this a row entry one position down"); rowDownButton.setEnabled(false); rowDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex + 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex + 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); rowsTable.setSizeFull(); rowUpButton.setSizeFull(); rowDownButton.setSizeFull(); rowsAddButton.setSizeFull(); rowsEditButton.setSizeFull(); rowsRemoveButton.setSizeFull(); rowsTable.setImmediate(true); /** * ...and a listener */ rowsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (rowsTable.getValue() != null); rowsRemoveButton.setEnabled(somethingSelected); rowsEditButton.setEnabled(somethingSelected); rowsAddButton.setEnabled(true); rowUpButton.setEnabled(somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() > 0); rowDownButton.setEnabled( somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() < rowOrder.size() - 1); } }); /** * Create form layouts... */ FormLayout baseFormLayout = new FormLayout(); baseFormLayout.addComponent(titleField); baseFormLayout.addComponent(refreshSecondsField); FormLayout columnTableFormLayout = new FormLayout(); columnTableFormLayout.addComponent(columnsAddButton); columnTableFormLayout.addComponent(columnsEditButton); columnTableFormLayout.addComponent(columnsRemoveButton); columnTableFormLayout.addComponent(columnUpButton); columnTableFormLayout.addComponent(columnDownButton); FormLayout rowTableFormLayout = new FormLayout(); rowTableFormLayout.addComponent(rowsAddButton); rowTableFormLayout.addComponent(rowsEditButton); rowTableFormLayout.addComponent(rowsRemoveButton); rowTableFormLayout.addComponent(rowUpButton); rowTableFormLayout.addComponent(rowDownButton); /** * Adding the different {@link com.vaadin.ui.FormLayout} instances to a {@link com.vaadin.ui.GridLayout} */ baseFormLayout.setMargin(true); columnTableFormLayout.setMargin(true); rowTableFormLayout.setMargin(true); GridLayout gridLayout = new GridLayout(); gridLayout.setSizeFull(); gridLayout.setColumns(4); gridLayout.setRows(1); gridLayout.setMargin(true); gridLayout.addComponent(rowsTable); gridLayout.addComponent(rowTableFormLayout); gridLayout.addComponent(columnsTable); gridLayout.addComponent(columnTableFormLayout); gridLayout.setColumnExpandRatio(1, 0.5f); gridLayout.setColumnExpandRatio(2, 1.0f); gridLayout.setColumnExpandRatio(3, 0.5f); gridLayout.setColumnExpandRatio(4, 1.0f); /** * Creating the vertical layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(baseFormLayout); verticalLayout.addComponent(gridLayout); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth(100, Unit.PERCENTAGE); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing properties"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); horizontalLayout.addComponent(cancel); horizontalLayout.setExpandRatio(cancel, 1); horizontalLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!titleField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please use an unique title", Notification.Type.ERROR_MESSAGE); return; } if (!refreshSecondsField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please enter a valid number in the \"Refresh seconds\" field", Notification.Type.ERROR_MESSAGE); return; } if (columns.getItemIds().isEmpty() || rows.getItemIds().isEmpty()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "You must define at least one row category and one column category", Notification.Type.ERROR_MESSAGE); return; } View finalView = new View(); for (ColumnDef columnDef : columns.getItemIds()) { finalView.getColumns().add(columnDef); } for (RowDef rowDef : rows.getItemIds()) { finalView.getRows().add(rowDef); } finalView.setName(titleField.getValue()); finalView.setRefreshSeconds(Integer.parseInt(refreshSecondsField.getValue())); saveActionListener.save(finalView); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); horizontalLayout.addComponent(ok); verticalLayout.addComponent(horizontalLayout); setContent(verticalLayout); }
From source file:org.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceEdgeEditWindow.java
License:Open Source License
/** * Constructor//from w ww .j av a 2 s . c om * * @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.vaadin.core.KeyValueInputDialogWindow.java
License:Open Source License
/** * Constructor responsible for creating new instances of this class * * @param caption the window's title/*from w w w. j a v a2s. co m*/ * @param keyName the title of the key input field * @param valueName the title of the value input field */ public KeyValueInputDialogWindow(String caption, String keyName, String valueName) { super(caption); /** * set window properties */ setModal(true); setClosable(false); setResizable(false); /** * create the main layout */ VerticalLayout verticalLayout = new VerticalLayout(); /** * add the key input field */ m_keyInputField = new TextField(keyName); m_keyInputField.setValue(""); m_keyInputField.setId("keyField"); m_keyInputField.selectAll(); m_keyInputField.setImmediate(true); m_keyInputField.focus(); /** * add the value input field */ m_valueInputField = new TextField(valueName); m_valueInputField.setValue(""); m_valueInputField.setId("valueField"); m_valueInputField.selectAll(); m_valueInputField.setImmediate(true); /** * create nested FormLayout instance */ FormLayout formLayout = new FormLayout(); formLayout.setSizeUndefined(); formLayout.setMargin(true); formLayout.addComponent(m_keyInputField); formLayout.addComponent(m_valueInputField); /** * add the buttons in a horizontal layout */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth("100%"); /** * create cancel button */ m_cancelButton = new Button("Cancel"); m_cancelButton.setId("cancelBtn"); m_cancelButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); m_cancelButton.addClickListener(this); horizontalLayout.addComponent(m_cancelButton); horizontalLayout.setExpandRatio(m_cancelButton, 1); horizontalLayout.setComponentAlignment(m_cancelButton, Alignment.TOP_RIGHT); /** * create ok button */ m_okButton = new Button("OK"); m_okButton.setId("okBtn"); m_okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); m_okButton.addClickListener(this); horizontalLayout.addComponent(m_okButton); formLayout.addComponent(horizontalLayout); verticalLayout.addComponent(formLayout); addFocusListener(new FieldEvents.FocusListener() { @Override public void focus(FieldEvents.FocusEvent event) { if (m_focusKey) { m_keyInputField.focus(); } else { m_valueInputField.focus(); } } }); /** * the close listener */ addCloseListener(this); /** * set the content */ setContent(verticalLayout); }
From source file:org.opennms.netmgt.vaadin.core.StringInputDialogWindow.java
License:Open Source License
/** * Constructor responsible for creating new instances of this class * * @param caption the window's title//from w w w .j a v a2 s. c om * @param fieldName the title of the input field */ public StringInputDialogWindow(String caption, String fieldName) { super(caption); /** * set window properties */ setModal(true); setClosable(false); setResizable(false); /** * create the main layout */ VerticalLayout verticalLayout = new VerticalLayout(); /** * add the input field */ m_inputField = new TextField(fieldName); m_inputField.setValue(""); m_inputField.focus(); m_inputField.selectAll(); m_inputField.setImmediate(true); /** * create nested FormLayout instance */ FormLayout formLayout = new FormLayout(); formLayout.setSizeUndefined(); formLayout.setMargin(true); formLayout.addComponent(m_inputField); /** * add the buttons in a horizontal layout */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth("100%"); /** * create cancel button */ m_cancelButton = new Button("Cancel"); m_cancelButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); m_cancelButton.addClickListener(this); horizontalLayout.addComponent(m_cancelButton); horizontalLayout.setExpandRatio(m_cancelButton, 1); horizontalLayout.setComponentAlignment(m_cancelButton, Alignment.TOP_RIGHT); /** * create ok button */ m_okButton = new Button("OK"); m_okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); m_okButton.addClickListener(this); horizontalLayout.addComponent(m_okButton); formLayout.addComponent(horizontalLayout); verticalLayout.addComponent(formLayout); /** * the close listener */ addCloseListener(this); /** * set the content */ setContent(verticalLayout); }