Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server Page getCurrent.

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

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

License:Open Source License

/**
 * Constructor for creating ne instances of this class.
 *
 * @param criteriaBuilderHelper the {@link CriteriaBuilderHelper} to be used
 * @param restriction           the criteria string
 *//*  ww w  . j av  a  2s.  co  m*/
public CriteriaRestrictionComponent(CriteriaBuilderHelper criteriaBuilderHelper, String restriction) {
    /**
     * Setting the member fields
     */
    m_criteriaBuilderHelper = criteriaBuilderHelper;

    /**
     * Setting up this component
     */
    setWidth(100, Unit.PERCENTAGE);

    m_rightLayout = new HorizontalLayout();
    m_leftLayout = new HorizontalLayout();

    setSpacing(true);
    setMargin(true);

    Page.getCurrent().getStyles().add(".criteriaBackground { background:#dddddd; }");

    addStyleName("criteriaBackground");

    /**
     * Adding the restriction's select box
     */
    m_restrictionSelect = new NativeSelect();
    m_restrictionSelect.setCaption("Restriction");
    m_restrictionSelect.setNullSelectionAllowed(false);
    m_restrictionSelect.setMultiSelect(false);
    m_restrictionSelect.setNewItemsAllowed(false);
    m_restrictionSelect.setImmediate(true);
    m_restrictionSelect.setDescription("Restriction selection");

    for (CriteriaRestriction criteriaRestriction : CriteriaRestriction.values()) {
        m_restrictionSelect.addItem(criteriaRestriction.name());
    }

    /**
     * Parsing the criteria
     */
    final String[] arr = restriction.split("[(),]+");

    CriteriaRestriction criteriaRestriction = CriteriaRestriction.valueOf(arr[0]);

    m_restrictionSelect.select(criteriaRestriction.toString());

    m_restrictionSelect.addValueChangeListener(new com.vaadin.data.Property.ValueChangeListener() {
        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent valueChangeEvent) {
            CriteriaRestriction newCriteriaRestriction = CriteriaRestriction
                    .valueOf(String.valueOf(valueChangeEvent.getProperty().getValue()));
            refreshComponents(newCriteriaRestriction); //, Arrays.copyOfRange(arr, 1, arr.length));
        }
    });

    setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    m_leftLayout.addComponent(m_restrictionSelect);
    m_leftLayout.setSpacing(true);

    refreshComponents(criteriaRestriction, Arrays.copyOfRange(arr, 1, arr.length));

    /**
     * Adding the layouts
     */
    addComponent(m_leftLayout);
    addComponent(m_rightLayout);

    setExpandRatio(m_leftLayout, 3.0f);
    setExpandRatio(m_rightLayout, 1.0f);

    setComponentAlignment(m_leftLayout, Alignment.MIDDLE_LEFT);
    setComponentAlignment(m_rightLayout, Alignment.MIDDLE_RIGHT);
}

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

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {

    if (m_wallboardComponent == null) {
        m_wallboardComponent = new AbstractDashletComponent() {

            private VerticalLayout m_verticalLayout;

            {//from www.  ja  v  a  2 s  . c o m
                m_verticalLayout = new VerticalLayout();
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setWidth("100%");

                refresh();
            }

            /**
             * Injects CSS styles on current page for this dashlet
             */
            private void injectWallboardStyles() {
                Page.getCurrent().getStyles().add(
                        ".alert-details.cleared { background: #AAAAAA; border-left: 14px solid #858585; }");
                Page.getCurrent().getStyles()
                        .add(".alert-details.normal { background: #AAAAAA; border-left: 14px solid #336600; }");
                Page.getCurrent().getStyles().add(
                        ".alert-details.indeterminate { background: #AAAAAA; border-left: 14px solid #999; }");
                Page.getCurrent().getStyles().add(
                        ".alert-details.warning { background: #AAAAAA; border-left: 14px solid #FFCC00; }");
                Page.getCurrent().getStyles()
                        .add(".alert-details.minor { background: #AAAAAA; border-left: 14px solid #FF9900; }");
                Page.getCurrent().getStyles()
                        .add(".alert-details.major { background: #AAAAAA; border-left: 14px solid #FF3300; }");
                Page.getCurrent().getStyles().add(
                        ".alert-details.critical { background: #AAAAAA; border-left: 14px solid #CC0000; }");
                Page.getCurrent().getStyles()
                        .add(".alert-details-font {color: #000000; font-size: 17px; line-height: normal; }");
                Page.getCurrent().getStyles()
                        .add(".alert-details-noalarms-font { font-size: 17px; line-height: normal; }");
                Page.getCurrent().getStyles().add(".alert-details { padding: 5px 5px; margin: 1px; }");
            }

            @Override
            public void refresh() {
                List<OnmsAlarm> alarms = getAlarms();
                m_verticalLayout.removeAllComponents();
                injectWallboardStyles();

                setBoosted(false);

                addComponents(m_verticalLayout, alarms);

                setBoosted(checkBoosted(alarms));
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }
    return m_wallboardComponent;
}

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

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {
    if (m_wallboardComponent == null) {
        m_wallboardComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {/*w ww  .j a  v  a2  s .c  om*/
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setWidth("100%");
                injectWallboardStyles();
                refresh();
            }

            /**
             * Injects CSS styles on current page for this dashlet
             */
            private void injectWallboardStyles() {
                Page.getCurrent().getStyles()
                        .add(".alerts.cleared { background: #000000; border-left: 15px solid #858585; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.normal { background: #000000; border-left: 15px solid #336600; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.indeterminate {  background: #000000; border-left: 15px solid #999; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.warning { background: #000000; border-left: 15px solid #FFCC00; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.minor { background: #000000;  border-left: 15px solid #FF9900; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.major { background: #000000; border-left: 15px solid #FF3300; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.critical { background: #000000; border-left: 15px solid #CC0000; }");
                Page.getCurrent().getStyles()
                        .add(".alerts-font {color: #3ba300; font-size: 18px; line-height: normal; }");
                Page.getCurrent().getStyles()
                        .add(".alerts-noalarms-font { font-size: 18px; line-height: normal; }");
                Page.getCurrent().getStyles().add(".alerts { padding: 5px 5px; margin: 1px; }");
                Page.getCurrent().getStyles().add(".v-slot-alerts-font { overflow: hidden; }");
            }

            @Override
            public void refresh() {
                List<OnmsAlarm> alarms = getAlarms();

                OnmsSeverity boostSeverity = OnmsSeverity
                        .valueOf(getDashletSpec().getParameters().get("boostSeverity"));

                m_verticalLayout.removeAllComponents();

                boosted = false;

                addComponents(m_verticalLayout, alarms);

            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }
    return m_wallboardComponent;
}

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

License:Open Source License

@Override
public DashletComponent getDashboardComponent() {
    if (m_dashboardComponent == null) {
        m_dashboardComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {/*from   w w  w .  jav  a2  s.co  m*/
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setWidth("100%");
                injectDashboardStyles();
                refresh();
            }

            /**
             * Injects CSS styles on current page for this dashlet
             */
            private void injectDashboardStyles() {
                Page.getCurrent().getStyles()
                        .add(".alerts.cleared { background: #000000; border-left: 8px solid #858585; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.normal { background: #000000; border-left: 8px solid #336600; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.indeterminate {  background: #000000; border-left: 8px solid #999; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.warning { background: #000000; border-left: 8px solid #FFCC00; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.minor { background: #000000;  border-left: 8px solid #FF9900; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.major { background: #000000; border-left: 8px solid #FF3300; }");
                Page.getCurrent().getStyles()
                        .add(".alerts.critical { background: #000000; border-left: 8px solid #CC0000; }");
                Page.getCurrent().getStyles()
                        .add(".alerts-font {color: #3ba300; font-size: 11px; line-height: normal; }");
                Page.getCurrent().getStyles()
                        .add(".alerts-noalarms-font { font-size: 11px; line-height: normal; }");
                Page.getCurrent().getStyles().add(".alerts { padding: 5px 5px; margin: 1px; }");
                Page.getCurrent().getStyles().add(".v-slot-alerts-font { overflow: hidden; }");
            }

            @Override
            public void refresh() {
                List<OnmsAlarm> alarms = getAlarms();

                m_verticalLayout.removeAllComponents();

                boosted = false;

                addComponents(m_verticalLayout, alarms);
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }
    return m_dashboardComponent;
}

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 www  .j a  v  a2  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.KscDashlet.java

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {
    if (m_wallboardComponent == null) {
        m_wallboardComponent = new AbstractDashletComponent() {
            private GridLayout m_gridLayout = new GridLayout();

            {/*from  w  w w . j av  a 2s  .c  om*/
                m_gridLayout.setCaption(getName());
                m_gridLayout.setSizeFull();
                m_gridLayout.setColumns(1);
                m_gridLayout.setRows(1);
            }

            @Override
            public void refresh() {
                m_gridLayout.removeAllComponents();

                /**
                 * initializing the parameters
                 */
                int columns = 0;
                int rows = 0;

                String kscReportName = getDashletSpec().getParameters().get("kscReport");

                if (kscReportName == null || "".equals(kscReportName)) {
                    return;
                }

                KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory
                        .getInstance();

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

                int kscReportId = -1;

                for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) {

                    if (kscReportName.equals(entry.getValue())) {
                        kscReportId = entry.getKey();
                        break;
                    }
                }

                if (kscReportId == -1) {
                    return;
                }

                Report kscReport = kscPerformanceReportFactory.getReportByIndex(kscReportId);

                columns = kscReport.getGraphs_per_line();

                if (columns == 0) {
                    columns = 1;
                }

                rows = kscReport.getGraphCount() / columns;

                if (rows == 0) {
                    rows = 1;
                }

                if (kscReport.getGraphCount() % columns > 0) {
                    rows++;
                }

                /**
                 * setting new columns/rows
                 */
                m_gridLayout.setColumns(columns);
                m_gridLayout.setRows(rows);

                int i = 0;

                /**
                 * adding the components
                 */

                Page.getCurrent().getStyles().add(
                        ".box { margin: 5px; background-color: #444; border: 1px solid #999; border-top: 0; overflow: auto; }");
                Page.getCurrent().getStyles().add(
                        ".text { color:#ffffff; line-height: 11px; font-size: 9px; font-family: 'Lucida Grande', Verdana, sans-serif; font-weight: bold; }");
                Page.getCurrent().getStyles().add(".margin { margin:5px; }");

                for (int y = 0; y < m_gridLayout.getRows(); y++) {
                    for (int x = 0; x < m_gridLayout.getColumns(); x++) {

                        if (i < kscReport.getGraphCount()) {
                            Graph graph = kscReport.getGraph(i);

                            Map<String, String> data = getDataForResourceId(graph.getNodeId(),
                                    graph.getResourceId());

                            Calendar beginTime = Calendar.getInstance();
                            Calendar endTime = Calendar.getInstance();

                            KSC_PerformanceReportFactory.getBeginEndTime(graph.getTimespan(), beginTime,
                                    endTime);

                            GraphContainer graphContainer = getGraphContainer(graph, beginTime.getTime(),
                                    endTime.getTime());

                            VerticalLayout verticalLayout = new VerticalLayout();

                            HorizontalLayout horizontalLayout = new HorizontalLayout();
                            horizontalLayout.addStyleName("box");
                            horizontalLayout.setWidth("100%");
                            horizontalLayout.setHeight("42px");

                            VerticalLayout leftLayout = new VerticalLayout();
                            leftLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT);
                            leftLayout.addStyleName("margin");

                            Label labelTitle;

                            if (graph.getTitle() == null || "".equals(graph.getTitle())) {
                                labelTitle = new Label("&nbsp;");
                                labelTitle.setContentMode(ContentMode.HTML);
                            } else {
                                labelTitle = new Label(graph.getTitle());
                            }

                            labelTitle.addStyleName("text");

                            Label labelFrom = new Label("From: " + beginTime.getTime().toString());
                            labelFrom.addStyleName("text");

                            Label labelTo = new Label("To: " + endTime.getTime().toString());
                            labelTo.addStyleName("text");

                            Label labelNodeLabel = new Label(data.get("nodeLabel"));
                            labelNodeLabel.addStyleName("text");

                            Label labelResourceLabel = new Label(
                                    data.get("resourceTypeLabel") + ": " + data.get("resourceLabel"));
                            labelResourceLabel.addStyleName("text");

                            leftLayout.addComponent(labelTitle);
                            leftLayout.addComponent(labelFrom);
                            leftLayout.addComponent(labelTo);

                            VerticalLayout rightLayout = new VerticalLayout();
                            rightLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT);
                            rightLayout.addStyleName("margin");

                            rightLayout.addComponent(labelNodeLabel);
                            rightLayout.addComponent(labelResourceLabel);

                            horizontalLayout.addComponent(leftLayout);
                            horizontalLayout.addComponent(rightLayout);

                            horizontalLayout.setExpandRatio(leftLayout, 1.0f);
                            horizontalLayout.setExpandRatio(rightLayout, 1.0f);

                            verticalLayout.addComponent(horizontalLayout);
                            verticalLayout.addComponent(graphContainer);
                            verticalLayout.setWidth(DEFAULT_GRAPH_WIDTH_PX, Unit.PIXELS);

                            m_gridLayout.addComponent(verticalLayout, x, y);

                            verticalLayout.setComponentAlignment(horizontalLayout, Alignment.MIDDLE_CENTER);
                            verticalLayout.setComponentAlignment(graphContainer, Alignment.MIDDLE_CENTER);
                            m_gridLayout.setComponentAlignment(verticalLayout, Alignment.MIDDLE_CENTER);
                        }
                        i++;
                    }
                }
            }

            @Override
            public Component getComponent() {
                return m_gridLayout;
            }
        };
    }

    return m_wallboardComponent;
}

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

License:Open Source License

@Override
public DashletComponent getDashboardComponent() {
    if (m_dashboardComponent == null) {
        m_dashboardComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {/*  w  w w. j av a 2 s. c o m*/
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setSizeFull();
            }

            @Override
            public void refresh() {
                m_verticalLayout.removeAllComponents();

                String kscReportName = getDashletSpec().getParameters().get("kscReport");

                if (kscReportName == null || "".equals(kscReportName)) {
                    return;
                }

                KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory
                        .getInstance();

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

                int kscReportId = -1;

                for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) {

                    if (kscReportName.equals(entry.getValue())) {
                        kscReportId = entry.getKey();
                        break;
                    }
                }

                if (kscReportId == -1) {
                    return;
                }

                Report kscReport = kscPerformanceReportFactory.getReportByIndex(kscReportId);

                Page.getCurrent().getStyles().add(
                        ".box { margin: 5px; background-color: #444; border: 1px solid #999; border-top: 0; overflow: auto; }");
                Page.getCurrent().getStyles().add(
                        ".text { color:#ffffff; line-height: 11px; font-size: 9px; font-family: 'Lucida Grande', Verdana, sans-serif; font-weight: bold; }");
                Page.getCurrent().getStyles().add(".margin { margin:5px; }");

                Accordion accordion = new Accordion();
                accordion.setSizeFull();
                m_verticalLayout.addComponent(accordion);

                for (Graph graph : kscReport.getGraph()) {
                    Map<String, String> data = getDataForResourceId(graph.getNodeId(), graph.getResourceId());

                    Calendar beginTime = Calendar.getInstance();
                    Calendar endTime = Calendar.getInstance();

                    KSC_PerformanceReportFactory.getBeginEndTime(graph.getTimespan(), beginTime, endTime);

                    GraphContainer graphContainer = getGraphContainer(graph, beginTime.getTime(),
                            endTime.getTime());

                    VerticalLayout verticalLayout = new VerticalLayout();

                    HorizontalLayout horizontalLayout = new HorizontalLayout();
                    horizontalLayout.addStyleName("box");
                    horizontalLayout.setWidth("100%");
                    horizontalLayout.setHeight("42px");

                    VerticalLayout leftLayout = new VerticalLayout();
                    leftLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT);
                    leftLayout.addStyleName("margin");

                    Label labelTitle;

                    if (graph.getTitle() == null || "".equals(graph.getTitle())) {
                        labelTitle = new Label("&nbsp;");
                        labelTitle.setContentMode(ContentMode.HTML);
                    } else {
                        labelTitle = new Label(graph.getTitle());
                    }

                    labelTitle.addStyleName("text");

                    Label labelFrom = new Label("From: " + beginTime.getTime().toString());
                    labelFrom.addStyleName("text");

                    Label labelTo = new Label("To: " + endTime.getTime().toString());
                    labelTo.addStyleName("text");

                    Label labelNodeLabel = new Label(data.get("nodeLabel"));
                    labelNodeLabel.addStyleName("text");

                    Label labelResourceLabel = new Label(
                            data.get("resourceTypeLabel") + ": " + data.get("resourceLabel"));
                    labelResourceLabel.addStyleName("text");

                    leftLayout.addComponent(labelTitle);
                    leftLayout.addComponent(labelFrom);
                    leftLayout.addComponent(labelTo);

                    VerticalLayout rightLayout = new VerticalLayout();
                    rightLayout.setDefaultComponentAlignment(Alignment.TOP_LEFT);
                    rightLayout.addStyleName("margin");

                    rightLayout.addComponent(labelNodeLabel);
                    rightLayout.addComponent(labelResourceLabel);

                    horizontalLayout.addComponent(leftLayout);
                    horizontalLayout.addComponent(rightLayout);

                    horizontalLayout.setExpandRatio(leftLayout, 1.0f);
                    horizontalLayout.setExpandRatio(rightLayout, 1.0f);

                    verticalLayout.addComponent(horizontalLayout);
                    verticalLayout.addComponent(graphContainer);
                    verticalLayout.setWidth(DEFAULT_GRAPH_WIDTH_PX, Unit.PIXELS);

                    accordion.addTab(verticalLayout, data.get("nodeLabel") + "/" + data.get("resourceTypeLabel")
                            + ": " + data.get("resourceLabel"));

                    verticalLayout.setComponentAlignment(horizontalLayout, Alignment.MIDDLE_CENTER);
                    verticalLayout.setComponentAlignment(graphContainer, Alignment.MIDDLE_CENTER);
                    verticalLayout.setMargin(true);
                }
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }

    return m_dashboardComponent;
}

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

