Example usage for com.vaadin.ui HorizontalLayout addStyleName

List of usage examples for com.vaadin.ui HorizontalLayout addStyleName

Introduction

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

Prototype

@Override
    public void addStyleName(String style) 

Source Link

Usage

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   ww  w .  j a v a  2 s.c  o m*/
                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();

            {//  ww w.ja va 2 s  .  co 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

/**
 * Returns the graph component for a given graph of the {@link DashletSpec}.
 *
 * @param i              the entry id/*w  w  w  .j a  v a2 s  . c  om*/
 * @param width          the width
 * @param height         the height
 * @param timeFrameType  the timeframe type
 * @param timeFrameValue the timeframe value
 * @return the component
 */
private Component getGraphComponent(int i, int width, int height, int timeFrameType, int timeFrameValue) {
    String graphTitle = getDashletSpec().getParameters().get("graphLabel" + i);
    String graphName = RrdGraphHelper
            .getGraphNameFromQuery(getDashletSpec().getParameters().get("graphUrl" + i));
    String resourceId = getDashletSpec().getParameters().get("resourceId" + i);

    GraphContainer graph = new GraphContainer(graphName, resourceId);
    graph.setTitle(graphTitle);
    // Setup the time span
    Calendar cal = new GregorianCalendar();
    graph.setEnd(cal.getTime());
    cal.add(timeFrameType, -timeFrameValue);
    graph.setStart(cal.getTime());
    // Use all of the available width
    graph.setWidthRatio(1.0d);

    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 labelFrom = new Label(getDashletSpec().getParameters().get("nodeLabel" + i));
    labelFrom.addStyleName("text");

    Label labelTo = new Label(getDashletSpec().getParameters().get("resourceTypeLabel" + i) + ": "
            + getDashletSpec().getParameters().get("resourceLabel" + i));
    labelTo.addStyleName("text");

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

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

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(graph);
    verticalLayout.setWidth(width, Unit.PIXELS);

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

    return verticalLayout;
}

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

License:Open Source License

private Component getLegend(String entity) {
    HorizontalLayout horizontalLayout = new HorizontalLayout();

    horizontalLayout.setSpacing(true);//  w w w  . j  a  v a 2  s.  c o m
    horizontalLayout.addStyleName("summary");
    horizontalLayout.addStyleName("global");

    Label labelx = new Label(entity);
    labelx.addStyleName("summary-font-legend");

    Image ackdImage = new Image(null, new ThemeResource("img/acknowledged.png"));
    ackdImage.setWidth(16, Sizeable.Unit.PIXELS);

    Image unackdImage = new Image(null, new ThemeResource("img/unacknowledged.png"));
    unackdImage.setWidth(16, Sizeable.Unit.PIXELS);

    Label dummyLabel = new Label();
    dummyLabel.setWidth(32, Sizeable.Unit.PIXELS);

    horizontalLayout.addComponent(labelx);
    horizontalLayout.addComponent(ackdImage);
    horizontalLayout.addComponent(unackdImage);
    horizontalLayout.addComponent(dummyLabel);

    horizontalLayout.setComponentAlignment(ackdImage, Alignment.TOP_RIGHT);
    horizontalLayout.setComponentAlignment(unackdImage, Alignment.TOP_RIGHT);

    horizontalLayout.setExpandRatio(labelx, 4.0f);
    horizontalLayout.setExpandRatio(ackdImage, 1.0f);
    horizontalLayout.setExpandRatio(unackdImage, 1.0f);
    horizontalLayout.setExpandRatio(dummyLabel, 1.0f);

    horizontalLayout.setWidth(375, Sizeable.Unit.PIXELS);

    return horizontalLayout;
}

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

License:Open Source License

/**
 * Returns the component showing the alarms and the trends by severity
 *
 * @return the {@link Component}/* ww  w . j av  a  2 s.  c o  m*/
 */
private Component getComponentSeverity(int width) {
    VerticalLayout verticalLayout = new VerticalLayout();

    int overallSum = 0;
    int severitySum = 0;

    verticalLayout.addComponent(getLegend("Severity"));

    for (OnmsSeverity onmsSeverity : OnmsSeverity.values()) {
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        horizontalLayout.setSpacing(true);
        horizontalLayout.addStyleName("summary");
        horizontalLayout.addStyleName(onmsSeverity.name().toLowerCase());

        int acknowledged = countBySeverity(true, m_timeslot, onmsSeverity);
        int notAcknowledged = countBySeverity(false, m_timeslot, onmsSeverity);

        Label labelSeverity = new Label(onmsSeverity.getLabel());
        labelSeverity.addStyleName("summary-font");
        Label labelAcknowledge = new Label(String.valueOf(acknowledged));
        labelAcknowledge.addStyleName("summary-font");
        Label labelNotAcknowledged = new Label(String.valueOf(notAcknowledged));
        labelNotAcknowledged.addStyleName("summary-font");

        horizontalLayout.addComponent(labelSeverity);
        horizontalLayout.addComponent(labelAcknowledge);
        horizontalLayout.addComponent(labelNotAcknowledged);

        int status = computeTrend(acknowledged, notAcknowledged);

        severitySum += onmsSeverity.getId();
        overallSum += onmsSeverity.getId() * status;

        Image image = new Image(null, new ThemeResource("img/a" + status + ".png"));
        image.setWidth(width, Sizeable.Unit.PIXELS);
        horizontalLayout.addComponent(image);

        horizontalLayout.setExpandRatio(labelSeverity, 4.0f);
        horizontalLayout.setExpandRatio(labelAcknowledge, 1.0f);
        horizontalLayout.setExpandRatio(labelNotAcknowledged, 1.0f);
        horizontalLayout.setExpandRatio(image, 1.0f);

        horizontalLayout.setComponentAlignment(image, Alignment.TOP_CENTER);

        horizontalLayout.setWidth(375, Sizeable.Unit.PIXELS);
        verticalLayout.addComponent(horizontalLayout);
    }

    int globalTrend = (int) Math.max(0,
            Math.min(4, Math.round(((double) overallSum) / ((double) severitySum))));

    Image image = new Image(null, new ThemeResource("img/a" + globalTrend + ".png"));
    image.setWidth(width * 8, Sizeable.Unit.PIXELS);

    VerticalLayout globalTrendLayout = new VerticalLayout();
    globalTrendLayout.setSpacing(true);
    globalTrendLayout.addStyleName("summary");
    globalTrendLayout.addStyleName("global");
    globalTrendLayout.setSizeFull();

    Label labelTitle = new Label("Alarms trend by severity");
    labelTitle.addStyleName("summary-font");
    labelTitle.setSizeUndefined();

    Label labelTimeslot = new Label("(" + getHumanReadableFormat(m_timeslot) + ")");
    labelTimeslot.addStyleName("summary-font");
    labelTimeslot.setSizeUndefined();

    globalTrendLayout.addComponent(labelTitle);
    globalTrendLayout.addComponent(labelTimeslot);
    globalTrendLayout.addComponent(image);

    globalTrendLayout.setWidth(375, Sizeable.Unit.PIXELS);

    globalTrendLayout.setComponentAlignment(labelTitle, Alignment.MIDDLE_CENTER);
    globalTrendLayout.setComponentAlignment(labelTimeslot, Alignment.MIDDLE_CENTER);
    globalTrendLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER);

    globalTrendLayout.setExpandRatio(labelTitle, 1.0f);

    verticalLayout.addComponent(globalTrendLayout, 0);

    m_boosted = (globalTrend > 2);

    return verticalLayout;
}

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

