Example usage for com.vaadin.ui NativeSelect NativeSelect

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

Introduction

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

Prototype

public NativeSelect() 

Source Link

Document

Creates a new NativeSelect with an empty caption and no items.

Usage

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  w  w .j av  a  2 s . com
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.ChartsConfigurationWindow.java

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link DashletSpec} to be edited
 *///from w  w  w .ja v  a  2 s. c  o m
public ChartsConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    /**
     * Setting up the base layouts
     */

    setHeight(410, Unit.PIXELS);
    setWidth(40, Unit.PERCENTAGE);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setMargin(true);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(100, Unit.PERCENTAGE);
    formLayout.setSpacing(true);
    formLayout.setMargin(true);

    /**
     * Adding the checkboxes
     */
    m_maximizeWidth = new CheckBox();
    m_maximizeWidth.setCaption("Maximize width");
    m_maximizeWidth.setDescription("Maximize width");

    m_maximizeHeight = new CheckBox();
    m_maximizeHeight.setCaption("Maximize height");
    m_maximizeHeight.setDescription("Maximize height");

    String maximizeWidthString = m_dashletSpec.getParameters().get("maximizeWidth");
    String maximizeHeightString = m_dashletSpec.getParameters().get("maximizeHeight");

    boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString)
            || "1".equals(maximizeHeightString));
    boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString)
            || "1".equals(maximizeWidthString));

    m_maximizeWidth.setValue(maximizeWidth);
    m_maximizeHeight.setValue(maximizeHeight);

    m_chartSelect = new NativeSelect();
    m_chartSelect.setDescription("Select chart to be displayed");
    m_chartSelect.setCaption("Chart");
    m_chartSelect.setNullSelectionAllowed(false);
    m_chartSelect.setInvalidAllowed(false);
    m_chartSelect.setNewItemsAllowed(false);

    String firstChartName = null;

    try {
        Iterator<BarChart> it = ChartUtils.getChartCollectionIterator();

        while (it.hasNext()) {
            BarChart chartConfig = (BarChart) it.next();

            if (firstChartName == null) {
                firstChartName = chartConfig.getName();
            }

            m_chartSelect.addItem(chartConfig.getName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    String chartName = m_dashletSpec.getParameters().get("chart");

    if (chartName == null || "".equals(chartName)) {
        chartName = firstChartName;
    }

    final Panel panel = new Panel();

    panel.setWidth(230, Unit.PIXELS);

    panel.setCaption("Preview");

    formLayout.addComponent(m_chartSelect);

    Page.getCurrent().getStyles().add(".preview { width:225px; }");

    m_chartSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String newImage = "/opennms/charts?chart-name=" + valueChangeEvent.getProperty().getValue();
            Image image = new Image(null, new ExternalResource(newImage));
            image.setStyleName("preview");
            panel.setContent(image);
        }
    });

    m_chartSelect.setValue(chartName);
    m_chartSelect.setImmediate(true);

    formLayout.addComponent(m_maximizeWidth);
    formLayout.addComponent(m_maximizeHeight);

    horizontalLayout.addComponent(formLayout);
    horizontalLayout.addComponent(panel);

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

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

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

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_dashletSpec.getParameters().put("maximizeWidth", (m_maximizeWidth.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("maximizeHeight",
                    (m_maximizeHeight.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("chart", String.valueOf(m_chartSelect.getValue()));

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

            close();
        }
    });

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

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

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

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

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link org.opennms.features.vaadin.dashboard.model.DashletSpec} to be edited
 *///from  ww w.  ja v  a 2 s.c om
public KscDashletConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    setHeight(210, Unit.PIXELS);
    setWidth(40, Unit.PERCENTAGE);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setMargin(true);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(100, Unit.PERCENTAGE);
    formLayout.setSpacing(true);
    formLayout.setMargin(true);

    m_kscSelect = new NativeSelect();
    m_kscSelect.setDescription("Select KSC-report to be displayed");
    m_kscSelect.setCaption("KSC-Report");
    m_kscSelect.setImmediate(true);
    m_kscSelect.setNewItemsAllowed(false);
    m_kscSelect.setMultiSelect(false);
    m_kscSelect.setInvalidAllowed(false);
    m_kscSelect.setNullSelectionAllowed(false);
    m_kscSelect.setImmediate(true);

    final KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory.getInstance();

    Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList();

    for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) {
        m_kscSelect.addItem(entry.getKey());
        m_kscSelect.setItemCaption(entry.getKey(), entry.getValue());
        if (m_kscSelect.getValue() == null) {
            m_kscSelect.setValue(entry.getKey());
        }
    }

    String chartName = m_dashletSpec.getParameters().get("kscReport");

    if (chartName != null) {
        if (reportsMap.values().contains(chartName)) {
            m_kscSelect.setValue(chartName);
        }
    }

    formLayout.addComponent(m_kscSelect);

    m_kscSelect.setValue(chartName);
    m_kscSelect.setImmediate(true);

    horizontalLayout.addComponent(formLayout);

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

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

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

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList();

            m_dashletSpec.getParameters().put("kscReport", reportsMap.get(m_kscSelect.getValue()));

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

            close();
        }
    });

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

    if (reportsMap.size() == 0) {
        m_kscSelect.setEnabled(false);
        ok.setEnabled(false);
    }

    /**
     * Adding the layout and setting the content
     */

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

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

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link DashletSpec} to be edited
 *///  www.j  a  v a2  s. co  m
