Example usage for com.vaadin.ui Alignment TOP_RIGHT

List of usage examples for com.vaadin.ui Alignment TOP_RIGHT

Introduction

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

Prototype

Alignment TOP_RIGHT

To view the source code for com.vaadin.ui Alignment TOP_RIGHT.

Click Source Link

Usage

From source file:org.opencms.ui.dataview.CmsPagingControls.java

License:Open Source License

/**
 * Creates a new instance.<p>//from  w w w  .  jav  a 2  s  .  co m
 */
public CmsPagingControls() {
    setMargin(true);
    addComponent(m_label);
    addComponent(m_fastBack);
    addComponent(m_back);
    addComponent(m_forward);
    addComponent(m_fastForward);
    addComponent(m_resultsLabel);
    m_resultsLabel.setWidthUndefined();
    m_label.setWidthUndefined();
    setExpandRatio(m_resultsLabel, 1.0f);
    setComponentAlignment(m_resultsLabel, Alignment.TOP_RIGHT);
    setSpacing(true);

    m_forward.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void buttonClick(ClickEvent event) {

            setPage(Math.min(m_lastPage, m_page + 1), true);
            updateButtons();
        }
    });

    m_fastForward.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void buttonClick(ClickEvent event) {

            setPage(m_lastPage, true);
            updateButtons();

        }
    });
    m_back.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void buttonClick(ClickEvent event) {

            setPage(Math.max(0, m_page - 1), true);
            updateButtons();

        }

    });

    m_fastBack.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            setPage(0, true);
            updateButtons();

        }
    });
}

From source file:org.opennms.features.pluginmgr.vaadin.config.karaf.PluginManagerAdminApplication.java

License:Apache License

@Override
public void init(VaadinRequest request) {

    m_request = request;/*from  w  w w.j  a  va 2s . c  om*/

    m_rootLayout = new VerticalLayout();
    m_rootLayout.setSizeFull();
    m_rootLayout.addStyleName("root-layout");
    setContent(m_rootLayout);

    // dynamically inject style for non write borders - avoids changing themes css
    // Get the stylesheet of the page
    Styles styles = Page.getCurrent().getStyles();
    // inject the new font size as a style. We need .v-app to override Vaadin's default styles here
    styles.add(".v-app .v-textfield-readonly {border: 1px solid #b6b6b6!important;"
            + " border-top-color: #9d9d9d!important;" + "border-bottom-color: #d6d6d6!important;"
            + "border-right-color: #d6d6d6!important;" + " opacity: 1.0!important;" + "filter: none;  }");
    styles.add(".v-app .v-textarea-readonly {border: 1px solid #b6b6b6!important;"
            + " border-top-color: #9d9d9d!important;" + "border-bottom-color: #d6d6d6!important;"
            + "border-right-color: #d6d6d6!important;" + " opacity: 1.0!important;" + "filter: none;  }");

    // add header if provided
    if (headerComponent != null)
        m_rootLayout.addComponent(headerComponent);

    //add additional header page links if provided
    if (headerLinks != null) {
        // defining 2 horizontal layouts to force links to stay together
        HorizontalLayout horizontalLayout1 = new HorizontalLayout();
        horizontalLayout1.setWidth("100%");
        horizontalLayout1.setDefaultComponentAlignment(Alignment.TOP_RIGHT);
        HorizontalLayout horizontalLayout2 = new HorizontalLayout();
        horizontalLayout1.addComponent(horizontalLayout2);

        for (String name : headerLinks.keySet()) {
            String urlStr = headerLinks.get(name);
            ExternalResource urlResource = new ExternalResource(urlStr);
            Link link = new Link(name, urlResource);
            Label label = new Label("&nbsp;&nbsp;&nbsp;", ContentMode.HTML); // adds space between links
            horizontalLayout2.addComponent(link);
            horizontalLayout2.addComponent(label);
        }
        m_rootLayout.addComponent(horizontalLayout1);
    }

    PluginManagerUIMainPanel pluginManagerUIMainPanel = new PluginManagerUIMainPanel(sessionPluginManager);

    m_rootLayout.addComponent(pluginManagerUIMainPanel);

    // this forces the UI panel to use up all the available space below the header
    m_rootLayout.setExpandRatio(pluginManagerUIMainPanel, 1.0f);

}

