Example usage for com.vaadin.ui Button setDescription

List of usage examples for com.vaadin.ui Button setDescription

Introduction

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

Prototype

public void setDescription(String description) 

Source Link

Document

Sets the component's description.

Usage

From source file:org.opennms.features.topology.app.internal.TopologyWidgetTestApplication.java

License:Open Source License

@SuppressWarnings("serial")
@Override/*from   w  w  w.j  a  v a 2 s. c  o m*/
public void init() {
    setTheme("topo_default");

    m_rootLayout = new AbsoluteLayout();
    m_rootLayout.setSizeFull();

    m_window = new Window("OpenNMS Topology");
    m_window.setContent(m_rootLayout);
    setMainWindow(m_window);

    m_uriFragUtil = new UriFragmentUtility();
    m_window.addComponent(m_uriFragUtil);
    m_uriFragUtil.addListener(this);

    m_layout = new AbsoluteLayout();
    m_layout.setSizeFull();
    m_rootLayout.addComponent(m_layout);

    if (m_showHeader) {
        HEADER_HEIGHT = 100;
        Panel header = new Panel("header");
        header.setCaption(null);
        header.setSizeUndefined();
        header.addStyleName("onmsheader");
        m_rootLayout.addComponent(header, "top: 0px; left: 0px; right:0px;");

        try {
            CustomLayout customLayout = new CustomLayout(getHeaderLayout());
            header.setContent(customLayout);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        HEADER_HEIGHT = 0;
    }

    Refresher refresher = new Refresher();
    refresher.setRefreshInterval(5000);
    getMainWindow().addComponent(refresher);

    m_graphContainer.setLayoutAlgorithm(new FRLayoutAlgorithm());

    final Property scale = m_graphContainer.getScaleProperty();

    m_topologyComponent = new TopologyComponent(m_graphContainer, m_iconRepositoryManager, m_selectionManager,
            this);
    m_topologyComponent.setSizeFull();
    m_topologyComponent.addMenuItemStateListener(this);
    m_topologyComponent.addVertexUpdateListener(this);

    final Slider slider = new Slider(0, 1);

    slider.setPropertyDataSource(scale);
    slider.setResolution(1);
    slider.setHeight("300px");
    slider.setOrientation(Slider.ORIENTATION_VERTICAL);

    slider.setImmediate(true);

    final Button zoomInBtn = new Button();
    zoomInBtn.setIcon(new ThemeResource("images/plus.png"));
    zoomInBtn.setDescription("Expand Semantic Zoom Level");
    zoomInBtn.setStyleName("semantic-zoom-button");
    zoomInBtn.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            int szl = (Integer) m_graphContainer.getSemanticZoomLevel();
            szl++;
            m_graphContainer.setSemanticZoomLevel(szl);
            setSemanticZoomLevel(szl);
            saveHistory();
        }
    });

    Button zoomOutBtn = new Button();
    zoomOutBtn.setIcon(new ThemeResource("images/minus.png"));
    zoomOutBtn.setDescription("Collapse Semantic Zoom Level");
    zoomOutBtn.setStyleName("semantic-zoom-button");
    zoomOutBtn.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            int szl = (Integer) m_graphContainer.getSemanticZoomLevel();
            if (szl > 0) {
                szl--;
                m_graphContainer.setSemanticZoomLevel(szl);
                setSemanticZoomLevel(szl);
                saveHistory();
            }

        }
    });

    final Button panBtn = new Button();
    panBtn.setIcon(new ThemeResource("images/cursor_drag_arrow.png"));
    panBtn.setDescription("Pan Tool");
    panBtn.setStyleName("toolbar-button down");

    final Button selectBtn = new Button();
    selectBtn.setIcon(new ThemeResource("images/selection.png"));
    selectBtn.setDescription("Selection Tool");
    selectBtn.setStyleName("toolbar-button");
    selectBtn.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            selectBtn.setStyleName("toolbar-button down");
            panBtn.setStyleName("toolbar-button");
            m_topologyComponent.setActiveTool("select");
        }
    });

    panBtn.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            panBtn.setStyleName("toolbar-button down");
            selectBtn.setStyleName("toolbar-button");
            m_topologyComponent.setActiveTool("pan");
        }
    });

    VerticalLayout toolbar = new VerticalLayout();
    toolbar.setWidth("31px");
    toolbar.addComponent(panBtn);
    toolbar.addComponent(selectBtn);

    HorizontalLayout semanticLayout = new HorizontalLayout();
    semanticLayout.addComponent(zoomInBtn);
    semanticLayout.addComponent(m_zoomLevelLabel);
    semanticLayout.addComponent(zoomOutBtn);
    semanticLayout.setComponentAlignment(m_zoomLevelLabel, Alignment.MIDDLE_CENTER);

    AbsoluteLayout mapLayout = new AbsoluteLayout();

    mapLayout.addComponent(m_topologyComponent, "top:0px; left: 0px; right: 0px; bottom: 0px;");
    mapLayout.addComponent(slider, "top: 5px; left: 20px; z-index:1000;");
    mapLayout.addComponent(toolbar, "top: 324px; left: 12px;");
    mapLayout.addComponent(semanticLayout, "top: 380px; left: 2px;");
    mapLayout.setSizeFull();

    m_treeMapSplitPanel = new HorizontalSplitPanel();
    m_treeMapSplitPanel.setFirstComponent(createWestLayout());
    m_treeMapSplitPanel.setSecondComponent(mapLayout);
    m_treeMapSplitPanel.setSplitPosition(222, Sizeable.UNITS_PIXELS);
    m_treeMapSplitPanel.setSizeFull();

    m_commandManager.addCommandUpdateListener(this);

    menuBarUpdated(m_commandManager);
    if (m_widgetManager.widgetCount() != 0) {
        updateWidgetView(m_widgetManager);
    } else {
        m_layout.addComponent(m_treeMapSplitPanel, getBelowMenuPosition());
    }

    if (m_treeWidgetManager.widgetCount() != 0) {
        updateAccordionView(m_treeWidgetManager);
    }
}