public RrdDashletConfigurationWindow(DashletSpec dashletSpec, RrdGraphHelper rrdGraphHelper, NodeDao nodeDao) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;
    m_nodeDao = nodeDao;
    m_rrdGraphHelper = rrdGraphHelper;

    /**
     * creating the grid layout
     */
    m_gridLayout = new GridLayout();
    m_gridLayout.setSizeFull();
    m_gridLayout.setColumns(1);
    m_gridLayout.setRows(1);

    /**
     * setting up the layouts
     */
    FormLayout leftFormLayout = new FormLayout();
    FormLayout middleFormLayout = new FormLayout();
    FormLayout rightFormLayout = new FormLayout();

    /**
     * creating the columns and rows selection fields
     */
    m_columnsSelect = new NativeSelect();
    m_columnsSelect.setCaption("Columns");
    m_columnsSelect.setDescription("Number of columns");
    m_columnsSelect.setImmediate(true);
    m_columnsSelect.setNewItemsAllowed(false);
    m_columnsSelect.setMultiSelect(false);
    m_columnsSelect.setInvalidAllowed(false);
    m_columnsSelect.setNullSelectionAllowed(false);

    m_rowsSelect = new NativeSelect();
    m_rowsSelect.setCaption("Rows");
    m_rowsSelect.setDescription("Number of rows");
    m_rowsSelect.setImmediate(true);
    m_rowsSelect.setNewItemsAllowed(false);
    m_rowsSelect.setMultiSelect(false);
    m_rowsSelect.setInvalidAllowed(false);
    m_rowsSelect.setNullSelectionAllowed(false);

    for (int i = 1; i < 5; i++) {
        m_columnsSelect.addItem(i);
        m_rowsSelect.addItem(i);
    }

    /**
     * setting the values/defaults
     */
    int columns;
    int rows;

    try {
        columns = Integer.parseInt(m_dashletSpec.getParameters().get("columns"));
    } catch (NumberFormatException numberFormatException) {
        columns = 1;
    }

    try {
        rows = Integer.parseInt(m_dashletSpec.getParameters().get("rows"));
    } catch (NumberFormatException numberFormatException) {
        rows = 1;
    }

    m_columnsSelect.setValue(columns);
    m_rowsSelect.setValue(rows);

    /**
     * width and height fields
     */
    m_widthField = new TextField();
    m_widthField.setCaption("Graph Width");
    m_widthField.setDescription("Width of graphs");
    m_widthField.setValue(m_dashletSpec.getParameters().get("width"));

    m_heightField = new TextField();
    m_heightField.setCaption("Graph Height");
    m_heightField.setDescription("Height of graphs");
    m_heightField.setValue(m_dashletSpec.getParameters().get("height"));

    m_timeFrameValue = new TextField("Timeframe value");
    m_timeFrameValue.setDescription("Timeframe value");
    m_timeFrameValue.setValue(m_dashletSpec.getParameters().get("timeFrameValue"));

    m_timeFrameType = new NativeSelect("Timeframe type");
    m_timeFrameType.setDescription("Timeframe type");
    m_timeFrameType.setNullSelectionAllowed(false);
    m_timeFrameType.setMultiSelect(false);
    m_timeFrameType.setNewItemsAllowed(false);

    m_timeFrameType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.EXPLICIT);
    m_timeFrameType.addItem(String.valueOf(Calendar.MINUTE));
    m_timeFrameType.setItemCaption(String.valueOf(Calendar.MINUTE), "Minute");

    m_timeFrameType.addItem(String.valueOf(Calendar.HOUR_OF_DAY));
    m_timeFrameType.setItemCaption(String.valueOf(Calendar.HOUR_OF_DAY), "Hour");

    m_timeFrameType.addItem(String.valueOf(Calendar.DAY_OF_YEAR));
    m_timeFrameType.setItemCaption(String.valueOf(Calendar.DAY_OF_YEAR), "Day");

    m_timeFrameType.addItem(String.valueOf(Calendar.WEEK_OF_YEAR));
    m_timeFrameType.setItemCaption(String.valueOf(Calendar.WEEK_OF_YEAR), "Week");

    m_timeFrameType.addItem(String.valueOf(Calendar.MONTH));
    m_timeFrameType.setItemCaption(String.valueOf(Calendar.MONTH), "Month");

    m_timeFrameType.addItem(String.valueOf(Calendar.YEAR));
    m_timeFrameType.setItemCaption(String.valueOf(Calendar.YEAR), "Year");

    m_timeFrameType.setValue(m_dashletSpec.getParameters().get("timeFrameType"));

    m_timeFrameType.setImmediate(true);
    m_timeFrameValue.setImmediate(true);

    m_timeFrameType.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            updatePreview();
        }
    });

    m_timeFrameValue.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            updatePreview();
        }
    });

    /**
     * initial creation of the grid
     */
    recreateCells(columns, rows);

    /**
     * creating the value listeners for columns/rows
     */
    m_columnsSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            recreateCells(Integer.valueOf(valueChangeEvent.getProperty().getValue().toString()),
                    m_gridLayout.getRows());
        }
    });

    m_rowsSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            recreateCells(m_gridLayout.getColumns(),
                    Integer.valueOf(valueChangeEvent.getProperty().getValue().toString()));
        }
    });

    leftFormLayout.addComponent(m_columnsSelect);
    leftFormLayout.addComponent(m_widthField);
    leftFormLayout.addComponent(m_timeFrameValue);
    middleFormLayout.addComponent(m_rowsSelect);
    middleFormLayout.addComponent(m_heightField);
    middleFormLayout.addComponent(m_timeFrameType);

    /**
     * KSC import stuff
     */
    Button importButton = new Button("KSC Import");
    importButton.setDescription("Import KSC-report");
    final NativeSelect selectKSCReport = new NativeSelect();
    selectKSCReport.setDescription("KSC-report selection");
    selectKSCReport.setCaption("KSC Report");
    selectKSCReport.setImmediate(true);
    selectKSCReport.setNewItemsAllowed(false);
    selectKSCReport.setMultiSelect(false);
    selectKSCReport.setInvalidAllowed(false);
    selectKSCReport.setNullSelectionAllowed(false);
    selectKSCReport.setImmediate(true);

    kscPerformanceReportFactory = KSC_PerformanceReportFactory.getInstance();

    Map<Integer, String> mapOfKscReports = kscPerformanceReportFactory.getReportList();

    if (mapOfKscReports.size() == 0) {
        importButton.setEnabled(false);
    }

    for (Map.Entry<Integer, String> entry : mapOfKscReports.entrySet()) {
        selectKSCReport.addItem(entry.getKey());

        selectKSCReport.setItemCaption(entry.getKey(), entry.getValue());

        if (selectKSCReport.getValue() == null) {
            selectKSCReport.setValue(entry.getKey());
        }
    }

    importButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            importKscReport(Integer.valueOf(selectKSCReport.getValue().toString()));
        }
    });

    rightFormLayout.addComponent(selectKSCReport);
    rightFormLayout.addComponent(importButton);

    /**
     * setting up the layout
     */
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setMargin(true);

    horizontalLayout.addComponent(leftFormLayout);
    horizontalLayout.addComponent(middleFormLayout);
    horizontalLayout.addComponent(rightFormLayout);

    /**
     * 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) {
            /**
             * saving the data
             */
            m_dashletSpec.getParameters().put("width", m_widthField.getValue().toString());
            m_dashletSpec.getParameters().put("height", m_heightField.getValue().toString());
            m_dashletSpec.getParameters().put("columns", m_columnsSelect.getValue().toString());
            m_dashletSpec.getParameters().put("rows", m_rowsSelect.getValue().toString());

            int timeFrameValue;
            int timeFrameType;

            try {
                timeFrameValue = Integer.parseInt(m_timeFrameValue.getValue().toString());
            } catch (NumberFormatException numberFormatException) {
                timeFrameValue = 1;
            }

            try {
                timeFrameType = Integer.parseInt(m_timeFrameType.getValue().toString());
            } catch (NumberFormatException numberFormatException) {
                timeFrameType = Calendar.HOUR;
            }

            m_dashletSpec.getParameters().put("timeFrameType", String.valueOf(timeFrameType));
            m_dashletSpec.getParameters().put("timeFrameValue", String.valueOf(timeFrameValue));

            int i = 0;

            for (int y = 0; y < m_gridLayout.getRows(); y++) {
                for (int x = 0; x < m_gridLayout.getColumns(); x++) {
                    RrdGraphEntry rrdGraphEntry = (RrdGraphEntry) m_gridLayout.getComponent(x, y);
                    m_dashletSpec.getParameters().put("nodeLabel" + i, rrdGraphEntry.getNodeLabel());
                    m_dashletSpec.getParameters().put("nodeId" + i, rrdGraphEntry.getNodeId());
                    m_dashletSpec.getParameters().put("resourceTypeLabel" + i,
                            rrdGraphEntry.getResourceTypeLabel());
                    m_dashletSpec.getParameters().put("resourceTypeId" + i, rrdGraphEntry.getResourceTypeId());
                    m_dashletSpec.getParameters().put("resourceId" + i, rrdGraphEntry.getResourceId());
                    m_dashletSpec.getParameters().put("resourceLabel" + i, rrdGraphEntry.getResourceLabel());
                    m_dashletSpec.getParameters().put("graphLabel" + i, rrdGraphEntry.getGraphLabel());
                    m_dashletSpec.getParameters().put("graphId" + i, rrdGraphEntry.getGraphId());
                    m_dashletSpec.getParameters().put("graphUrl" + i, rrdGraphEntry.getGraphUrl());

                    i++;
                }
            }

            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 verticalLayout = new VerticalLayout();
    verticalLayout.setMargin(true);

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(m_gridLayout);
    verticalLayout.addComponent(buttonLayout);
    verticalLayout.setExpandRatio(m_gridLayout, 2.0f);
    verticalLayout.setSizeFull();

    setContent(verticalLayout);
}

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

