List of usage examples for com.vaadin.ui HorizontalLayout setMargin
@Override public void setMargin(boolean enabled)
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 *///from w w w . ja v a2 s . c om 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.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceEdgeEditWindow.java
License:Open Source License
/** * Constructor/* ww w.j av a2 s .c o m*/ * * @param businessService the Business Service DTO instance to be configured * @param businessServiceManager the Business Service Manager */ @SuppressWarnings("unchecked") public BusinessServiceEdgeEditWindow(final BusinessService businessService, final BusinessServiceManager businessServiceManager, final Edge edge) { super("Business Service Edge Edit"); /** * Basic window setup */ setModal(true); setClosable(false); setResizable(false); setWidth(650, Unit.PIXELS); setHeight(325, Unit.PIXELS); /** * Creating the root layout... */ final VerticalLayout rootLayout = new VerticalLayout(); rootLayout.setSpacing(true); rootLayout.setMargin(false); /** * ...and the nested layout */ final FormLayout formLayout = new FormLayout(); formLayout.setSpacing(true); formLayout.setMargin(true); /** * type selector box */ m_typeSelect = new NativeSelect("Type"); m_typeSelect.setId("edgeTypeSelector"); m_typeSelect.setMultiSelect(false); m_typeSelect.setNewItemsAllowed(false); m_typeSelect.setNullSelectionAllowed(false); m_typeSelect.setRequired(true); m_typeSelect.addItem(EdgeType.CHILD_SERVICE); m_typeSelect.setItemCaption(EdgeType.CHILD_SERVICE, "Child Service"); m_typeSelect.addItem(EdgeType.IP_SERVICE); m_typeSelect.setItemCaption(EdgeType.IP_SERVICE, "IP Service"); m_typeSelect.addItem(EdgeType.REDUCTION_KEY); m_typeSelect.setItemCaption(EdgeType.REDUCTION_KEY, "Reduction Key"); m_typeSelect.setWidth(100.0f, Unit.PERCENTAGE); formLayout.addComponent(m_typeSelect); // List of child services m_childServiceComponent = new ComboBox("Child Service"); m_childServiceComponent.setId("childServiceList"); m_childServiceComponent.setInputPrompt("No child service selected"); m_childServiceComponent.setNewItemsAllowed(false); m_childServiceComponent.setNullSelectionAllowed(false); m_childServiceComponent.setWidth(100.0f, Unit.PERCENTAGE); m_childServiceComponent.setVisible(false); m_childServiceComponent.setImmediate(true); m_childServiceComponent.setValidationVisible(true); m_childServiceComponent.setFilteringMode(FilteringMode.CONTAINS); m_childServiceComponent.addItems(businessServiceManager.getFeasibleChildServices(businessService).stream() .sorted(Ordering.natural().onResultOf(s -> BusinessServiceEditWindow.describeBusinessService(s))) .collect(Collectors.toList())); m_childServiceComponent.getItemIds().forEach(item -> m_childServiceComponent.setItemCaption(item, BusinessServiceEditWindow.describeBusinessService((BusinessService) item))); formLayout.addComponent(m_childServiceComponent); // List of IP services m_ipServiceComponent = new ComboBox("IP Service"); m_ipServiceComponent.setId("ipServiceList"); m_ipServiceComponent.setInputPrompt("No IP service selected"); m_ipServiceComponent.setNewItemsAllowed(false); m_ipServiceComponent.setNullSelectionAllowed(false); m_ipServiceComponent.setWidth(100.0f, Unit.PERCENTAGE); m_ipServiceComponent.setVisible(false); m_ipServiceComponent.setImmediate(true); m_ipServiceComponent.setValidationVisible(true); m_ipServiceComponent.setFilteringMode(FilteringMode.CONTAINS); m_ipServiceComponent.addItems(businessServiceManager.getAllIpServices().stream() .sorted(Ordering.natural().onResultOf(s -> BusinessServiceEditWindow.describeIpService(s))) .collect(Collectors.toList())); m_ipServiceComponent.getItemIds().forEach(item -> m_ipServiceComponent.setItemCaption(item, BusinessServiceEditWindow.describeIpService((IpService) item))); formLayout.addComponent(m_ipServiceComponent); /** * reduction key input field */ m_reductionKeyComponent = new TextField("Reduction Key"); m_reductionKeyComponent.setId("reductionKeyField"); m_reductionKeyComponent.setWidth(100.0f, Unit.PERCENTAGE); m_reductionKeyComponent.setVisible(false); m_reductionKeyComponent.setImmediate(true); m_reductionKeyComponent.setValidationVisible(true); formLayout.addComponent(m_reductionKeyComponent); /** * the friendly name */ m_friendlyNameField = new TextField("Friendly Name"); m_friendlyNameField.setId("friendlyNameField"); m_friendlyNameField.setWidth(100.0f, Unit.PERCENTAGE); m_friendlyNameField.setVisible(false); m_friendlyNameField.setImmediate(true); m_friendlyNameField.setValidationVisible(true); m_friendlyNameField.setNullSettingAllowed(true); m_friendlyNameField.setNullRepresentation(""); m_friendlyNameField.setMaxLength(FRIENDLY_NAME_MAXLENGTH); formLayout.addComponent(m_friendlyNameField); /** * show and hide components */ m_typeSelect.addValueChangeListener(event -> { m_childServiceComponent.setVisible(m_typeSelect.getValue() == EdgeType.CHILD_SERVICE); m_childServiceComponent.setRequired(m_typeSelect.getValue() == EdgeType.CHILD_SERVICE); m_ipServiceComponent.setVisible(m_typeSelect.getValue() == EdgeType.IP_SERVICE); m_ipServiceComponent.setRequired(m_typeSelect.getValue() == EdgeType.IP_SERVICE); m_reductionKeyComponent.setVisible(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY); m_reductionKeyComponent.setRequired(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY); m_friendlyNameField.setVisible(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY || m_typeSelect.getValue() == EdgeType.IP_SERVICE); }); /** * map function field */ m_mapFunctionSelect = new NativeSelect("Map Function", ImmutableList.builder().add(Decrease.class) .add(Identity.class).add(Ignore.class).add(Increase.class).add(SetTo.class).build()); m_mapFunctionSelect.setId("mapFunctionSelector"); m_mapFunctionSelect.setNullSelectionAllowed(false); m_mapFunctionSelect.setMultiSelect(false); m_mapFunctionSelect.setNewItemsAllowed(false); m_mapFunctionSelect.setRequired(true); m_mapFunctionSelect.setWidth(100.0f, Unit.PERCENTAGE); /** * setting the captions for items */ m_mapFunctionSelect.getItemIds() .forEach(itemId -> m_mapFunctionSelect.setItemCaption(itemId, ((Class<?>) itemId).getSimpleName())); formLayout.addComponent(m_mapFunctionSelect); /** * severity selection field */ m_mapFunctionSeveritySelect = new NativeSelect("Severity"); m_mapFunctionSeveritySelect.setMultiSelect(false); m_mapFunctionSeveritySelect.setNewItemsAllowed(false); m_mapFunctionSeveritySelect.setNullSelectionAllowed(false); m_mapFunctionSeveritySelect.setRequired(false); m_mapFunctionSeveritySelect.addItem(Status.CRITICAL); m_mapFunctionSeveritySelect.setItemCaption(Status.CRITICAL, "Critical"); m_mapFunctionSeveritySelect.addItem(Status.MAJOR); m_mapFunctionSeveritySelect.setItemCaption(Status.MAJOR, "Major"); m_mapFunctionSeveritySelect.addItem(Status.MINOR); m_mapFunctionSeveritySelect.setItemCaption(Status.MINOR, "Minor"); m_mapFunctionSeveritySelect.addItem(Status.WARNING); m_mapFunctionSeveritySelect.setItemCaption(Status.WARNING, "Warning"); m_mapFunctionSeveritySelect.addItem(Status.NORMAL); m_mapFunctionSeveritySelect.setItemCaption(Status.NORMAL, "Normal"); m_mapFunctionSeveritySelect.addItem(Status.INDETERMINATE); m_mapFunctionSeveritySelect.setItemCaption(Status.INDETERMINATE, "Indeterminate"); m_mapFunctionSeveritySelect.setWidth(100.0f, Unit.PERCENTAGE); m_mapFunctionSeveritySelect.setEnabled(false); m_mapFunctionSeveritySelect.setImmediate(true); m_mapFunctionSeveritySelect.setValidationVisible(true); formLayout.addComponent(m_mapFunctionSeveritySelect); /** * hide or show additional severity input field */ m_mapFunctionSelect.addValueChangeListener(event -> { m_mapFunctionSeveritySelect.setEnabled(SetTo.class.equals(m_mapFunctionSelect.getValue())); m_mapFunctionSeveritySelect.setRequired(SetTo.class.equals(m_mapFunctionSelect.getValue())); }); /** * the weight input field */ m_weightField = new TextField("Weight"); m_weightField.setId("weightField"); m_weightField.setRequired(true); m_weightField.setWidth(100.0f, Unit.PERCENTAGE); m_weightField.addValidator(value -> { try { int intValue = Integer.parseInt((String) value); if (intValue <= 0) { throw new Validator.InvalidValueException("Weight must be > 0"); } } catch (final NumberFormatException e) { throw new Validator.InvalidValueException("Weight must be a number"); } }); m_weightField.setImmediate(true); m_weightField.setValidationVisible(true); formLayout.addComponent(m_weightField); /** * setting the defaults */ m_typeSelect.setValue(EdgeType.CHILD_SERVICE); m_mapFunctionSelect.setValue(Identity.class); m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); m_weightField.setValue(Integer.toString(Edge.DEFAULT_WEIGHT)); /** * add the button layout... */ final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.setMargin(true); /** * ...and the save button */ final Button saveButton = new Button(edge == null ? "Add Edge" : "Update Edge"); saveButton.setId("saveEdgeButton"); saveButton.addClickListener(UIHelper.getCurrent(TransactionAwareUI.class) .wrapInTransactionProxy((Button.ClickListener) event -> { if (!m_weightField.isValid()) return; if (!m_ipServiceComponent.isValid()) return; if (!m_childServiceComponent.isValid()) return; if (!m_reductionKeyComponent.isValid()) return; final MapFunction mapFunction = getMapFunction(); final int weight = Integer.parseInt(m_weightField.getValue()); /** * in the case edge is not null, remove the old object... */ if (edge != null) { businessService.removeEdge(edge); } /** * ...and add the new edge */ switch ((EdgeType) m_typeSelect.getValue()) { case CHILD_SERVICE: businessService.addChildEdge((BusinessService) m_childServiceComponent.getValue(), mapFunction, weight); break; case IP_SERVICE: businessService.addIpServiceEdge((IpService) m_ipServiceComponent.getValue(), mapFunction, weight, m_friendlyNameField.getValue()); break; case REDUCTION_KEY: businessService.addReductionKeyEdge(m_reductionKeyComponent.getValue(), mapFunction, weight, m_friendlyNameField.getValue()); break; } close(); })); buttonLayout.addComponent(saveButton); /** * ...and a cancel button */ final Button cancelButton = new Button("Cancel"); cancelButton.setId("cancelEdgeButton"); cancelButton.addClickListener((Button.ClickListener) event -> close()); buttonLayout.addComponent(cancelButton); /** * when edge is not null, fill the components with values */ if (edge != null) { edge.accept(new EdgeVisitor<Void>() { @Override public Void visit(IpServiceEdge edge) { m_typeSelect.setValue(EdgeType.IP_SERVICE); for (IpService ipService : (Collection<IpService>) m_ipServiceComponent.getItemIds()) { if (ipService.getId() == edge.getIpService().getId()) { m_ipServiceComponent.setValue(ipService); break; } } m_friendlyNameField.setValue(edge.getFriendlyName()); m_ipServiceComponent.setEnabled(false); return null; } @Override public Void visit(ReductionKeyEdge edge) { m_typeSelect.setValue(EdgeType.REDUCTION_KEY); m_reductionKeyComponent.setValue(edge.getReductionKey()); m_friendlyNameField.setValue(edge.getFriendlyName()); m_reductionKeyComponent.setEnabled(false); return null; } @Override public Void visit(ChildEdge edge) { m_typeSelect.setValue(EdgeType.CHILD_SERVICE); m_childServiceComponent.setValue(edge.getChild()); m_childServiceComponent.setEnabled(false); return null; } }); m_typeSelect.setEnabled(false); m_mapFunctionSelect.setValue(edge.getMapFunction().getClass()); edge.getMapFunction().accept(new MapFunctionVisitor<Void>() { @Override public Void visit(Decrease decrease) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(Identity identity) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(Ignore ignore) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(Increase increase) { m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE); return null; } @Override public Void visit(SetTo setTo) { m_mapFunctionSeveritySelect.setValue(((SetTo) edge.getMapFunction()).getStatus()); return null; } }); m_weightField.setValue(String.valueOf(edge.getWeight())); } /** * now set the root layout */ rootLayout.addComponent(formLayout); rootLayout.addComponent(buttonLayout); rootLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT); setContent(rootLayout); }
From source file:org.opennms.netmgt.vaadin.core.KeyValueInputDialogWindow.java
License:Open Source License
/** * Constructor responsible for creating new instances of this class * * @param caption the window's title/*from w ww .j a v a2s . c o m*/ * @param keyName the title of the key input field * @param valueName the title of the value input field */ public KeyValueInputDialogWindow(String caption, String keyName, String valueName) { super(caption); /** * set window properties */ setModal(true); setClosable(false); setResizable(false); /** * create the main layout */ VerticalLayout verticalLayout = new VerticalLayout(); /** * add the key input field */ m_keyInputField = new TextField(keyName); m_keyInputField.setValue(""); m_keyInputField.setId("keyField"); m_keyInputField.selectAll(); m_keyInputField.setImmediate(true); m_keyInputField.focus(); /** * add the value input field */ m_valueInputField = new TextField(valueName); m_valueInputField.setValue(""); m_valueInputField.setId("valueField"); m_valueInputField.selectAll(); m_valueInputField.setImmediate(true); /** * create nested FormLayout instance */ FormLayout formLayout = new FormLayout(); formLayout.setSizeUndefined(); formLayout.setMargin(true); formLayout.addComponent(m_keyInputField); formLayout.addComponent(m_valueInputField); /** * add the buttons in a horizontal layout */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth("100%"); /** * create cancel button */ m_cancelButton = new Button("Cancel"); m_cancelButton.setId("cancelBtn"); m_cancelButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); m_cancelButton.addClickListener(this); horizontalLayout.addComponent(m_cancelButton); horizontalLayout.setExpandRatio(m_cancelButton, 1); horizontalLayout.setComponentAlignment(m_cancelButton, Alignment.TOP_RIGHT); /** * create ok button */ m_okButton = new Button("OK"); m_okButton.setId("okBtn"); m_okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); m_okButton.addClickListener(this); horizontalLayout.addComponent(m_okButton); formLayout.addComponent(horizontalLayout); verticalLayout.addComponent(formLayout); addFocusListener(new FieldEvents.FocusListener() { @Override public void focus(FieldEvents.FocusEvent event) { if (m_focusKey) { m_keyInputField.focus(); } else { m_valueInputField.focus(); } } }); /** * the close listener */ addCloseListener(this); /** * set the content */ setContent(verticalLayout); }
From source file:org.opennms.netmgt.vaadin.core.StringInputDialogWindow.java
License:Open Source License
/** * Constructor responsible for creating new instances of this class * * @param caption the window's title/* ww w . j a v a 2s .co m*/ * @param fieldName the title of the input field */ public StringInputDialogWindow(String caption, String fieldName) { super(caption); /** * set window properties */ setModal(true); setClosable(false); setResizable(false); /** * create the main layout */ VerticalLayout verticalLayout = new VerticalLayout(); /** * add the input field */ m_inputField = new TextField(fieldName); m_inputField.setValue(""); m_inputField.focus(); m_inputField.selectAll(); m_inputField.setImmediate(true); /** * create nested FormLayout instance */ FormLayout formLayout = new FormLayout(); formLayout.setSizeUndefined(); formLayout.setMargin(true); formLayout.addComponent(m_inputField); /** * add the buttons in a horizontal layout */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth("100%"); /** * create cancel button */ m_cancelButton = new Button("Cancel"); m_cancelButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); m_cancelButton.addClickListener(this); horizontalLayout.addComponent(m_cancelButton); horizontalLayout.setExpandRatio(m_cancelButton, 1); horizontalLayout.setComponentAlignment(m_cancelButton, Alignment.TOP_RIGHT); /** * create ok button */ m_okButton = new Button("OK"); m_okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); m_okButton.addClickListener(this); horizontalLayout.addComponent(m_okButton); formLayout.addComponent(horizontalLayout); verticalLayout.addComponent(formLayout); /** * the close listener */ addCloseListener(this); /** * set the content */ setContent(verticalLayout); }
From source file:org.ow2.sirocco.cloudmanager.AddressView.java
License:Open Source License
public AddressView() { this.setSizeFull(); HorizontalLayout actionButtonHeader = new HorizontalLayout(); actionButtonHeader.setMargin(true); actionButtonHeader.setSpacing(true); actionButtonHeader.setWidth("100%"); actionButtonHeader.setHeight("50px"); Button button = new Button("Allocate Address..."); button.setIcon(new ThemeResource("img/add.png")); button.addClickListener(new ClickListener() { @Override// ww w .j a v a2s. c o m public void buttonClick(final ClickEvent event) { if (AddressView.this.addressAllocationWizard.init(AddressView.this)) { UI.getCurrent().addWindow(AddressView.this.addressAllocationWizard); } } }); actionButtonHeader.addComponent(button); this.associateAddressButton = new Button("Associate"); this.associateAddressButton.setEnabled(false); this.associateAddressButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { Set<?> selectedAddressIds = (Set<?>) AddressView.this.addressTable.getValue(); final String addressId = (String) Iterables.getOnlyElement(selectedAddressIds); List<AddressAssociateDialog.MachineChoice> choices = new ArrayList<>(); Address address = null; try { address = AddressView.this.networkManager.getAddressByUuid(addressId); List<Machine> machines = AddressView.this.machineManager.getMachines( new QueryParams.Builder().filterByProvider(address.getCloudProviderAccount().getUuid()) .filterByLocation(address.getLocation().getUuid()).build()) .getItems(); for (Machine machine : machines) { MachineChoice machineChoice = new MachineChoice(); machineChoice.id = machine.getUuid(); machineChoice.name = machine.getName(); choices.add(machineChoice); } } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Internal error", e); } final String ipAddress = address.getIp(); AddressAssociateDialog addressAssociateDialog = new AddressAssociateDialog(choices, new AddressAssociateDialog.DialogCallback() { @Override public void response(final String machineId) { try { AddressView.this.networkManager.addAddressToMachine(machineId, ipAddress); } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Address association failure", e); } } }); UI.getCurrent().addWindow(addressAssociateDialog); } }); actionButtonHeader.addComponent(this.associateAddressButton); this.disassociateAddressButton = new Button("Disassociate"); this.disassociateAddressButton.setEnabled(false); this.disassociateAddressButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { Set<?> selectedAddressIds = (Set<?>) AddressView.this.addressTable.getValue(); String addressId = (String) selectedAddressIds.iterator().next(); try { Address address = AddressView.this.networkManager.getAddressByUuid(addressId); AddressView.this.networkManager.removeAddressFromMachine(address.getResource().getUuid(), address.getIp()); } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Address disassociation failure", e); } } }); actionButtonHeader.addComponent(this.disassociateAddressButton); this.releaseAddressButton = new Button("Release"); this.releaseAddressButton.setIcon(new ThemeResource("img/delete.png")); this.releaseAddressButton.setEnabled(false); this.releaseAddressButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { final Set<?> selectedAddressIds = (Set<?>) AddressView.this.addressTable.getValue(); String ip = AddressView.this.addresses.getItem(selectedAddressIds.iterator().next()).getBean() .getIp(); ConfirmDialog confirmDialog = ConfirmDialog.newConfirmDialog("Release Address", "Are you sure you want to release address " + ip + " ?", new ConfirmDialog.ConfirmationDialogCallback() { @Override public void response(final boolean ok, final boolean ignored) { if (ok) { for (Object id : selectedAddressIds) { try { AddressView.this.networkManager.deleteAddress(id.toString()); } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Address delete failure", e); } } AddressView.this.refresh(); } } }); AddressView.this.getUI().addWindow(confirmDialog); } }); actionButtonHeader.addComponent(this.releaseAddressButton); Label spacer = new Label(); spacer.setWidth("100%"); actionButtonHeader.addComponent(spacer); actionButtonHeader.setExpandRatio(spacer, 1.0f); button = new Button("Refresh", new ClickListener() { @Override public void buttonClick(final ClickEvent event) { AddressView.this.refresh(); } }); button.setIcon(new ThemeResource("img/refresh.png")); actionButtonHeader.addComponent(button); this.addComponent(actionButtonHeader); this.addComponent(this.addressTable = this.createAddressTable()); this.setExpandRatio(this.addressTable, 1.0f); }
From source file:org.ow2.sirocco.cloudmanager.CloudProviderView.java
License:Open Source License
public CloudProviderView() { this.setSizeFull(); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull();/* w w w. j a v a2 s .co m*/ HorizontalLayout actionButtonHeader = new HorizontalLayout(); actionButtonHeader.setMargin(true); actionButtonHeader.setSpacing(true); actionButtonHeader.setWidth("100%"); actionButtonHeader.setHeight("50px"); Button button = new Button("Add Provider Account..."); button.setIcon(new ThemeResource("img/add.png")); button.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { CloudProviderView.this.providerAccountCreationWizard.init(CloudProviderView.this); UI.getCurrent().addWindow(CloudProviderView.this.providerAccountCreationWizard); } }); actionButtonHeader.addComponent(button); Label spacer = new Label(); spacer.setWidth("100%"); actionButtonHeader.addComponent(spacer); actionButtonHeader.setExpandRatio(spacer, 1.0f); button = new Button("Refresh", new ClickListener() { @Override public void buttonClick(final ClickEvent event) { CloudProviderView.this.refresh(); } }); button.setIcon(new ThemeResource("img/refresh.png")); actionButtonHeader.addComponent(button); verticalLayout.addComponent(actionButtonHeader); verticalLayout.addComponent(this.providerAccountTable = this.createCloudProviderAccountTable()); verticalLayout.setExpandRatio(this.providerAccountTable, 1.0f); this.setFirstComponent(verticalLayout); this.setSecondComponent(this.detailView = new ProviderAccountDetailView(this)); this.setSplitPosition(60.0f); }
From source file:org.ow2.sirocco.cloudmanager.KeyPairView.java
License:Open Source License
public KeyPairView() { this.setSizeFull(); HorizontalLayout actionButtonHeader = new HorizontalLayout(); actionButtonHeader.setMargin(true); actionButtonHeader.setSpacing(true); actionButtonHeader.setWidth("100%"); actionButtonHeader.setHeight("50px"); Button button = new Button("Import Key Pair..."); button.setIcon(new ThemeResource("img/add.png")); button.addClickListener(new ClickListener() { @Override//from ww w.ja v a 2 s . c o m public void buttonClick(final ClickEvent event) { KeyPairImportDialog dialog = new KeyPairImportDialog(new KeyPairImportDialog.DialogCallback() { @Override public void response(final String name, final String publicKey) { try { CredentialsCreate credentialsCreate = new CredentialsCreate(); credentialsCreate.setName(name); CredentialsTemplate credentialsTemplate = new CredentialsTemplate(); credentialsTemplate.setPublicKey(publicKey); credentialsCreate.setCredentialTemplate(credentialsTemplate); KeyPairView.this.credentialManager.createCredentials(credentialsCreate); } catch (CloudProviderException e) { Notification.show("Key Pair creation failure", e.getMessage(), Notification.Type.ERROR_MESSAGE); } KeyPairView.this.refresh(); KeyPairView.this.valueChange(null); } }); UI.getCurrent().addWindow(dialog); } }); actionButtonHeader.addComponent(button); this.deleteKeyPairButton = new Button("Delete"); this.deleteKeyPairButton.setIcon(new ThemeResource("img/delete.png")); this.deleteKeyPairButton.setEnabled(false); this.deleteKeyPairButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { final Set<?> selectedKeyPairIds = (Set<?>) KeyPairView.this.keyPairTable.getValue(); String name = KeyPairView.this.keyPairs.getItem(selectedKeyPairIds.iterator().next()).getBean() .getName(); ConfirmDialog confirmDialog = ConfirmDialog.newConfirmDialog("Delete Image", "Are you sure you want to delete key pair " + name + " ?", new ConfirmDialog.ConfirmationDialogCallback() { @Override public void response(final boolean ok, final boolean ignored) { if (ok) { for (Object id : selectedKeyPairIds) { try { KeyPairView.this.credentialManager.deleteCredentials(id.toString()); KeyPairView.this.keyPairs.removeItem(id); } catch (CloudProviderException e) { e.printStackTrace(); } } KeyPairView.this.keyPairTable.setValue(null); KeyPairView.this.valueChange(null); } } }); KeyPairView.this.getUI().addWindow(confirmDialog); } }); actionButtonHeader.addComponent(this.deleteKeyPairButton); Label spacer = new Label(); spacer.setWidth("100%"); actionButtonHeader.addComponent(spacer); actionButtonHeader.setExpandRatio(spacer, 1.0f); button = new Button("Refresh", new ClickListener() { @Override public void buttonClick(final ClickEvent event) { KeyPairView.this.refresh(); } }); button.setIcon(new ThemeResource("img/refresh.png")); actionButtonHeader.addComponent(button); this.addComponent(actionButtonHeader); this.addComponent(this.keyPairTable = this.createkeyPairTable()); this.setExpandRatio(this.keyPairTable, 1.0f); }
From source file:org.ow2.sirocco.cloudmanager.MachineImageView.java
License:Open Source License
public MachineImageView() { this.setSizeFull(); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull();/* w w w . j a v a 2 s. c o m*/ HorizontalLayout actionButtonHeader = new HorizontalLayout(); actionButtonHeader.setMargin(true); actionButtonHeader.setSpacing(true); actionButtonHeader.setWidth("100%"); actionButtonHeader.setHeight("50px"); this.registerMachineImageButton = new Button("Register Image..."); this.registerMachineImageButton.setIcon(new ThemeResource("img/add.png")); this.registerMachineImageButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { if (MachineImageView.this.machineImageRegisterWizard.init(MachineImageView.this)) { UI.getCurrent().addWindow(MachineImageView.this.machineImageRegisterWizard); } } }); actionButtonHeader.addComponent(this.registerMachineImageButton); this.deleteMachineImageButton = new Button("Delete"); this.deleteMachineImageButton.setIcon(new ThemeResource("img/delete.png")); this.deleteMachineImageButton.setEnabled(false); this.deleteMachineImageButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { final Set<?> selectedImageIds = (Set<?>) MachineImageView.this.machineImageTable.getValue(); StringBuilder sb = new StringBuilder(); sb.append("Are you sure you want to delete "); if (selectedImageIds.size() == 1) { Object id = selectedImageIds.iterator().next(); sb.append("image " + MachineImageView.this.images.getItem(id).getBean().getName() + " ?"); } else { sb.append(" these " + selectedImageIds.size() + " images ?"); } String name = MachineImageView.this.images.getItem(selectedImageIds.iterator().next()).getBean() .getName(); ConfirmDialog confirmDialog = ConfirmDialog.newConfirmDialogWithOption("Delete Image", sb.toString(), "delete image on provider", new ConfirmDialog.ConfirmationDialogCallback() { @Override public void response(final boolean ok, final boolean deleteOnProvider) { if (ok) { for (Object id : selectedImageIds) { try { if (deleteOnProvider) { MachineImageView.this.machineImageManager .deleteMachineImage(id.toString()); } else { MachineImageView.this.machineImageManager .unregisterMachineImage(id.toString()); } } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Image delete failure", e); } } MachineImageView.this.valueChange(null); } } }); MachineImageView.this.getUI().addWindow(confirmDialog); } }); actionButtonHeader.addComponent(this.deleteMachineImageButton); Label spacer = new Label(); spacer.setWidth("100%"); actionButtonHeader.addComponent(spacer); actionButtonHeader.setExpandRatio(spacer, 1.0f); Button button = new Button("Refresh", new ClickListener() { @Override public void buttonClick(final ClickEvent event) { MachineImageView.this.refresh(); } }); button.setIcon(new ThemeResource("img/refresh.png")); actionButtonHeader.addComponent(button); verticalLayout.addComponent(actionButtonHeader); verticalLayout.addComponent(this.machineImageTable = this.createMachineImageTable()); verticalLayout.setExpandRatio(this.machineImageTable, 1.0f); this.setFirstComponent(verticalLayout); this.setSecondComponent(this.detailView = new MachineImageDetailView(this)); this.setSplitPosition(60.0f); }
From source file:org.ow2.sirocco.cloudmanager.MachineView.java
License:Open Source License
public MachineView() { this.setSizeFull(); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull();// w w w .jav a 2 s . co m HorizontalLayout actionButtonHeader = new HorizontalLayout(); actionButtonHeader.setMargin(true); actionButtonHeader.setSpacing(true); actionButtonHeader.setWidth("100%"); actionButtonHeader.setHeight("50px"); Button button = new Button("Launch Instance..."); button.setIcon(new ThemeResource("img/add.png")); button.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { if (MachineView.this.machineCreationWizard.init(MachineView.this)) { UI.getCurrent().addWindow(MachineView.this.machineCreationWizard); } } }); actionButtonHeader.addComponent(button); this.startMachineButton = new Button("Start"); this.startMachineButton.setIcon(new ThemeResource("img/poweron.png")); this.startMachineButton.setEnabled(false); this.startMachineButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { Set<?> selectedMachineIds = (Set<?>) MachineView.this.machineTable.getValue(); String id = (String) selectedMachineIds.iterator().next(); try { MachineView.this.machineManager.startMachine(id); } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Cannot start instance", e); } } }); actionButtonHeader.addComponent(this.startMachineButton); this.stopMachineButton = new Button("Stop"); this.stopMachineButton.setIcon(new ThemeResource("img/poweroff.png")); this.stopMachineButton.setEnabled(false); this.stopMachineButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { Set<?> selectedMachineIds = (Set<?>) MachineView.this.machineTable.getValue(); String id = (String) selectedMachineIds.iterator().next(); try { MachineView.this.machineManager.stopMachine(id); } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Cannot stop instance", e); } } }); actionButtonHeader.addComponent(this.stopMachineButton); this.restartMachineButton = new Button("Reboot"); this.restartMachineButton.setIcon(new ThemeResource("img/restart.png")); this.restartMachineButton.setEnabled(false); this.restartMachineButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { Set<?> selectedMachineIds = (Set<?>) MachineView.this.machineTable.getValue(); String id = (String) selectedMachineIds.iterator().next(); try { MachineView.this.machineManager.restartMachine(id, false); } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Cannot reboot instance", e); } } }); actionButtonHeader.addComponent(this.restartMachineButton); this.deleteMachineButton = new Button("Delete"); this.deleteMachineButton.setIcon(new ThemeResource("img/delete.png")); this.deleteMachineButton.setEnabled(false); this.deleteMachineButton.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { final Set<?> selectedMachineIds = (Set<?>) MachineView.this.machineTable.getValue(); StringBuilder sb = new StringBuilder(); sb.append("Are you sure you want to delete "); if (selectedMachineIds.size() == 1) { Object id = selectedMachineIds.iterator().next(); sb.append("instance " + MachineView.this.machines.getItem(id).getBean().getName() + " ?"); } else { sb.append(" these " + selectedMachineIds.size() + " instances ?"); } ConfirmDialog confirmDialog = ConfirmDialog.newConfirmDialog("Delete Machine", sb.toString(), new ConfirmDialog.ConfirmationDialogCallback() { @Override public void response(final boolean ok, final boolean ignored) { if (ok) { for (Object id : selectedMachineIds) { try { MachineView.this.machineManager.deleteMachine(id.toString()); } catch (CloudProviderException e) { Util.diplayErrorMessageBox("Cannot delete instance", e); } } MachineView.this.valueChange(null); } } }); MachineView.this.getUI().addWindow(confirmDialog); } }); actionButtonHeader.addComponent(this.deleteMachineButton); Label spacer = new Label(); spacer.setWidth("100%"); actionButtonHeader.addComponent(spacer); actionButtonHeader.setExpandRatio(spacer, 1.0f); button = new Button("Refresh", new ClickListener() { @Override public void buttonClick(final ClickEvent event) { MachineView.this.refresh(); } }); button.setIcon(new ThemeResource("img/refresh.png")); actionButtonHeader.addComponent(button); verticalLayout.addComponent(actionButtonHeader); verticalLayout.addComponent(this.machineTable = this.createMachineTable()); verticalLayout.setExpandRatio(this.machineTable, 1.0f); this.setFirstComponent(verticalLayout); this.setSecondComponent(this.detailView = new MachineDetailView(this)); this.setSplitPosition(60.0f); }
From source file:org.ow2.sirocco.cloudmanager.MyUI.java
License:Open Source License
@Override protected void init(final VaadinRequest request) { this.userName = request.getUserPrincipal().getName(); this.identityContext.setUserName(this.userName); this.getPage().setTitle("Sirocco Dashboard"); final VerticalLayout layout = new VerticalLayout(); layout.setSizeFull();/*w w w. j a v a 2 s. co m*/ this.setContent(layout); // Top header ********************* HorizontalLayout header = new HorizontalLayout(); header.setMargin(true); header.setWidth("100%"); header.setHeight("70px"); header.setStyleName("topHeader"); // logo Image image = new Image(null, new ThemeResource("img/sirocco_small_logo.png")); header.addComponent(image); // spacer Label spacer = new Label(); spacer.setWidth("100%"); header.addComponent(spacer); header.setExpandRatio(spacer, 1.0f); HorizontalLayout rightButtons = new HorizontalLayout(); rightButtons.setStyleName("topHeader"); rightButtons.setSpacing(true); this.userName = request.getUserPrincipal().getName(); User user = null; try { user = this.userManager.getUserByUsername(this.userName); } catch (CloudProviderException e) { e.printStackTrace(); } Label label = new Label("Tenant:"); label.setStyleName("topHeaderLabel"); rightButtons.addComponent(label); final ComboBox tenantSelect = new ComboBox(); tenantSelect.setTextInputAllowed(false); tenantSelect.setNullSelectionAllowed(false); for (Tenant tenant : user.getTenants()) { tenantSelect.addItem(tenant.getName()); } tenantSelect.setValue(user.getTenants().iterator().next().getName()); tenantSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(final ValueChangeEvent event) { Notification.show("Switching to tenant " + tenantSelect.getValue()); } }); tenantSelect.setImmediate(true); rightButtons.addComponent(tenantSelect); this.tenantId = user.getTenants().iterator().next().getUuid(); this.identityContext.setTenantId(this.tenantId); // logged user name label = new Label("Logged in as: " + this.userName); label.setStyleName("topHeaderLabel"); rightButtons.addComponent(label); // sign out button Button button = new Button("Sign Out"); // button.setStyleName(BaseTheme.BUTTON_LINK); button.addClickListener(new Button.ClickListener() { public void buttonClick(final ClickEvent event) { MyUI.this.logout(); } }); rightButtons.addComponent(button); header.addComponent(rightButtons); layout.addComponent(header); // Split view HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); splitPanel.setSizeFull(); splitPanel.setFirstComponent(this.createLeftMenu()); this.inventoryContainer = new VerticalLayout(); this.inventoryContainer.setSizeFull(); this.inventoryContainer.addComponent(this.machineView); splitPanel.setSecondComponent(this.inventoryContainer); splitPanel.setSplitPosition(15); layout.addComponent(splitPanel); layout.setExpandRatio(splitPanel, 1.0f); this.listenToNotifications(); }