List of usage examples for com.vaadin.ui VerticalLayout setComponentAlignment
@Override public void setComponentAlignment(Component childComponent, Alignment alignment)
From source file:org.opennms.features.vaadin.dashboard.dashlets.KscDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_wallboardComponent == null) { m_wallboardComponent = new AbstractDashletComponent() { private GridLayout m_gridLayout = new GridLayout(); {/* ww w. j av a 2 s. co m*/ m_gridLayout.setCaption(getName()); m_gridLayout.setSizeFull(); m_gridLayout.setColumns(1); m_gridLayout.setRows(1); } @Override public void refresh() { m_gridLayout.removeAllComponents(); /** * initializing the parameters */ int columns = 0; int rows = 0; String kscReportName = getDashletSpec().getParameters().get("kscReport"); if (kscReportName == null || "".equals(kscReportName)) { return; } KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory .getInstance(); Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList(); int kscReportId = -1; for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) { if (kscReportName.equals(entry.getValue())) { kscReportId = entry.getKey(); break; } } if (kscReportId == -1) { return; } Report kscReport = kscPerformanceReportFactory.getReportByIndex(kscReportId); columns = kscReport.getGraphs_per_line(); if (columns == 0) { columns = 1; } rows = kscReport.getGraphCount() / columns; if (rows == 0) { rows = 1; } if (kscReport.getGraphCount() % columns > 0) { rows++; } /** * setting new columns/rows */ m_gridLayout.setColumns(columns); m_gridLayout.setRows(rows); int i = 0; /** * adding the components */ Page.getCurrent().getStyles().add( ".box { margin: 5px; background-color: #444; border: 1px solid #999; border-top: 0; overflow: auto; }"); Page.getCurrent().getStyles().add( ".text { color:#ffffff; line-height: 11px; font-size: 9px; font-family: 'Lucida Grande', Verdana, sans-serif; font-weight: bold; }"); Page.getCurrent().getStyles().add(".margin { margin:5px; }"); for (int y = 0; y < m_gridLayout.getRows(); y++) { for (int x = 0; x < m_gridLayout.getColumns(); x++) { if (i < kscReport.getGraphCount()) { Graph graph = kscReport.getGraph(i); Map<String, String> data = getDataForResourceId(graph.getNodeId(), graph.getResourceId()); Calendar beginTime = Calendar.getInstance(); Calendar endTime = Calendar.getInstance(); KSC_PerformanceReportFactory.getBeginEndTime(graph.getTimespan(), beginTime, endTime); GraphContainer graphContainer = getGraphContainer(graph, beginTime.getTime(), endTime.getTime()); VerticalLayout verticalLayout = new VerticalLayout(); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.addStyleName("box"); horizontalLayout.setWidth("100%"); horizontalLayout.setHeight("42px"); VerticalLayout leftLayout = new VerticalLayout(); leftLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT); leftLayout.addStyleName("margin"); Label labelTitle; if (graph.getTitle() == null || "".equals(graph.getTitle())) { labelTitle = new Label(" "); labelTitle.setContentMode(ContentMode.HTML); } else { labelTitle = new Label(graph.getTitle()); } labelTitle.addStyleName("text"); Label labelFrom = new Label("From: " + beginTime.getTime().toString()); labelFrom.addStyleName("text"); Label labelTo = new Label("To: " + endTime.getTime().toString()); labelTo.addStyleName("text"); Label labelNodeLabel = new Label(data.get("nodeLabel")); labelNodeLabel.addStyleName("text"); Label labelResourceLabel = new Label( data.get("resourceTypeLabel") + ": " + data.get("resourceLabel")); labelResourceLabel.addStyleName("text"); leftLayout.addComponent(labelTitle); leftLayout.addComponent(labelFrom); leftLayout.addComponent(labelTo); VerticalLayout rightLayout = new VerticalLayout(); rightLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT); rightLayout.addStyleName("margin"); rightLayout.addComponent(labelNodeLabel); rightLayout.addComponent(labelResourceLabel); horizontalLayout.addComponent(leftLayout); horizontalLayout.addComponent(rightLayout); horizontalLayout.setExpandRatio(leftLayout, 1.0f); horizontalLayout.setExpandRatio(rightLayout, 1.0f); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(graphContainer); verticalLayout.setWidth(DEFAULT_GRAPH_WIDTH_PX, Unit.PIXELS); m_gridLayout.addComponent(verticalLayout, x, y); verticalLayout.setComponentAlignment(horizontalLayout, Alignment.MIDDLE_CENTER); verticalLayout.setComponentAlignment(graphContainer, Alignment.MIDDLE_CENTER); m_gridLayout.setComponentAlignment(verticalLayout, Alignment.MIDDLE_CENTER); } i++; } } } @Override public Component getComponent() { return m_gridLayout; } }; } return m_wallboardComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.KscDashlet.java
License:Open Source License
@Override public DashletComponent getDashboardComponent() { if (m_dashboardComponent == null) { m_dashboardComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {/* w w w . j a v a2s . co m*/ m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { m_verticalLayout.removeAllComponents(); String kscReportName = getDashletSpec().getParameters().get("kscReport"); if (kscReportName == null || "".equals(kscReportName)) { return; } KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory .getInstance(); Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList(); int kscReportId = -1; for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) { if (kscReportName.equals(entry.getValue())) { kscReportId = entry.getKey(); break; } } if (kscReportId == -1) { return; } Report kscReport = kscPerformanceReportFactory.getReportByIndex(kscReportId); Page.getCurrent().getStyles().add( ".box { margin: 5px; background-color: #444; border: 1px solid #999; border-top: 0; overflow: auto; }"); Page.getCurrent().getStyles().add( ".text { color:#ffffff; line-height: 11px; font-size: 9px; font-family: 'Lucida Grande', Verdana, sans-serif; font-weight: bold; }"); Page.getCurrent().getStyles().add(".margin { margin:5px; }"); Accordion accordion = new Accordion(); accordion.setSizeFull(); m_verticalLayout.addComponent(accordion); for (Graph graph : kscReport.getGraph()) { Map<String, String> data = getDataForResourceId(graph.getNodeId(), graph.getResourceId()); Calendar beginTime = Calendar.getInstance(); Calendar endTime = Calendar.getInstance(); KSC_PerformanceReportFactory.getBeginEndTime(graph.getTimespan(), beginTime, endTime); GraphContainer graphContainer = getGraphContainer(graph, beginTime.getTime(), endTime.getTime()); VerticalLayout verticalLayout = new VerticalLayout(); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.addStyleName("box"); horizontalLayout.setWidth("100%"); horizontalLayout.setHeight("42px"); VerticalLayout leftLayout = new VerticalLayout(); leftLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT); leftLayout.addStyleName("margin"); Label labelTitle; if (graph.getTitle() == null || "".equals(graph.getTitle())) { labelTitle = new Label(" "); labelTitle.setContentMode(ContentMode.HTML); } else { labelTitle = new Label(graph.getTitle()); } labelTitle.addStyleName("text"); Label labelFrom = new Label("From: " + beginTime.getTime().toString()); labelFrom.addStyleName("text"); Label labelTo = new Label("To: " + endTime.getTime().toString()); labelTo.addStyleName("text"); Label labelNodeLabel = new Label(data.get("nodeLabel")); labelNodeLabel.addStyleName("text"); Label labelResourceLabel = new Label( data.get("resourceTypeLabel") + ": " + data.get("resourceLabel")); labelResourceLabel.addStyleName("text"); leftLayout.addComponent(labelTitle); leftLayout.addComponent(labelFrom); leftLayout.addComponent(labelTo); VerticalLayout rightLayout = new VerticalLayout(); rightLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT); rightLayout.addStyleName("margin"); rightLayout.addComponent(labelNodeLabel); rightLayout.addComponent(labelResourceLabel); horizontalLayout.addComponent(leftLayout); horizontalLayout.addComponent(rightLayout); horizontalLayout.setExpandRatio(leftLayout, 1.0f); horizontalLayout.setExpandRatio(rightLayout, 1.0f); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(graphContainer); verticalLayout.setWidth(DEFAULT_GRAPH_WIDTH_PX, Unit.PIXELS); accordion.addTab(verticalLayout, data.get("nodeLabel") + "/" + data.get("resourceTypeLabel") + ": " + data.get("resourceLabel")); verticalLayout.setComponentAlignment(horizontalLayout, Alignment.MIDDLE_CENTER); verticalLayout.setComponentAlignment(graphContainer, Alignment.MIDDLE_CENTER); verticalLayout.setMargin(true); } } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashboardComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.RrdDashlet.java
License:Open Source License
/** * Returns the graph component for a given graph of the {@link DashletSpec}. * * @param i the entry id//from www.j a v a 2 s .co m * @param width the width * @param height the height * @param timeFrameType the timeframe type * @param timeFrameValue the timeframe value * @return the component */ private Component getGraphComponent(int i, int width, int height, int timeFrameType, int timeFrameValue) { String graphTitle = getDashletSpec().getParameters().get("graphLabel" + i); String graphName = RrdGraphHelper .getGraphNameFromQuery(getDashletSpec().getParameters().get("graphUrl" + i)); String resourceId = getDashletSpec().getParameters().get("resourceId" + i); GraphContainer graph = new GraphContainer(graphName, resourceId); graph.setTitle(graphTitle); // Setup the time span Calendar cal = new GregorianCalendar(); graph.setEnd(cal.getTime()); cal.add(timeFrameType, -timeFrameValue); graph.setStart(cal.getTime()); // Use all of the available width graph.setWidthRatio(1.0d); VerticalLayout verticalLayout = new VerticalLayout(); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.addStyleName("box"); horizontalLayout.setWidth("100%"); horizontalLayout.setHeight("42px"); VerticalLayout leftLayout = new VerticalLayout(); leftLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT); leftLayout.addStyleName("margin"); Label labelFrom = new Label(getDashletSpec().getParameters().get("nodeLabel" + i)); labelFrom.addStyleName("text"); Label labelTo = new Label(getDashletSpec().getParameters().get("resourceTypeLabel" + i) + ": " + getDashletSpec().getParameters().get("resourceLabel" + i)); labelTo.addStyleName("text"); leftLayout.addComponent(labelFrom); leftLayout.addComponent(labelTo); horizontalLayout.addComponent(leftLayout); horizontalLayout.setExpandRatio(leftLayout, 1.0f); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(graph); verticalLayout.setWidth(width, Unit.PIXELS); verticalLayout.setComponentAlignment(horizontalLayout, Alignment.MIDDLE_CENTER); verticalLayout.setComponentAlignment(graph, Alignment.MIDDLE_CENTER); verticalLayout.setMargin(true); return 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}//from ww w. j a v a2 s . co 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; }
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}/*from w w w .ja v a2 s .com*/ */ private Component getComponentUei(int width) { VerticalLayout verticalLayout = new VerticalLayout(); int overallSum = 0; int severitySum = 0; verticalLayout.addComponent(getLegend("UEI")); String[] ueis = { "uei.opennms.org/nodes/nodeLostService", "uei.opennms.org/nodes/interfaceDown", "uei.opennms.org/nodes/nodeDown" }; for (int i = 0; i < ueis.length; i++) { String uei = ueis[i]; HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setSpacing(true); horizontalLayout.addStyleName("summary"); if (i == 0) { horizontalLayout.addStyleName(OnmsSeverity.MINOR.name().toLowerCase()); } else { if (i == 1) { horizontalLayout.addStyleName(OnmsSeverity.MINOR.name().toLowerCase()); } else { horizontalLayout.addStyleName(OnmsSeverity.MAJOR.name().toLowerCase()); } } int acknowledged = countByUei(true, m_timeslot, uei); int notAcknowledged = countByUei(false, m_timeslot, uei); Label labelSeverity = new Label(uei.replace("uei.opennms.org/nodes/", "")); 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 += i; overallSum += i * 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 UEI"); 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; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.SummaryDashlet.java
License:Open Source License
@Override public DashletComponent getDashboardComponent() { if (m_dashboardComponent == null) { m_dashboardComponent = new AbstractDashletComponent() { private HorizontalLayout m_horizontalLayout = new HorizontalLayout(); {/* ww w .ja va2 s .c om*/ m_horizontalLayout.setCaption(getName()); m_horizontalLayout.setSizeFull(); } /** * Injects CSS styles in the current page */ private void injectDashboardStyles() { Page.getCurrent().getStyles() .add(".summary.cleared { background: #000000; border-left: 8px solid #858585; }"); Page.getCurrent().getStyles() .add(".summary.normal { background: #000000; border-left: 8px solid #336600; }"); Page.getCurrent().getStyles() .add(".summary.indeterminate { background: #000000; border-left: 8px solid #999; }"); Page.getCurrent().getStyles() .add(".summary.warning { background: #000000; border-left: 8px solid #FFCC00; }"); Page.getCurrent().getStyles() .add(".summary.minor { background: #000000; border-left: 8px solid #FF9900; }"); Page.getCurrent().getStyles() .add(".summary.major { background: #000000; border-left: 8px solid #FF3300; }"); Page.getCurrent().getStyles() .add(".summary.critical { background: #000000; border-left: 8px solid #CC0000; }"); Page.getCurrent().getStyles() .add(".summary.global { background: #000000; border-left: 8px solid #000000; }"); Page.getCurrent().getStyles().add(".summary { padding: 5px 5px; margin: 1px; }"); Page.getCurrent().getStyles().add( ".summary-font { font-size: 17px; line-height: normal; text-align: right; color: #3ba300; }"); Page.getCurrent().getStyles().add( ".summary-font-legend { font-size: 9px; line-height: normal; text-align: right; color: #3ba300; }"); } @Override public void refresh() { m_timeslot = 3600; try { m_timeslot = Math.max(1, Integer.parseInt(getDashletSpec().getParameters().get("timeslot"))); } catch (NumberFormatException numberFormatException) { /** * Just ignore */ } m_horizontalLayout.removeAllComponents(); Accordion accordion = new Accordion(); accordion.setSizeFull(); injectDashboardStyles(); Component severity = getComponentSeverity(16); Component uei = getComponentUei(16); VerticalLayout v1 = new VerticalLayout(severity); v1.setSizeFull(); v1.setComponentAlignment(severity, Alignment.MIDDLE_CENTER); v1.setMargin(true); accordion.addTab(v1, "by Severity"); VerticalLayout v2 = new VerticalLayout(uei); v2.setSizeFull(); v2.setComponentAlignment(uei, Alignment.MIDDLE_CENTER); v2.setMargin(true); accordion.addTab(v2, "by Uei"); m_horizontalLayout.addComponent(accordion); } @Override public Component getComponent() { return m_horizontalLayout; } @Override public boolean isBoosted() { return SummaryDashlet.this.m_boosted; } }; } return m_dashboardComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.UndefinedDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { DashletComponent dashletComponent = new AbstractDashletComponent() { @Override/* w ww. ja va 2 s . c om*/ public void refresh() { } @Override public Component getComponent() { VerticalLayout verticalLayout = new VerticalLayout(); Label label = new Label("The specified dashlet could not be found!"); verticalLayout.addComponent(label); verticalLayout.setComponentAlignment(label, Alignment.MIDDLE_CENTER); return verticalLayout; } }; return dashletComponent; }
From source file:org.opennms.features.vaadin.datacollection.AbstractStrategyField.java
License:Open Source License
@Override public Component initContent() { VerticalLayout layout = new VerticalLayout(); layout.addComponent(combo);//from w w w . j a va2s .co m layout.addComponent(table); layout.addComponent(toolbar); layout.setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT); return layout; }
From source file:org.opennms.features.vaadin.datacollection.DataCollectionGroupPanel.java
License:Open Source License
/** * Instantiates a new data collection group panel. * * @param dataCollectionConfigDao the OpenNMS Data Collection Configuration DAO * @param group the data collection group object * @param logger the logger object/*from w w w. j a va 2 s. c om*/ * @param existingFile the existing file */ public DataCollectionGroupPanel(final DataCollectionConfigDao dataCollectionConfigDao, final DatacollectionGroup group, final Logger logger, final File existingFile) { this.existingFile = existingFile; setCaption("Data Collection"); addStyleName("light"); // Data Collection Group - Main Fields groupName.setPropertyDataSource(new ObjectProperty<String>(group.getName())); groupName.setNullSettingAllowed(false); groupName.setImmediate(true); if (isExistingGroup()) { // If we allow to rename an existing group, we should modify the SNMP Collection as well groupName.setEnabled(false); } boolean mibGroupEditable = !(isExistingGroup() && ResourceTypeUtils.isStoreByGroup()); resourceTypes = new ResourceTypePanel(dataCollectionConfigDao, group, logger); groups = new GroupPanel(dataCollectionConfigDao, group, logger, mibGroupEditable); systemDefs = new SystemDefPanel(dataCollectionConfigDao, group, logger); // Button Toolbar final HorizontalLayout toolbar = new HorizontalLayout(); toolbar.addComponent(new Button("Save Data Collection File", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { processDataCollection(dataCollectionConfigDao, logger); } })); toolbar.addComponent(new Button("Cancel", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { cancel(); logger.info("Data collection processing has been canceled"); } })); // Tab Panel final TabSheet tabs = new TabSheet(); tabs.addStyleName("light"); tabs.setSizeFull(); tabs.addTab(resourceTypes, "Resource Types"); tabs.addTab(groups, "MIB Groups"); tabs.addTab(systemDefs, "System Definitions"); // Main Layout final VerticalLayout mainLayout = new VerticalLayout(); mainLayout.setSpacing(true); mainLayout.setMargin(true); mainLayout.addComponent(toolbar); mainLayout.addComponent(groupName); mainLayout.addComponent(tabs); mainLayout.setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT); setContent(mainLayout); }
From source file:org.opennms.features.vaadin.datacollection.GroupPanel.java
License:Open Source License
/** * Instantiates a new group panel.//from w w w . j a va 2 s. c o m * * @param dataCollectionConfigDao the OpenNMS Data Collection Configuration DAO * @param source the OpenNMS Data Collection Group object * @param logger the logger object * @param mibGroupEditable true, if the MIB group can be modified */ public GroupPanel(final DataCollectionConfigDao dataCollectionConfigDao, final DatacollectionGroup source, final Logger logger, boolean mibGroupEditable) { if (dataCollectionConfigDao == null) { throw new RuntimeException("dataCollectionConfigDao cannot be null."); } if (source == null) { throw new RuntimeException("source cannot be null."); } addStyleName("light"); // Adding all resource types already defined on this source final List<String> resourceTypes = new ArrayList<String>(); for (ResourceType type : source.getResourceTypes()) { resourceTypes.add(type.getName()); } // Adding all defined resource types resourceTypes.addAll(dataCollectionConfigDao.getConfiguredResourceTypes().keySet()); groupTable = new GroupTable(source.getGroups()); final GroupForm groupForm = new GroupForm(resourceTypes, mibGroupEditable); groupForm.setVisible(false); final EditorToolbar bottomToolbar = new EditorToolbar() { @Override public boolean save() { Group group = groupForm.getGroup(); if (!isNew && !group.getName().equals(groupForm.getGroupName())) { Set<String> systemDefMap = getParentSystemDefs(dataCollectionConfigDao, group.getName()); if (!systemDefMap.isEmpty()) { final String msg = "The group cannot be renamed because it is being referenced by:\n" + systemDefMap.toString(); Notification.show(msg, Notification.Type.WARNING_MESSAGE); return false; } } logger.info("SNMP Group " + group.getName() + " has been " + (isNew ? "created." : "updated.")); try { groupForm.commit(); groupForm.setReadOnly(true); groupTable.refreshRowCache(); return true; } catch (CommitException e) { String msg = "Can't save the changes: " + e.getMessage(); logger.error(msg); Notification.show(msg, Notification.Type.ERROR_MESSAGE); return false; } } @Override public boolean delete() { Object groupId = groupTable.getValue(); if (groupId != null) { Group group = groupTable.getGroup(groupId); Set<String> systemDefMap = getParentSystemDefs(dataCollectionConfigDao, group.getName()); if (!systemDefMap.isEmpty()) { final String msg = "The group cannot be deleted because it is being referenced by:\n" + systemDefMap.toString(); Notification.show(msg, Notification.Type.WARNING_MESSAGE); return false; } logger.info("SNMP Group " + group.getName() + " has been removed."); groupTable.select(null); groupTable.removeItem(groupId); groupTable.refreshRowCache(); } return true; } @Override public boolean edit() { groupForm.setReadOnly(false); return true; } @Override public boolean cancel() { groupForm.discard(); groupForm.setReadOnly(true); return true; } }; bottomToolbar.setVisible(false); groupTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { if (groupForm.isVisible() && !groupForm.isReadOnly()) { groupTable.select(selectedGroupId); Notification.show( "A group seems to be being edited.\nPlease save or cancel your current changes.", Notification.Type.WARNING_MESSAGE); } else { Object groupId = groupTable.getValue(); if (groupId != null) { selectedGroupId = groupId; groupForm.setGroup(groupTable.getGroup(groupId)); } groupForm.setReadOnly(true); groupForm.setVisible(groupId != null); bottomToolbar.setReadOnly(true); bottomToolbar.setVisible(groupId != null); } } }); final Button add = new Button("Add SNMP Group", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { groupTable.addGroup(groupForm.createBasicGroup()); groupForm.setReadOnly(false); bottomToolbar.setReadOnly(false); setIsNew(true); } }); final VerticalLayout mainLayout = new VerticalLayout(); mainLayout.setSpacing(true); mainLayout.setMargin(true); mainLayout.addComponent(groupTable); mainLayout.addComponent(add); mainLayout.addComponent(groupForm); mainLayout.addComponent(bottomToolbar); mainLayout.setComponentAlignment(add, Alignment.MIDDLE_RIGHT); setContent(mainLayout); }