From source file:org.opennms.features.topology.app.internal.ui.breadcrumbs.BreadcrumbComponent.java

License:Open Source License

private static Button createButton(GraphContainer container, Breadcrumb breadcrumb) {
    final Button button = new Button();
    final String layerName = getLayerName(container, breadcrumb.getTargetNamespace());
    if (breadcrumb.getSourceVertices().isEmpty()) {
        button.setCaption(layerName);/*from   w  ww .  j  a  v a 2s .  co  m*/
    } else {
        String sourceLayerName = getLayerName(container, breadcrumb.getSourceVertices().get(0).getNamespace());
        if (breadcrumb.getSourceVertices().size() > 2) {
            button.setCaption("Multiple " + layerName);
            button.setDescription(String.format("Multiple vertices from %s", sourceLayerName));
        } else {
            button.setCaption(breadcrumb.getSourceVertices().stream().map(b -> b.getLabel())
                    .collect(Collectors.joining(", ")));
            button.setDescription(String.format("%s from %s", button.getCaption(), sourceLayerName));
        }
    }
    button.addStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener((event) -> breadcrumb.clicked(container));
    return button;
}

From source file:org.opennms.features.topology.app.internal.ui.ToolbarPanel.java

License:Open Source License

public ToolbarPanel(final ToolbarPanelController controller) {
    addStyleName(Styles.TOOLBAR);/*  w w w .ja va  2 s. c om*/
    this.layoutManager = controller.getLayoutManager();

    final Property<Double> scale = controller.getScaleProperty();
    final Boolean[] eyeClosed = new Boolean[] { false };
    final Button showFocusVerticesBtn = new Button();
    showFocusVerticesBtn.setIcon(FontAwesome.EYE);
    showFocusVerticesBtn.setDescription("Toggle Highlight Focus Nodes");
    showFocusVerticesBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (eyeClosed[0]) {
                showFocusVerticesBtn.setIcon(FontAwesome.EYE);
            } else {
                showFocusVerticesBtn.setIcon(FontAwesome.EYE_SLASH);
            }
            eyeClosed[0] = !eyeClosed[0]; // toggle
            controller.toggleHighlightFocus();
        }
    });

    final Button magnifyBtn = new Button();
    magnifyBtn.setIcon(FontAwesome.PLUS);
    magnifyBtn.setDescription("Magnify");
    magnifyBtn.addClickListener(
            (Button.ClickListener) event -> scale.setValue(Math.min(1, scale.getValue() + 0.25)));

    final Button demagnifyBtn = new Button();
    demagnifyBtn.setIcon(FontAwesome.MINUS);
    demagnifyBtn.setDescription("Demagnify");
    demagnifyBtn.addClickListener(
            (Button.ClickListener) event -> scale.setValue(Math.max(0, scale.getValue() - 0.25)));

    m_szlOutBtn = new Button();
    m_szlOutBtn.setId("szlOutBtn");
    m_szlOutBtn.setIcon(FontAwesome.ANGLE_DOWN);
    m_szlOutBtn.setDescription("Decrease Semantic Zoom Level");
    m_szlOutBtn.setEnabled(controller.getSemanticZoomLevel() > 0);
    m_szlOutBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            int szl = controller.getSemanticZoomLevel();
            if (szl > 0) {
                setSemanticZoomLevel(controller, szl - 1);
                controller.saveHistory();
            }
        }
    });

    final Button szlInBtn = new Button();
    szlInBtn.setId("szlInBtn");
    szlInBtn.setIcon(FontAwesome.ANGLE_UP);
    szlInBtn.setDescription("Increase Semantic Zoom Level");
    szlInBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            setSemanticZoomLevel(controller, controller.getSemanticZoomLevel() + 1);
            controller.saveHistory();
        }
    });

    m_zoomLevelLabel.setId("szlInputLabel");

    m_panBtn = new Button();
    m_panBtn.setIcon(FontAwesome.ARROWS);
    m_panBtn.setDescription("Pan Tool");
    m_panBtn.addStyleName(Styles.SELECTED);

    m_selectBtn = new Button();
    m_selectBtn.setIcon(IonicIcons.ANDROID_EXPAND);
    m_selectBtn.setDescription("Selection Tool");
    m_selectBtn.setStyleName("toolbar-button");
    m_selectBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_selectBtn.addStyleName(Styles.SELECTED);
            m_panBtn.removeStyleName(Styles.SELECTED);
            controller.setActiveTool(ActiveTool.select);
        }
    });

    m_panBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_panBtn.addStyleName(Styles.SELECTED);
            m_selectBtn.removeStyleName(Styles.SELECTED);
            controller.setActiveTool(ActiveTool.pan);
        }
    });

    Button showAllMapBtn = new Button();
    showAllMapBtn.setId("showEntireMapBtn");
    showAllMapBtn.setIcon(FontAwesome.GLOBE);
    showAllMapBtn.setDescription("Show Entire Map");
    showAllMapBtn.addClickListener((Button.ClickListener) event -> controller.showAllMap());

    Button centerSelectionBtn = new Button();
    centerSelectionBtn.setIcon(FontAwesome.LOCATION_ARROW);
    centerSelectionBtn.setDescription("Center On Selection");
    centerSelectionBtn.addClickListener((Button.ClickListener) event -> controller.centerMapOnSelection());

    Button shareButton = new Button("", FontAwesome.SHARE_SQUARE_O);
    shareButton.setDescription("Share");
    shareButton.addClickListener((x) -> {
        // Create the share link
        String fragment = getUI().getPage().getLocation().getFragment();
        String url = getUI().getPage().getLocation().toString().replace("#" + fragment, "");
        String shareLink = String.format("%s?%s=%s", url, PARAMETER_HISTORY_FRAGMENT, fragment);

        // Create the Window
        Window shareWindow = new Window();
        shareWindow.setCaption("Share Link");
        shareWindow.setModal(true);
        shareWindow.setClosable(true);
        shareWindow.setResizable(false);
        shareWindow.setWidth(400, Sizeable.Unit.PIXELS);

        TextArea shareLinkField = new TextArea();
        shareLinkField.setValue(shareLink);
        shareLinkField.setReadOnly(true);
        shareLinkField.setRows(3);
        shareLinkField.setWidth(100, Sizeable.Unit.PERCENTAGE);

        // Close Button
        Button close = new Button("Close");
        close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
        close.addClickListener(event -> shareWindow.close());

        // Layout for Buttons
        HorizontalLayout buttonLayout = new HorizontalLayout();
        buttonLayout.setMargin(true);
        buttonLayout.setSpacing(true);
        buttonLayout.setWidth("100%");
        buttonLayout.addComponent(close);
        buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT);

        // Content Layout
        VerticalLayout verticalLayout = new VerticalLayout();
        verticalLayout.setMargin(true);
        verticalLayout.setSpacing(true);
        verticalLayout.addComponent(
                new Label("Please use the following link to share the current view with others."));
        verticalLayout.addComponent(shareLinkField);
        verticalLayout.addComponent(buttonLayout);

        shareWindow.setContent(verticalLayout);

        getUI().addWindow(shareWindow);
    });

    // Refresh Button
    Button refreshButton = new Button();
    refreshButton.setId("refreshNow");
    refreshButton.setIcon(FontAwesome.REFRESH);
    refreshButton.setDescription("Refresh Now");
    refreshButton.addClickListener((event) -> controller.refreshUI());

    // Layer Layout
    layerLayout = new VerticalLayout();
    layerLayout.setId("layerComponent");
    layerLayout.setSpacing(true);
    layerLayout.setMargin(true);

    // Layer Button
    layerButton = new Button();
    layerButton.setId("layerToggleButton");
    layerButton.setIcon(FontAwesome.BARS);
    layerButton.setDescription("Layers");
    layerButton.addClickListener((event) -> {
        boolean isCollapsed = layerButton.getStyleName().contains(Styles.EXPANDED);
        setLayerLayoutVisible(!isCollapsed);
    });

    // Save button
    layerSaveButton = new Button();
    layerSaveButton.setId("saveLayerButton");
    layerSaveButton.setIcon(FontAwesome.FLOPPY_O);
    layerSaveButton.addClickListener((event) -> controller.saveLayout());

    // Actual Layout for the Toolbar
    CssLayout contentLayout = new CssLayout();
    contentLayout.addStyleName("toolbar-component");
    contentLayout.addComponent(createGroup(szlInBtn, m_zoomLevelLabel, m_szlOutBtn));
    contentLayout.addComponent(
            createGroup(refreshButton, centerSelectionBtn, showAllMapBtn, layerButton, showFocusVerticesBtn));
    contentLayout.addComponent(createGroup(m_panBtn, m_selectBtn));
    contentLayout.addComponent(createGroup(magnifyBtn, demagnifyBtn));
    contentLayout.addComponent(createGroup(shareButton));
    contentLayout.addComponent(createGroup(layerSaveButton));

    // Toolbar
    addComponent(contentLayout);
}