License:Open Source License

/**
 * Default constructor.//from   w  w  w . j  a v a  2 s .co m
 */
public HeaderLayout() {
    /**
     * Setting up the layout
     */
    addStyleName("header");
    setMargin(new MarginInfo(false, true, false, false));
    setSpacing(true);
    setWidth("100%");
    setHeight(64, Unit.PIXELS);

    /**
     * Adding the logo
     */
    Label link = new Label();
    link.setContentMode(ContentMode.HTML);
    link.setValue("<a href=\"/opennms/index.jsp\" id=\"onmslogo\"></a>");
    addComponent(link);
    setExpandRatio(link, 1.0f);

    /**
     * Adding the selection box
     */
    m_nativeSelect = new NativeSelect();
    m_nativeSelect.setDescription("Select Ops Board configuration");
    m_nativeSelect.setContainerDataSource(WallboardProvider.getInstance().getBeanContainer());
    m_nativeSelect.setItemCaptionPropertyId("title");
    m_nativeSelect.setNullSelectionAllowed(false);
    m_nativeSelect.setImmediate(true);

    m_nativeSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            m_wallboardButton.setEnabled(true);
            m_dashboardButton.setEnabled(true);
        }
    });

    m_dashboardButton = new Button("Ops Panel", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().getNavigator().addViewChangeListener(HeaderLayout.this);
            UI.getCurrent().getNavigator().navigateTo(
                    "dashboard/" + m_nativeSelect.getContainerProperty(m_nativeSelect.getValue(), "title"));
        }
    });
    m_dashboardButton.setDescription("Ops Panel view");

    /**
     * Adding the wallboard button
     */
    m_pauseButton = new Button("Pause", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (m_wallboardView instanceof WallboardView) {
                if (((WallboardView) m_wallboardView).isPaused()) {
                    ((WallboardView) m_wallboardView).resume();
                } else {
                    ((WallboardView) m_wallboardView).pause();
                }
            } else {
                if (m_wallboardView instanceof DashboardView) {
                    ((DashboardView) m_wallboardView).updateAll();
                }
            }

            updatePauseButton();
        }
    });

    /**
     * Adding the wallboard button
     */
    m_wallboardButton = new Button("Ops Board", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().getNavigator().addViewChangeListener(HeaderLayout.this);
            UI.getCurrent().getNavigator().navigateTo(
                    "wallboard/" + m_nativeSelect.getContainerProperty(m_nativeSelect.getValue(), "title"));
        }
    });
    m_wallboardButton.setDescription("Ops Board view");

    m_pauseButton.setEnabled(false);
    m_wallboardButton.setEnabled(false);
    m_dashboardButton.setEnabled(false);

    addComponents(m_nativeSelect, m_dashboardButton, m_wallboardButton, m_pauseButton);
    setComponentAlignment(m_nativeSelect, Alignment.MIDDLE_CENTER);
    setComponentAlignment(m_dashboardButton, Alignment.MIDDLE_CENTER);
    setComponentAlignment(m_wallboardButton, Alignment.MIDDLE_CENTER);
    setComponentAlignment(m_pauseButton, Alignment.MIDDLE_CENTER);
}

