Example usage for com.vaadin.ui FormLayout FormLayout

List of usage examples for com.vaadin.ui FormLayout FormLayout

Introduction

In this page you can find the example usage for com.vaadin.ui FormLayout FormLayout.

Prototype

public FormLayout() 

Source Link

Usage

From source file:org.opennms.features.topology.plugins.topo.bsm.info.BusinessServiceVertexAttributesInfoPanelItem.java

License:Open Source License

@Override
protected Component getComponent(VertexRef ref, GraphContainer container) {
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(false);/*from w  ww .  j  a  va2  s.  com*/
    formLayout.setMargin(false);

    final BusinessService businessService = this.businessServiceManager
            .getBusinessServiceById(((BusinessServiceVertex) ref).getServiceId());

    for (Map.Entry<String, String> e : businessService.getAttributes().entrySet()) {
        formLayout.addComponent(createLabel(e.getKey(), e.getValue()));
    }

    return formLayout;
}

From source file:org.opennms.features.topology.plugins.topo.bsm.info.BusinessServiceVertexAttributesInfoPanelItemProvider.java

License:Open Source License

private Component createComponent(VertexRef ref) {
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(false);//from  w  w w  .  j  ava  2 s  .  c  om
    formLayout.setMargin(false);

    final BusinessService businessService = businessServiceManager
            .getBusinessServiceById(((BusinessServiceVertex) ref).getServiceId());

    for (Map.Entry<String, String> e : businessService.getAttributes().entrySet()) {
        formLayout.addComponent(createLabel(e.getKey(), e.getValue()));
    }

    return formLayout;
}

From source file:org.opennms.features.topology.plugins.topo.bsm.info.BusinessServiceVertexInfoPanelItem.java

License:Open Source License

@Override
protected Component getComponent(VertexRef ref, GraphContainer container) {
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(false);/* w w w .  j  a v  a 2s . c o m*/
    formLayout.setMargin(false);

    ((AbstractBusinessServiceVertex) ref).accept(new BusinessServiceVertexVisitor<Void>() {
        @Override
        public Void visit(BusinessServiceVertex vertex) {
            final BusinessService businessService = businessServiceManager
                    .getBusinessServiceById(vertex.getServiceId());
            formLayout.addComponent(createLabel("Reduce function",
                    getReduceFunctionDescription(businessService.getReduceFunction())));

            // Apply Reduce Function specific details
            businessService.getReduceFunction().accept(new ReduceFunctionVisitor<Void>() {
                @Override
                public Void visit(HighestSeverity highestSeverity) {
                    return null;
                }

                @Override
                public Void visit(HighestSeverityAbove highestSeverityAbove) {
                    return null;
                }

                @Override
                // Threshold is not very transparent, we add an Explain Button in these cases
                public Void visit(Threshold threshold) {
                    final Button explainButton = createButton("Explain", "Explain the Threshold function",
                            FontAwesome.TABLE, (Button.ClickListener) event -> {
                                ThresholdExplanationWindow explainWindow = new ThresholdExplanationWindow(
                                        SimulationAwareStateMachineFactory
                                                .createSimulatedStateMachine(businessServiceManager,
                                                        container.getCriteria())
                                                .explain(businessService,
                                                        (Threshold) businessService.getReduceFunction()));
                                UI.getCurrent().addWindow(explainWindow);
                            });
                    explainButton.setStyleName(BaseTheme.BUTTON_LINK);
                    formLayout.addComponent(explainButton);
                    return null;
                }
            });
            return null;
        }

        @Override
        public Void visit(IpServiceVertex vertex) {
            IpService ipService = businessServiceManager.getIpServiceById(vertex.getIpServiceId());
            formLayout.addComponent(createLabel("Interface", ipService.getIpAddress()));
            formLayout.addComponent(createLabel("Service", ipService.getServiceName()));
            if (!ipService.getServiceName().equals(vertex.getLabel())) {
                formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
            }
            return null;
        }

        @Override
        public Void visit(ReductionKeyVertex vertex) {
            formLayout.addComponent(createLabel("Reduction Key", vertex.getReductionKey()));
            if (!vertex.getReductionKey().equals(vertex.getLabel())) {
                formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
            }
            return null;
        }
    });

    return formLayout;
}