From source file:org.opennms.features.topology.plugins.browsers.NodeSelectionLinkGenerator.java

License:Open Source License

@Override
public Object generateCell(final Table source, final Object itemId, Object columnId) {
    final Property<Integer> nodeIdProperty = source.getContainerProperty(itemId, m_nodeIdProperty);
    Object cellValue = m_generator.generateCell(source, itemId, columnId);
    if (cellValue == null) {
        return null;
    } else {//from  w w  w.j  av  a 2  s. c o m
        if (nodeIdProperty.getValue() == null) {
            return cellValue;
        } else {
            Button button = new Button(cellValue.toString());
            button.setStyleName(BaseTheme.BUTTON_LINK);
            button.setDescription(nodeIdProperty.getValue().toString());
            button.addClickListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Integer nodeId = nodeIdProperty.getValue();
                    String nodeLabel = (String) source.getContainerProperty(itemId, m_nodeLabelProperty)
                            .getValue();
                    VertexRef vertexRef = new DefaultVertexRef("nodes", String.valueOf(nodeId), nodeLabel);
                    fireVertexUpdatedEvent(vertexRef);
                }
            });
            return button;
        }
    }
}

From source file:org.opennms.features.topology.plugins.topo.application.browsers.ApplicationSelectionLinkGenerator.java