From source file:org.opennms.features.vaadin.surveillanceviews.ui.dashboard.SurveillanceViewGraphComponent.java

License:Open Source License

/**
 * Constructor for instantiating this component.
 *
 * @param surveillanceViewService the surveillance view service to be used
 * @param enabled                 the flag should links be enabled?
 *///from  w w  w .java2 s  . c  o m
public SurveillanceViewGraphComponent(SurveillanceViewService surveillanceViewService, boolean enabled) {
    /**
     * set the fields
     */
    m_surveillanceViewService = surveillanceViewService;
    m_enabled = enabled;

    /**
     * create layout for caption
     */
    HorizontalLayout horizontalLayout = new HorizontalLayout();

    horizontalLayout.setWidth(100, Unit.PERCENTAGE);
    horizontalLayout.setSpacing(false);
    horizontalLayout.setPrimaryStyleName("v-caption-surveillance-view");
    horizontalLayout.addComponent(new Label("Resource Graphs"));
    addComponent(horizontalLayout);

    /**
     * create node selection box
     */
    m_nodeSelect = new NativeSelect();
    m_nodeSelect.setNullSelectionAllowed(false);

    m_nodeSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            Integer onmsNodeId = (Integer) m_nodeSelect.getValue();

            m_resourceSelect.removeAllItems();

            if (onmsNodeId != null) {
                Map<OnmsResourceType, List<OnmsResource>> map = getSurveillanceViewService()
                        .getResourceTypeMapForNodeId(onmsNodeId);

                for (OnmsResourceType onmsResourceType : map.keySet()) {
                    for (OnmsResource onmsResource : map.get(onmsResourceType)) {
                        m_resourceSelect.addItem(onmsResource.getId());
                        m_resourceSelect.setItemCaption(onmsResource.getId(),
                                onmsResourceType.getLabel() + ": " + onmsResource.getLabel());
                    }
                }

                Iterator<?> i = m_resourceSelect.getItemIds().iterator();

                if (i.hasNext()) {
                    m_resourceSelect.select(i.next());
                }
            }
        }
    });

    /**
     * create resource selection box
     */
    m_resourceSelect = new NativeSelect();
    m_resourceSelect.setNullSelectionAllowed(false);

    m_resourceSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String onmsResourceId = (String) m_resourceSelect.getValue();

            m_graphSelect.removeAllItems();

            if (onmsResourceId != null) {
                Map<String, String> map = getSurveillanceViewService()
                        .getGraphResultsForResourceId(onmsResourceId);

                for (String string : map.keySet()) {
                    m_graphSelect.addItem(map.get(string));
                    m_graphSelect.setItemCaption(map.get(string), string);
                }

                Iterator<?> i = m_graphSelect.getItemIds().iterator();

                if (i.hasNext()) {
                    m_graphSelect.select(i.next());
                }
            }
        }
    });

    /**
     * create graph selection box
     */
    m_graphSelect = new NativeSelect();
    m_graphSelect.setNullSelectionAllowed(false);

    m_graphSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String graphName = (String) m_graphSelect.getValue();
            String resourceId = (String) m_resourceSelect.getValue();
            replaceGraph(graphName, resourceId);
        }
    });

    /**
     * set box sizes to full
     */
    m_nodeSelect.setSizeFull();
    m_resourceSelect.setSizeFull();
    m_graphSelect.setSizeFull();

    /**
     * add box styles
     */
    m_nodeSelect.addStyleName("surveillance-view");
    m_resourceSelect.addStyleName("surveillance-view");
    m_graphSelect.addStyleName("surveillance-view");

    /**
     * create layout for storing the graph
     */
    m_graphLayout = new VerticalLayout();
    m_graphLayout.setSizeUndefined();
    m_graphLayout.setWidth(100, Unit.PERCENTAGE);

    /**
     * create layout for selection boxes
     */
    HorizontalLayout selectionBoxesLayout = new HorizontalLayout();
    selectionBoxesLayout.setSizeFull();
    selectionBoxesLayout.addComponent(m_nodeSelect);
    selectionBoxesLayout.addComponent(m_resourceSelect);
    selectionBoxesLayout.addComponent(m_graphSelect);

    m_graphLayout.setId("graphLayout");

    /**
     * ...and call it when page is constructed. Also add a resize listener...
     */
    addAttachListener(new AttachListener() {
        @Override
        public void attach(AttachEvent attachEvent) {
            getUI().getPage().addBrowserWindowResizeListener(SurveillanceViewGraphComponent.this);
        }
    });

    /**
     * ... and remove the resize listener on detach event
     */
    addDetachListener(new DetachListener() {
        @Override
        public void detach(DetachEvent detachEvent) {
            getUI().getPage().removeBrowserWindowResizeListener(SurveillanceViewGraphComponent.this);
        }
    });

    /**
     * add layout for selection boxes and image
     */
    addComponent(selectionBoxesLayout);
    addComponent(m_graphLayout);
}