From source file:org.opennms.features.topology.plugins.topo.bsm.info.BusinessServiceVertexInfoPanelItemProvider.java

License:Open Source License

private Component createComponent(AbstractBusinessServiceVertex ref, GraphContainer graphContainer) {
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(false);/*w  w w .j  a  va 2s  .  c  om*/
    formLayout.setMargin(false);

    ref.accept(new BusinessServiceVertexVisitor<Void>() {
        @Override
        public Void visit(BusinessServiceVertex vertex) {
            final BusinessService businessService = businessServiceManager
                    .getBusinessServiceById(vertex.getServiceId());
            formLayout.addComponent(createLabel("Reduce function",
                    getReduceFunctionDescription(businessService.getReduceFunction())));

            // Apply Reduce Function specific details
            businessService.getReduceFunction().accept(new ReduceFunctionVisitor<Void>() {
                @Override
                public Void visit(HighestSeverity highestSeverity) {
                    return null;
                }

                @Override
                public Void visit(HighestSeverityAbove highestSeverityAbove) {
                    return null;
                }

                @Override
                // Threshold is not very transparent, we add an Explain Button in these cases
                public Void visit(Threshold threshold) {
                    final Button explainButton = createButton("Explain", "Explain the Threshold function",
                            FontAwesome.TABLE, (Button.ClickListener) event -> {
                                ThresholdExplanationWindow explainWindow = new ThresholdExplanationWindow(
                                        SimulationAwareStateMachineFactory
                                                .createSimulatedStateMachine(businessServiceManager,
                                                        graphContainer.getCriteria())
                                                .explain(businessService,
                                                        (Threshold) businessService.getReduceFunction()));
                                UI.getCurrent().addWindow(explainWindow);
                            });
                    explainButton.setStyleName(BaseTheme.BUTTON_LINK);
                    formLayout.addComponent(explainButton);
                    return null;
                }

                @Override
                public Void visit(ExponentialPropagation exponentialPropagation) {
                    return null;
                }
            });
            return null;
        }

        @Override
        public Void visit(IpServiceVertex vertex) {
            IpService ipService = businessServiceManager.getIpServiceById(vertex.getIpServiceId());
            formLayout.addComponent(createLabel("Interface", ipService.getIpAddress()));
            formLayout.addComponent(createLabel("Service", ipService.getServiceName()));
            if (!ipService.getServiceName().equals(vertex.getLabel())) {
                formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
            }
            return null;
        }

        @Override
        public Void visit(ReductionKeyVertex vertex) {
            formLayout.addComponent(createLabel("Reduction Key", vertex.getReductionKey()));
            if (!vertex.getReductionKey().equals(vertex.getLabel())) {
                formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
            }
            return null;
        }
    });

    return formLayout;
}

From source file:org.opennms.features.topology.plugins.topo.bsm.info.BusinessServiceVertexStatusInfoPanelItem.java

License:Open Source License

@Override
protected Component getComponent(VertexRef ref, GraphContainer container) {
    final BusinessServiceVertex vertex = (BusinessServiceVertex) ref;

    final FormLayout rootLayout = new FormLayout();
    rootLayout.setSizeFull();//from  www. j  a v a2  s.co m
    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 &times; %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.BusinessServiceVertexStatusInfoPanelItemProvider.java

License:Open Source License

private Component createComponent(BusinessServiceVertex vertex, GraphContainer container) {
    final FormLayout rootLayout = new FormLayout();
    rootLayout.setSizeFull();//from  ww  w .jav  a  2 s . c  o m
    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 &times; %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);/*from w w w  .j  av a2 s.c  o  m*/
    formLayout.setMargin(false);

    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);/*from w  ww.j  av a  2s.co m*/
    formLayout.setMargin(false);

    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.config.ui.DashletSpecEditor.java

License:Open Source License

/**
 * Constructor for the DashletSpecEditor.
 *
 * @param wallboardEditor the {@link WallboardEditor} wallboard editor this editor belongs to
 * @param dashletSelector the {@link DashletSelector} used to query available {@link DashletFactory} instances
 * @param dashletSpec     the associated {@link DashletSpec} instance
 *///from  w  w w  .j  av  a  2 s .c  o  m