License:Open Source License

@Override
public Object generateCell(final Table source, final Object itemId, Object columnId) {
    final Property<Integer> idProperty = source.getContainerProperty(itemId, idPropertyName);
    final Property<String> labelProperty = source.getContainerProperty(itemId, labelPropertyName);

    Object cellValue = columnGenerator.generateCell(source, itemId, columnId);
    if (cellValue == null) {
        return null;
    } else {/*from w  ww . j av  a  2 s.com*/
        if (idProperty.getValue() == null) {
            return cellValue;
        } else {
            Button button = new Button(cellValue.toString());
            button.setStyleName(BaseTheme.BUTTON_LINK);
            button.setDescription(idProperty.getValue().toString());
            button.addClickListener(new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    Integer applicationId = idProperty.getValue();
                    String applicationName = labelProperty.getValue();
                    ApplicationVertex vertex = new ApplicationVertex(applicationId.toString(), applicationName);
                    fireVertexUpdatedEvent(vertex);
                }
            });
            return button;
        }
    }
}

From source file:org.opennms.features.topology.plugins.topo.bsm.browsers.BusinessServicesSelectionLinkGenerator.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public Object generateCell(final Table source, final Object itemId, Object columnId) {
    final Property<Long> idProperty = source.getContainerProperty(itemId, m_idPropertyName);
    final Property<String> labelProperty = source.getContainerProperty(itemId, m_labelPropertyName);

    final Object cellValue = m_columnGenerator.generateCell(source, itemId, columnId);
    if (cellValue == null) {
        return null;
    } else {/*  w  w w  .ja v a2 s  . c  om*/
        if (idProperty.getValue() == null) {
            return cellValue;
        } else {
            Button button = new Button(cellValue.toString());
            button.setStyleName(BaseTheme.BUTTON_LINK);
            button.setDescription(idProperty.getValue().toString());
            button.addClickListener(new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    Long businessServiceId = idProperty.getValue();
                    String businessServiceLabel = labelProperty.getValue();
                    BusinessServiceVertex vertex = new BusinessServiceVertex(businessServiceId,
                            businessServiceLabel, 0 /* does not matter in this case*/);
                    fireVertexUpdatedEvent(vertex);
                }
            });
            return button;
        }
    }
}

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  a  v  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.editors.CriteriaBuilderComponent.java

