List of usage examples for com.vaadin.ui VerticalLayout setWidth
@Override public void setWidth(float width, Unit unit)
From source file:org.inakirj.imagerulette.screens.DiceGallerySetupView.java
License:Open Source License
/** * Sets the layout./* w w w.j a va2 s.c om*/ * * @param urlList * the new layout */ private void setLayout(List<String> urlList) { removeAllComponents(); VerticalLayout layout = new VerticalLayout(); layout.setWidth(100, Unit.PERCENTAGE); // Table Table urlTable = new Table(); for (String url : urlList) { addRow(url); } newDataSource.sort(propertyIds, ascendingIds); urlTable.setContainerDataSource(newDataSource); urlTable.setVisibleColumns("url", "img", "validateImg", "deleteImg"); urlTable.setColumnHeaders("PATH", "IMAGE", "SAVE", "DELETE"); urlTable.setColumnExpandRatio("url", 3); urlTable.setColumnExpandRatio("img", 3); urlTable.setColumnExpandRatio("validateImg", 2); urlTable.setColumnExpandRatio("deleteImg", 2); urlTable.setWidth(100, Unit.PERCENTAGE); urlTable.addStyleName("upload-table"); // urlTable.setPageLength(urlList.size()); layout.addComponent(urlTable); addComponent(layout); }
From source file:org.jdal.vaadin.ui.form.SimpleBoxFormBuilder.java
License:Apache License
/** * Builds the panel form./*from w w w . ja va2s . c om*/ * @return the form component */ public Component getForm() { for (int i = 0; i < columns.size(); i++) { VerticalLayout box = columns.get(i); int width = columnsWidth.get(i); if (width > SIZE_UNDEFINED && width < SIZE_FULL) { box.setWidth(width, Unit.PIXELS); // shrink container container.setExpandRatio(box, 0); } else if (width == SIZE_FULL) { box.setWidth("100%"); container.setExpandRatio(box, 1); } else { container.setExpandRatio(box, 0); box.setWidth(Sizeable.SIZE_UNDEFINED, Unit.PIXELS); } for (int j = 0; j < rowsHeight.size(); j++) { Component c = box.getComponent(j); int height = rowsHeight.get(j); if (height > SIZE_UNDEFINED && height < SIZE_FULL) { c.setHeight(height, Unit.PIXELS); box.setExpandRatio(c, 0); } else if (height == SIZE_FULL) { c.setHeight("100%"); box.setExpandRatio(c, 1); } else { box.setExpandRatio(c, 0); } } } if (fixedHeight) { container.setHeight(getFormHeight(), Unit.PIXELS); } else { container.setHeight(100, Unit.PERCENTAGE); } if (fixedWidth) { container.setWidth(Sizeable.SIZE_UNDEFINED, Unit.PIXELS); } else { container.setWidth(100, Unit.PERCENTAGE); } container.addStyleName("jd-box"); if (debug) container.addStyleName("jd-box-debug"); return container; }
From source file:org.jumpmind.metl.ui.views.design.ManageProjectsPanel.java
License:Open Source License
protected Component buildVersionGrid(Project project) { context.getConfigurationService().refresh(project); List<ProjectVersion> versions = project.getProjectVersions(); BeanItemContainer<ProjectVersion> versionGridContainer = new BeanItemContainer<>(ProjectVersion.class); Grid versionGrid = new Grid(); VerticalLayout layout = new VerticalLayout(); layout.setWidth(100, Unit.PERCENTAGE); layout.setMargin(true);//from w w w . j av a 2 s .c o m layout.setSpacing(true); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button openButton = new Button("Open", (event) -> { Collection<Object> selected = versionGrid.getSelectedRows(); for (Object object : selected) { projectNavigator.addProjectVersion(((ProjectVersion) object)); } }); buttons.addComponent(openButton); Button newButton = new Button("New Version", (event) -> newVersion(versionGrid)); buttons.addComponent(newButton); Button editButton = new Button("Edit Version", (event) -> edit(versionGrid)); buttons.addComponent(editButton); Button removeButton = new Button("Remove Version", (event) -> removeVersion(versionGrid)); buttons.addComponent(removeButton); openButton.setEnabled(false); newButton.setEnabled(false); removeButton.setEnabled(false); editButton.setEnabled(false); layout.addComponent(buttons); versionGrid.setWidth(100, Unit.PERCENTAGE); versionGrid.setHeight(3 + (versions.size() * ROW_EM), Unit.EM); versionGrid.setEditorEnabled(true); versionGrid.setSelectionMode(SelectionMode.MULTI); versionGrid.addColumn("versionLabel", String.class).setHeaderCaption("Version").setExpandRatio(2); versionGrid.addColumn("description", String.class).setHeaderCaption("Description").setExpandRatio(1); versionGrid.addColumn("readOnly", Boolean.class).setHeaderCaption("Read Only").setMaximumWidth(100) .setRenderer(new HtmlRenderer(), new StringToBooleanConverter() { private static final long serialVersionUID = 1L; protected String getTrueString() { return FontAwesome.CHECK.getHtml(); }; protected String getFalseString() { return ""; }; }); versionGrid.addColumn("createTime", Date.class).setHeaderCaption("Create Time").setWidth(185) .setMaximumWidth(200).setRenderer(new DateRenderer(UiConstants.DATETIME_FORMAT)).setEditable(false); versionGrid.setContainerDataSource(versionGridContainer); versionGrid.setEditorFieldFactory(new FieldFactory()); versionGrid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() { private static final long serialVersionUID = 1L; @Override public void preCommit(CommitEvent commitEvent) throws CommitException { } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { ProjectVersion item = (ProjectVersion) versionGrid.getEditedItemId(); IConfigurationService configurationService = context.getConfigurationService(); configurationService.save(item); projectGrid.markAsDirty(); } }); versionGrid.addSelectionListener((event) -> { int numberSelected = versionGrid.getSelectedRows().size(); boolean currentlyEditing = projectGrid.getEditedItemId() != null; boolean selected = numberSelected > 0 && !currentlyEditing; openButton.setEnabled(selected); newButton.setEnabled(selected); removeButton.setEnabled(selected); editButton.setEnabled(selected); }); versionGrid.addItemClickListener(new GridClickListener(versionGrid)); layout.addComponent(versionGrid); layout.setExpandRatio(versionGrid, 1); layout.addComponent(new Label(" ")); versionGridContainer.addAll(versions); versionGrid.sort("versionLabel", SortDirection.DESCENDING); return layout; }
From source file:org.jumpmind.vaadin.ui.sqlexplorer.SqlExplorer.java
License:Open Source License
public SqlExplorer(String configDir, IDbProvider databaseProvider, ISettingsProvider settingsProvider, String user, float leftSplitSize, IDbMenuItem... additionalMenuItems) { this.databaseProvider = databaseProvider; this.settingsProvider = settingsProvider; this.savedSplitPosition = leftSplitSize; this.additionalMenuItems = additionalMenuItems; setSizeFull();//www . j av a 2 s. c o m addStyleName("sqlexplorer"); VerticalLayout leftLayout = new VerticalLayout(); leftLayout.setSizeFull(); leftLayout.addStyleName(ValoTheme.MENU_ROOT); leftLayout.addComponent(buildLeftMenu()); Panel scrollable = new Panel(); scrollable.setSizeFull(); dbTree = buildDbTree(); scrollable.setContent(dbTree); leftLayout.addComponent(scrollable); leftLayout.setExpandRatio(scrollable, 1); VerticalLayout rightLayout = new VerticalLayout(); rightLayout.setSizeFull(); VerticalLayout rightMenuWrapper = new VerticalLayout(); rightMenuWrapper.setWidth(100, Unit.PERCENTAGE); rightMenuWrapper.addStyleName(ValoTheme.MENU_ROOT); contentMenuBar = new MenuBar(); contentMenuBar.addStyleName(ValoTheme.MENUBAR_BORDERLESS); contentMenuBar.setWidth(100, Unit.PERCENTAGE); addShowButton(contentMenuBar); rightMenuWrapper.addComponent(contentMenuBar); rightLayout.addComponent(rightMenuWrapper); contentTabs = new SqlExplorerTabPanel(); contentTabs.addSelectedTabChangeListener(new SelectedTabChangeListener() { private static final long serialVersionUID = 1L; @Override public void selectedTabChange(SelectedTabChangeEvent event) { selectContentTab((IContentTab) contentTabs.getSelectedTab()); } }); rightLayout.addComponent(contentTabs); rightLayout.setExpandRatio(contentTabs, 1); addComponents(leftLayout, rightLayout); setSplitPosition(savedSplitPosition, Unit.PIXELS); }
From source file:org.openeos.usertask.ui.internal.vaadin.TasksWindow.java
License:Apache License
private void displayTask(UserTask task) { Panel mainPanel = new Panel(); mainPanel.setStyleName("background-default"); VerticalLayout layout = new VerticalLayout(); layout.setMargin(true);/* w w w . j a v a2s. c om*/ layout.setSpacing(true); layout.setWidth(100f, VerticalLayout.UNITS_PERCENTAGE); mainPanel.setContent(layout); mainPanel.setSizeFull(); mainPanel.addComponent(createTaskTitle(task)); mainPanel.addComponent(createTaskSummary(task)); Component customComponent = createCustomComponent(task); if (customComponent != null) { mainPanel.addComponent(customComponent); } mainSplitPanel.setSecondComponent(mainPanel); }
From source file:org.openeos.usertask.ui.internal.vaadin.TasksWindow.java
License:Apache License
private ComponentContainer createSummaryButtons(final UserTask task) { Button completeButton = new Button("Task completed"); completeButton.setWidth("100%"); completeButton.addListener(new Button.ClickListener() { @Override//from www. j a v a2s . c om public void buttonClick(ClickEvent event) { completeTask(task); } }); VerticalLayout buttonsLayout = new VerticalLayout(); buttonsLayout.addComponent(completeButton); buttonsLayout.setWidth(16, VerticalLayout.UNITS_EM); return buttonsLayout; }
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();/*from ww w. ja v a2 s.c o m*/ Layout mainArea = createMainArea(description); content.addComponent(mainArea); content.addComponent(footer); content.setExpandRatio(mainArea, 1); return content; }
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 va 2 s. c o m*/ public BSMConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; /** * Setting up the base layouts */ setHeight(91, Unit.PERCENTAGE); setWidth(60, Unit.PERCENTAGE); /** * Retrieve the config... */ boolean filterByName = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterByName"); String nameValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "nameValue", ""); boolean filterByAttribute = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterByAttribute"); String attributeKey = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeKey", ""); String attributeValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeValue", ""); boolean filterBySeverity = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterBySeverity"); String severityValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "severityValue", Status.WARNING.name()); String severityCompareOperator = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "severityCompareOperator", BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name()); String orderBy = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderBy", BusinessServiceSearchCriteriaBuilder.Order.Name.name()); String orderSequence = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderSequence", BusinessServiceSearchCriteriaBuilder.Sequence.Ascending.name()); int resultsLimit = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "resultsLimit", 10); int columnCountBoard = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountBoard", 10); int columnCountPanel = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountPanel", 5); /** * Adding the "Filter By Name" panel */ m_filterByNameCheckBox = new CheckBox(); m_filterByNameCheckBox.setCaption("Enable"); m_filterByNameCheckBox.setDescription("Filter by Business Service name"); VerticalLayout nameLayout = new VerticalLayout(); nameLayout.setSpacing(true); nameLayout.setMargin(true); nameLayout.setSizeFull(); m_nameTextField = new TextField("Name (REGEXP)"); m_nameTextField.setEnabled(false); addToComponent(nameLayout, m_filterByNameCheckBox); addToComponent(nameLayout, m_nameTextField); Panel namePanel = new Panel(); namePanel.setCaption("Filter by Name"); namePanel.setContent(nameLayout); m_filterByNameCheckBox.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { m_nameTextField.setEnabled(m_filterByNameCheckBox.getValue()); } }); m_nameTextField.setValue(nameValue); m_filterByNameCheckBox.setValue(filterByName); /** * Adding the "Filter By Attribute" panel */ m_filterByAttributeCheckBox = new CheckBox(); m_filterByAttributeCheckBox.setCaption("Enable"); m_filterByAttributeCheckBox.setDescription("Filter by Business Service attribute"); VerticalLayout attributeLayout = new VerticalLayout(); attributeLayout.setSpacing(true); attributeLayout.setMargin(true); attributeLayout.setSizeFull(); m_attributeKeyTextField = new TextField("Key"); m_attributeKeyTextField.setEnabled(false); m_attributeValueTextField = new TextField("Value (REGEXP)"); m_attributeValueTextField.setEnabled(false); addToComponent(attributeLayout, m_filterByAttributeCheckBox); addToComponent(attributeLayout, m_attributeKeyTextField); addToComponent(attributeLayout, m_attributeValueTextField); Panel attributePanel = new Panel(); attributePanel.setCaption("Filter by Attribute"); attributePanel.setContent(attributeLayout); m_filterByAttributeCheckBox.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { m_attributeKeyTextField.setEnabled(m_filterByAttributeCheckBox.getValue()); m_attributeValueTextField.setEnabled(m_filterByAttributeCheckBox.getValue()); } }); m_attributeKeyTextField.setValue(attributeKey); m_attributeValueTextField.setValue(attributeValue); m_filterByAttributeCheckBox.setValue(filterByAttribute); /** * Adding the "Filter By Severity" panel */ m_filterBySeverityCheckBox = new CheckBox(); m_filterBySeverityCheckBox.setCaption("Enable"); m_filterBySeverityCheckBox.setDescription("Filter by Business Service severity"); VerticalLayout severityLayout = new VerticalLayout(); severityLayout.setSpacing(true); severityLayout.setMargin(true); severityLayout.setSizeFull(); m_severitySelect = new NativeSelect("Severity"); m_severitySelect.setEnabled(false); m_severitySelect.setNullSelectionAllowed(false); m_severitySelect.setMultiSelect(false); for (Status eachStatus : Status.values()) { m_severitySelect.addItem(eachStatus.name()); } m_compareOperatorSelect = new NativeSelect("Comparator"); m_compareOperatorSelect.setEnabled(false); m_compareOperatorSelect.setNullSelectionAllowed(false); m_compareOperatorSelect.setMultiSelect(false); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Lower.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.LowerOrEqual.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Equal.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name()); m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Greater.name()); addToComponent(severityLayout, m_filterBySeverityCheckBox); addToComponent(severityLayout, m_severitySelect); addToComponent(severityLayout, m_compareOperatorSelect); Panel severityPanel = new Panel(); severityPanel.setCaption("Filter by Severity"); severityPanel.setContent(severityLayout); m_filterBySeverityCheckBox.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { m_severitySelect.setEnabled(m_filterBySeverityCheckBox.getValue()); m_compareOperatorSelect.setEnabled(m_filterBySeverityCheckBox.getValue()); } }); m_severitySelect.setValue(severityValue); m_compareOperatorSelect.setValue(severityCompareOperator); m_filterBySeverityCheckBox.setValue(filterBySeverity); /** * Adding the "Results" panel */ VerticalLayout limitLayout = new VerticalLayout(); limitLayout.setSpacing(true); limitLayout.setMargin(true); limitLayout.setSizeFull(); m_limitTextField = new TextField("Limit"); m_orderBy = new NativeSelect("Order by"); m_orderBy.setNullSelectionAllowed(false); m_orderBy.setMultiSelect(false); m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Name.name()); m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Severity.name()); m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Level.name()); m_orderSequence = new NativeSelect("Asc/Desc "); m_orderSequence.setNullSelectionAllowed(false); m_orderSequence.setMultiSelect(false); m_orderSequence.addItem("Ascending"); m_orderSequence.addItem("Descending"); m_columnCountBoardTextField = new TextField("Ops Board Column Count"); m_columnCountBoardTextField.addValidator(new AbstractStringValidator("Number greater zero expected") { @Override protected boolean isValidValue(String value) { try { int i = Integer.parseInt(value); return i > 0; } catch (NumberFormatException e) { return false; } } }); m_columnCountPanelTextField = new TextField("Ops Panel Column Count"); m_columnCountPanelTextField.addValidator(new AbstractStringValidator("Number greater zero expected") { @Override protected boolean isValidValue(String value) { try { int i = Integer.parseInt(value); return i > 0; } catch (NumberFormatException e) { return false; } } }); addToComponent(limitLayout, m_limitTextField); addToComponent(limitLayout, m_orderBy); addToComponent(limitLayout, m_orderSequence); addToComponent(limitLayout, m_columnCountBoardTextField); addToComponent(limitLayout, m_columnCountPanelTextField); Panel limitPanel = new Panel(); limitPanel.setSizeFull(); limitPanel.setCaption("Results"); limitPanel.setContent(limitLayout); m_limitTextField.setValue(String.valueOf(resultsLimit)); m_orderBy.setValue(orderBy); m_orderSequence.setValue(orderSequence); m_columnCountBoardTextField.setValue(String.valueOf(columnCountBoard)); m_columnCountPanelTextField.setValue(String.valueOf(columnCountPanel)); m_limitTextField.addValidator(new AbstractStringValidator("Number greater or equal zero expected") { @Override protected boolean isValidValue(String value) { try { int i = Integer.parseInt(value); return i >= 0; } catch (NumberFormatException e) { return false; } } }); /** * Create the main layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setWidth(100, Unit.PERCENTAGE); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); verticalLayout.addComponent(namePanel); verticalLayout.addComponent(attributePanel); HorizontalLayout bottomLayout = new HorizontalLayout(severityPanel, limitPanel); bottomLayout.setSpacing(true); bottomLayout.setSizeFull(); bottomLayout.setWidth(100, Unit.PERCENTAGE); verticalLayout.addComponent(bottomLayout); /** * Using an additional {@link HorizontalLayout} for layouting the buttons */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); Label label = new Label("Note: Multiple enabled filter constraints will be combined by a logical AND."); buttonLayout.addComponent(label); buttonLayout.setExpandRatio(label, 1.0f); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); buttonLayout.addComponent(cancel); buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!m_limitTextField.isValid() || !m_columnCountPanelTextField.isValid() || !m_columnCountBoardTextField.isValid()) { return; } m_dashletSpec.getParameters().put("filterByName", (m_filterByNameCheckBox.getValue() ? "true" : "false")); if (m_filterByNameCheckBox.getValue()) { m_dashletSpec.getParameters().put("nameValue", m_nameTextField.getValue()); } else { m_dashletSpec.getParameters().put("nameValue", ""); } m_dashletSpec.getParameters().put("filterByAttribute", (m_filterByAttributeCheckBox.getValue() ? "true" : "false")); if (m_filterByAttributeCheckBox.getValue()) { m_dashletSpec.getParameters().put("attributeKey", m_attributeKeyTextField.getValue()); m_dashletSpec.getParameters().put("attributeValue", m_attributeValueTextField.getValue()); } else { m_dashletSpec.getParameters().put("attributeKey", ""); m_dashletSpec.getParameters().put("attributeValue", ""); } m_dashletSpec.getParameters().put("filterBySeverity", (m_filterBySeverityCheckBox.getValue() ? "true" : "false")); if (m_filterBySeverityCheckBox.getValue() && m_severitySelect.getValue() != null) { m_dashletSpec.getParameters().put("severityValue", m_severitySelect.getValue().toString()); } else { m_dashletSpec.getParameters().put("severityValue", Status.WARNING.getLabel()); } if (m_filterBySeverityCheckBox.getValue() && m_compareOperatorSelect.getValue() != null) { m_dashletSpec.getParameters().put("severityCompareOperator", m_compareOperatorSelect.getValue().toString()); } else { m_dashletSpec.getParameters().put("severityCompareOperator", BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name()); } if (m_orderBy.getValue() != null) { m_dashletSpec.getParameters().put("orderBy", m_orderBy.getValue().toString()); } else { m_dashletSpec.getParameters().put("orderBy", BusinessServiceSearchCriteriaBuilder.Order.Name.name()); } if (m_orderSequence.getValue() != null) { m_dashletSpec.getParameters().put("orderSequence", m_orderSequence.getValue().toString()); } else { m_dashletSpec.getParameters().put("orderSequence", "Ascending"); } m_dashletSpec.getParameters().put("resultsLimit", m_limitTextField.getValue().toString()); m_dashletSpec.getParameters().put("columnCountBoard", m_columnCountBoardTextField.getValue().toString()); m_dashletSpec.getParameters().put("columnCountPanel", m_columnCountPanelTextField.getValue().toString()); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties"); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonLayout.addComponent(ok); /** * Adding the layout and setting the content */ verticalLayout.addComponent(buttonLayout); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.KscDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_wallboardComponent == null) { m_wallboardComponent = new AbstractDashletComponent() { private GridLayout m_gridLayout = new GridLayout(); {//from www. ja v a 2 s . c om 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(); {//from www. j a v a 2 s. c o 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; }