License:Open Source License

/**
 * Returns the component showing the alarms and the trends by severity
 *
 * @return the {@link Component}/*from   w  w w. j  a  v a 2  s .  com*/
 */
private Component getComponentUei(int width) {
    VerticalLayout verticalLayout = new VerticalLayout();

    int overallSum = 0;
    int severitySum = 0;

    verticalLayout.addComponent(getLegend("UEI"));

    String[] ueis = { "uei.opennms.org/nodes/nodeLostService", "uei.opennms.org/nodes/interfaceDown",
            "uei.opennms.org/nodes/nodeDown" };

    for (int i = 0; i < ueis.length; i++) {
        String uei = ueis[i];
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        horizontalLayout.setSpacing(true);
        horizontalLayout.addStyleName("summary");

        if (i == 0) {
            horizontalLayout.addStyleName(OnmsSeverity.MINOR.name().toLowerCase());
        } else {
            if (i == 1) {
                horizontalLayout.addStyleName(OnmsSeverity.MINOR.name().toLowerCase());
            } else {
                horizontalLayout.addStyleName(OnmsSeverity.MAJOR.name().toLowerCase());
            }
        }

        int acknowledged = countByUei(true, m_timeslot, uei);
        int notAcknowledged = countByUei(false, m_timeslot, uei);

        Label labelSeverity = new Label(uei.replace("uei.opennms.org/nodes/", ""));
        labelSeverity.addStyleName("summary-font");
        Label labelAcknowledge = new Label(String.valueOf(acknowledged));
        labelAcknowledge.addStyleName("summary-font");
        Label labelNotAcknowledged = new Label(String.valueOf(notAcknowledged));
        labelNotAcknowledged.addStyleName("summary-font");

        horizontalLayout.addComponent(labelSeverity);
        horizontalLayout.addComponent(labelAcknowledge);
        horizontalLayout.addComponent(labelNotAcknowledged);

        int status = computeTrend(acknowledged, notAcknowledged);

        severitySum += i;
        overallSum += i * status;

        Image image = new Image(null, new ThemeResource("img/a" + status + ".png"));
        image.setWidth(width, Sizeable.Unit.PIXELS);
        horizontalLayout.addComponent(image);

        horizontalLayout.setExpandRatio(labelSeverity, 4.0f);
        horizontalLayout.setExpandRatio(labelAcknowledge, 1.0f);
        horizontalLayout.setExpandRatio(labelNotAcknowledged, 1.0f);
        horizontalLayout.setExpandRatio(image, 1.0f);

        horizontalLayout.setComponentAlignment(image, Alignment.TOP_CENTER);

        horizontalLayout.setWidth(375, Sizeable.Unit.PIXELS);
        verticalLayout.addComponent(horizontalLayout);
    }

    int globalTrend = (int) Math.max(0,
            Math.min(4, Math.round(((double) overallSum) / ((double) severitySum))));

    Image image = new Image(null, new ThemeResource("img/a" + globalTrend + ".png"));
    image.setWidth(width * 8, Sizeable.Unit.PIXELS);

    VerticalLayout globalTrendLayout = new VerticalLayout();
    globalTrendLayout.setSpacing(true);
    globalTrendLayout.addStyleName("summary");
    globalTrendLayout.addStyleName("global");
    globalTrendLayout.setSizeFull();

    Label labelTitle = new Label("Alarms trend by UEI");
    labelTitle.addStyleName("summary-font");
    labelTitle.setSizeUndefined();

    Label labelTimeslot = new Label("(" + getHumanReadableFormat(m_timeslot) + ")");
    labelTimeslot.addStyleName("summary-font");
    labelTimeslot.setSizeUndefined();

    globalTrendLayout.addComponent(labelTitle);
    globalTrendLayout.addComponent(labelTimeslot);
    globalTrendLayout.addComponent(image);

    globalTrendLayout.setWidth(375, Sizeable.Unit.PIXELS);

    globalTrendLayout.setComponentAlignment(labelTitle, Alignment.MIDDLE_CENTER);
    globalTrendLayout.setComponentAlignment(labelTimeslot, Alignment.MIDDLE_CENTER);
    globalTrendLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER);

    globalTrendLayout.setExpandRatio(labelTitle, 1.0f);

    verticalLayout.addComponent(globalTrendLayout, 0);

    m_boosted = (globalTrend > 2);

    return verticalLayout;
}