public DashletSpecEditor(WallboardEditor wallboardEditor, DashletSelector dashletSelector,
        DashletSpec dashletSpec) {
    /**
     * Setting the member fields
     */
    this.m_wallboardEditor = wallboardEditor;
    this.m_dashletSpec = dashletSpec;
    this.m_dashletSelector = dashletSelector;

    /**
     * Setting defaults
     */

    DashletFactory dashletFactory = dashletSelector.getDashletFactoryForName(dashletSpec.getDashletName());

    final Map<String, String> requiredParameters = dashletFactory.getRequiredParameters();

    for (Map.Entry<String, String> entry : requiredParameters.entrySet()) {
        if (!dashletSpec.getParameters().containsKey(entry.getKey())) {
            dashletSpec.getParameters().put(entry.getKey(), requiredParameters.get(entry.getKey()));
        }
    }

    /**
     * Setting up this component with size and layout
     */
    setWidth(100.0f, Unit.PERCENTAGE);

    GridLayout gridLayout = new GridLayout();
    gridLayout.setColumns(6);
    gridLayout.setRows(1);
    gridLayout.setMargin(true);

    /**
     * Priority field setup, layout and adding listener and validator
     */
    final TextField priorityField = new TextField();
    priorityField.setValue(String.valueOf(dashletSpec.getPriority()));
    priorityField.setImmediate(true);
    priorityField.setCaption("Priority");
    priorityField.setDescription("Priority of this dashlet");

    priorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") {
        @Override
        protected boolean isValidValue(String s) {
            try {
                Integer.parseInt(s);
            } catch (NumberFormatException numberFormatException) {
                return false;
            }
            return true;
        }
    });

    priorityField.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            if (priorityField.isValid()) {
                m_dashletSpec.setPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue()));
                WallboardProvider.getInstance().save();
                ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority");
            }
        }
    });

    /**
     * Boost priority field setup, layout and adding listener and validator
     */
    final TextField boostPriorityField = new TextField();
    boostPriorityField.setValue(String.valueOf(dashletSpec.getBoostPriority()));
    boostPriorityField.setImmediate(true);
    boostPriorityField.setCaption("Boost-Priority");
    boostPriorityField.setDescription("Boost priority of this dashlet");

    boostPriorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") {
        @Override
        protected boolean isValidValue(String s) {
            try {
                Integer.parseInt(s);
            } catch (NumberFormatException numberFormatException) {
                return false;
            }
            return true;
        }
    });

    boostPriorityField.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            if (boostPriorityField.isValid()) {
                m_dashletSpec
                        .setBoostPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue()));
                WallboardProvider.getInstance().save();
                ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority");
            }
        }
    });

    /**
     * Duration field setup, layout and adding listener and validator
     */
    final TextField durationField = new TextField();
    durationField.setValue(String.valueOf(dashletSpec.getDuration()));
    durationField.setImmediate(true);
    durationField.setCaption("Duration");
    durationField.setDescription("Duration for this dashlet");

    durationField.addValidator(new AbstractStringValidator("Only numbers allowed here") {
        @Override
        protected boolean isValidValue(String s) {
            try {
                Integer.parseInt(s);
            } catch (NumberFormatException numberFormatException) {
                return false;
            }
            return true;
        }
    });

    durationField.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            if (durationField.isValid()) {
                m_dashletSpec.setDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue()));
                WallboardProvider.getInstance().save();
                ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration");
            }
        }
    });

    /**
     * Boost duration field setup, layout and adding listener and validator
     */
    final TextField boostDurationField = new TextField();
    boostDurationField.setValue(String.valueOf(dashletSpec.getBoostDuration()));
    boostDurationField.setImmediate(true);
    boostDurationField.setCaption("Boost-Duration");
    boostDurationField.setDescription("Boost duration for this dashlet");

    boostDurationField.addValidator(new AbstractStringValidator("Only numbers allowed here") {
        @Override
        protected boolean isValidValue(String s) {
            try {
                Integer.parseInt(s);
            } catch (NumberFormatException numberFormatException) {
                return false;
            }
            return true;
        }
    });

    boostDurationField.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            if (boostDurationField.isValid()) {
                m_dashletSpec
                        .setBoostDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue()));
                WallboardProvider.getInstance().save();
                ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration");
            }
        }
    });

    boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName())
            .isBoostable();

    boostPriorityField.setEnabled(boostable);
    boostDurationField.setEnabled(boostable);

    /**
     * Setting up the dashlet selection
     */

    m_dashletSelect = new NativeSelect();

    m_dashletSelect.setCaption("Dashlet");

    updateDashletSelection(dashletSelector.getDashletFactoryList());

    m_dashletSelect.setImmediate(true);
    m_dashletSelect.setNewItemsAllowed(false);
    m_dashletSelect.setNullSelectionItemId("Undefined");
    m_dashletSelect.setNullSelectionAllowed(false);
    m_dashletSelect.select(dashletSpec.getDashletName());
    m_dashletSelect.setDescription("Dashlet selection");

    m_dashletSelect.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            if (m_savingDisabled) {
                return;
            }

            if (valueChangeEvent.getProperty().getValue() == null) {
                m_dashletSpec.setDashletName("Undefined");
            } else {
                m_dashletSpec.setDashletName(valueChangeEvent.getProperty().getValue().toString());
                m_dashletSelect.removeItem("Undefined");
            }

            m_dashletSpec.getParameters().clear();

            Map<String, String> requiredParameters = m_dashletSelector
                    .getDashletFactoryForName(m_dashletSpec.getDashletName()).getRequiredParameters();

            for (Map.Entry<String, String> entry : requiredParameters.entrySet()) {
                m_dashletSpec.getParameters().put(entry.getKey(), entry.getValue());
            }

            m_propertiesButton.setEnabled(requiredParameters.size() > 0);

            boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName())
                    .isBoostable();

            boostPriorityField.setEnabled(boostable);
            boostDurationField.setEnabled(boostable);

            WallboardProvider.getInstance().save();
            ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Dashlet");
        }
    });

    m_titleField = new TextField();
    m_titleField.setValue(dashletSpec.getTitle());
    m_titleField.setImmediate(true);
    m_titleField.setCaption("Title");
    m_titleField.setDescription("Title for this dashlet instance");

    m_titleField.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            m_dashletSpec.setTitle((String) valueChangeEvent.getProperty().getValue());
            WallboardProvider.getInstance().save();
            ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Title");
        }
    });

    FormLayout f1 = new FormLayout();
    f1.addComponent(m_dashletSelect);
    f1.addComponent(m_titleField);

    /**
     * Adding the required input fields and buttons to several {@link FormLayout} instances for better layout.
     */
    FormLayout f2 = new FormLayout();
    f2.addComponent(priorityField);
    f2.addComponent(durationField);

    FormLayout f3 = new FormLayout();
    f3.addComponent(boostPriorityField);
    f3.addComponent(boostDurationField);

    /**
     * Adding the properties button...
     */
    m_propertiesButton = new Button("Properties");

    m_propertiesButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            DashletConfigurationWindow configurationWindow = m_dashletSelector
                    .getDashletFactoryForName(m_dashletSpec.getDashletName())
                    .configurationWindow(m_dashletSpec);
            getUI().addWindow(configurationWindow);
        }
    });

    m_propertiesButton.setEnabled(m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName())
            .getRequiredParameters().size() > 0);

    m_propertiesButton.setStyleName("small");
    m_propertiesButton.setDescription("Open properties dialog for this dashlet");

    /**
     * ...and the remove button
     */
    Button removeButton = new Button("Remove");
    removeButton.setDescription("Remove this dashlet entry");

    FormLayout f4 = new FormLayout();
    f4.addComponent(m_propertiesButton);
    f4.addComponent(removeButton);

    removeButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent clickEvent) {
            m_wallboardEditor.removeDashletSpecEditor(DashletSpecEditor.this);
        }
    });

    removeButton.setStyleName("small");

    Button upButton = new Button();
    upButton.setStyleName("small");
    upButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png"));
    upButton.setDescription("Move this a dashlet entry one position up");

    Button downButton = new Button();
    downButton.setStyleName("small");
    downButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png"));
    downButton.setDescription("Move this a dashlet entry one position down");

    FormLayout f5 = new FormLayout();
    f5.addComponent(upButton);
    f5.addComponent(downButton);

    Button previewButton = new Button("Preview");
    previewButton.setStyleName("small");
    previewButton.setDescription("Preview this single dashlet entry");

    Wallboard wallboard = new Wallboard();
    wallboard.getDashletSpecs().add(m_dashletSpec);

    previewButton.addClickListener(new PreviewClickListener(this, wallboard));

    FormLayout f6 = new FormLayout();
    f6.addComponent(previewButton);

    upButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            m_wallboardEditor.swapDashletSpec(m_dashletSpec, -1);
        }
    });

    downButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            m_wallboardEditor.swapDashletSpec(m_dashletSpec, +1);
        }
    });

    /**
     * Adding the different {@link FormLayout} instances to a {@link GridLayout}
     */
    f1.setMargin(true);
    f2.setMargin(true);
    f3.setMargin(true);
    f4.setMargin(true);
    f5.setMargin(true);
    f6.setMargin(true);

    gridLayout.addComponent(f1);
    gridLayout.addComponent(f2);
    gridLayout.addComponent(f3);
    gridLayout.addComponent(f4);
    gridLayout.addComponent(f5);
    gridLayout.addComponent(f6);

    setContent(gridLayout);
}