From source file:org.opennms.features.pluginmgr.vaadin.config.karaf.SimpleIframeApplication.java

License:Apache License

@Override
public void init(VaadinRequest request) {
    if (iframePageUrl == null)
        throw new RuntimeException("iframePageUrl must not be null");

    m_request = request;//w w w  .  ja v  a2 s. co m

    m_rootLayout = new VerticalLayout();

    m_rootLayout = new VerticalLayout();
    m_rootLayout.setSizeFull();
    m_rootLayout.addStyleName("root-layout");
    setContent(m_rootLayout);

    // add header if provided
    if (headerComponent != null)
        m_rootLayout.addComponent(headerComponent);

    //add additional header page links if provided
    if (headerLinks != null) {
        // defining 2 horizontal layouts to force links to stay together
        HorizontalLayout horizontalLayout1 = new HorizontalLayout();
        horizontalLayout1.setWidth("100%");
        horizontalLayout1.setDefaultComponentAlignment(Alignment.TOP_RIGHT);
        HorizontalLayout horizontalLayout2 = new HorizontalLayout();
        horizontalLayout1.addComponent(horizontalLayout2);

        for (String name : headerLinks.keySet()) {
            String urlStr = headerLinks.get(name);
            ExternalResource urlResource = new ExternalResource(urlStr);
            Link link = new Link(name, urlResource);
            Label label = new Label("&nbsp;&nbsp;&nbsp;", ContentMode.HTML); // adds space between links
            horizontalLayout2.addComponent(link);
            horizontalLayout2.addComponent(label);
        }
        m_rootLayout.addComponent(horizontalLayout1);
    }

    ExternalResource iframPageResource = new ExternalResource(iframePageUrl);

    BrowserFrame browser = new BrowserFrame("", iframPageResource);
    browser.setWidth("100%");
    browser.setHeight("100%");
    m_rootLayout.addComponent(browser);

    // this forces the UI panel to use up all the available space below the header
    m_rootLayout.setExpandRatio(browser, 1.0f);

}

From source file:org.opennms.features.pluginmgr.vaadin.config.opennms.PluginManagerAdminApplication.java

License:Open Source License

@Override
public void init(VaadinRequest request) {

    m_rootLayout = new VerticalLayout();
    m_rootLayout.setSizeFull();/*from  w  w w  .j a  v  a2s  .c  o m*/
    m_rootLayout.addStyleName("root-layout");
    setContent(m_rootLayout);

    // dynamically inject style for non write borders - avoids changing themes css
    // Get the stylesheet of the page
    Styles styles = Page.getCurrent().getStyles();
    // inject the new font size as a style. We need .v-app to override Vaadin's default styles here
    styles.add(".v-app .v-textfield-readonly {border: 1px solid #b6b6b6!important;"
            + " border-top-color: #9d9d9d!important;" + "border-bottom-color: #d6d6d6!important;"
            + "border-right-color: #d6d6d6!important;" + " opacity: 1.0!important;" + "filter: none;  }");
    styles.add(".v-app .v-textarea-readonly {border: 1px solid #b6b6b6!important;"
            + " border-top-color: #9d9d9d!important;" + "border-bottom-color: #d6d6d6!important;"
            + "border-right-color: #d6d6d6!important;" + " opacity: 1.0!important;" + "filter: none;  }");

    addHeader(request);

    //add diagnostic page links
    if (headerLinks != null) {
        // defining 2 horizontal layouts to force links to stay together
        HorizontalLayout horizontalLayout1 = new HorizontalLayout();
        horizontalLayout1.setWidth("100%");
        horizontalLayout1.setDefaultComponentAlignment(Alignment.TOP_RIGHT);
        HorizontalLayout horizontalLayout2 = new HorizontalLayout();
        horizontalLayout1.addComponent(horizontalLayout2);

        for (String name : headerLinks.keySet()) {
            String urlStr = headerLinks.get(name);
            ExternalResource urlResource = new ExternalResource(urlStr);
            Link link = new Link(name, urlResource);
            Label label = new Label("&nbsp;&nbsp;&nbsp;", ContentMode.HTML); // adds space between links
            horizontalLayout2.addComponent(link);
            horizontalLayout2.addComponent(label);
        }
        m_rootLayout.addComponent(horizontalLayout1);
    }

    PluginManagerUIMainPanel pluginManagerUIMainPanel = new PluginManagerUIMainPanel(sessionPluginManager);

    m_rootLayout.addComponent(pluginManagerUIMainPanel);

    // this forces the UI panel to use up all the available space below the header
    m_rootLayout.setExpandRatio(pluginManagerUIMainPanel, 1.0f);

}