From source file:org.vaadin.addons.core.window.DialogWindow.java

License:Apache License

private VerticalLayout buildContent(String title, VaadinIcons type, Component content,
        ButtonType[] buttonTypes) {/*from w w w.j  a va  2  s  .com*/
    VerticalLayout root = new VerticalLayout();
    root.setMargin(false);
    root.setSpacing(false);

    float width = -1;
    float height = 0;

    if (title != null) {
        HorizontalLayout header = new HorizontalLayout();
        header.setMargin(true);
        header.setHeightUndefined();
        header.setWidth("100%");
        header.addStyleName(ValoTheme.WINDOW_TOP_TOOLBAR);
        Label l = new Label("<font size=\"4\">" + title + "</font>", ContentMode.HTML);
        width = l.getWidth();
        header.addComponent(l);
        header.setComponentAlignment(l, Alignment.MIDDLE_LEFT);

        if (type != null) {
            Label i = new Label(type.getHtml(), ContentMode.HTML);
            header.addComponent(i);
            header.setComponentAlignment(i, Alignment.MIDDLE_RIGHT);
        }

        height = header.getHeight();
        root.addComponent(header);
    }

    if (content != null) {
        content.setSizeFull();
        HorizontalLayout contentRoot = new HorizontalLayout(content);
        contentRoot.setMargin(true);
        root.addComponent(contentRoot);
        height = height + contentRoot.getHeight();
    }

    HorizontalLayout footer = new HorizontalLayout();
    footer.setHeightUndefined();
    footer.setWidth("100%");
    footer.setMargin(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    HorizontalLayout buttons = new HorizontalLayout();
    if (buttonTypes != null) {
        Stream.of(buttonTypes).forEach(buttonType -> {
            Button b = new Button(buttonType.getCaption());
            if (buttonType.getIcon() != null) {
                b.setIcon(buttonType.getIcon());
            }
            if (buttonType.getDescription() != null) {
                b.setDescription(buttonType.getDescription());
            }
            if (buttonType.getStyle() != null) {
                b.addStyleName(buttonType.getStyle());
            }
            b.addClickListener(event -> buttonType.getActions().forEach(buttonAction -> {
                ButtonTypeClickEvent event1 = new ButtonTypeClickEvent(buttonType, DialogWindow.this);
                buttonAction.getListener().buttonClick(event1);
            }));
            buttons.addComponent(b);
        });
    }
    buttons.setSizeUndefined();
    buttons.setMargin(false);
    buttons.setSpacing(true);

    footer.addComponent(buttons);
    footer.setComponentAlignment(buttons, Alignment.MIDDLE_RIGHT);

    if (buttons.getWidth() > width) {
        width = buttons.getWidth();
    }

    root.addComponent(footer);
    root.setComponentAlignment(footer, Alignment.BOTTOM_LEFT);
    height = height + footer.getHeight();

    root.setHeight(height, Unit.PIXELS);
    root.setWidth(width, Unit.PIXELS);
    return root;
}

From source file:org.vaadin.alump.fancylayouts.demo.CssLayoutDemo.java

License:Apache License

private void addCssLayoutContent(final FancyCssLayout layout) {
    final HorizontalLayout hLayout = new HorizontalLayout();
    hLayout.addStyleName("demo-removable-layout");

    if (boxMode) {
        hLayout.addStyleName("demo-removable-two");
    }//from w w w.j a v  a2 s. c o  m

    hLayout.setSpacing(true);
    hLayout.setWidth("100%");
    Button remove = new Button("");
    remove.addStyleName("remove-button");
    remove.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            layout.fancyRemoveComponent(hLayout);
        }
    });
    hLayout.addComponent(remove);
    hLayout.setComponentAlignment(remove, Alignment.MIDDLE_CENTER);

    VerticalLayout vLayout = new VerticalLayout();
    vLayout.setWidth("100%");
    hLayout.addComponent(vLayout);
    hLayout.setExpandRatio(vLayout, 1.0f);

    Label label = new Label("Entry #" + (++layoutCounter));
    label.addStyleName("demo-big-label");
    vLayout.addComponent(label);

    Label label2 = new Label("Lorem ipsum, foo bar?");
    label2.addStyleName("demo-small-label-" + String.valueOf(layoutCounter % 4));
    vLayout.addComponent(label2);

    if (addCssMiddle) {
        layout.addComponent(hLayout, layout.getComponentCount() / 2);
    } else {
        layout.addComponent(hLayout);
    }
}

