List of usage examples for com.vaadin.server ThemeResource ThemeResource
public ThemeResource(String resourceId)
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.ja 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.ow2.sirocco.cloudmanager.AddressView.java
License:Open Source License
public AddressView() { this.setSizeFull(); HorizontalLayout actionButtonHeader = new HorizontalLayout(); actionButtonHeader.setMargin(true);/* w ww . j a v a2s. c o m*/ 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 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();/*from w w w . j a va 2 s . com*/ 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.IconRegistry.java
License:Open Source License
public ThemeResource getLoadingIcon() { if (this.loadingIcon == null) { this.loadingIcon = new ThemeResource("img/loading.gif"); }/* w ww. jav a 2 s . c om*/ return this.loadingIcon; }
From source file:org.ow2.sirocco.cloudmanager.IconRegistry.java
License:Open Source License
public ThemeResource getGreenBallIcon() { if (this.greenBallIcon == null) { this.greenBallIcon = new ThemeResource("img/ball_green.gif"); }//from w w w .j a va 2 s .c om return this.greenBallIcon; }
From source file:org.ow2.sirocco.cloudmanager.IconRegistry.java
License:Open Source License
public ThemeResource getRedBallIcon() { if (this.redBallIcon == null) { this.redBallIcon = new ThemeResource("img/ball_red.gif"); }// www . j a va 2s . c o m return this.redBallIcon; }
From source file:org.ow2.sirocco.cloudmanager.IconRegistry.java
License:Open Source License
public ThemeResource getYellowBallIcon() { if (this.yellowBallIcon == null) { this.yellowBallIcon = new ThemeResource("img/ball_yellow.gif"); }//from w w w.j av a 2 s . c o m return this.yellowBallIcon; }
From source file:org.ow2.sirocco.cloudmanager.KeyPairView.java
License:Open Source License
public KeyPairView() { this.setSizeFull(); HorizontalLayout actionButtonHeader = new HorizontalLayout(); actionButtonHeader.setMargin(true);/*from w w w . j av a 2s . c o m*/ 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 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();//from ww w. j ava2 s.c om 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 . j a v a 2s .c om*/ 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); }