License:Open Source License

/**
 * This method updates the criteria components.
 *//* w w w  .j a va 2 s  . c o m*/
private void renderComponents() {
    m_criteriaLayout.removeAllComponents();

    boolean isFirst = true;
    boolean isLast;

    for (int i = 0; i < m_criteriaRestrictionComponents.size(); i++) {
        final CriteriaRestrictionComponent criteriaRestrictionComponent = m_criteriaRestrictionComponents
                .get(i);
        final int index = i;

        isLast = (i == m_criteriaRestrictionComponents.size() - 1);

        criteriaRestrictionComponent.getRightLayout().removeAllComponents();

        Button plusButton = new Button();
        plusButton.setStyleName("small");
        plusButton.setIcon(new ThemeResource("../runo/icons/16/document-add.png"));
        plusButton.setDescription("Add a new criteria entry");

        Button minusButton = new Button();
        minusButton.setStyleName("small");
        minusButton.setIcon(new ThemeResource("../runo/icons/16/document-delete.png"));
        minusButton.setDescription("Remove this criteria entry");

        Button upButton = new Button();
        upButton.setStyleName("small");
        upButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png"));
        upButton.setDescription("Move this a criteria 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 criteria entry one position down");

        criteriaRestrictionComponent.getRightLayout().addComponent(upButton);
        criteriaRestrictionComponent.getRightLayout().addComponent(downButton);
        criteriaRestrictionComponent.getRightLayout().addComponent(plusButton);
        criteriaRestrictionComponent.getRightLayout().addComponent(minusButton);

        if (m_criteriaRestrictionComponents.size() == 1) {
            minusButton.setEnabled(false);
            upButton.setEnabled(false);
            downButton.setEnabled(false);
        } else {
            if (isFirst) {
                upButton.setEnabled(false);
            }

            if (isLast) {
                downButton.setEnabled(false);
            }
        }

        upButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent clickEvent) {
                Collections.swap(m_criteriaRestrictionComponents, index, index - 1);
                renderComponents();
            }
        });

        downButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent clickEvent) {
                Collections.swap(m_criteriaRestrictionComponents, index, index + 1);
                renderComponents();
            }
        });

        minusButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent clickEvent) {
                m_criteriaRestrictionComponents.remove(criteriaRestrictionComponent);
                renderComponents();
            }
        });

        plusButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent clickEvent) {
                m_criteriaRestrictionComponents.add(index + 1,
                        new CriteriaRestrictionComponent(m_criteriaBuilderHelper, "Limit(10)"));
                renderComponents();
            }
        });

        isFirst = false;

        m_criteriaLayout.addComponent(criteriaRestrictionComponent);
    }
}

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