From source file:org.vaadin.johannes.VaadingraphApplication.java

License:LGPL

private Component getStyleSelect() {
    final NativeSelect styleSelect = new NativeSelect();
    styleSelect.setCaption("Visual Style");
    styleSelect.addItem("default");
    styleSelect.addItem("Nested Network Style");
    styleSelect.addItem("Sample1");
    styleSelect.addItem("Solid");
    styleSelect.addItem("Universe");

    styleSelect.setNullSelectionAllowed(false);
    styleSelect.setImmediate(true);/*from w w  w  . j  a v  a 2  s.c  om*/
    styleSelect.select("default");
    styleSelect.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 8021555546280140242L;

        public void valueChange(final ValueChangeEvent event) {
            reLayout = true;
            Cytoscape.getVisualMappingManager().setVisualStyle(styleSelect.getValue().toString());
            final VaadinGraph g = getNetworkGraph(WIDTH, HEIGHT);
            hl2.replaceComponent(graph, g);
            graph = g;
        }
    });
    return styleSelect;
}

From source file:org.vaadin.johannes.VaadingraphApplication.java

License:LGPL

private Component getNodeSizeSelect() {
    final NativeSelect sizeSelect = new NativeSelect();
    sizeSelect.setCaption("Node size");
    sizeSelect.addItem("5");
    sizeSelect.addItem("10");
    sizeSelect.addItem("15");
    sizeSelect.addItem("20");
    sizeSelect.addItem("30");
    sizeSelect.setNullSelectionAllowed(false);
    sizeSelect.setImmediate(true);/* w w w  .j  av a 2  s.c  o  m*/
    sizeSelect.select("10");
    sizeSelect.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 8021555546280140242L;

        public void valueChange(final ValueChangeEvent event) {
            if (sizeSelect.getValue() == null) {
                nodeSize = -1;
            } else {
                nodeSize = Double.valueOf(sizeSelect.getValue().toString());
            }
            final VaadinGraph g = getNetworkGraph(WIDTH, HEIGHT);
            hl2.replaceComponent(graph, g);
            graph = g;
        }
    });
    return sizeSelect;
}