From source file:org.opennms.features.pluginmgr.vaadin.config.opennms.SimpleIframeInVaadinApplication.java

License:Open Source License

@Override
public void init(VaadinRequest request) {
    if (iframePageUrl == null)
        throw new RuntimeException("iframePageUrl must not be null");

    m_rootLayout = new VerticalLayout();
    m_rootLayout.setSizeFull();/* ww w  .  j av  a  2  s  .  c  o  m*/
    m_rootLayout.addStyleName("root-layout");
    setContent(m_rootLayout);
    addHeader(request);

    //add diagnostic page links
    if (headerLinks != null) {
        // defining 2 horizontal layouts to force links to stay together
        HorizontalLayout horizontalLayout1 = new HorizontalLayout();
        horizontalLayout1.setWidth("100%");
        horizontalLayout1.setDefaultComponentAlignment(Alignment.TOP_RIGHT);
        HorizontalLayout horizontalLayout2 = new HorizontalLayout();
        horizontalLayout1.addComponent(horizontalLayout2);

        for (String name : headerLinks.keySet()) {
            String urlStr = headerLinks.get(name);
            ExternalResource urlResource = new ExternalResource(urlStr);
            Link link = new Link(name, urlResource);
            Label label = new Label("&nbsp;&nbsp;&nbsp;", ContentMode.HTML); // adds space between links
            horizontalLayout2.addComponent(link);
            horizontalLayout2.addComponent(label);
        }
        m_rootLayout.addComponent(horizontalLayout1);
    }

    ExternalResource iframPageResource = new ExternalResource(iframePageUrl);

    BrowserFrame browser = new BrowserFrame("", iframPageResource);
    browser.setWidth("100%");
    browser.setHeight("100%");
    m_rootLayout.addComponent(browser);

    // this forces the UI panel to use up all the available space below the header
    m_rootLayout.setExpandRatio(browser, 1.0f);

}

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.  j a  v a2 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}.
 *//*from www. ja  v a  2s  .c om*/
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);
                }
            });
        }
    });
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.AlarmConfigurationWindow.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 2s. co m
public AlarmConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    /**
     * Setting up the base layouts
     */
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setHeight(100, Unit.PERCENTAGE);
    verticalLayout.setSizeFull();
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);

    /**
     * Adding the selection box
     */
    m_boostedSeveritySelect = new NativeSelect();
    m_boostedSeveritySelect.setCaption("Boosted Severity");
    m_boostedSeveritySelect.setDescription("Select the boost severity");
    m_boostedSeveritySelect.setMultiSelect(false);
    m_boostedSeveritySelect.setNullSelectionAllowed(false);
    m_boostedSeveritySelect.setInvalidAllowed(false);
    m_boostedSeveritySelect.setNewItemsAllowed(false);

    for (OnmsSeverity onmsSeverity : OnmsSeverity.values()) {
        m_boostedSeveritySelect.addItem(onmsSeverity.name());
    }

    String boostSeverity = m_dashletSpec.getParameters().get("boostSeverity");

    if (boostSeverity == null || "".equals(boostSeverity)) {
        boostSeverity = OnmsSeverity.CLEARED.name();
    }

    m_boostedSeveritySelect.setValue(boostSeverity);

    verticalLayout.addComponent(m_boostedSeveritySelect);

    /**
     * Setting up the {@link CriteriaBuilderComponent} component
     */
    CriteriaBuilderHelper criteriaBuilderHelper = new CriteriaBuilderHelper(OnmsAlarm.class, OnmsNode.class,
            OnmsEvent.class, OnmsCategory.class);

    final CriteriaBuilderComponent criteriaBuilderComponent = new CriteriaBuilderComponent(
            criteriaBuilderHelper, m_dashletSpec.getParameters().get("criteria"));

    verticalLayout.addComponent(criteriaBuilderComponent);
    verticalLayout.setExpandRatio(criteriaBuilderComponent, 1.0f);

    /**
     * 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.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });
    cancel.setDescription("Cancel editing");
    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("criteria", criteriaBuilderComponent.getCriteria());
            m_dashletSpec.getParameters().put("boostSeverity",
                    String.valueOf(m_boostedSeveritySelect.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);

    setContent(verticalLayout);
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.BSMConfigurationWindow.java

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link DashletSpec} to be edited
 *//*w  w w. j av a  2 s. c  om*/
public BSMConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    /**
     * Setting up the base layouts
     */

    setHeight(91, Unit.PERCENTAGE);
    setWidth(60, Unit.PERCENTAGE);

    /**
     * Retrieve the config...
     */

    boolean filterByName = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterByName");
    String nameValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "nameValue", "");
    boolean filterByAttribute = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(),
            "filterByAttribute");
    String attributeKey = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeKey", "");
    String attributeValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeValue",
            "");
    boolean filterBySeverity = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(),
            "filterBySeverity");
    String severityValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "severityValue",
            Status.WARNING.name());
    String severityCompareOperator = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(),
            "severityCompareOperator",
            BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name());
    String orderBy = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderBy",
            BusinessServiceSearchCriteriaBuilder.Order.Name.name());
    String orderSequence = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderSequence",
            BusinessServiceSearchCriteriaBuilder.Sequence.Ascending.name());
    int resultsLimit = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "resultsLimit", 10);
    int columnCountBoard = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountBoard",
            10);
    int columnCountPanel = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountPanel",
            5);

    /**
     * Adding the "Filter By Name" panel
     */

    m_filterByNameCheckBox = new CheckBox();
    m_filterByNameCheckBox.setCaption("Enable");
    m_filterByNameCheckBox.setDescription("Filter by Business Service name");

    VerticalLayout nameLayout = new VerticalLayout();
    nameLayout.setSpacing(true);
    nameLayout.setMargin(true);
    nameLayout.setSizeFull();

    m_nameTextField = new TextField("Name (REGEXP)");
    m_nameTextField.setEnabled(false);

    addToComponent(nameLayout, m_filterByNameCheckBox);
    addToComponent(nameLayout, m_nameTextField);

    Panel namePanel = new Panel();
    namePanel.setCaption("Filter by Name");
    namePanel.setContent(nameLayout);

    m_filterByNameCheckBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            m_nameTextField.setEnabled(m_filterByNameCheckBox.getValue());
        }
    });

    m_nameTextField.setValue(nameValue);
    m_filterByNameCheckBox.setValue(filterByName);

    /**
     * Adding the "Filter By Attribute" panel
     */

    m_filterByAttributeCheckBox = new CheckBox();
    m_filterByAttributeCheckBox.setCaption("Enable");
    m_filterByAttributeCheckBox.setDescription("Filter by Business Service attribute");

    VerticalLayout attributeLayout = new VerticalLayout();
    attributeLayout.setSpacing(true);
    attributeLayout.setMargin(true);
    attributeLayout.setSizeFull();

    m_attributeKeyTextField = new TextField("Key");
    m_attributeKeyTextField.setEnabled(false);
    m_attributeValueTextField = new TextField("Value (REGEXP)");
    m_attributeValueTextField.setEnabled(false);
    addToComponent(attributeLayout, m_filterByAttributeCheckBox);
    addToComponent(attributeLayout, m_attributeKeyTextField);
    addToComponent(attributeLayout, m_attributeValueTextField);

    Panel attributePanel = new Panel();
    attributePanel.setCaption("Filter by Attribute");
    attributePanel.setContent(attributeLayout);

    m_filterByAttributeCheckBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            m_attributeKeyTextField.setEnabled(m_filterByAttributeCheckBox.getValue());
            m_attributeValueTextField.setEnabled(m_filterByAttributeCheckBox.getValue());
        }
    });

    m_attributeKeyTextField.setValue(attributeKey);
    m_attributeValueTextField.setValue(attributeValue);
    m_filterByAttributeCheckBox.setValue(filterByAttribute);

    /**
     * Adding the "Filter By Severity" panel
     */

    m_filterBySeverityCheckBox = new CheckBox();
    m_filterBySeverityCheckBox.setCaption("Enable");
    m_filterBySeverityCheckBox.setDescription("Filter by Business Service severity");

    VerticalLayout severityLayout = new VerticalLayout();
    severityLayout.setSpacing(true);
    severityLayout.setMargin(true);
    severityLayout.setSizeFull();

    m_severitySelect = new NativeSelect("Severity");
    m_severitySelect.setEnabled(false);
    m_severitySelect.setNullSelectionAllowed(false);
    m_severitySelect.setMultiSelect(false);

    for (Status eachStatus : Status.values()) {
        m_severitySelect.addItem(eachStatus.name());
    }

    m_compareOperatorSelect = new NativeSelect("Comparator");
    m_compareOperatorSelect.setEnabled(false);
    m_compareOperatorSelect.setNullSelectionAllowed(false);
    m_compareOperatorSelect.setMultiSelect(false);

    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Lower.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.LowerOrEqual.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Equal.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Greater.name());

    addToComponent(severityLayout, m_filterBySeverityCheckBox);
    addToComponent(severityLayout, m_severitySelect);
    addToComponent(severityLayout, m_compareOperatorSelect);

    Panel severityPanel = new Panel();
    severityPanel.setCaption("Filter by Severity");
    severityPanel.setContent(severityLayout);

    m_filterBySeverityCheckBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            m_severitySelect.setEnabled(m_filterBySeverityCheckBox.getValue());
            m_compareOperatorSelect.setEnabled(m_filterBySeverityCheckBox.getValue());
        }
    });

    m_severitySelect.setValue(severityValue);
    m_compareOperatorSelect.setValue(severityCompareOperator);
    m_filterBySeverityCheckBox.setValue(filterBySeverity);

    /**
     * Adding the "Results" panel
     */

    VerticalLayout limitLayout = new VerticalLayout();
    limitLayout.setSpacing(true);
    limitLayout.setMargin(true);
    limitLayout.setSizeFull();

    m_limitTextField = new TextField("Limit");

    m_orderBy = new NativeSelect("Order by");
    m_orderBy.setNullSelectionAllowed(false);
    m_orderBy.setMultiSelect(false);

    m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Name.name());
    m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Severity.name());
    m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Level.name());

    m_orderSequence = new NativeSelect("Asc/Desc ");
    m_orderSequence.setNullSelectionAllowed(false);
    m_orderSequence.setMultiSelect(false);

    m_orderSequence.addItem("Ascending");
    m_orderSequence.addItem("Descending");

    m_columnCountBoardTextField = new TextField("Ops Board Column Count");
    m_columnCountBoardTextField.addValidator(new AbstractStringValidator("Number greater zero expected") {
        @Override
        protected boolean isValidValue(String value) {
            try {
                int i = Integer.parseInt(value);
                return i > 0;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    m_columnCountPanelTextField = new TextField("Ops Panel Column Count");
    m_columnCountPanelTextField.addValidator(new AbstractStringValidator("Number greater zero expected") {
        @Override
        protected boolean isValidValue(String value) {
            try {
                int i = Integer.parseInt(value);
                return i > 0;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    addToComponent(limitLayout, m_limitTextField);
    addToComponent(limitLayout, m_orderBy);
    addToComponent(limitLayout, m_orderSequence);
    addToComponent(limitLayout, m_columnCountBoardTextField);
    addToComponent(limitLayout, m_columnCountPanelTextField);

    Panel limitPanel = new Panel();
    limitPanel.setSizeFull();
    limitPanel.setCaption("Results");
    limitPanel.setContent(limitLayout);

    m_limitTextField.setValue(String.valueOf(resultsLimit));
    m_orderBy.setValue(orderBy);
    m_orderSequence.setValue(orderSequence);
    m_columnCountBoardTextField.setValue(String.valueOf(columnCountBoard));
    m_columnCountPanelTextField.setValue(String.valueOf(columnCountPanel));

    m_limitTextField.addValidator(new AbstractStringValidator("Number greater or equal zero expected") {
        @Override
        protected boolean isValidValue(String value) {
            try {
                int i = Integer.parseInt(value);
                return i >= 0;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    /**
     * Create the main layout...
     */

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.setWidth(100, Unit.PERCENTAGE);
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);

    verticalLayout.addComponent(namePanel);
    verticalLayout.addComponent(attributePanel);

    HorizontalLayout bottomLayout = new HorizontalLayout(severityPanel, limitPanel);
    bottomLayout.setSpacing(true);
    bottomLayout.setSizeFull();
    bottomLayout.setWidth(100, Unit.PERCENTAGE);

    verticalLayout.addComponent(bottomLayout);

    /**
     * Using an additional {@link HorizontalLayout} for layouting the buttons
     */
    HorizontalLayout buttonLayout = new HorizontalLayout();

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");

    Label label = new Label("Note: Multiple enabled filter constraints will be combined by a logical AND.");
    buttonLayout.addComponent(label);
    buttonLayout.setExpandRatio(label, 1.0f);

    /**
     * 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.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (!m_limitTextField.isValid() || !m_columnCountPanelTextField.isValid()
                    || !m_columnCountBoardTextField.isValid()) {
                return;
            }

            m_dashletSpec.getParameters().put("filterByName",
                    (m_filterByNameCheckBox.getValue() ? "true" : "false"));

            if (m_filterByNameCheckBox.getValue()) {
                m_dashletSpec.getParameters().put("nameValue", m_nameTextField.getValue());
            } else {
                m_dashletSpec.getParameters().put("nameValue", "");
            }

            m_dashletSpec.getParameters().put("filterByAttribute",
                    (m_filterByAttributeCheckBox.getValue() ? "true" : "false"));

            if (m_filterByAttributeCheckBox.getValue()) {
                m_dashletSpec.getParameters().put("attributeKey", m_attributeKeyTextField.getValue());
                m_dashletSpec.getParameters().put("attributeValue", m_attributeValueTextField.getValue());
            } else {
                m_dashletSpec.getParameters().put("attributeKey", "");
                m_dashletSpec.getParameters().put("attributeValue", "");
            }

            m_dashletSpec.getParameters().put("filterBySeverity",
                    (m_filterBySeverityCheckBox.getValue() ? "true" : "false"));

            if (m_filterBySeverityCheckBox.getValue() && m_severitySelect.getValue() != null) {
                m_dashletSpec.getParameters().put("severityValue", m_severitySelect.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("severityValue", Status.WARNING.getLabel());
            }

            if (m_filterBySeverityCheckBox.getValue() && m_compareOperatorSelect.getValue() != null) {
                m_dashletSpec.getParameters().put("severityCompareOperator",
                        m_compareOperatorSelect.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("severityCompareOperator",
                        BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name());
            }

            if (m_orderBy.getValue() != null) {
                m_dashletSpec.getParameters().put("orderBy", m_orderBy.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("orderBy",
                        BusinessServiceSearchCriteriaBuilder.Order.Name.name());
            }

            if (m_orderSequence.getValue() != null) {
                m_dashletSpec.getParameters().put("orderSequence", m_orderSequence.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("orderSequence", "Ascending");
            }

            m_dashletSpec.getParameters().put("resultsLimit", m_limitTextField.getValue().toString());
            m_dashletSpec.getParameters().put("columnCountBoard",
                    m_columnCountBoardTextField.getValue().toString());
            m_dashletSpec.getParameters().put("columnCountPanel",
                    m_columnCountPanelTextField.getValue().toString());

            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);

    setContent(verticalLayout);
}

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