From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardConfigView.java

License:Open Source License

/**
 * This method is used to add a new {@link TabSheet.Tab} component. It creates a new window querying the user for the name of the new {@link Wallboard}.
 *//*from   w  w  w  .j a  va2s  .  c o m*/
protected void addNewTabComponent() {
    final Window window = new Window("New Ops Board");

    window.setModal(true);
    window.setClosable(false);
    window.setResizable(false);
    window.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(Window.CloseEvent e) {
            m_dashboardOverview.refreshTable();
        }
    });
    getUI().addWindow(window);

    window.setContent(new VerticalLayout() {
        TextField name = new TextField("Ops Board Name");

        {
            addComponent(new FormLayout() {
                {
                    setSizeUndefined();
                    setMargin(true);

                    String newName = "Untitled";
                    int i = 1;
                    if (WallboardProvider.getInstance().containsWallboard(newName)) {
                        do {
                            i++;
                            newName = "Untitled #" + i;
                        } while (WallboardProvider.getInstance().containsWallboard(newName));
                    }
                    name.setValue(newName);
                    addComponent(name);
                    name.focus();
                    name.selectAll();

                    name.addValidator(new AbstractStringValidator("Title must be unique") {
                        @Override
                        protected boolean isValidValue(String s) {
                            return (!WallboardProvider.getInstance().containsWallboard(s) && !"".equals(s));
                        }
                    });
                }
            });

            addComponent(new HorizontalLayout() {
                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");

                    Button cancel = new Button("Cancel");
                    cancel.setDescription("Cancel editing");
                    cancel.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            // NMS-7560: Toggle the tab in order to allow us to click it again
                            m_tabSheet.togglePlusTab();
                            window.close();
                        }
                    });

                    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
                    addComponent(cancel);
                    setExpandRatio(cancel, 1);
                    setComponentAlignment(cancel, Alignment.TOP_RIGHT);

                    Button ok = new Button("Save");
                    ok.setDescription("Save configuration");
                    ok.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            if (name.isValid()) {
                                Wallboard wallboard = new Wallboard();
                                wallboard.setTitle(name.getValue());

                                WallboardProvider.getInstance().addWallboard(wallboard);
                                WallboardProvider.getInstance().save();

                                WallboardEditor wallboardEditor = new WallboardEditor(m_dashletSelector,
                                        wallboard);
                                TabSheet.Tab tab = m_tabSheet.addTab(wallboardEditor, wallboard.getTitle());

                                wallboardEditor.setTab(tab);

                                m_wallboardEditorMap.put(wallboard, tab);

                                tab.setClosable(true);

                                m_tabSheet.setSelectedTab(tab);

                                window.close();
                            }
                        }
                    });

                    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

                    addComponent(ok);
                }
            });
        }
    });
}