List of usage examples for com.vaadin.ui GridLayout GridLayout
public GridLayout()
From source file:org.lunifera.christmastree.control.MobileControlComponent.java
License:Creative Commons License
@SuppressWarnings("deprecation") protected GridLayout buildContent() { // common part: create layout contentLayout = new GridLayout(); contentLayout.setImmediate(false);//from w w w.j a v a 2 s.co m contentLayout.setMargin(false); contentLayout.setSpacing(true); contentLayout.setColumns(2); contentLayout.setRows(5); // button_off button_off = new Embedded("Off", new ThemeResource("./images/off.png")); button_off.setImmediate(true); button_off.setWidth("-1px"); button_off.setHeight("-1px"); button_off.addClickListener(listener); button_off.setStyleName("xmas-button-off"); contentLayout.addComponent(button_off, 0, 0); contentLayout.setComponentAlignment(button_off, Alignment.MIDDLE_LEFT); // button_on button_on = new Embedded("On", new ThemeResource("./images/on.png")); button_on.setImmediate(true); button_on.setWidth("-1px"); button_on.setHeight("-1px"); button_on.addListener(listener); button_on.setStyleName("xmas-button-on"); contentLayout.addComponent(button_on, 1, 0); contentLayout.setComponentAlignment(button_on, Alignment.MIDDLE_RIGHT); // button_red button_red = new Embedded(null, new ThemeResource("./images/red.png")); button_red.setCaption("Red"); button_red.setImmediate(true); button_red.setWidth("-1px"); button_red.setHeight("-1px"); button_red.addListener(listener); button_red.setStyleName("xmas-button-red"); contentLayout.addComponent(button_red, 0, 1); contentLayout.setComponentAlignment(button_red, Alignment.MIDDLE_LEFT); // button_blue button_blue = new Embedded(null, new ThemeResource("./images/blue.png")); button_blue.setCaption("Blue"); button_blue.setImmediate(true); button_blue.setWidth("-1px"); button_blue.setHeight("-1px"); button_blue.setStyleName("xmas-button-blue"); button_blue.addListener(listener); contentLayout.addComponent(button_blue, 1, 1); contentLayout.setComponentAlignment(button_blue, Alignment.MIDDLE_RIGHT); // button_flash button_flash = new Embedded(null, new ThemeResource("./images/flash.png")); button_flash.setCaption("Flash"); button_flash.setImmediate(true); button_flash.setWidth("-1px"); button_flash.setHeight("-1px"); button_flash.addListener(listener); button_flash.setStyleName("xmas-button-flash"); contentLayout.addComponent(button_flash, 0, 2); contentLayout.setComponentAlignment(button_flash, Alignment.MIDDLE_LEFT); // button_strobe button_strobe = new Embedded(null, new ThemeResource("./images/strobe.png")); button_strobe.setCaption("Strobo"); button_strobe.setImmediate(true); button_strobe.setWidth("-1px"); button_strobe.setHeight("-1px"); button_strobe.addListener(listener); button_strobe.setStyleName("xmas-button-strobe"); contentLayout.addComponent(button_strobe, 1, 2); contentLayout.setComponentAlignment(button_strobe, Alignment.MIDDLE_RIGHT); // button_snow button_snow = new Embedded(null, new ThemeResource("./images/snowflake.png")); button_snow.setCaption("Let it snow"); button_snow.setImmediate(true); button_snow.setWidth("-1px"); button_snow.setHeight("-1px"); button_snow.addListener(listener); button_snow.setStyleName("xmas-button-snow"); contentLayout.addComponent(button_snow, 0, 3); contentLayout.setComponentAlignment(button_snow, Alignment.MIDDLE_LEFT); // button_angel button_angel = new Embedded(null, new ThemeResource("./images/angel.png")); button_angel.setCaption("Angel"); button_angel.setImmediate(true); button_angel.setWidth("-1px"); button_angel.setHeight("-1px"); button_angel.addListener(listener); button_angel.setStyleName("xmas-button-angel"); contentLayout.addComponent(button_angel, 1, 3); contentLayout.setComponentAlignment(button_angel, Alignment.MIDDLE_RIGHT); // button_star button_star = new Embedded(null, new ThemeResource("./images/star.png")); button_star.setCaption("Star"); button_star.setImmediate(true); button_star.setWidth("-1px"); button_star.setHeight("-1px"); button_star.addListener(listener); button_star.setStyleName("xmas-button-star"); contentLayout.addComponent(button_star, 0, 4); contentLayout.setComponentAlignment(button_star, Alignment.MIDDLE_LEFT); return contentLayout; }
From source file:org.opennms.features.vaadin.dashboard.config.ui.DashletSpecEditor.java
License:Open Source License
/** * Constructor for the DashletSpecEditor. * * @param wallboardEditor the {@link WallboardEditor} wallboard editor this editor belongs to * @param dashletSelector the {@link DashletSelector} used to query available {@link DashletFactory} instances * @param dashletSpec the associated {@link DashletSpec} instance *//*from w ww.j a va 2s .c o m*/ public DashletSpecEditor(WallboardEditor wallboardEditor, DashletSelector dashletSelector, DashletSpec dashletSpec) { /** * Setting the member fields */ this.m_wallboardEditor = wallboardEditor; this.m_dashletSpec = dashletSpec; this.m_dashletSelector = dashletSelector; /** * Setting defaults */ DashletFactory dashletFactory = dashletSelector.getDashletFactoryForName(dashletSpec.getDashletName()); final Map<String, String> requiredParameters = dashletFactory.getRequiredParameters(); for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { if (!dashletSpec.getParameters().containsKey(entry.getKey())) { dashletSpec.getParameters().put(entry.getKey(), requiredParameters.get(entry.getKey())); } } /** * Setting up this component with size and layout */ setWidth(100.0f, Unit.PERCENTAGE); GridLayout gridLayout = new GridLayout(); gridLayout.setColumns(6); gridLayout.setRows(1); gridLayout.setMargin(true); /** * Priority field setup, layout and adding listener and validator */ final TextField priorityField = new TextField(); priorityField.setValue(String.valueOf(dashletSpec.getPriority())); priorityField.setImmediate(true); priorityField.setCaption("Priority"); priorityField.setDescription("Priority of this dashlet"); priorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); priorityField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (priorityField.isValid()) { m_dashletSpec.setPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority"); } } }); /** * Boost priority field setup, layout and adding listener and validator */ final TextField boostPriorityField = new TextField(); boostPriorityField.setValue(String.valueOf(dashletSpec.getBoostPriority())); boostPriorityField.setImmediate(true); boostPriorityField.setCaption("Boost-Priority"); boostPriorityField.setDescription("Boost priority of this dashlet"); boostPriorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); boostPriorityField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (boostPriorityField.isValid()) { m_dashletSpec .setBoostPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority"); } } }); /** * Duration field setup, layout and adding listener and validator */ final TextField durationField = new TextField(); durationField.setValue(String.valueOf(dashletSpec.getDuration())); durationField.setImmediate(true); durationField.setCaption("Duration"); durationField.setDescription("Duration for this dashlet"); durationField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); durationField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (durationField.isValid()) { m_dashletSpec.setDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration"); } } }); /** * Boost duration field setup, layout and adding listener and validator */ final TextField boostDurationField = new TextField(); boostDurationField.setValue(String.valueOf(dashletSpec.getBoostDuration())); boostDurationField.setImmediate(true); boostDurationField.setCaption("Boost-Duration"); boostDurationField.setDescription("Boost duration for this dashlet"); boostDurationField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); boostDurationField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (boostDurationField.isValid()) { m_dashletSpec .setBoostDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration"); } } }); boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .isBoostable(); boostPriorityField.setEnabled(boostable); boostDurationField.setEnabled(boostable); /** * Setting up the dashlet selection */ m_dashletSelect = new NativeSelect(); m_dashletSelect.setCaption("Dashlet"); updateDashletSelection(dashletSelector.getDashletFactoryList()); m_dashletSelect.setImmediate(true); m_dashletSelect.setNewItemsAllowed(false); m_dashletSelect.setNullSelectionItemId("Undefined"); m_dashletSelect.setNullSelectionAllowed(false); m_dashletSelect.select(dashletSpec.getDashletName()); m_dashletSelect.setDescription("Dashlet selection"); m_dashletSelect.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (m_savingDisabled) { return; } if (valueChangeEvent.getProperty().getValue() == null) { m_dashletSpec.setDashletName("Undefined"); } else { m_dashletSpec.setDashletName(valueChangeEvent.getProperty().getValue().toString()); m_dashletSelect.removeItem("Undefined"); } m_dashletSpec.getParameters().clear(); Map<String, String> requiredParameters = m_dashletSelector .getDashletFactoryForName(m_dashletSpec.getDashletName()).getRequiredParameters(); for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { m_dashletSpec.getParameters().put(entry.getKey(), entry.getValue()); } m_propertiesButton.setEnabled(requiredParameters.size() > 0); boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .isBoostable(); boostPriorityField.setEnabled(boostable); boostDurationField.setEnabled(boostable); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Dashlet"); } }); m_titleField = new TextField(); m_titleField.setValue(dashletSpec.getTitle()); m_titleField.setImmediate(true); m_titleField.setCaption("Title"); m_titleField.setDescription("Title for this dashlet instance"); m_titleField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { m_dashletSpec.setTitle((String) valueChangeEvent.getProperty().getValue()); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Title"); } }); FormLayout f1 = new FormLayout(); f1.addComponent(m_dashletSelect); f1.addComponent(m_titleField); /** * Adding the required input fields and buttons to several {@link FormLayout} instances for better layout. */ FormLayout f2 = new FormLayout(); f2.addComponent(priorityField); f2.addComponent(durationField); FormLayout f3 = new FormLayout(); f3.addComponent(boostPriorityField); f3.addComponent(boostDurationField); /** * Adding the properties button... */ m_propertiesButton = new Button("Properties"); m_propertiesButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { DashletConfigurationWindow configurationWindow = m_dashletSelector .getDashletFactoryForName(m_dashletSpec.getDashletName()) .configurationWindow(m_dashletSpec); getUI().addWindow(configurationWindow); } }); m_propertiesButton.setEnabled(m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .getRequiredParameters().size() > 0); m_propertiesButton.setStyleName("small"); m_propertiesButton.setDescription("Open properties dialog for this dashlet"); /** * ...and the remove button */ Button removeButton = new Button("Remove"); removeButton.setDescription("Remove this dashlet entry"); FormLayout f4 = new FormLayout(); f4.addComponent(m_propertiesButton); f4.addComponent(removeButton); removeButton.addClickListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.removeDashletSpecEditor(DashletSpecEditor.this); } }); removeButton.setStyleName("small"); Button upButton = new Button(); upButton.setStyleName("small"); upButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); upButton.setDescription("Move this a dashlet entry one position up"); Button downButton = new Button(); downButton.setStyleName("small"); downButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); downButton.setDescription("Move this a dashlet entry one position down"); FormLayout f5 = new FormLayout(); f5.addComponent(upButton); f5.addComponent(downButton); Button previewButton = new Button("Preview"); previewButton.setStyleName("small"); previewButton.setDescription("Preview this single dashlet entry"); Wallboard wallboard = new Wallboard(); wallboard.getDashletSpecs().add(m_dashletSpec); previewButton.addClickListener(new PreviewClickListener(this, wallboard)); FormLayout f6 = new FormLayout(); f6.addComponent(previewButton); upButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.swapDashletSpec(m_dashletSpec, -1); } }); downButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.swapDashletSpec(m_dashletSpec, +1); } }); /** * Adding the different {@link FormLayout} instances to a {@link GridLayout} */ f1.setMargin(true); f2.setMargin(true); f3.setMargin(true); f4.setMargin(true); f5.setMargin(true); f6.setMargin(true); gridLayout.addComponent(f1); gridLayout.addComponent(f2); gridLayout.addComponent(f3); gridLayout.addComponent(f4); gridLayout.addComponent(f5); gridLayout.addComponent(f6); setContent(gridLayout); }
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 w w w . jav a2 s . c o 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.RrdDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_wallboardComponent == null) { m_wallboardComponent = new AbstractDashletComponent() { private GridLayout m_gridLayout = new GridLayout(); {// w w w . ja va2 s . c om m_gridLayout.setCaption(getName()); m_gridLayout.setSizeFull(); m_gridLayout.setColumns(1); m_gridLayout.setRows(1); } @Override public void refresh() { /** * removing old components */ m_gridLayout.removeAllComponents(); /** * iniatizing the parameters */ int columns = 0; int rows = 0; int width = 0; int height = 0; try { columns = Integer.parseInt(getDashletSpec().getParameters().get("columns")); } catch (NumberFormatException numberFormatException) { columns = 1; } try { rows = Integer.parseInt(getDashletSpec().getParameters().get("rows")); } catch (NumberFormatException numberFormatException) { rows = 1; } try { width = Integer.parseInt(getDashletSpec().getParameters().get("width")); } catch (NumberFormatException numberFormatException) { width = 400; } try { height = Integer.parseInt(getDashletSpec().getParameters().get("height")); } catch (NumberFormatException numberFormatException) { height = 100; } /** * getting the timeframe values */ int timeFrameValue; int timeFrameType; try { timeFrameValue = Integer.parseInt(getDashletSpec().getParameters().get("timeFrameValue")); } catch (NumberFormatException numberFormatException) { timeFrameValue = 1; } try { timeFrameType = Integer.parseInt(getDashletSpec().getParameters().get("timeFrameType")); } catch (NumberFormatException numberFormatException) { timeFrameType = Calendar.HOUR; } /** * setting new columns/rows */ m_gridLayout.setColumns(columns); m_gridLayout.setRows(rows); int i = 0; 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; }"); /** * adding the components */ for (int y = 0; y < m_gridLayout.getRows(); y++) { for (int x = 0; x < m_gridLayout.getColumns(); x++) { String graphUrl = getDashletSpec().getParameters().get("graphUrl" + i); if (graphUrl != null && !"".equals(graphUrl)) { Component component = getGraphComponent(i, width, height, timeFrameType, timeFrameValue); m_gridLayout.addComponent(component, x, y); m_gridLayout.setComponentAlignment(component, Alignment.MIDDLE_CENTER); } i++; } } } @Override public Component getComponent() { return m_gridLayout; } }; } return m_wallboardComponent; }
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 a2s . co 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.surveillanceviews.ui.SurveillanceViewConfigurationWindow.java
License:Open Source License
/** * The constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used * @param view the view to edit * @param saveActionListener the save action listener */// ww w . j a v a 2 s . c o m public SurveillanceViewConfigurationWindow(final SurveillanceViewService surveillanceViewService, final View view, final SaveActionListener saveActionListener) { /** * Setting the title */ super("Surveillance view configuration"); /** * Setting the modal and size properties */ setModal(true); setClosable(false); setResizable(false); setWidth(80, Sizeable.Unit.PERCENTAGE); setHeight(75, Sizeable.Unit.PERCENTAGE); /** * Title field */ final TextField titleField = new TextField(); titleField.setValue(view.getName()); titleField.setImmediate(true); titleField.setCaption("Title"); titleField.setDescription("Title of this surveillance view"); titleField.setWidth(25, Unit.PERCENTAGE); /** * Adding simple validator */ titleField.addValidator(new AbstractStringValidator("Please use an unique name for the surveillance view") { @Override protected boolean isValidValue(String string) { if ("".equals(string.trim())) { return false; } if (SurveillanceViewProvider.getInstance().containsView(string) && !view.getName().equals(string)) { return false; } return true; } }); /** * Refresh seconds field setup and validator */ final TextField refreshSecondsField = new TextField(); refreshSecondsField.setValue(String.valueOf(view.getRefreshSeconds())); refreshSecondsField.setImmediate(true); refreshSecondsField.setCaption("Refresh seconds"); refreshSecondsField.setDescription("Refresh duration in seconds"); refreshSecondsField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { int number; try { number = Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return (number >= 0); } }); /** * Columns table */ final Table columnsTable = new Table(); columnsTable.setSortEnabled(false); columnsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<ColumnDef> columns = new BeanItemContainer<ColumnDef>(ColumnDef.class, view.getColumns()); final Map<ColumnDef, Integer> columnOrder = new HashMap<>(); int c = 0; for (ColumnDef columnDef : view.getColumns()) { columnOrder.put(columnDef, c++); } columnsTable.setContainerDataSource(columns); columnsTable.setVisibleColumns("label"); columnsTable.setColumnHeader("label", "Columns"); columnsTable.setColumnExpandRatio("label", 1.0f); columnsTable.setSelectable(true); columnsTable.setMultiSelect(false); /** * Create custom sorter */ columns.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (columnOrder.get(o1).intValue() == columnOrder.get(o2).intValue()) { return 0; } else { if (columnOrder.get(o1).intValue() > columnOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button columnsAddButton = new Button("Add"); columnsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), new ColumnDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, columnOrder.size()); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); columnsAddButton.setEnabled(true); columnsAddButton.setStyleName("small"); columnsAddButton.setDescription("Add column"); columnsAddButton.setEnabled(true); final Button columnsEditButton = new Button("Edit"); columnsEditButton.setEnabled(true); columnsEditButton.setStyleName("small"); columnsEditButton.setDescription("Edit column"); columnsEditButton.setEnabled(false); columnsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), (ColumnDef) columnsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { ColumnDef columnToBeReplaced = (ColumnDef) columnsTable.getValue(); int index = columnOrder.get(columnToBeReplaced); columns.removeItem(columnToBeReplaced); columnOrder.remove(columnToBeReplaced); columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, index); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); final Button columnsRemoveButton = new Button("Remove"); columnsRemoveButton.setEnabled(true); columnsRemoveButton.setStyleName("small"); columnsRemoveButton.setDescription("Remove column"); columnsRemoveButton.setEnabled(false); columnsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { columnsTable.unselect(columnDef); columns.removeItem(columnDef); } columnsTable.refreshRowCache(); } }); final Button columnUpButton = new Button(); columnUpButton.setStyleName("small"); columnUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); columnUpButton.setDescription("Move this a column entry one position up"); columnUpButton.setEnabled(false); columnUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex - 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex - 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); final Button columnDownButton = new Button(); columnDownButton.setStyleName("small"); columnDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); columnDownButton.setDescription("Move this a column entry one position down"); columnDownButton.setEnabled(false); columnDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex + 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex + 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); columnsTable.setSizeFull(); columnUpButton.setSizeFull(); columnDownButton.setSizeFull(); columnsAddButton.setSizeFull(); columnsEditButton.setSizeFull(); columnsRemoveButton.setSizeFull(); columnsTable.setImmediate(true); /** * ...and a listener */ columnsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (columnsTable.getValue() != null); columnsRemoveButton.setEnabled(somethingSelected); columnsEditButton.setEnabled(somethingSelected); columnsAddButton.setEnabled(true); columnUpButton .setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() > 0); columnDownButton.setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() < columnOrder.size() - 1); } }); /** * Rows table */ final Table rowsTable = new Table(); rowsTable.setSortEnabled(false); rowsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<RowDef> rows = new BeanItemContainer<RowDef>(RowDef.class, view.getRows()); final Map<RowDef, Integer> rowOrder = new HashMap<>(); int r = 0; for (RowDef rowDef : view.getRows()) { rowOrder.put(rowDef, r++); } rowsTable.setContainerDataSource(rows); rowsTable.setVisibleColumns("label"); rowsTable.setColumnHeader("label", "Rows"); rowsTable.setColumnExpandRatio("label", 1.0f); rowsTable.setSelectable(true); rowsTable.setMultiSelect(false); /** * Create custom sorter */ rows.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (rowOrder.get(o1).intValue() == rowOrder.get(o2).intValue()) { return 0; } else { if (rowOrder.get(o1).intValue() > rowOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button rowsAddButton = new Button("Add"); rowsAddButton.setEnabled(true); rowsAddButton.setStyleName("small"); rowsAddButton.setDescription("Add row"); rowsAddButton.setEnabled(true); rowsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), new RowDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { rows.addItem((RowDef) def); rowOrder.put((RowDef) def, rowOrder.size()); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsEditButton = new Button("Edit"); rowsEditButton.setEnabled(true); rowsEditButton.setStyleName("small"); rowsEditButton.setDescription("Edit row"); rowsEditButton.setEnabled(false); rowsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), (RowDef) rowsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { RowDef rowToBeReplaced = (RowDef) rowsTable.getValue(); int index = rowOrder.get(rowToBeReplaced); rows.removeItem(rowToBeReplaced); rowOrder.remove(rowToBeReplaced); rows.addItem((RowDef) def); rowOrder.put((RowDef) def, index); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsRemoveButton = new Button("Remove"); rowsRemoveButton.setEnabled(true); rowsRemoveButton.setStyleName("small"); rowsRemoveButton.setDescription("Remove row"); rowsRemoveButton.setEnabled(false); rowsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { rowsTable.unselect(rowDef); rows.removeItem(rowDef); } rowsTable.refreshRowCache(); } }); final Button rowUpButton = new Button(); rowUpButton.setStyleName("small"); rowUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); rowUpButton.setDescription("Move this a row entry one position up"); rowUpButton.setEnabled(false); rowUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex - 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex - 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); final Button rowDownButton = new Button(); rowDownButton.setStyleName("small"); rowDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); rowDownButton.setDescription("Move this a row entry one position down"); rowDownButton.setEnabled(false); rowDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex + 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex + 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); rowsTable.setSizeFull(); rowUpButton.setSizeFull(); rowDownButton.setSizeFull(); rowsAddButton.setSizeFull(); rowsEditButton.setSizeFull(); rowsRemoveButton.setSizeFull(); rowsTable.setImmediate(true); /** * ...and a listener */ rowsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (rowsTable.getValue() != null); rowsRemoveButton.setEnabled(somethingSelected); rowsEditButton.setEnabled(somethingSelected); rowsAddButton.setEnabled(true); rowUpButton.setEnabled(somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() > 0); rowDownButton.setEnabled( somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() < rowOrder.size() - 1); } }); /** * Create form layouts... */ FormLayout baseFormLayout = new FormLayout(); baseFormLayout.addComponent(titleField); baseFormLayout.addComponent(refreshSecondsField); FormLayout columnTableFormLayout = new FormLayout(); columnTableFormLayout.addComponent(columnsAddButton); columnTableFormLayout.addComponent(columnsEditButton); columnTableFormLayout.addComponent(columnsRemoveButton); columnTableFormLayout.addComponent(columnUpButton); columnTableFormLayout.addComponent(columnDownButton); FormLayout rowTableFormLayout = new FormLayout(); rowTableFormLayout.addComponent(rowsAddButton); rowTableFormLayout.addComponent(rowsEditButton); rowTableFormLayout.addComponent(rowsRemoveButton); rowTableFormLayout.addComponent(rowUpButton); rowTableFormLayout.addComponent(rowDownButton); /** * Adding the different {@link com.vaadin.ui.FormLayout} instances to a {@link com.vaadin.ui.GridLayout} */ baseFormLayout.setMargin(true); columnTableFormLayout.setMargin(true); rowTableFormLayout.setMargin(true); GridLayout gridLayout = new GridLayout(); gridLayout.setSizeFull(); gridLayout.setColumns(4); gridLayout.setRows(1); gridLayout.setMargin(true); gridLayout.addComponent(rowsTable); gridLayout.addComponent(rowTableFormLayout); gridLayout.addComponent(columnsTable); gridLayout.addComponent(columnTableFormLayout); gridLayout.setColumnExpandRatio(1, 0.5f); gridLayout.setColumnExpandRatio(2, 1.0f); gridLayout.setColumnExpandRatio(3, 0.5f); gridLayout.setColumnExpandRatio(4, 1.0f); /** * Creating the vertical layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(baseFormLayout); verticalLayout.addComponent(gridLayout); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth(100, Unit.PERCENTAGE); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing properties"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); horizontalLayout.addComponent(cancel); horizontalLayout.setExpandRatio(cancel, 1); horizontalLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!titleField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please use an unique title", Notification.Type.ERROR_MESSAGE); return; } if (!refreshSecondsField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please enter a valid number in the \"Refresh seconds\" field", Notification.Type.ERROR_MESSAGE); return; } if (columns.getItemIds().isEmpty() || rows.getItemIds().isEmpty()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "You must define at least one row category and one column category", Notification.Type.ERROR_MESSAGE); return; } View finalView = new View(); for (ColumnDef columnDef : columns.getItemIds()) { finalView.getColumns().add(columnDef); } for (RowDef rowDef : rows.getItemIds()) { finalView.getRows().add(rowDef); } finalView.setName(titleField.getValue()); finalView.setRefreshSeconds(Integer.parseInt(refreshSecondsField.getValue())); saveActionListener.save(finalView); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); horizontalLayout.addComponent(ok); verticalLayout.addComponent(horizontalLayout); setContent(verticalLayout); }
From source file:org.sensorhub.ui.GenericConfigForm.java
License:Mozilla Public License
protected Component buildTabs(final String propId, final ContainerProperty prop, final FieldGroup fieldGroup) { GridLayout layout = new GridLayout(); layout.setWidth(100.0f, Unit.PERCENTAGE); // title bar/* w w w . j av a2s. c om*/ HorizontalLayout titleBar = new HorizontalLayout(); titleBar.setMargin(new MarginInfo(true, false, false, false)); titleBar.setSpacing(true); String label = prop.getLabel(); if (label == null) label = DisplayUtils.getPrettyName((String) propId); Label sectionLabel = new Label(label); sectionLabel.setDescription(prop.getDescription()); sectionLabel.addStyleName(STYLE_H3); sectionLabel.addStyleName(STYLE_COLORED); titleBar.addComponent(sectionLabel); layout.addComponent(titleBar); // create one tab per item in container final MyBeanItemContainer<Object> container = prop.getValue(); final TabSheet tabs = new TabSheet(); tabs.setSizeFull(); int i = 1; for (Object itemId : container.getItemIds()) { MyBeanItem<Object> childBeanItem = (MyBeanItem<Object>) container.getItem(itemId); IModuleConfigForm subform = AdminUI.getInstance().generateForm(childBeanItem.getBean().getClass()); subform.build(null, childBeanItem); ((MarginHandler) subform).setMargin(new MarginInfo(true, false, true, false)); allForms.add(subform); Tab tab = tabs.addTab(subform, "Item #" + (i++)); tab.setClosable(true); // store item id so we can map a tab with the corresponding bean item ((AbstractComponent) subform).setData(itemId); } // draw icon on last tab to add new items tabs.addTab(new VerticalLayout(), "", UIConstants.ADD_ICON); // catch close event to delete item tabs.setCloseHandler(new CloseHandler() { private static final long serialVersionUID = 1L; @Override public void onTabClose(TabSheet tabsheet, Component tabContent) { final Tab tab = tabs.getTab(tabContent); final ConfirmDialog popup = new ConfirmDialog( "Are you sure you want to delete " + tab.getCaption() + "?</br>All settings will be lost."); popup.addCloseListener(new CloseListener() { private static final long serialVersionUID = 1L; @Override public void windowClose(CloseEvent e) { if (popup.isConfirmed()) { // retrieve id of item shown on tab AbstractComponent tabContent = (AbstractComponent) tab.getComponent(); Object itemId = tabContent.getData(); // remove from UI int deletedTabPos = tabs.getTabPosition(tab); tabs.removeTab(tab); tabs.setSelectedTab(deletedTabPos - 1); // remove from container container.removeItem(itemId); } } }); popup.setModal(true); AdminUI.getInstance().addWindow(popup); } }); // catch select event on '+' tab to add new item tabs.addSelectedTabChangeListener(new SelectedTabChangeListener() { private static final long serialVersionUID = 1L; public void selectedTabChange(SelectedTabChangeEvent event) { Component selectedTab = event.getTabSheet().getSelectedTab(); final Tab tab = tabs.getTab(selectedTab); final int selectedTabPos = tabs.getTabPosition(tab); // case of + tab to add new item if (tab.getCaption().equals("")) { tabs.setSelectedTab(selectedTabPos - 1); try { // show popup to select among available module types String title = "Please select the desired option"; Map<String, Class<?>> typeList = GenericConfigForm.this.getPossibleTypes(propId); ObjectTypeSelectionPopup popup = new ObjectTypeSelectionPopup(title, typeList, new ObjectTypeSelectionCallback() { public void typeSelected(Class<?> objectType) { try { // add new item to container MyBeanItem<Object> childBeanItem = container.addBean( objectType.newInstance(), ((String) propId) + PROP_SEP); // generate form for new item IModuleConfigForm subform = AdminUI.getInstance() .generateForm(childBeanItem.getBean().getClass()); subform.build(null, childBeanItem); ((MarginHandler) subform) .setMargin(new MarginInfo(true, false, true, false)); allForms.add(subform); // add new tab and select it Tab newTab = tabs.addTab(subform, "Item #" + (selectedTabPos + 1), null, selectedTabPos); newTab.setClosable(true); tabs.setSelectedTab(newTab); } catch (Exception e) { Notification.show("Error", e.getMessage(), Notification.Type.ERROR_MESSAGE); } } }); popup.setModal(true); AdminUI.getInstance().addWindow(popup); } catch (Exception e) { e.printStackTrace(); } } } }); // also register commit handler fieldGroup.addCommitHandler(new CommitHandler() { private static final long serialVersionUID = 1L; @Override public void preCommit(CommitEvent commitEvent) throws CommitException { } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { // make sure new items are transfered to model prop.setValue(prop.getValue()); } }); layout.addComponent(tabs); return layout; }
From source file:org.sensorhub.ui.NetworkAdminPanel.java
License:Mozilla Public License
@Override public void build(final MyBeanItem<ModuleConfig> beanItem, final ICommNetwork<?> module) { super.build(beanItem, module); // add sub form final GridLayout form = new GridLayout(); form.setWidth(100.0f, Unit.PERCENTAGE); form.setMargin(false);/*from w w w . j av a2s .c o m*/ form.setSpacing(true); // add sections addAvailableNetworks(form, module); addScannedDevices(form, module); addComponent(form); }
From source file:org.sensorhub.ui.SensorAdminPanel.java
License:Mozilla Public License
@Override public void build(final MyBeanItem<ModuleConfig> beanItem, final ISensorModule<?> module) { super.build(beanItem, module); // add section label final GridLayout form = new GridLayout(); form.setWidth(100.0f, Unit.PERCENTAGE); form.setMargin(false);/* w w w . java 2 s . com*/ form.setSpacing(true); // section title form.addComponent(new Label("")); HorizontalLayout titleBar = new HorizontalLayout(); titleBar.setSpacing(true); Label sectionLabel = new Label("Inputs/Outputs"); sectionLabel.addStyleName(STYLE_H3); sectionLabel.addStyleName(STYLE_COLORED); titleBar.addComponent(sectionLabel); titleBar.setComponentAlignment(sectionLabel, Alignment.MIDDLE_LEFT); // refresh button to show latest record Button refreshButton = new Button("Refresh"); refreshButton.setDescription("Load latest data from sensor"); refreshButton.setIcon(REFRESH_ICON); refreshButton.addStyleName(STYLE_QUIET); titleBar.addComponent(refreshButton); titleBar.setComponentAlignment(refreshButton, Alignment.MIDDLE_LEFT); refreshButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { rebuildSwePanels(form, module); } }); form.addComponent(titleBar); // add I/O panel rebuildSwePanels(form, module); addComponent(form); }
From source file:org.sensorhub.ui.StorageAdminPanel.java
License:Mozilla Public License
@Override public void build(final MyBeanItem<ModuleConfig> beanItem, final IRecordStorageModule<?> storage) { super.build(beanItem, storage); if (storage != null) { // section layout final GridLayout form = new GridLayout(); form.setWidth(100.0f, Unit.PERCENTAGE); form.setMargin(false);/* w w w. j a v a 2 s .co m*/ form.setSpacing(true); // section title form.addComponent(new Label("")); HorizontalLayout titleBar = new HorizontalLayout(); titleBar.setSpacing(true); Label sectionLabel = new Label("Data Store Content"); sectionLabel.addStyleName(STYLE_H3); sectionLabel.addStyleName(STYLE_COLORED); titleBar.addComponent(sectionLabel); titleBar.setComponentAlignment(sectionLabel, Alignment.MIDDLE_LEFT); // refresh button to show latest record Button refreshButton = new Button("Refresh"); refreshButton.setDescription("Reload data from storage"); refreshButton.setIcon(REFRESH_ICON); refreshButton.addStyleName(STYLE_QUIET); titleBar.addComponent(refreshButton); titleBar.setComponentAlignment(refreshButton, Alignment.MIDDLE_LEFT); refreshButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { buildDataPanel(form, storage); } }); form.addComponent(titleBar); // add I/O panel buildDataPanel(form, storage); addComponent(form); } }