List of usage examples for com.vaadin.ui VerticalLayout setExpandRatio
public void setExpandRatio(Component component, float ratio)
This method is used to control how excess space in layout is distributed among components.
From source file:org.opennms.features.topology.api.support.DialogWindow.java
License:Open Source License
private Layout createContent(final String description) { VerticalLayout content = new VerticalLayout(); content.setWidth(100, Unit.PERCENTAGE); Layout footer = createFooter();/*w ww. j av a 2 s . com*/ Layout mainArea = createMainArea(description); content.addComponent(mainArea); content.addComponent(footer); content.setExpandRatio(mainArea, 1); return content; }
From source file:org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog.java
License:Open Source License
public IconSelectionDialog(String selectedIconId) { setCaption("Change Icon"); setModal(true);/*from w w w .j a v a 2s .co m*/ setResizable(false); setClosable(false); setWidth(700, Unit.PIXELS); setHeight(600, Sizeable.Unit.PIXELS); addCloseListener(this); okButton = new Button("Ok", this); okButton.setId("iconSelectionDialog.button.ok"); cancelButton = new Button("Cancel", this); cancelButton.setId("iconSelectionDialog.button.cancel"); iconSelectionComponent = new IconSelectionComponent(getElementsToShow(), selectedIconId); VerticalLayout iconLayout = new VerticalLayout(); iconLayout.addStyleName("icon-selection-component"); iconLayout.setSpacing(true); iconLayout.setSizeFull(); iconLayout.addComponent(iconSelectionComponent); final HorizontalLayout buttonLayout = new HorizontalLayout(okButton, cancelButton); buttonLayout.setSpacing(true); VerticalLayout mainLayout = new VerticalLayout(); mainLayout.setSpacing(true); mainLayout.setMargin(true); mainLayout.setSizeFull(); mainLayout.addComponent(iconLayout); mainLayout.addComponent(buttonLayout); mainLayout.setExpandRatio(iconLayout, 1); mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT); setContent(mainLayout); center(); }
From source file:org.opennms.features.topology.netutils.internal.ping.PingWindow.java
License:Open Source License
/** * Creates the PingWindow to make ping requests. * * @param locations All available locations to ping from. Must not be null. * @param defaultLocation The location to pre-select from the locations. Ensure <code>defaultLocation</code> is also available in the <code>locations</code> list. * @param ipAddresses All available ipAddresses. Must not be null or empty. * @param defaultIp The default ip to pre-select from the ip addresses. Ensure <code>defaultIp</code> is also available in the <code>ipAddresses</code> list. * @param pingClient The LocationAwarePingClient to ping. Must not be null. *///from w w w . j av a2 s . c o m public PingWindow(LocationAwarePingClient pingClient, List<String> locations, List<InetAddress> ipAddresses, String defaultLocation, InetAddress defaultIp, String caption) { Objects.requireNonNull(pingClient); Objects.requireNonNull(ipAddresses); Objects.requireNonNull(defaultIp); Objects.requireNonNull(locations); Objects.requireNonNull(defaultLocation); Objects.requireNonNull(caption); // Remember initial poll interval, as we poll as soon as we start pinging final int initialPollInterval = UI.getCurrent().getPollInterval(); // Ping Form pingForm = new PingForm(locations, defaultLocation, ipAddresses, defaultIp); // Result final TextArea resultArea = new TextArea(); resultArea.setRows(15); resultArea.setSizeFull(); // Progress Indicator progressIndicator = new ProgressBar(); progressIndicator.setIndeterminate(true); // Buttons cancelButton = new Button("Cancel"); cancelButton.addClickListener((event) -> { cancel(pingFuture); resultArea.setValue(resultArea.getValue() + "\n" + "Ping cancelled by user"); getUI().setPollInterval(initialPollInterval); setRunning(false); }); pingButton = new Button("Ping"); pingButton.addClickListener((event) -> { try { final PingRequest pingRequest = pingForm.getPingRequest(); resultArea.setValue(""); // Clear setRunning(true); getUI().setPollInterval(POLL_INTERVAL); pingFuture = pingClient.ping(pingRequest.getInetAddress()).withRetries(pingRequest.getRetries()) .withPacketSize(pingRequest.getPacketSize()) .withTimeout(pingRequest.getTimeout(), TimeUnit.MILLISECONDS) .withLocation(pingRequest.getLocation()) .withNumberOfRequests(pingRequest.getNumberRequests()) .withProgressCallback((newSequence, summary) -> { getUI().accessSynchronously(() -> { if (pingFuture != null && !pingFuture.isCancelled()) { setRunning(!summary.isComplete()); resultArea.setValue(PingStringUtils.renderAll(summary)); if (summary.isComplete()) { getUI().setPollInterval(initialPollInterval); } } }); }).execute(); } catch (FieldGroup.CommitException e) { Notification.show("Validation errors", "Please correct them. Make sure all required fields are set.", Notification.Type.ERROR_MESSAGE); } }); // Button Layout final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.addComponent(pingButton); buttonLayout.addComponent(cancelButton); buttonLayout.addComponent(progressIndicator); // Root Layout final VerticalLayout rootLayout = new VerticalLayout(); rootLayout.setSpacing(true); rootLayout.setMargin(true); rootLayout.addComponent(pingForm); rootLayout.addComponent(buttonLayout); rootLayout.addComponent(new Label("<b>Results</b>", ContentMode.HTML)); rootLayout.addComponent(resultArea); rootLayout.setExpandRatio(resultArea, 1.0f); // Window Config setCaption(caption); setResizable(false); setModal(true); setWidth(800, Unit.PIXELS); setHeight(600, Unit.PIXELS); setContent(rootLayout); center(); setRunning(false); // Set back to default, when closing addCloseListener((CloseListener) e -> { cancel(pingFuture); getUI().setPollInterval(initialPollInterval); }); }
From source file:org.opennms.features.topology.netutils.internal.PingWindow.java
License:Open Source License
/** * Creates the PingWindow to make ping requests. * * @param vertex The vertex which IP Address is pinged. * It is expected that the IP Address os not null and parseable. * @param pingService The {@link PingService} to actually make the ping request. *//*from ww w.j a va 2 s . c o m*/ public PingWindow(Vertex vertex, PingService pingService) { Objects.requireNonNull(vertex); Objects.requireNonNull(pingService); // Remember initial poll interval, as we poll as soon as we start pinging final int initialPollInterval = UI.getCurrent().getPollInterval(); // Ping Form pingForm = new PingForm(InetAddressUtils.getInetAddress(vertex.getIpAddress())); // Result final TextArea resultArea = new TextArea(); resultArea.setRows(15); resultArea.setSizeFull(); // Progress Indicator progressIndicator = new ProgressBar(); progressIndicator.setIndeterminate(true); // Buttons cancelButton = new Button("Cancel"); cancelButton.addClickListener((event) -> { pingService.cancel(); resultArea.setValue(resultArea.getValue() + "\n" + "Ping cancelled by user"); getUI().setPollInterval(initialPollInterval); setRunning(false); }); pingButton = new Button("Ping"); pingButton.addClickListener((event) -> { try { final PingRequest pingRequest = pingForm.getPingRequest(); setRunning(true); getUI().setPollInterval(POLL_INTERVAL); resultArea.setValue(""); // Clear pingService.ping(pingRequest, (result) -> { setRunning(!result.isComplete()); resultArea.setValue(result.toDetailString()); if (result.isComplete()) { getUI().setPollInterval(initialPollInterval); } }); } catch (FieldGroup.CommitException e) { Notification.show("Validation errors", "Please correct them. Make sure all required fields are set.", Notification.Type.ERROR_MESSAGE); } }); // Button Layout final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.addComponent(pingButton); buttonLayout.addComponent(cancelButton); buttonLayout.addComponent(progressIndicator); // Root Layout final VerticalLayout rootLayout = new VerticalLayout(); rootLayout.setSpacing(true); rootLayout.setMargin(true); rootLayout.addComponent(pingForm); rootLayout.addComponent(buttonLayout); rootLayout.addComponent(new Label("<b>Results</b>", ContentMode.HTML)); rootLayout.addComponent(resultArea); rootLayout.setExpandRatio(resultArea, 1.0f); // Window Config setCaption(String.format("Ping - %s (%s)", vertex.getLabel(), vertex.getIpAddress())); setResizable(false); setModal(true); setWidth(800, Unit.PIXELS); setHeight(550, Unit.PIXELS); setContent(rootLayout); center(); setRunning(false); // Set back to default, when closing addCloseListener((CloseListener) e -> { pingService.cancel(); getUI().setPollInterval(initialPollInterval); }); }
From source file:org.opennms.features.topology.netutils.internal.TracerouteWindow.java
License:Open Source License
/** * The TracerouteWindow method constructs a TracerouteWindow component with a size proportionate to the * width and height of the main window.//from www . j av a 2 s .co m * @param node * @param width Width of Main window * @param height Height of Main window */ public TracerouteWindow(final Node node, final String url) { this.tracerouteUrl = url; String label = ""; String ipAddress = ""; if (node != null) { label = node.getLabel(); ipAddress = node.getIPAddress(); } String caption = ""; /*Sets up window settings*/ if (label == null || label.equals("") || label.equalsIgnoreCase(noLabel)) { label = ""; } if (!label.equals("")) caption = " - " + label; setCaption("Traceroute" + caption); setImmediate(true); setResizable(false); /*Initialize the header of the Sub-window with the name of the selected Node*/ String nodeName = "<div style=\"text-align: center; font-size: 18pt; font-weight:bold;\">" + label + "</div>"; nodeLabel = new Label(nodeName); nodeLabel.setContentMode(ContentMode.HTML); /*Creating various layouts to encapsulate all of the components*/ VerticalLayout mainLayout = new VerticalLayout(); mainLayout.setSizeFull(); vSplit = new VerticalSplitPanel(); topLayout = new VerticalLayout(); bottomLayout = new VerticalLayout(); VerticalLayout form = new VerticalLayout(); GridLayout grid = new GridLayout(2, 2); grid.setWidth("420"); grid.setHeight("62"); /*Sets up IP Address dropdown with the Name as default*/ ipDropdown = new NativeSelect(); ipDropdown.addItem(ipAddress); ipDropdown.select(ipAddress); /*Creates the Numerical Output Check box and sets up the listener*/ numericalDataCheckBox = new CheckBox("Use Numerical Node Names"); numericalDataCheckBox.setImmediate(true); numericalDataCheckBox.setValue(false); /*Creates the form labels and text fields*/ Label ipLabel = new Label("IP Address: "); Label forcedHopLabel = new Label("Forced Hop IP: "); forcedHopField = new TextField(); forcedHopField.setMaxLength(15); /*Add all of the components to the GridLayout*/ grid.addComponent(ipLabel); grid.setComponentAlignment(ipLabel, Alignment.MIDDLE_LEFT); grid.addComponent(ipDropdown); grid.setComponentAlignment(ipDropdown, Alignment.MIDDLE_LEFT); grid.addComponent(forcedHopLabel); grid.setComponentAlignment(forcedHopLabel, Alignment.MIDDLE_LEFT); grid.addComponent(forcedHopField); grid.setComponentAlignment(forcedHopField, Alignment.MIDDLE_LEFT); /*Creates the Ping button and sets up the listener*/ tracerouteButton = new Button("Traceroute"); tracerouteButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { changeBrowserURL(buildURL()); } }); /*Adds components to the form and sets the width and spacing*/ form.addComponent(grid); form.addComponent(numericalDataCheckBox); form.addComponent(tracerouteButton); form.setWidth("100%"); form.setSpacing(true); /*Adds components to the Top Layout and sets the width and margins*/ topLayout.addComponent(nodeLabel); topLayout.setComponentAlignment(nodeLabel, Alignment.MIDDLE_CENTER); topLayout.addComponent(form); topLayout.setSizeFull(); topLayout.setMargin(new MarginInfo(true, true, false, true)); /*Adds components to the Bottom Layout and sets the width and margins*/ bottomLayout.setSizeFull(); bottomLayout.setMargin(true); bottomLayout.setImmediate(true); buildEmbeddedBrowser(); /*Setting first and second components for the split panel and setting the panel divider position*/ vSplit.setFirstComponent(topLayout); vSplit.setSecondComponent(bottomLayout); vSplit.setSplitPosition(splitHeight, Unit.PIXELS); vSplit.setLocked(true); /*Adds split panel to the main layout and expands the split panel to 100% of the layout space*/ mainLayout.addComponent(vSplit); mainLayout.setExpandRatio(vSplit, 1); setContent(mainLayout); }
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 ww w . j a v a2 s . 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.dashlets.AlarmConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited *//*from www . 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.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 . ja v a 2 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.RrdDashletConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited *//*from ww w .j a v a 2 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); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.SummaryDashlet.java
License:Open Source License
/** * Returns the component showing the alarms and the trends by severity * * @return the {@link Component}// ww w. j a va2s. c o m */ private Component getComponentSeverity(int width) { VerticalLayout verticalLayout = new VerticalLayout(); int overallSum = 0; int severitySum = 0; verticalLayout.addComponent(getLegend("Severity")); for (OnmsSeverity onmsSeverity : OnmsSeverity.values()) { HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setSpacing(true); horizontalLayout.addStyleName("summary"); horizontalLayout.addStyleName(onmsSeverity.name().toLowerCase()); int acknowledged = countBySeverity(true, m_timeslot, onmsSeverity); int notAcknowledged = countBySeverity(false, m_timeslot, onmsSeverity); Label labelSeverity = new Label(onmsSeverity.getLabel()); labelSeverity.addStyleName("summary-font"); Label labelAcknowledge = new Label(String.valueOf(acknowledged)); labelAcknowledge.addStyleName("summary-font"); Label labelNotAcknowledged = new Label(String.valueOf(notAcknowledged)); labelNotAcknowledged.addStyleName("summary-font"); horizontalLayout.addComponent(labelSeverity); horizontalLayout.addComponent(labelAcknowledge); horizontalLayout.addComponent(labelNotAcknowledged); int status = computeTrend(acknowledged, notAcknowledged); severitySum += onmsSeverity.getId(); overallSum += onmsSeverity.getId() * status; Image image = new Image(null, new ThemeResource("img/a" + status + ".png")); image.setWidth(width, Sizeable.Unit.PIXELS); horizontalLayout.addComponent(image); horizontalLayout.setExpandRatio(labelSeverity, 4.0f); horizontalLayout.setExpandRatio(labelAcknowledge, 1.0f); horizontalLayout.setExpandRatio(labelNotAcknowledged, 1.0f); horizontalLayout.setExpandRatio(image, 1.0f); horizontalLayout.setComponentAlignment(image, Alignment.TOP_CENTER); horizontalLayout.setWidth(375, Sizeable.Unit.PIXELS); verticalLayout.addComponent(horizontalLayout); } int globalTrend = (int) Math.max(0, Math.min(4, Math.round(((double) overallSum) / ((double) severitySum)))); Image image = new Image(null, new ThemeResource("img/a" + globalTrend + ".png")); image.setWidth(width * 8, Sizeable.Unit.PIXELS); VerticalLayout globalTrendLayout = new VerticalLayout(); globalTrendLayout.setSpacing(true); globalTrendLayout.addStyleName("summary"); globalTrendLayout.addStyleName("global"); globalTrendLayout.setSizeFull(); Label labelTitle = new Label("Alarms trend by severity"); labelTitle.addStyleName("summary-font"); labelTitle.setSizeUndefined(); Label labelTimeslot = new Label("(" + getHumanReadableFormat(m_timeslot) + ")"); labelTimeslot.addStyleName("summary-font"); labelTimeslot.setSizeUndefined(); globalTrendLayout.addComponent(labelTitle); globalTrendLayout.addComponent(labelTimeslot); globalTrendLayout.addComponent(image); globalTrendLayout.setWidth(375, Sizeable.Unit.PIXELS); globalTrendLayout.setComponentAlignment(labelTitle, Alignment.MIDDLE_CENTER); globalTrendLayout.setComponentAlignment(labelTimeslot, Alignment.MIDDLE_CENTER); globalTrendLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER); globalTrendLayout.setExpandRatio(labelTitle, 1.0f); verticalLayout.addComponent(globalTrendLayout, 0); m_boosted = (globalTrend > 2); return verticalLayout; }