From source file:org.vaadin.johannes.VaadingraphApplication.java

License:LGPL

private Component getNetworkSelect() {
    networkSelect = new NativeSelect();
    networkSelect.setCaption("Network sif file");
    networkSelect.addContainerProperty("path", String.class, null);
    Item i = networkSelect.addItem("sample");
    i.getItemProperty("path").setValue(path + "sample.sif");
    i = networkSelect.addItem("multiWordProteins");
    i.getItemProperty("path").setValue(path + "multiWordProteins.sif");
    i = networkSelect.addItem("galFiltered");
    i.getItemProperty("path").setValue(path + "galFiltered.sif");

    networkSelect.setNullSelectionAllowed(false);
    networkSelect.setImmediate(true);// ww  w . ja  v  a  2 s  .co m
    networkSelect.select("sample");
    networkSelect.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 8021555546280140242L;

        public void valueChange(final ValueChangeEvent event) {
            reLayout = true;
            fileName = networkSelect.getItem(networkSelect.getValue()).getItemProperty("path").toString();
            final VaadinGraph g = getNetworkGraph(WIDTH, HEIGHT);
            hl2.replaceComponent(graph, g);
            graph = g;
        }
    });

    return networkSelect;
}

From source file:org.vaadin.johannes.VaadingraphApplication.java

License:LGPL

private Component getSessionSelect() {
    sessionSelect = new NativeSelect();
    sessionSelect.setImmediate(true);//from w w w.  j  a v a  2  s .  c o  m
    sessionSelect.setNullSelectionAllowed(true);
    sessionSelect.setNullSelectionItemId("-no selection-");
    sessionSelect.setCaption("Cytoscape session file");
    sessionSelect.addContainerProperty("path", String.class, null);

    Item i = sessionSelect.addItem("example");
    i.getItemProperty("path").setValue(path + "example.cys");

    i = sessionSelect.addItem("example2");
    i.getItemProperty("path").setValue(path + "example2.cys");

    i = sessionSelect.addItem("galFiltered");
    i.getItemProperty("path").setValue(path + "galFiltered.cys");

    sessionSelect.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 6954002045682969159L;

        public void valueChange(final ValueChangeEvent event) {
            reLayout = true;
            if (sessionSelect.getValue() == null) {
                networkSelect.setEnabled(true);
                fileName = networkSelect.getItem(networkSelect.getValue()).getItemProperty("path").toString();
            } else {
                networkSelect.setEnabled(false);
                fileName = sessionSelect.getItem(sessionSelect.getValue()).getItemProperty("path").toString();
            }
            final VaadinGraph g = getNetworkGraph(WIDTH, HEIGHT);
            hl2.replaceComponent(graph, g);
            graph = g;
        }
    });
    return sessionSelect;
}