From source file:org.vaadin.spring.samples.security.ui.login.views.LoginView.java

License:Apache License

private Component buildFields() {
    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);/*from   w ww .  j a va  2 s. c  om*/
    fields.addStyleName("fields");

    username = new TextField("Username");
    username.setIcon(FontAwesome.USER);
    username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    password = new PasswordField("Password");
    password.setIcon(FontAwesome.LOCK);
    password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final Button signin = new Button("Sign In");
    signin.addStyleName(ValoTheme.BUTTON_PRIMARY);
    signin.setClickShortcut(KeyCode.ENTER);
    signin.focus();

    fields.addComponents(username, password, signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    signin.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {

            try {

                security.login(username.getValue(), password.getValue());

            } catch (AuthenticationException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            // TODO Register Remember me Token

            /*
             * Redirect is handled by the VaadinRedirectStrategy
             * User is redirected to either always the default
             * or the URL the user request before authentication
             * 
             * Strategy is configured within SecurityConfiguration
             * Defaults to User request URL.
             */
        }
    });

    return fields;
}

From source file:org.vaadin.tori.component.AuthoringComponent.java

License:Apache License

private Component buildButtons() {
    HorizontalLayout result = new HorizontalLayout();
    result.addStyleName("buttonslayout");
    result.setWidth(100.0f, Unit.PERCENTAGE);
    result.setSpacing(true);//w  ww  .  j  a va2  s . c om
    result.setMargin(true);
    postButton = new Button("Post Reply", new Button.ClickListener() {

        @Override
        public void buttonClick(final ClickEvent event) {
            if (editor.getValue().trim().isEmpty()) {
                postButton.setEnabled(true);
            } else {
                listener.submit(editor.getValue(), attachments, followCheckbox.getValue());
            }
        }
    });
    postButton.setDisableOnClick(true);
    result.addComponent(postButton);

    attach = buildAttachUpload();
    result.addComponent(attach);
    followCheckbox = new CheckBox("Follow topic after posting", true);
    result.addComponent(followCheckbox);
    result.setComponentAlignment(followCheckbox, Alignment.MIDDLE_RIGHT);

    result.setExpandRatio(attach, 1.0f);
    result.setExpandRatio(followCheckbox, 1.0f);

    return result;
}