License:Open Source License

/**
 * Constructor for instantiating a {@link PropertiesWindow} for a given {@link DashletSpec}.
 *
 * @param dashletSpec    the {@link DashletSpec} to edit
 * @param dashletFactory the {@link DashletFactory} for querying the property data
 *//* w w w.  ja v a  2 s .c o m*/
public PropertiesWindow(final DashletSpec dashletSpec, final DashletFactory dashletFactory) {
    /**
     * Using a vertical layout for content
     */
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setMargin(true);
    //verticalLayout.addStyleName("debug");
    verticalLayout.setSizeFull();
    verticalLayout.setHeight(100, Unit.PERCENTAGE);

    /**
     * Setting up the table object for displaying the parameters
     */
    final Table table = new Table();

    table.setTableFieldFactory(new DefaultFieldFactory() {
        @Override
        public Field<?> createField(Container container, Object itemId, Object propertyId,
                Component uiContext) {
            Field<?> field = super.createField(container, itemId, propertyId, uiContext);
            if (propertyId.equals("Key")) {
                field.setReadOnly(true);
            } else {
                field.setSizeFull();
            }
            return field;
        }
    });

    table.setEditable(true);
    table.setSizeFull();
    table.setImmediate(true);

    table.addContainerProperty("Key", String.class, "");
    table.addContainerProperty("Value", String.class, "");

    /**
     * Filling the date with parameter data
     */
    final Map<String, String> requiredParameters = dashletFactory.getRequiredParameters();

    for (Map.Entry<String, String> entry : requiredParameters.entrySet()) {
        table.addItem(new Object[] { entry.getKey(), dashletSpec.getParameters().get(entry.getKey()) },
                entry.getKey());
    }

    table.setColumnWidth("Key", 100);
    table.setColumnWidth("Value", -1);
    table.setSizeFull();
    verticalLayout.addComponent(table);

    /**
     * Using an additional {@link 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) {
            for (Map.Entry<String, String> entry : requiredParameters.entrySet()) {
                String newValue = table.getItem(entry.getKey()).getItemProperty("Value").getValue().toString();
                dashletSpec.getParameters().put(entry.getKey(), newValue);
            }

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

            close();
        }
    });

    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    horizontalLayout.addComponent(ok);
    //horizontalLayout.addStyleName("debug");

    /**
     * Adding the layout and setting the content
     */
    verticalLayout.addComponent(horizontalLayout);

    verticalLayout.setExpandRatio(table, 1.0f);

    setContent(verticalLayout);
}

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}.
 *///  w  w w .j  a  v  a  2  s . 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);
                }
            });
        }
    });
}