List of usage examples for com.vaadin.ui Button setClickShortcut
public void setClickShortcut(int keyCode, int... modifiers)
From source file:org.opennms.features.topology.app.internal.TopologyUI.java
License:Open Source License
@Override public void menuBarUpdated(CommandManager commandManager) { if (m_menuBar != null) { m_rootLayout.removeComponent(m_menuBar); }/*from ww w . j a va2 s . c o m*/ if (m_contextMenu != null) { m_contextMenu.detach(); } m_menuBar = commandManager.getMenuBar(m_graphContainer, this); m_menuBar.setWidth(100, Unit.PERCENTAGE); // Set expand ratio so that extra space is not allocated to this vertical component if (m_showHeader) { m_rootLayout.addComponent(m_menuBar, 1); } else { m_rootLayout.addComponent(m_menuBar, 0); } m_contextMenu = commandManager .getContextMenu(new DefaultOperationContext(this, m_graphContainer, DisplayLocation.CONTEXTMENU)); m_contextMenu.setAsContextMenuOf(this); // Add Menu Item to share the View with others m_menuBar.addItem("Share", FontAwesome.SHARE, new MenuBar.Command() { @Override public void menuSelected(MenuItem selectedItem) { // create the share link String fragment = getPage().getLocation().getFragment(); String url = getPage().getLocation().toString().replace("#" + getPage().getLocation().getFragment(), ""); String shareLink = String.format("%s?%s=%s", url, TopologyUIRequestHandler.PARAMETER_HISTORY_FRAGMENT, fragment); // Create the Window Window shareWindow = new Window(); shareWindow.setCaption("Share Link"); shareWindow.setModal(true); shareWindow.setClosable(true); shareWindow.setResizable(false); shareWindow.setWidth(400, Unit.PIXELS); TextArea shareLinkField = new TextArea(); shareLinkField.setValue(shareLink); shareLinkField.setReadOnly(true); shareLinkField.setRows(3); shareLinkField.setWidth(100, Unit.PERCENTAGE); // Close Button Button close = new Button("Close"); close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); close.addClickListener(event -> shareWindow.close()); // Layout for Buttons HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); buttonLayout.addComponent(close); buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT); // Content Layout VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.setSpacing(true); verticalLayout.addComponent( new Label("Please use the following link to share the current view with others.")); verticalLayout.addComponent(shareLinkField); verticalLayout.addComponent(buttonLayout); shareWindow.setContent(verticalLayout); getUI().addWindow(shareWindow); } }); updateMenuItems(); }
From source file:org.opennms.features.topology.app.internal.ui.ToolbarPanel.java
License:Open Source License
public ToolbarPanel(final ToolbarPanelController controller) { addStyleName(Styles.TOOLBAR);/*w w w.j a v a2 s . c o m*/ this.layoutManager = controller.getLayoutManager(); final Property<Double> scale = controller.getScaleProperty(); final Boolean[] eyeClosed = new Boolean[] { false }; final Button showFocusVerticesBtn = new Button(); showFocusVerticesBtn.setIcon(FontAwesome.EYE); showFocusVerticesBtn.setDescription("Toggle Highlight Focus Nodes"); showFocusVerticesBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (eyeClosed[0]) { showFocusVerticesBtn.setIcon(FontAwesome.EYE); } else { showFocusVerticesBtn.setIcon(FontAwesome.EYE_SLASH); } eyeClosed[0] = !eyeClosed[0]; // toggle controller.toggleHighlightFocus(); } }); final Button magnifyBtn = new Button(); magnifyBtn.setIcon(FontAwesome.PLUS); magnifyBtn.setDescription("Magnify"); magnifyBtn.addClickListener( (Button.ClickListener) event -> scale.setValue(Math.min(1, scale.getValue() + 0.25))); final Button demagnifyBtn = new Button(); demagnifyBtn.setIcon(FontAwesome.MINUS); demagnifyBtn.setDescription("Demagnify"); demagnifyBtn.addClickListener( (Button.ClickListener) event -> scale.setValue(Math.max(0, scale.getValue() - 0.25))); m_szlOutBtn = new Button(); m_szlOutBtn.setId("szlOutBtn"); m_szlOutBtn.setIcon(FontAwesome.ANGLE_DOWN); m_szlOutBtn.setDescription("Decrease Semantic Zoom Level"); m_szlOutBtn.setEnabled(controller.getSemanticZoomLevel() > 0); m_szlOutBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { int szl = controller.getSemanticZoomLevel(); if (szl > 0) { setSemanticZoomLevel(controller, szl - 1); controller.saveHistory(); } } }); final Button szlInBtn = new Button(); szlInBtn.setId("szlInBtn"); szlInBtn.setIcon(FontAwesome.ANGLE_UP); szlInBtn.setDescription("Increase Semantic Zoom Level"); szlInBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { setSemanticZoomLevel(controller, controller.getSemanticZoomLevel() + 1); controller.saveHistory(); } }); m_zoomLevelLabel.setId("szlInputLabel"); m_panBtn = new Button(); m_panBtn.setIcon(FontAwesome.ARROWS); m_panBtn.setDescription("Pan Tool"); m_panBtn.addStyleName(Styles.SELECTED); m_selectBtn = new Button(); m_selectBtn.setIcon(IonicIcons.ANDROID_EXPAND); m_selectBtn.setDescription("Selection Tool"); m_selectBtn.setStyleName("toolbar-button"); m_selectBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { m_selectBtn.addStyleName(Styles.SELECTED); m_panBtn.removeStyleName(Styles.SELECTED); controller.setActiveTool(ActiveTool.select); } }); m_panBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { m_panBtn.addStyleName(Styles.SELECTED); m_selectBtn.removeStyleName(Styles.SELECTED); controller.setActiveTool(ActiveTool.pan); } }); Button showAllMapBtn = new Button(); showAllMapBtn.setId("showEntireMapBtn"); showAllMapBtn.setIcon(FontAwesome.GLOBE); showAllMapBtn.setDescription("Show Entire Map"); showAllMapBtn.addClickListener((Button.ClickListener) event -> controller.showAllMap()); Button centerSelectionBtn = new Button(); centerSelectionBtn.setIcon(FontAwesome.LOCATION_ARROW); centerSelectionBtn.setDescription("Center On Selection"); centerSelectionBtn.addClickListener((Button.ClickListener) event -> controller.centerMapOnSelection()); Button shareButton = new Button("", FontAwesome.SHARE_SQUARE_O); shareButton.setDescription("Share"); shareButton.addClickListener((x) -> { // Create the share link String fragment = getUI().getPage().getLocation().getFragment(); String url = getUI().getPage().getLocation().toString().replace("#" + fragment, ""); String shareLink = String.format("%s?%s=%s", url, PARAMETER_HISTORY_FRAGMENT, fragment); // Create the Window Window shareWindow = new Window(); shareWindow.setCaption("Share Link"); shareWindow.setModal(true); shareWindow.setClosable(true); shareWindow.setResizable(false); shareWindow.setWidth(400, Sizeable.Unit.PIXELS); TextArea shareLinkField = new TextArea(); shareLinkField.setValue(shareLink); shareLinkField.setReadOnly(true); shareLinkField.setRows(3); shareLinkField.setWidth(100, Sizeable.Unit.PERCENTAGE); // Close Button Button close = new Button("Close"); close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); close.addClickListener(event -> shareWindow.close()); // Layout for Buttons HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); buttonLayout.addComponent(close); buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT); // Content Layout VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.setSpacing(true); verticalLayout.addComponent( new Label("Please use the following link to share the current view with others.")); verticalLayout.addComponent(shareLinkField); verticalLayout.addComponent(buttonLayout); shareWindow.setContent(verticalLayout); getUI().addWindow(shareWindow); }); // Refresh Button Button refreshButton = new Button(); refreshButton.setId("refreshNow"); refreshButton.setIcon(FontAwesome.REFRESH); refreshButton.setDescription("Refresh Now"); refreshButton.addClickListener((event) -> controller.refreshUI()); // Layer Layout layerLayout = new VerticalLayout(); layerLayout.setId("layerComponent"); layerLayout.setSpacing(true); layerLayout.setMargin(true); // Layer Button layerButton = new Button(); layerButton.setId("layerToggleButton"); layerButton.setIcon(FontAwesome.BARS); layerButton.setDescription("Layers"); layerButton.addClickListener((event) -> { boolean isCollapsed = layerButton.getStyleName().contains(Styles.EXPANDED); setLayerLayoutVisible(!isCollapsed); }); // Save button layerSaveButton = new Button(); layerSaveButton.setId("saveLayerButton"); layerSaveButton.setIcon(FontAwesome.FLOPPY_O); layerSaveButton.addClickListener((event) -> controller.saveLayout()); // Actual Layout for the Toolbar CssLayout contentLayout = new CssLayout(); contentLayout.addStyleName("toolbar-component"); contentLayout.addComponent(createGroup(szlInBtn, m_zoomLevelLabel, m_szlOutBtn)); contentLayout.addComponent( createGroup(refreshButton, centerSelectionBtn, showAllMapBtn, layerButton, showFocusVerticesBtn)); contentLayout.addComponent(createGroup(m_panBtn, m_selectBtn)); contentLayout.addComponent(createGroup(magnifyBtn, demagnifyBtn)); contentLayout.addComponent(createGroup(shareButton)); contentLayout.addComponent(createGroup(layerSaveButton)); // Toolbar addComponent(contentLayout); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.PropertiesWindow.java
License:Open Source License
/** * Constructor for instantiating a {@link PropertiesWindow} for a given {@link DashletSpec}. * * @param dashletSpec the {@link DashletSpec} to edit * @param dashletFactory the {@link DashletFactory} for querying the property data *///from w w w . ja va2s. c o m public PropertiesWindow(final DashletSpec dashletSpec, final DashletFactory dashletFactory) { /** * Using a vertical layout for content */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); //verticalLayout.addStyleName("debug"); verticalLayout.setSizeFull(); verticalLayout.setHeight(100, Unit.PERCENTAGE); /** * Setting up the table object for displaying the parameters */ final Table table = new Table(); table.setTableFieldFactory(new DefaultFieldFactory() { @Override public Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) { Field<?> field = super.createField(container, itemId, propertyId, uiContext); if (propertyId.equals("Key")) { field.setReadOnly(true); } else { field.setSizeFull(); } return field; } }); table.setEditable(true); table.setSizeFull(); table.setImmediate(true); table.addContainerProperty("Key", String.class, ""); table.addContainerProperty("Value", String.class, ""); /** * Filling the date with parameter data */ final Map<String, String> requiredParameters = dashletFactory.getRequiredParameters(); for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { table.addItem(new Object[] { entry.getKey(), dashletSpec.getParameters().get(entry.getKey()) }, entry.getKey()); } table.setColumnWidth("Key", 100); table.setColumnWidth("Value", -1); table.setSizeFull(); verticalLayout.addComponent(table); /** * Using an additional {@link 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) { for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { String newValue = table.getItem(entry.getKey()).getItemProperty("Value").getValue().toString(); dashletSpec.getParameters().put(entry.getKey(), newValue); } WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties"); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); horizontalLayout.addComponent(ok); //horizontalLayout.addStyleName("debug"); /** * Adding the layout and setting the content */ verticalLayout.addComponent(horizontalLayout); verticalLayout.setExpandRatio(table, 1.0f); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardConfigView.java
License:Open Source License
/** * This method is used to add a new {@link TabSheet.Tab} component. It creates a new window querying the user for the name of the new {@link Wallboard}. *//* ww w.j a v a 2 s . co m*/ protected void addNewTabComponent() { final Window window = new Window("New Ops Board"); window.setModal(true); window.setClosable(false); window.setResizable(false); window.addCloseListener(new Window.CloseListener() { @Override public void windowClose(Window.CloseEvent e) { m_dashboardOverview.refreshTable(); } }); getUI().addWindow(window); window.setContent(new VerticalLayout() { TextField name = new TextField("Ops Board Name"); { addComponent(new FormLayout() { { setSizeUndefined(); setMargin(true); String newName = "Untitled"; int i = 1; if (WallboardProvider.getInstance().containsWallboard(newName)) { do { i++; newName = "Untitled #" + i; } while (WallboardProvider.getInstance().containsWallboard(newName)); } name.setValue(newName); addComponent(name); name.focus(); name.selectAll(); name.addValidator(new AbstractStringValidator("Title must be unique") { @Override protected boolean isValidValue(String s) { return (!WallboardProvider.getInstance().containsWallboard(s) && !"".equals(s)); } }); } }); addComponent(new HorizontalLayout() { { setMargin(true); setSpacing(true); setWidth("100%"); Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { // NMS-7560: Toggle the tab in order to allow us to click it again m_tabSheet.togglePlusTab(); window.close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); addComponent(cancel); setExpandRatio(cancel, 1); setComponentAlignment(cancel, Alignment.TOP_RIGHT); Button ok = new Button("Save"); ok.setDescription("Save configuration"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (name.isValid()) { Wallboard wallboard = new Wallboard(); wallboard.setTitle(name.getValue()); WallboardProvider.getInstance().addWallboard(wallboard); WallboardProvider.getInstance().save(); WallboardEditor wallboardEditor = new WallboardEditor(m_dashletSelector, wallboard); TabSheet.Tab tab = m_tabSheet.addTab(wallboardEditor, wallboard.getTitle()); wallboardEditor.setTab(tab); m_wallboardEditorMap.put(wallboard, tab); tab.setClosable(true); m_tabSheet.setSelectedTab(tab); window.close(); } } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); addComponent(ok); } }); } }); }
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 *///from w ww . j a v a 2 s . c o m 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 w w. j a v a 2 s.c om*/ 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 *//*from w w w . j av a 2s. 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.GraphSelectionWindow.java
License:Open Source License
/** * Constructor for creating new instances. * * @param nodeDao the node dao instance * @param rrdGraphHelper the rrd graph helper instance * @param rrdGraphEntry the entry to be edited *///from w ww . j av a2 s .c o m public GraphSelectionWindow(final NodeDao nodeDao, final RrdGraphHelper rrdGraphHelper, final RrdGraphEntry rrdGraphEntry) { /** * Setting the title */ super("Select RRD graph"); /** * setting up the component */ setModal(true); setClosable(false); setResizable(false); setWidth(50, Unit.PERCENTAGE); setHeight(70, Unit.PERCENTAGE); /** * setting up the container */ final HierarchicalContainer hierarchicalContainer = new HierarchicalContainer(); hierarchicalContainer.addContainerProperty("id", String.class, null); hierarchicalContainer.addContainerProperty("label", String.class, null); hierarchicalContainer.addContainerProperty("type", String.class, null); hierarchicalContainer.addContainerProperty("nodeId", String.class, null); hierarchicalContainer.addContainerProperty("nodeLabel", String.class, null); hierarchicalContainer.addContainerProperty("resourceId", String.class, null); hierarchicalContainer.addContainerProperty("resourceLabel", String.class, null); hierarchicalContainer.addContainerProperty("resourceTypeId", String.class, null); hierarchicalContainer.addContainerProperty("resourceTypeLabel", String.class, null); hierarchicalContainer.addContainerProperty("graphId", String.class, null); hierarchicalContainer.addContainerProperty("graphLabel", String.class, null); hierarchicalContainer.addContainerProperty("graphUrl", String.class, null); /** * filling the container with node data */ List<OnmsNode> onmsNodeList = nodeDao.findAll(); for (OnmsNode onmsNode : onmsNodeList) { Item item = hierarchicalContainer.addItem(onmsNode.getId().toString()); item.getItemProperty("label").setValue(onmsNode.getLabel() + " (" + onmsNode.getId() + ")"); item.getItemProperty("id").setValue(onmsNode.getId().toString()); item.getItemProperty("type").setValue("node"); item.getItemProperty("nodeId").setValue(onmsNode.getId().toString()); } /** * creating a panel for the tree component */ Panel panel = new Panel(); m_tree = new Tree(); m_tree.setCaption("Graph"); m_tree.setSizeFull(); m_tree.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); m_tree.setItemCaptionPropertyId("label"); m_tree.setContainerDataSource(hierarchicalContainer); m_tree.setMultiSelect(false); m_tree.setNewItemsAllowed(false); m_tree.setImmediate(true); /** * adding en expand listener for lazy loading the resourceType and resource data */ m_tree.addExpandListener(new Tree.ExpandListener() { @Override public void nodeExpand(Tree.ExpandEvent expandEvent) { String itemToExpandId = String.valueOf(expandEvent.getItemId()); /** * if the data has already been loaded, return */ if (m_tree.hasChildren(itemToExpandId)) { return; } Item itemToExpand = m_tree.getItem(expandEvent.getItemId()); String type = itemToExpand.getItemProperty("type").getValue().toString(); /** * a node is selected */ if ("node".equals(type)) { Map<OnmsResourceType, List<OnmsResource>> resourceTypeMap = rrdGraphHelper .getResourceTypeMapForNodeId( String.valueOf(itemToExpand.getItemProperty("id").getValue())); for (Map.Entry<OnmsResourceType, List<OnmsResource>> resourceTypeMapEntry : resourceTypeMap .entrySet()) { String newResourceTypeItemId = "node[" + itemToExpandId + "]." + resourceTypeMapEntry.getKey().getName(); Item newResourceTypeItem = hierarchicalContainer.addItem(newResourceTypeItemId); newResourceTypeItem.getItemProperty("label") .setValue(resourceTypeMapEntry.getKey().getLabel()); newResourceTypeItem.getItemProperty("type").setValue("resourceType"); newResourceTypeItem.getItemProperty("nodeId").setValue(itemToExpandId); newResourceTypeItem.getItemProperty("nodeLabel") .setValue(itemToExpand.getItemProperty("label").getValue()); newResourceTypeItem.getItemProperty("resourceTypeId").setValue(newResourceTypeItemId); newResourceTypeItem.getItemProperty("resourceTypeLabel") .setValue(resourceTypeMapEntry.getKey().getLabel()); m_tree.setParent(newResourceTypeItemId, itemToExpandId); m_tree.setChildrenAllowed(newResourceTypeItemId, true); for (OnmsResource onmsResource : resourceTypeMapEntry.getValue()) { String newResourceItemId = null; try { newResourceItemId = URLDecoder.decode(onmsResource.getId(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Item newResourceItem = hierarchicalContainer.addItem(newResourceItemId); newResourceItem.getItemProperty("label").setValue(onmsResource.getLabel()); newResourceItem.getItemProperty("type").setValue("resource"); newResourceItem.getItemProperty("nodeId").setValue(itemToExpandId); newResourceItem.getItemProperty("nodeLabel") .setValue(itemToExpand.getItemProperty("label").getValue()); newResourceItem.getItemProperty("resourceId").setValue(newResourceItemId); newResourceItem.getItemProperty("resourceLabel").setValue(onmsResource.getLabel()); newResourceItem.getItemProperty("resourceTypeId").setValue(newResourceTypeItemId); newResourceItem.getItemProperty("resourceTypeLabel") .setValue(newResourceTypeItem.getItemProperty("label").getValue()); m_tree.setParent(newResourceItemId, newResourceTypeItemId); m_tree.setChildrenAllowed(newResourceItemId, true); } } } /** * a resource is selected */ if ("resource".equals(type)) { Map<String, String> map = rrdGraphHelper.getGraphResultsForResourceId(itemToExpandId); Map<String, String> titleNameMapping = rrdGraphHelper .getGraphTitleNameMappingForResourceId(itemToExpandId); for (Map.Entry<String, String> entry : titleNameMapping.entrySet()) { String newGraphItemId = itemToExpandId + "." + entry.getKey(); /* if (hierarchicalContainer.containsId(newGraphItemId)) { continue; } */ Item newGraphItem = hierarchicalContainer.addItem(newGraphItemId); newGraphItem.getItemProperty("label").setValue(entry.getKey()); newGraphItem.getItemProperty("type").setValue("graph"); newGraphItem.getItemProperty("nodeId") .setValue(String.valueOf(itemToExpand.getItemProperty("nodeId").getValue())); newGraphItem.getItemProperty("nodeLabel") .setValue(String.valueOf(itemToExpand.getItemProperty("nodeLabel").getValue())); newGraphItem.getItemProperty("resourceId") .setValue(String.valueOf(itemToExpand.getItemProperty("resourceId").getValue())); newGraphItem.getItemProperty("resourceLabel") .setValue(String.valueOf(itemToExpand.getItemProperty("resourceLabel").getValue())); newGraphItem.getItemProperty("resourceTypeId").setValue( String.valueOf(itemToExpand.getItemProperty("resourceTypeId").getValue())); newGraphItem.getItemProperty("resourceTypeLabel").setValue( String.valueOf(itemToExpand.getItemProperty("resourceTypeLabel").getValue())); newGraphItem.getItemProperty("graphId").setValue(newGraphItemId); newGraphItem.getItemProperty("graphLabel").setValue(entry.getKey()); newGraphItem.getItemProperty("graphUrl").setValue(map.get(entry.getValue())); m_tree.setParent(newGraphItemId, itemToExpandId); m_tree.setChildrenAllowed(newGraphItemId, false); } } } }); /** * adding button to a horizontal layout */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); final Button cancel = new Button("Cancel"); 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); buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ final Button ok = new Button("Select"); ok.setEnabled(false); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (m_tree.getValue() != null) { /** * saving the data */ Item selectedItem = m_tree.getItem(m_tree.getValue()); rrdGraphEntry.setGraphId(String.valueOf(selectedItem.getItemProperty("graphId").getValue())); rrdGraphEntry.setResourceTypeId( String.valueOf(selectedItem.getItemProperty("resourceTypeId").getValue())); rrdGraphEntry .setResourceId(String.valueOf(selectedItem.getItemProperty("resourceId").getValue())); rrdGraphEntry.setNodeId(String.valueOf(selectedItem.getItemProperty("nodeId").getValue())); rrdGraphEntry .setGraphLabel(String.valueOf(selectedItem.getItemProperty("graphLabel").getValue())); rrdGraphEntry.setResourceTypeLabel( String.valueOf(selectedItem.getItemProperty("resourceTypeLabel").getValue())); rrdGraphEntry.setResourceLabel( String.valueOf(selectedItem.getItemProperty("resourceLabel").getValue())); rrdGraphEntry .setNodeLabel(String.valueOf(selectedItem.getItemProperty("nodeLabel").getValue())); rrdGraphEntry.setGraphUrl(String.valueOf(selectedItem.getItemProperty("graphUrl").getValue())); rrdGraphEntry.update(); } close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonLayout.addComponent(ok); /** * if data is available expand the required nodes */ if (rrdGraphEntry.getNodeId() != null) { m_tree.expandItem(rrdGraphEntry.getNodeId()); if (rrdGraphEntry.getResourceTypeId() != null) { m_tree.expandItem(rrdGraphEntry.getResourceTypeId()); if (rrdGraphEntry.getResourceId() != null) { m_tree.expandItem(rrdGraphEntry.getResourceId()); /** * and select the specified entry */ if (rrdGraphEntry.getGraphId() != null) { m_tree.select(rrdGraphEntry.getGraphId()); } } } } /** * adding a value change listener that checks if leaf node is selected */ m_tree.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (valueChangeEvent.getProperty().getValue() != null) { Item selectedItem = m_tree.getItem(valueChangeEvent.getProperty().getValue()); Object object = selectedItem.getItemProperty("graphId").getValue(); ok.setEnabled(object != null); } } }); /** * creating the layout and setting the content */ panel.setContent(m_tree); panel.setCaption("Graph"); panel.setSizeFull(); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull(); verticalLayout.setMargin(true); verticalLayout.addComponent(panel); verticalLayout.setExpandRatio(panel, 1.0f); 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 */// w w w.j ava 2s.co 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 *//*from www . ja v a2 s .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); }