List of usage examples for com.vaadin.ui Button setDescription
public void setDescription(String description)
From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardEditor.java
License:Open Source License
/** * Constructor used for instantiating a new object. * * @param dashletSelector the {@link DashletSelector} to be used * @param wallboard the associated {@link Wallboard} instance *//*from w w w .j a va 2s. c om*/ public WallboardEditor(DashletSelector dashletSelector, Wallboard wallboard) { /** * Setting the member fields */ this.m_dashletSelector = dashletSelector; this.m_wallboard = wallboard; /** * Adding the {@link DashletSpec} instances */ for (DashletSpec dashletSpec : wallboard.getDashletSpecs()) { addDashletSpec(dashletSpec); } /** * Setting up layout component and adding text field and button */ setMargin(true); HorizontalLayout upperHorizontalLayout = new HorizontalLayout(); Label label = new Label("Ops Board configuration"); label.addStyleName("configuration-title"); upperHorizontalLayout.addComponent(label); upperHorizontalLayout.addComponent(label); Button helpButton = new Button("Help"); helpButton.setDescription("Display help and usage"); helpButton.setStyleName("small"); helpButton.addClickListener(new HelpClickListener(this, m_dashletSelector)); upperHorizontalLayout.addComponent(helpButton); upperHorizontalLayout.setWidth(100, Unit.PERCENTAGE); upperHorizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT); upperHorizontalLayout.setComponentAlignment(helpButton, Alignment.MIDDLE_RIGHT); addComponent(upperHorizontalLayout); HorizontalLayout horizontalLayout = new HorizontalLayout(); final Button addButton = new Button("Add dashlet"); addButton.setStyleName("small"); addButton.setDescription("Add a new dashlet instance"); addButton.addClickListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent clickEvent) { addDashletSpec(new DashletSpec()); } }); final TextField titleField = new TextField(); titleField.setDescription("Title for this Ops Board configuration"); titleField.setValue(wallboard.getTitle()); titleField.setImmediate(true); titleField.addValidator(new AbstractStringValidator("Title must be unique") { @Override protected boolean isValidValue(String s) { return (!WallboardProvider.getInstance().containsWallboard(s) || WallboardProvider.getInstance().getWallboard(s).equals(m_wallboard)) && !"".equals(s); } }); titleField.addTextChangeListener(new FieldEvents.TextChangeListener() { public void textChange(FieldEvents.TextChangeEvent textChangeEvent) { AbstractTextField source = (AbstractTextField) textChangeEvent.getSource(); source.setValue(textChangeEvent.getText()); if (source.isValid()) { m_tab.setCaption(textChangeEvent.getText()); m_wallboard.setTitle(textChangeEvent.getText()); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Title"); } } }); titleField.setCaption("Title"); final Button previewButton = new Button("Preview"); previewButton.setDescription("Preview this Ops Board configuration"); previewButton.setStyleName("small"); previewButton.addClickListener(new PreviewClickListener(this, m_wallboard)); /** * Adding the layout components to this component */ FormLayout formLayout1 = new FormLayout(); formLayout1.addComponent(titleField); horizontalLayout.addComponent(formLayout1); FormLayout formLayout2 = new FormLayout(); formLayout2.addComponent(addButton); horizontalLayout.addComponent(formLayout2); FormLayout formLayout3 = new FormLayout(); formLayout3.addComponent(previewButton); horizontalLayout.addComponent(formLayout3); addComponent(horizontalLayout); addComponent(m_verticalLayout); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardOverview.java
License:Open Source License
/** * Constructor for creating new instances. * * @param wallboardConfigView the {@link WallboardConfigView} *//* ww w. jav a2 s. c o m*/ public WallboardOverview(WallboardConfigView wallboardConfigView) { /** * Setting the member fields */ this.m_wallboardConfigView = wallboardConfigView; /** * Setting up the layout component */ setSizeFull(); setMargin(true); setSpacing(true); Label label = new Label("Overview"); label.addStyleName("configuration-title"); Button button = new Button("Help"); button.setStyleName("small"); button.setDescription("Display help and usage"); button.addClickListener(new HelpClickListener(this, m_wallboardConfigView.getDashletSelector())); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.addComponent(label); horizontalLayout.addComponent(button); horizontalLayout.setWidth(100, Unit.PERCENTAGE); horizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT); horizontalLayout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT); addComponent(horizontalLayout); /** * Adding the table with the required {@link Table.ColumnGenerator} objects */ m_table = new Table(); m_table.setSizeFull(); m_table.addGeneratedColumn("Edit", new Table.ColumnGenerator() { public Object generateCell(Table source, final Object itemId, Object columnId) { Button button = new Button("Edit"); button.setDescription("Edit this Ops Board configuration"); button.setStyleName("small"); button.addClickListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardConfigView.openWallboardEditor((Wallboard) itemId); } }); return button; } }); m_table.addGeneratedColumn("Remove", new Table.ColumnGenerator() { public Object generateCell(Table source, final Object itemId, Object columnId) { Button button = new Button("Remove"); button.setDescription("Delete this Ops Board configuration"); button.setStyleName("small"); button.addClickListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardConfigView.removeTab(((Wallboard) itemId).getTitle()); WallboardProvider.getInstance().removeWallboard((Wallboard) itemId); refreshTable(); } }); return button; } }); m_table.addGeneratedColumn("Preview", new Table.ColumnGenerator() { public Object generateCell(Table source, final Object itemId, Object columnId) { Button button = new Button("Preview"); button.setDescription("Preview this Ops Board configuration"); button.setStyleName("small"); button.addClickListener(new PreviewClickListener(WallboardOverview.this, (Wallboard) itemId)); return button; } }); m_table.addGeneratedColumn("Default", new Table.ColumnGenerator() { public Object generateCell(Table source, final Object itemId, Object columnId) { CheckBox checkBox = new CheckBox(); checkBox.setImmediate(true); checkBox.setDescription("Make this Ops Board configuration the default"); final Wallboard wallboard = m_beanItemContainer.getItem(itemId).getBean(); checkBox.setValue(wallboard.isDefault()); checkBox.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean newValue = ((Boolean) valueChangeEvent.getProperty().getValue()); if (newValue) { for (Wallboard wallboard1 : m_beanItemContainer.getItemIds()) { wallboard1.setDefault(false); } } wallboard.setDefault(newValue); m_table.refreshRowCache(); WallboardProvider.getInstance().save(); } }); return checkBox; } }); refreshTable(); /** * Adding the table */ addComponent(m_table); setExpandRatio(m_table, 1.0f); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.AlarmConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited */// w w w .j a v a 2 s . c om public AlarmConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; /** * Setting up the base layouts */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setHeight(100, Unit.PERCENTAGE); verticalLayout.setSizeFull(); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); /** * Adding the selection box */ m_boostedSeveritySelect = new NativeSelect(); m_boostedSeveritySelect.setCaption("Boosted Severity"); m_boostedSeveritySelect.setDescription("Select the boost severity"); m_boostedSeveritySelect.setMultiSelect(false); m_boostedSeveritySelect.setNullSelectionAllowed(false); m_boostedSeveritySelect.setInvalidAllowed(false); m_boostedSeveritySelect.setNewItemsAllowed(false); for (OnmsSeverity onmsSeverity : OnmsSeverity.values()) { m_boostedSeveritySelect.addItem(onmsSeverity.name()); } String boostSeverity = m_dashletSpec.getParameters().get("boostSeverity"); if (boostSeverity == null || "".equals(boostSeverity)) { boostSeverity = OnmsSeverity.CLEARED.name(); } m_boostedSeveritySelect.setValue(boostSeverity); verticalLayout.addComponent(m_boostedSeveritySelect); /** * Setting up the {@link CriteriaBuilderComponent} component */ CriteriaBuilderHelper criteriaBuilderHelper = new CriteriaBuilderHelper(OnmsAlarm.class, OnmsNode.class, OnmsEvent.class, OnmsCategory.class); final CriteriaBuilderComponent criteriaBuilderComponent = new CriteriaBuilderComponent( criteriaBuilderHelper, m_dashletSpec.getParameters().get("criteria")); verticalLayout.addComponent(criteriaBuilderComponent); verticalLayout.setExpandRatio(criteriaBuilderComponent, 1.0f); /** * 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.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setDescription("Cancel editing"); 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("criteria", criteriaBuilderComponent.getCriteria()); m_dashletSpec.getParameters().put("boostSeverity", String.valueOf(m_boostedSeveritySelect.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); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.BSMConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited *///from w ww . ja v a2 s .co m public BSMConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; /** * Setting up the base layouts */ setHeight(91, Unit.PERCENTAGE); setWidth(60, Unit.PERCENTAGE); /** * Retrieve the config... */ boolean filterByName = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterByName"); String nameValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "nameValue", ""); boolean filterByAttribute = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterByAttribute"); String attributeKey = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeKey", ""); String attributeValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeValue", ""); boolean filterBySeverity = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterBySeverity"); String severityValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "severityValue", Status.WARNING.name()); String severityCompareOperator = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "severityCompareOperator", BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name()); String orderBy = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderBy", BusinessServiceSearchCriteriaBuilder.Order.Name.name()); String orderSequence = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderSequence", BusinessServiceSearchCriteriaBuilder.Sequence.Ascending.name()); int resultsLimit = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "resultsLimit", 10); int columnCountBoard = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountBoard", 10); int columnCountPanel = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountPanel", 5); /** * Adding the "Filter By Name" panel */ m_filterByNameCheckBox = new CheckBox(); m_filterByNameCheckBox.setCaption("Enable"); m_filterByNameCheckBox.setDescription("Filter by Business Service name"); VerticalLayout nameLayout = new VerticalLayout(); nameLayout.setSpacing(true); nameLayout.setMargin(true); nameLayout.setSizeFull(); m_nameTextField = new TextField("Name (REGEXP)"); m_nameTextField.setEnabled(false); addToComponent(nameLayout, m_filterByNameCheckBox); addToComponent(nameLayout, m_nameTextField); Panel namePanel = new Panel(); namePanel.setCaption("Filter by Name"); namePanel.setContent(nameLayout); m_filterByNameCheckBox.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { m_nameTextField.setEnabled(m_filterByNameCheckBox.getValue()); } }); m_nameTextField.setValue(nameValue); m_filterByNameCheckBox.setValue(filterByName); /** * Adding the "Filter By Attribute" panel */ m_filterByAttributeCheckBox = new CheckBox(); m_filterByAttributeCheckBox.setCaption("Enable"); m_filterByAttributeCheckBox.setDescription("Filter by Business Service attribute"); VerticalLayout attributeLayout = new VerticalLayout(); attributeLayout.setSpacing(true); attributeLayout.setMargin(true); attributeLayout.setSizeFull(); m_attributeKeyTextField = new TextField("Key"); m_attributeKeyTextField.setEnabled(false); m_attributeValueTextField = new TextField("Value (REGEXP)"); m_attributeValueTextField.setEnabled(false); addToComponent(attributeLayout, m_filterByAttributeCheckBox); addToComponent(attributeLayout, m_attributeKeyTextField); addToComponent(attributeLayout, m_attributeValueTextField); Panel attributePanel = new Panel(); attributePanel.setCaption("Filter by Attribute"); attributePanel.setContent(attributeLayout); m_filterByAttributeCheckBox.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { m_attributeKeyTextField.setEnabled(m_filterByAttributeCheckBox.getValue()); m_attributeValueTextField.setEnabled(m_filterByAttributeCheckBox.getValue()); } }); m_attributeKeyTextField.setValue(attributeKey); m_attributeValueTextField.setValue(attributeValue); m_filterByAttributeCheckBox.setValue(filterByAttribute); /** * Adding the "Filter By Severity" panel */ m_filterBySeverityCheckBox = new CheckBox(); m_filterBySeverityCheckBox.setCaption("Enable"); m_filterBySeverityCheckBox.setDescription("Filter by Business Service severity"); VerticalLayout severityLayout = new VerticalLayout(); severityLayout.setSpacing(true); severityLayout.setMargin(true); severityLayout.setSizeFull(); m_severitySelect = new NativeSelect("Severity"); m_severitySelect.setEnabled(false); m_severitySelect.setNullSelectionAllowed(false); m_severitySelect.setMultiSelect(false); for (Status eachStatus : Status.values()) { m_severitySelect.addItem(eachStatus.name()); } m_compareOperatorSelect = new NativeSelect("Comparator"); m_compareOperatorSelect.setEnabled(false); m_compareOperatorSelect.setNullSelectionAllowed(false); m_compareOperatorSelect.setMultiSelect(false); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Lower.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.LowerOrEqual.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Equal.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Greater.name()); addToComponent(severityLayout, m_filterBySeverityCheckBox); addToComponent(severityLayout, m_severitySelect); addToComponent(severityLayout, m_compareOperatorSelect); Panel severityPanel = new Panel(); severityPanel.setCaption("Filter by Severity"); severityPanel.setContent(severityLayout); m_filterBySeverityCheckBox.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { m_severitySelect.setEnabled(m_filterBySeverityCheckBox.getValue()); m_compareOperatorSelect.setEnabled(m_filterBySeverityCheckBox.getValue()); } }); m_severitySelect.setValue(severityValue); m_compareOperatorSelect.setValue(severityCompareOperator); m_filterBySeverityCheckBox.setValue(filterBySeverity); /** * Adding the "Results" panel */ VerticalLayout limitLayout = new VerticalLayout(); limitLayout.setSpacing(true); limitLayout.setMargin(true); limitLayout.setSizeFull(); m_limitTextField = new TextField("Limit"); m_orderBy = new NativeSelect("Order by"); m_orderBy.setNullSelectionAllowed(false); m_orderBy.setMultiSelect(false); m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Name.name()); m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Severity.name()); m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Level.name()); m_orderSequence = new NativeSelect("Asc/Desc "); m_orderSequence.setNullSelectionAllowed(false); m_orderSequence.setMultiSelect(false); m_orderSequence.addItem("Ascending"); m_orderSequence.addItem("Descending"); m_columnCountBoardTextField = new TextField("Ops Board Column Count"); m_columnCountBoardTextField.addValidator(new AbstractStringValidator("Number greater zero expected") { @Override protected boolean isValidValue(String value) { try { int i = Integer.parseInt(value); return i > 0; } catch (NumberFormatException e) { return false; } } }); m_columnCountPanelTextField = new TextField("Ops Panel Column Count"); m_columnCountPanelTextField.addValidator(new AbstractStringValidator("Number greater zero expected") { @Override protected boolean isValidValue(String value) { try { int i = Integer.parseInt(value); return i > 0; } catch (NumberFormatException e) { return false; } } }); addToComponent(limitLayout, m_limitTextField); addToComponent(limitLayout, m_orderBy); addToComponent(limitLayout, m_orderSequence); addToComponent(limitLayout, m_columnCountBoardTextField); addToComponent(limitLayout, m_columnCountPanelTextField); Panel limitPanel = new Panel(); limitPanel.setSizeFull(); limitPanel.setCaption("Results"); limitPanel.setContent(limitLayout); m_limitTextField.setValue(String.valueOf(resultsLimit)); m_orderBy.setValue(orderBy); m_orderSequence.setValue(orderSequence); m_columnCountBoardTextField.setValue(String.valueOf(columnCountBoard)); m_columnCountPanelTextField.setValue(String.valueOf(columnCountPanel)); m_limitTextField.addValidator(new AbstractStringValidator("Number greater or equal zero expected") { @Override protected boolean isValidValue(String value) { try { int i = Integer.parseInt(value); return i >= 0; } catch (NumberFormatException e) { return false; } } }); /** * Create the main layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setWidth(100, Unit.PERCENTAGE); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); verticalLayout.addComponent(namePanel); verticalLayout.addComponent(attributePanel); HorizontalLayout bottomLayout = new HorizontalLayout(severityPanel, limitPanel); bottomLayout.setSpacing(true); bottomLayout.setSizeFull(); bottomLayout.setWidth(100, Unit.PERCENTAGE); verticalLayout.addComponent(bottomLayout); /** * Using an additional {@link HorizontalLayout} for layouting the buttons */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); Label label = new Label("Note: Multiple enabled filter constraints will be combined by a logical AND."); buttonLayout.addComponent(label); buttonLayout.setExpandRatio(label, 1.0f); /** * 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.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 (!m_limitTextField.isValid() || !m_columnCountPanelTextField.isValid() || !m_columnCountBoardTextField.isValid()) { return; } m_dashletSpec.getParameters().put("filterByName", (m_filterByNameCheckBox.getValue() ? "true" : "false")); if (m_filterByNameCheckBox.getValue()) { m_dashletSpec.getParameters().put("nameValue", m_nameTextField.getValue()); } else { m_dashletSpec.getParameters().put("nameValue", ""); } m_dashletSpec.getParameters().put("filterByAttribute", (m_filterByAttributeCheckBox.getValue() ? "true" : "false")); if (m_filterByAttributeCheckBox.getValue()) { m_dashletSpec.getParameters().put("attributeKey", m_attributeKeyTextField.getValue()); m_dashletSpec.getParameters().put("attributeValue", m_attributeValueTextField.getValue()); } else { m_dashletSpec.getParameters().put("attributeKey", ""); m_dashletSpec.getParameters().put("attributeValue", ""); } m_dashletSpec.getParameters().put("filterBySeverity", (m_filterBySeverityCheckBox.getValue() ? "true" : "false")); if (m_filterBySeverityCheckBox.getValue() && m_severitySelect.getValue() != null) { m_dashletSpec.getParameters().put("severityValue", m_severitySelect.getValue().toString()); } else { m_dashletSpec.getParameters().put("severityValue", Status.WARNING.getLabel()); } if (m_filterBySeverityCheckBox.getValue() && m_compareOperatorSelect.getValue() != null) { m_dashletSpec.getParameters().put("severityCompareOperator", m_compareOperatorSelect.getValue().toString()); } else { m_dashletSpec.getParameters().put("severityCompareOperator", BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name()); } if (m_orderBy.getValue() != null) { m_dashletSpec.getParameters().put("orderBy", m_orderBy.getValue().toString()); } else { m_dashletSpec.getParameters().put("orderBy", BusinessServiceSearchCriteriaBuilder.Order.Name.name()); } if (m_orderSequence.getValue() != null) { m_dashletSpec.getParameters().put("orderSequence", m_orderSequence.getValue().toString()); } else { m_dashletSpec.getParameters().put("orderSequence", "Ascending"); } m_dashletSpec.getParameters().put("resultsLimit", m_limitTextField.getValue().toString()); m_dashletSpec.getParameters().put("columnCountBoard", m_columnCountBoardTextField.getValue().toString()); m_dashletSpec.getParameters().put("columnCountPanel", m_columnCountPanelTextField.getValue().toString()); 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); setContent(verticalLayout); }
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 *//* ww w. j a v a 2 s .c o 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 *//*from www .j ava 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.dashboard.dashlets.RrdDashletConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited *///w w w .j a v a 2s . c o m public RrdDashletConfigurationWindow(DashletSpec dashletSpec, RrdGraphHelper rrdGraphHelper, NodeDao nodeDao) { /** * Setting the members */ m_dashletSpec = dashletSpec; m_nodeDao = nodeDao; m_rrdGraphHelper = rrdGraphHelper; /** * creating the grid layout */ m_gridLayout = new GridLayout(); m_gridLayout.setSizeFull(); m_gridLayout.setColumns(1); m_gridLayout.setRows(1); /** * setting up the layouts */ FormLayout leftFormLayout = new FormLayout(); FormLayout middleFormLayout = new FormLayout(); FormLayout rightFormLayout = new FormLayout(); /** * creating the columns and rows selection fields */ m_columnsSelect = new NativeSelect(); m_columnsSelect.setCaption("Columns"); m_columnsSelect.setDescription("Number of columns"); m_columnsSelect.setImmediate(true); m_columnsSelect.setNewItemsAllowed(false); m_columnsSelect.setMultiSelect(false); m_columnsSelect.setInvalidAllowed(false); m_columnsSelect.setNullSelectionAllowed(false); m_rowsSelect = new NativeSelect(); m_rowsSelect.setCaption("Rows"); m_rowsSelect.setDescription("Number of rows"); m_rowsSelect.setImmediate(true); m_rowsSelect.setNewItemsAllowed(false); m_rowsSelect.setMultiSelect(false); m_rowsSelect.setInvalidAllowed(false); m_rowsSelect.setNullSelectionAllowed(false); for (int i = 1; i < 5; i++) { m_columnsSelect.addItem(i); m_rowsSelect.addItem(i); } /** * setting the values/defaults */ int columns; int rows; try { columns = Integer.parseInt(m_dashletSpec.getParameters().get("columns")); } catch (NumberFormatException numberFormatException) { columns = 1; } try { rows = Integer.parseInt(m_dashletSpec.getParameters().get("rows")); } catch (NumberFormatException numberFormatException) { rows = 1; } m_columnsSelect.setValue(columns); m_rowsSelect.setValue(rows); /** * width and height fields */ m_widthField = new TextField(); m_widthField.setCaption("Graph Width"); m_widthField.setDescription("Width of graphs"); m_widthField.setValue(m_dashletSpec.getParameters().get("width")); m_heightField = new TextField(); m_heightField.setCaption("Graph Height"); m_heightField.setDescription("Height of graphs"); m_heightField.setValue(m_dashletSpec.getParameters().get("height")); m_timeFrameValue = new TextField("Timeframe value"); m_timeFrameValue.setDescription("Timeframe value"); m_timeFrameValue.setValue(m_dashletSpec.getParameters().get("timeFrameValue")); m_timeFrameType = new NativeSelect("Timeframe type"); m_timeFrameType.setDescription("Timeframe type"); m_timeFrameType.setNullSelectionAllowed(false); m_timeFrameType.setMultiSelect(false); m_timeFrameType.setNewItemsAllowed(false); m_timeFrameType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.EXPLICIT); m_timeFrameType.addItem(String.valueOf(Calendar.MINUTE)); m_timeFrameType.setItemCaption(String.valueOf(Calendar.MINUTE), "Minute"); m_timeFrameType.addItem(String.valueOf(Calendar.HOUR_OF_DAY)); m_timeFrameType.setItemCaption(String.valueOf(Calendar.HOUR_OF_DAY), "Hour"); m_timeFrameType.addItem(String.valueOf(Calendar.DAY_OF_YEAR)); m_timeFrameType.setItemCaption(String.valueOf(Calendar.DAY_OF_YEAR), "Day"); m_timeFrameType.addItem(String.valueOf(Calendar.WEEK_OF_YEAR)); m_timeFrameType.setItemCaption(String.valueOf(Calendar.WEEK_OF_YEAR), "Week"); m_timeFrameType.addItem(String.valueOf(Calendar.MONTH)); m_timeFrameType.setItemCaption(String.valueOf(Calendar.MONTH), "Month"); m_timeFrameType.addItem(String.valueOf(Calendar.YEAR)); m_timeFrameType.setItemCaption(String.valueOf(Calendar.YEAR), "Year"); m_timeFrameType.setValue(m_dashletSpec.getParameters().get("timeFrameType")); m_timeFrameType.setImmediate(true); m_timeFrameValue.setImmediate(true); m_timeFrameType.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { updatePreview(); } }); m_timeFrameValue.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { updatePreview(); } }); /** * initial creation of the grid */ recreateCells(columns, rows); /** * creating the value listeners for columns/rows */ m_columnsSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { recreateCells(Integer.valueOf(valueChangeEvent.getProperty().getValue().toString()), m_gridLayout.getRows()); } }); m_rowsSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { recreateCells(m_gridLayout.getColumns(), Integer.valueOf(valueChangeEvent.getProperty().getValue().toString())); } }); leftFormLayout.addComponent(m_columnsSelect); leftFormLayout.addComponent(m_widthField); leftFormLayout.addComponent(m_timeFrameValue); middleFormLayout.addComponent(m_rowsSelect); middleFormLayout.addComponent(m_heightField); middleFormLayout.addComponent(m_timeFrameType); /** * KSC import stuff */ Button importButton = new Button("KSC Import"); importButton.setDescription("Import KSC-report"); final NativeSelect selectKSCReport = new NativeSelect(); selectKSCReport.setDescription("KSC-report selection"); selectKSCReport.setCaption("KSC Report"); selectKSCReport.setImmediate(true); selectKSCReport.setNewItemsAllowed(false); selectKSCReport.setMultiSelect(false); selectKSCReport.setInvalidAllowed(false); selectKSCReport.setNullSelectionAllowed(false); selectKSCReport.setImmediate(true); kscPerformanceReportFactory = KSC_PerformanceReportFactory.getInstance(); Map<Integer, String> mapOfKscReports = kscPerformanceReportFactory.getReportList(); if (mapOfKscReports.size() == 0) { importButton.setEnabled(false); } for (Map.Entry<Integer, String> entry : mapOfKscReports.entrySet()) { selectKSCReport.addItem(entry.getKey()); selectKSCReport.setItemCaption(entry.getKey(), entry.getValue()); if (selectKSCReport.getValue() == null) { selectKSCReport.setValue(entry.getKey()); } } importButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { importKscReport(Integer.valueOf(selectKSCReport.getValue().toString())); } }); rightFormLayout.addComponent(selectKSCReport); rightFormLayout.addComponent(importButton); /** * setting up the layout */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.addComponent(leftFormLayout); horizontalLayout.addComponent(middleFormLayout); horizontalLayout.addComponent(rightFormLayout); /** * 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) { /** * saving the data */ m_dashletSpec.getParameters().put("width", m_widthField.getValue().toString()); m_dashletSpec.getParameters().put("height", m_heightField.getValue().toString()); m_dashletSpec.getParameters().put("columns", m_columnsSelect.getValue().toString()); m_dashletSpec.getParameters().put("rows", m_rowsSelect.getValue().toString()); int timeFrameValue; int timeFrameType; try { timeFrameValue = Integer.parseInt(m_timeFrameValue.getValue().toString()); } catch (NumberFormatException numberFormatException) { timeFrameValue = 1; } try { timeFrameType = Integer.parseInt(m_timeFrameType.getValue().toString()); } catch (NumberFormatException numberFormatException) { timeFrameType = Calendar.HOUR; } m_dashletSpec.getParameters().put("timeFrameType", String.valueOf(timeFrameType)); m_dashletSpec.getParameters().put("timeFrameValue", String.valueOf(timeFrameValue)); int i = 0; for (int y = 0; y < m_gridLayout.getRows(); y++) { for (int x = 0; x < m_gridLayout.getColumns(); x++) { RrdGraphEntry rrdGraphEntry = (RrdGraphEntry) m_gridLayout.getComponent(x, y); m_dashletSpec.getParameters().put("nodeLabel" + i, rrdGraphEntry.getNodeLabel()); m_dashletSpec.getParameters().put("nodeId" + i, rrdGraphEntry.getNodeId()); m_dashletSpec.getParameters().put("resourceTypeLabel" + i, rrdGraphEntry.getResourceTypeLabel()); m_dashletSpec.getParameters().put("resourceTypeId" + i, rrdGraphEntry.getResourceTypeId()); m_dashletSpec.getParameters().put("resourceId" + i, rrdGraphEntry.getResourceId()); m_dashletSpec.getParameters().put("resourceLabel" + i, rrdGraphEntry.getResourceLabel()); m_dashletSpec.getParameters().put("graphLabel" + i, rrdGraphEntry.getGraphLabel()); m_dashletSpec.getParameters().put("graphId" + i, rrdGraphEntry.getGraphId()); m_dashletSpec.getParameters().put("graphUrl" + i, rrdGraphEntry.getGraphUrl()); i++; } } 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 verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(m_gridLayout); verticalLayout.addComponent(buttonLayout); verticalLayout.setExpandRatio(m_gridLayout, 2.0f); verticalLayout.setSizeFull(); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.jmxconfiggenerator.ui.UIHelper.java
License:Open Source License
public static Button createButton(final String buttonCaption, final String buttonDescription, final Resource icon, final ClickListener clickListener) { Button button = new Button(); button.setCaption(buttonCaption);//from w ww. j a v a2 s .c o m button.setIcon(icon); if (buttonDescription != null) button.setDescription(buttonDescription); if (clickListener != null) button.addClickListener(clickListener); return button; }
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 w ww. ja v a 2 s. com*/ 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 *///from w w w. j a va2 s . com 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); }