License:Open Source License

@Override
public DashletComponent getDashboardComponent() {
    if (m_dashboardComponent == null) {
        m_dashboardComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {/*  www. j a va 2 s  .  com*/
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setSizeFull();
            }

            @Override
            public void refresh() {
                /**
                 * removing old components
                 */
                m_verticalLayout.removeAllComponents();

                /**
                 * iniatizing the parameters
                 */
                int columns = 0;
                int rows = 0;
                int width = 0;
                int height = 0;

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

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

                try {
                    width = Integer.parseInt(getDashletSpec().getParameters().get("width"));
                } catch (NumberFormatException numberFormatException) {
                    width = 400;
                }

                try {
                    height = Integer.parseInt(getDashletSpec().getParameters().get("height"));
                } catch (NumberFormatException numberFormatException) {
                    height = 100;
                }

                /**
                 * getting the timeframe values
                 */
                int timeFrameValue;
                int timeFrameType;

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

                try {
                    timeFrameType = Integer.parseInt(getDashletSpec().getParameters().get("timeFrameType"));
                } catch (NumberFormatException numberFormatException) {
                    timeFrameType = Calendar.HOUR;
                }

                int i = 0;

                Page.getCurrent().getStyles().add(
                        ".box { margin: 5px; background-color: #444; border: 1px solid #999; border-top: 0; overflow: auto; }");
                Page.getCurrent().getStyles().add(
                        ".text { color:#ffffff; line-height: 11px; font-size: 9px; font-family: 'Lucida Grande', Verdana, sans-serif; font-weight: bold; }");
                Page.getCurrent().getStyles().add(".margin { margin:5px; }");

                Accordion accordion = new Accordion();
                accordion.setSizeFull();

                /**
                 * adding the components
                 */
                for (int y = 0; y < rows; y++) {
                    for (int x = 0; x < columns; x++) {
                        String graphUrl = getDashletSpec().getParameters().get("graphUrl" + i);

                        if (graphUrl != null && !"".equals(graphUrl)) {
                            accordion.addTab(getGraphComponent(i, width, height, timeFrameType, timeFrameValue),
                                    getDashletSpec().getParameters().get("nodeLabel" + i) + "/"
                                            + getDashletSpec().getParameters().get("resourceTypeLabel" + i)
                                            + ": " + getDashletSpec().getParameters().get("resourceLabel" + i));
                        }
                        i++;
                    }
                }

                m_verticalLayout.addComponent(accordion);
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }

    return m_dashboardComponent;
}

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

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {
    if (m_wallboardComponent == null) {
        m_wallboardComponent = new AbstractDashletComponent() {
            private GridLayout m_gridLayout = new GridLayout();

            {/*  w w  w  .  j av  a2s. co  m*/
                m_gridLayout.setCaption(getName());
                m_gridLayout.setSizeFull();
                m_gridLayout.setColumns(1);
                m_gridLayout.setRows(1);
            }

            @Override
            public void refresh() {
                /**
                 * removing old components
                 */
                m_gridLayout.removeAllComponents();

                /**
                 * iniatizing the parameters
                 */
                int columns = 0;
                int rows = 0;
                int width = 0;
                int height = 0;

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

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

                try {
                    width = Integer.parseInt(getDashletSpec().getParameters().get("width"));
                } catch (NumberFormatException numberFormatException) {
                    width = 400;
                }

                try {
                    height = Integer.parseInt(getDashletSpec().getParameters().get("height"));
                } catch (NumberFormatException numberFormatException) {
                    height = 100;
                }

                /**
                 * getting the timeframe values
                 */
                int timeFrameValue;
                int timeFrameType;

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

                try {
                    timeFrameType = Integer.parseInt(getDashletSpec().getParameters().get("timeFrameType"));
                } catch (NumberFormatException numberFormatException) {
                    timeFrameType = Calendar.HOUR;
                }

                /**
                 * setting new columns/rows
                 */
                m_gridLayout.setColumns(columns);
                m_gridLayout.setRows(rows);

                int i = 0;

                Page.getCurrent().getStyles().add(
                        ".box { margin: 5px; background-color: #444; border: 1px solid #999; border-top: 0; overflow: auto; }");
                Page.getCurrent().getStyles().add(
                        ".text { color:#ffffff; line-height: 11px; font-size: 9px; font-family: 'Lucida Grande', Verdana, sans-serif; font-weight: bold; }");
                Page.getCurrent().getStyles().add(".margin { margin:5px; }");

                /**
                 * adding the components
                 */
                for (int y = 0; y < m_gridLayout.getRows(); y++) {
                    for (int x = 0; x < m_gridLayout.getColumns(); x++) {
                        String graphUrl = getDashletSpec().getParameters().get("graphUrl" + i);

                        if (graphUrl != null && !"".equals(graphUrl)) {
                            Component component = getGraphComponent(i, width, height, timeFrameType,
                                    timeFrameValue);
                            m_gridLayout.addComponent(component, x, y);
                            m_gridLayout.setComponentAlignment(component, Alignment.MIDDLE_CENTER);
                        }
                        i++;
                    }
                }
            }

            @Override
            public Component getComponent() {
                return m_gridLayout;
            }
        };
    }

    return m_wallboardComponent;
}

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

License:Open Source License

/**
 * Constrcutor for creating new instances of this class.
 *
 * @param nodeDao        the node dao instance to be used
 * @param rrdGraphHelper the rrd graph helper instancce to be used
 * @param x              the x-position of this entry
 * @param y              the y-position of this entry
 *///from w  w w  .ja  v  a2  s  . c o m
public RrdGraphEntry(final NodeDao nodeDao, final RrdGraphHelper rrdGraphHelper, int x, int y) {
    /**
     * setting the member fields
     */
    this.m_x = x;
    this.m_y = y;

    /**
     * setting up the buttons
     */
    m_changeButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            GraphSelectionWindow graphSelectionWindow = new GraphSelectionWindow(nodeDao, rrdGraphHelper,
                    RrdGraphEntry.this);

            getUI().addWindow(graphSelectionWindow);
        }
    });

    m_removeButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            setGraphId(null);
            setGraphLabel(null);
            setGraphUrl(null);
            setNodeId(null);
            setNodeLabel(null);
            setResourceId(null);
            setResourceLabel(null);
            setResourceTypeId(null);
            setResourceTypeLabel(null);

            update();
        }
    });

    m_removeButton.addStyleName(BaseTheme.BUTTON_LINK);
    m_changeButton.addStyleName(BaseTheme.BUTTON_LINK);

    /**
     * setting up the layout
     */
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    m_graphLayout.setSizeUndefined();
    m_graphLayout.setWidth(200, Unit.PIXELS);
    m_graphLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    /**
     * adding the components
     */
    verticalLayout.addComponent(m_nodeLabelComponent);
    verticalLayout.addComponent(m_graphLabelComponent);
    verticalLayout.addComponent(m_changeButton);
    verticalLayout.addComponent(m_removeButton);
    verticalLayout.addComponent(m_graphLayout);

    m_nodeLabelComponent.setSizeUndefined();
    m_graphLabelComponent.setSizeUndefined();

    verticalLayout.setWidth(100, Unit.PERCENTAGE);

    setSizeFull();

    /**
     * inject the preview style
     */
    Page.getCurrent().getStyles().add(".preview { width:175px; }");

    /**
     * initial update
     */
    update();

    /**
     * setting the content
     */
    setContent(verticalLayout);
}