List of usage examples for com.vaadin.ui FormLayout setSpacing
@Override public void setSpacing(boolean spacing)
From source file:org.opennms.features.topology.plugins.topo.bsm.info.BusinessServiceVertexStatusInfoPanelItemProvider.java
License:Open Source License
private Component createComponent(BusinessServiceVertex vertex, GraphContainer container) { final FormLayout rootLayout = new FormLayout(); rootLayout.setSizeFull();//w ww . j a va 2s . com rootLayout.setSpacing(false); rootLayout.setMargin(false); rootLayout.addStyleName("severity"); final BusinessServiceStateMachine stateMachine = SimulationAwareStateMachineFactory .createStateMachine(businessServiceManager, container.getCriteria()); final Status overallStatus = BusinessServicesStatusProvider.getStatus(stateMachine, vertex); rootLayout.addComponent(createStatusLabel("Overall", overallStatus)); rootLayout.addComponent(new Label()); final BusinessServiceGraph graph = stateMachine.getGraph(); final BusinessService businessService = businessServiceManager .getBusinessServiceById(vertex.getServiceId()); final Set<GraphVertex> impactingVertices = getImpactingVertices(stateMachine, graph, businessService); for (final Edge edge : businessService.getEdges()) { // Get the topology vertex for the child to determine the display label final Vertex childVertex = businessServicesTopologyProvider .getVertex(edge.accept(new EdgeVisitor<VertexRef>() { @Override public VertexRef visit(final IpServiceEdge edge) { return new IpServiceVertex(edge.getIpService(), 0); } @Override public VertexRef visit(final ReductionKeyEdge edge) { return new ReductionKeyVertex(edge.getReductionKey(), 0); } @Override public VertexRef visit(final ChildEdge edge) { return new BusinessServiceVertex(edge.getChild(), 0); } })); final Status edgeStatus = stateMachine.getOperationalStatus(edge); rootLayout.addComponent(createStatusLabel(childVertex.getLabel(), edgeStatus, String.format( "%s × %d <i class=\"pull-right glyphicon %s\"></i>", edgeStatus.getLabel(), edge.getWeight(), impactingVertices.contains(graph.getVertexByEdgeId(edge.getId())) ? "glyphicon-flash" : ""))); } return rootLayout; }
From source file:org.opennms.features.topology.plugins.topo.bsm.info.SimulationModeReductionKeyInfoPanelItem.java
License:Open Source License
@Override public Component getComponent(VertexRef ref, GraphContainer container) { final ReductionKeyVertex vertex = (ReductionKeyVertex) ref; final FormLayout formLayout = new FormLayout(); formLayout.setSpacing(false); formLayout.setMargin(false);//from ww w . j av a 2 s. c o m NativeSelect dropdown = new NativeSelect("Severity"); dropdown.setMultiSelect(false); dropdown.setNewItemsAllowed(false); dropdown.setNullSelectionAllowed(true); dropdown.setImmediate(true); dropdown.setRequired(true); dropdown.addItems(Arrays.asList(Status.values())); SetStatusToCriteria setStatusTo = findCriteria(container, vertex); if (setStatusTo != null) { dropdown.setValue(setStatusTo.getStatus()); } else { dropdown.setValue(null); } dropdown.addValueChangeListener(event -> { // The set of criteria may have changed since we last queried it above // do we issue try finding it again, instead of using the same existing object SetStatusToCriteria currentSetStatusTo = findCriteria(container, vertex); Status selectedStatus = (Status) dropdown.getValue(); if (currentSetStatusTo != null) { currentSetStatusTo.setStatus(selectedStatus); } else { currentSetStatusTo = new SetStatusToCriteria(vertex.getReductionKey(), selectedStatus); container.addCriteria(currentSetStatusTo); } // Remove the current selection before redrawing the layout in order // to avoid centering on the current vertex container.getSelectionManager().setSelectedVertexRefs(Collections.emptyList()); container.getSelectionManager().setSelectedEdgeRefs(Collections.emptyList()); container.redoLayout(); }); formLayout.addComponent(dropdown); return formLayout; }
From source file:org.opennms.features.topology.plugins.topo.bsm.info.SimulationModeReductionKeyInfoPanelItemProvider.java
License:Open Source License
private Component createComponent(ReductionKeyVertex vertex, GraphContainer container) { final FormLayout formLayout = new FormLayout(); formLayout.setSpacing(false); formLayout.setMargin(false);/*from w w w . j a v a2s . c om*/ NativeSelect dropdown = new NativeSelect("Severity"); dropdown.setMultiSelect(false); dropdown.setNewItemsAllowed(false); dropdown.setNullSelectionAllowed(true); dropdown.setImmediate(true); dropdown.setRequired(true); dropdown.addItems(Arrays.asList(Status.values())); SetStatusToCriteria setStatusTo = findCriteria(container, vertex); if (setStatusTo != null) { dropdown.setValue(setStatusTo.getStatus()); } else { dropdown.setValue(null); } dropdown.addValueChangeListener(event -> { // The set of criteria may have changed since we last queried it above // do we issue try finding it again, instead of using the same existing object SetStatusToCriteria currentSetStatusTo = findCriteria(container, vertex); Status selectedStatus = (Status) dropdown.getValue(); if (currentSetStatusTo != null) { currentSetStatusTo.setStatus(selectedStatus); } else { currentSetStatusTo = new SetStatusToCriteria(vertex.getReductionKey(), selectedStatus); container.addCriteria(currentSetStatusTo); } // Remove the current selection before redrawing the layout in order // to avoid centering on the current vertex container.getSelectionManager().setSelectedVertexRefs(Collections.emptyList()); container.getSelectionManager().setSelectedEdgeRefs(Collections.emptyList()); container.redoLayout(); }); formLayout.addComponent(dropdown); return formLayout; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited *///from w ww . j a v a 2 s . c o m public ChartsConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; /** * Setting up the base layouts */ setHeight(410, Unit.PIXELS); setWidth(40, Unit.PERCENTAGE); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setWidth(100, Unit.PERCENTAGE); horizontalLayout.setSpacing(true); horizontalLayout.setMargin(true); FormLayout formLayout = new FormLayout(); formLayout.setWidth(100, Unit.PERCENTAGE); formLayout.setSpacing(true); formLayout.setMargin(true); /** * Adding the checkboxes */ m_maximizeWidth = new CheckBox(); m_maximizeWidth.setCaption("Maximize width"); m_maximizeWidth.setDescription("Maximize width"); m_maximizeHeight = new CheckBox(); m_maximizeHeight.setCaption("Maximize height"); m_maximizeHeight.setDescription("Maximize height"); String maximizeWidthString = m_dashletSpec.getParameters().get("maximizeWidth"); String maximizeHeightString = m_dashletSpec.getParameters().get("maximizeHeight"); boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString) || "1".equals(maximizeHeightString)); boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString) || "1".equals(maximizeWidthString)); m_maximizeWidth.setValue(maximizeWidth); m_maximizeHeight.setValue(maximizeHeight); m_chartSelect = new NativeSelect(); m_chartSelect.setDescription("Select chart to be displayed"); m_chartSelect.setCaption("Chart"); m_chartSelect.setNullSelectionAllowed(false); m_chartSelect.setInvalidAllowed(false); m_chartSelect.setNewItemsAllowed(false); String firstChartName = null; try { Iterator<BarChart> it = ChartUtils.getChartCollectionIterator(); while (it.hasNext()) { BarChart chartConfig = (BarChart) it.next(); if (firstChartName == null) { firstChartName = chartConfig.getName(); } m_chartSelect.addItem(chartConfig.getName()); } } catch (Exception e) { e.printStackTrace(); } String chartName = m_dashletSpec.getParameters().get("chart"); if (chartName == null || "".equals(chartName)) { chartName = firstChartName; } final Panel panel = new Panel(); panel.setWidth(230, Unit.PIXELS); panel.setCaption("Preview"); formLayout.addComponent(m_chartSelect); Page.getCurrent().getStyles().add(".preview { width:225px; }"); m_chartSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { String newImage = "/opennms/charts?chart-name=" + valueChangeEvent.getProperty().getValue(); Image image = new Image(null, new ExternalResource(newImage)); image.setStyleName("preview"); panel.setContent(image); } }); m_chartSelect.setValue(chartName); m_chartSelect.setImmediate(true); formLayout.addComponent(m_maximizeWidth); formLayout.addComponent(m_maximizeHeight); horizontalLayout.addComponent(formLayout); horizontalLayout.addComponent(panel); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); buttonLayout.addComponent(cancel); buttonLayout.setExpandRatio(cancel, 1.0f); buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { m_dashletSpec.getParameters().put("maximizeWidth", (m_maximizeWidth.getValue() ? "true" : "false")); m_dashletSpec.getParameters().put("maximizeHeight", (m_maximizeHeight.getValue() ? "true" : "false")); m_dashletSpec.getParameters().put("chart", String.valueOf(m_chartSelect.getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties"); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonLayout.addComponent(ok); /** * Adding the layout and setting the content */ //verticalLayout.addComponent(buttonLayout); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(buttonLayout); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.KscDashletConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link org.opennms.features.vaadin.dashboard.model.DashletSpec} to be edited *//* ww w . j ava2 s . c o m*/ public KscDashletConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; setHeight(210, Unit.PIXELS); setWidth(40, Unit.PERCENTAGE); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setWidth(100, Unit.PERCENTAGE); horizontalLayout.setSpacing(true); horizontalLayout.setMargin(true); FormLayout formLayout = new FormLayout(); formLayout.setWidth(100, Unit.PERCENTAGE); formLayout.setSpacing(true); formLayout.setMargin(true); m_kscSelect = new NativeSelect(); m_kscSelect.setDescription("Select KSC-report to be displayed"); m_kscSelect.setCaption("KSC-Report"); m_kscSelect.setImmediate(true); m_kscSelect.setNewItemsAllowed(false); m_kscSelect.setMultiSelect(false); m_kscSelect.setInvalidAllowed(false); m_kscSelect.setNullSelectionAllowed(false); m_kscSelect.setImmediate(true); final KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory.getInstance(); Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList(); for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) { m_kscSelect.addItem(entry.getKey()); m_kscSelect.setItemCaption(entry.getKey(), entry.getValue()); if (m_kscSelect.getValue() == null) { m_kscSelect.setValue(entry.getKey()); } } String chartName = m_dashletSpec.getParameters().get("kscReport"); if (chartName != null) { if (reportsMap.values().contains(chartName)) { m_kscSelect.setValue(chartName); } } formLayout.addComponent(m_kscSelect); m_kscSelect.setValue(chartName); m_kscSelect.setImmediate(true); horizontalLayout.addComponent(formLayout); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); buttonLayout.addComponent(cancel); buttonLayout.setExpandRatio(cancel, 1.0f); buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList(); m_dashletSpec.getParameters().put("kscReport", reportsMap.get(m_kscSelect.getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties"); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonLayout.addComponent(ok); if (reportsMap.size() == 0) { m_kscSelect.setEnabled(false); ok.setEnabled(false); } /** * Adding the layout and setting the content */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(buttonLayout); setContent(verticalLayout); }
From source file:org.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceEdgeEditWindow.java
License:Open Source License
/** * Constructor/*from w w w .ja v a 2 s. co 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.ow2.sirocco.cloudmanager.KeyPairImportDialog.java
License:Open Source License
public KeyPairImportDialog(final DialogCallback callback) { super("Import Key Pair"); this.callback = callback; this.center(); this.setClosable(false); this.setModal(true); this.setResizable(false); VerticalLayout content = new VerticalLayout(); content.setSizeFull();//from w w w .j a v a 2s. c om content.setMargin(true); content.setSpacing(true); content.setWidth("500px"); content.setHeight("250px"); FormLayout form = new FormLayout(); form.setWidth("100%"); form.setMargin(true); form.setSpacing(true); this.nameField = new TextField("Name"); this.nameField.setWidth("50%"); this.nameField.setRequired(true); this.nameField.setRequiredError("Please enter a name for your key pair"); form.addComponent(this.nameField); this.publicKeyField = new TextArea("Public Key"); this.publicKeyField.setWidth("100%"); this.publicKeyField.setRequired(true); this.publicKeyField.setRequiredError("Please enter a name for your key pair"); form.addComponent(this.publicKeyField); content.addComponent(form); final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); this.okButton = new Button("Ok", this); this.cancelButton = new Button("Cancel", this); this.cancelButton.focus(); buttonLayout.addComponent(this.okButton); buttonLayout.addComponent(this.cancelButton); content.addComponent(buttonLayout); content.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT); this.setContent(content); }
From source file:org.ozkar.vaadinBootstrapp.login.LoginPage.java
public LoginPage() { final VerticalLayout root = new VerticalLayout(); final FormLayout loginForm = new FormLayout(); txtUsername.setRequired(true);//from w ww .j a va 2 s.c om txtPassword.setRequired(true); btnOk.setClickShortcut(KeyCode.ENTER); root.addComponent(loginForm); root.setComponentAlignment(loginForm, Alignment.MIDDLE_CENTER); root.setSizeFull(); loginForm.addComponent(txtUsername); loginForm.addComponent(txtPassword); loginForm.addComponent(btnOk); loginForm.setSpacing(true); loginForm.setMargin(new MarginInfo(true, true, true, false)); loginForm.setCaption(":::LOGIN:::"); loginForm.setSizeUndefined(); this.setSizeFull(); this.setCompositionRoot(root); /* Event Handling */ btnOk.addClickListener((Button.ClickEvent event) -> { User user = User.getUser(txtUsername.getValue()); if (AuthUtils.validUser(user, txtPassword.getValue())) { Notification.show("Bienvenido..."); AuthUtils.logIn(getUI(), user); getUI().getNavigator().navigateTo(HomePage.URL); } else { Notification.show("Usuario o Contrasea Incorrecto."); } }); }