Example usage for com.vaadin.ui VerticalLayout setDefaultComponentAlignment

List of usage examples for com.vaadin.ui VerticalLayout setDefaultComponentAlignment

Introduction

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

Prototype

@Override
    public void setDefaultComponentAlignment(Alignment defaultAlignment) 

Source Link

Usage

From source file:de.gedoplan.webclients.vaadin.LoginUi.java

@Override
protected void init(VaadinRequest request) {
    TextField name = new TextField(Messages.login_name.value());
    name.focus();/*from  www .  ja  v  a  2  s.c  o  m*/
    PasswordField password = new PasswordField(Messages.login_password.value());
    Button login = new Button(Messages.login_submit.value(), e -> {
        try {
            JaasAccessControl.login(name.getValue(), password.getValue());
            Page.getCurrent().setLocation(Konstanten.VAADIN_UI_PATH);
        } catch (ServletException ex) {
            Notification.show(Messages.login_invalid.value(), Notification.Type.ERROR_MESSAGE);
        }
    });
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    FormLayout fieldLayout = new FormLayout(name, password, login);
    fieldLayout.setMargin(true);
    fieldLayout.setSpacing(true);
    Panel loginPanel = new Panel(Messages.login_title.value(), fieldLayout);
    loginPanel.setSizeUndefined();
    VerticalLayout page = new VerticalLayout();
    page.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    page.addComponent(loginPanel);
    page.setSizeFull();
    setContent(page);
}

From source file:de.gedoplan.webclients.vaadin.VaadinDemoUi.java

public Panel createFooter() {
    Panel footer = new Panel();
    footer.setStyleName(ValoTheme.PANEL_WELL);
    footer.setHeight(75, Unit.PIXELS);//from   w  ww .  j  a  va2  s . c om
    Label footerText = new Label(" 2016 gedoplan.de");
    footerText.setSizeUndefined();
    VerticalLayout footerLayout = new VerticalLayout();
    footerLayout.setSizeFull();
    footerLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    footerLayout.addComponent(footerText);
    footer.setContent(footerLayout);
    return footer;
}

From source file:lifetime.component.welcome.register.RegistrationForm.java

License:Apache License

public RegistrationForm(String language) {
    super();//from ww  w.j  ava2s .c o m
    setSizeUndefined();
    setMargin(true);
    setSpacing(true);
    Label text = new Label("Register");
    setSpacing(true);
    text.setStyleName("login");

    defaultLanguage = new LocalesComboBox(language);
    /* Creates the firstname text field and registers a validator */
    firstname = new LifetimeTextField("Firstname"); // Creates text field
    firstname.addValidator(new NameValidator()); // Register Validator
    firstname.setValidationVisible(true); // Automatic validation
    firstname.setId(StyleClassName.REGISTRATION_FORM_FIRSTNAME.getId());

    /* Creates lastnames text field and registers a validator */
    lastname = new LifetimeTextField("Lastname");
    lastname.addValidator(new NameValidator());
    lastname.setValidationVisible(true);
    lastname.setRequired(true);
    lastname.setId(StyleClassName.REGISTRATION_FORM_LASTNAME.getId());

    /* Creates email text field and registers a validator */
    email = new LifetimeTextField("Email / Username");
    email.addValidator(new EmailValidator("Invalid email address"));
    email.setValidationVisible(true);
    email.setId(StyleClassName.REGISTRATION_FORM_EMAIL.getId());

    /* Creates password text field and registers a validator */
    password = new PasswordField("Password");
    password.addValidator(new PasswordValidator());
    password.setId(StyleClassName.REGISTRATION_FORM_ENCRYPTED.getId());

    passwordRepeat = new PasswordField("Repeat password");
    passwordRepeat.setId(StyleClassName.REGISTRATION_FORM_ENCRYPTED_REPEAT.getId());

    birthDate = new DateField("Birthdate");
    birthDate.setLocale(new Locale(language));
    birthDate.setId(StyleClassName.REGISTRATION_FORM_BIRTHDATE.getId());

    //
    birthPlace = new LifetimeTextField("Birth place");
    birthPlace.setId(StyleClassName.REGISTRATION_FORM_BIRTHPLACE.getId());

    VerticalLayout personalData = new VerticalLayout(defaultLanguage, firstname, lastname, email, password,
            passwordRepeat);
    VerticalLayout birthData = new VerticalLayout(birthDate, birthPlace);
    birthData.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
    addComponents(personalData, birthData);
    setStyleName(StyleClassName.REGISTRATION_FORM.getStyleName());
    setId(StyleClassName.REGISTRATION_FORM.getId());
}

From source file:lu.uni.lassy.excalibur.examples.icrash.dev.web.java.views.AdminAuthView.java

License:Open Source License

public AdminAuthView() {

    setSizeFull();/* ww  w.j  ava  2  s .  co m*/

    VerticalLayout header = new VerticalLayout();
    header.setSizeFull();

    HorizontalLayout content = new HorizontalLayout();
    content.setSizeFull();

    addComponents(header, content);
    setExpandRatio(header, 1);
    setExpandRatio(content, 6);

    welcomeText.setValue("<h1>Welcome to the iCrash Administrator console!</h1>");
    welcomeText.setContentMode(ContentMode.HTML);
    welcomeText.setSizeUndefined();
    header.addComponent(welcomeText);
    header.setComponentAlignment(welcomeText, Alignment.MIDDLE_CENTER);

    Panel controlPanel = new Panel("Administrator control panel");
    controlPanel.setSizeUndefined();

    Panel addCoordPanel = new Panel("Create a new coordinator");
    addCoordPanel.setSizeUndefined();

    Panel messagesPanel = new Panel("Administrator messages");
    messagesPanel.setWidth("580px");

    Table adminMessagesTable = new Table();

    adminMessagesTable.setContainerDataSource(actAdmin.getMessagesDataSource());

    adminMessagesTable.setColumnWidth("inputEvent", 180);
    adminMessagesTable.setSizeFull();

    VerticalLayout controlLayout = new VerticalLayout(controlPanel);
    controlLayout.setSizeFull();
    controlLayout.setMargin(false);
    controlLayout.setComponentAlignment(controlPanel, Alignment.TOP_CENTER);

    VerticalLayout coordOperationsLayout = new VerticalLayout(addCoordPanel);
    coordOperationsLayout.setSizeFull();
    coordOperationsLayout.setMargin(false);
    coordOperationsLayout.setComponentAlignment(addCoordPanel, Alignment.TOP_CENTER);

    /******************************************/
    coordOperationsLayout.setVisible(true); // main layout in the middle
    addCoordPanel.setVisible(false); // ...which contains the panel "Create a new coordinator"
    /******************************************/

    HorizontalLayout messagesExternalLayout = new HorizontalLayout(messagesPanel);
    VerticalLayout messagesInternalLayout = new VerticalLayout(adminMessagesTable);

    messagesExternalLayout.setSizeFull();
    messagesExternalLayout.setMargin(false);
    messagesExternalLayout.setComponentAlignment(messagesPanel, Alignment.TOP_CENTER);

    messagesInternalLayout.setMargin(false);
    messagesInternalLayout.setSizeFull();
    messagesInternalLayout.setComponentAlignment(adminMessagesTable, Alignment.TOP_CENTER);

    messagesPanel.setContent(messagesInternalLayout);

    TextField idCoordAdd = new TextField();
    TextField loginCoord = new TextField();
    PasswordField pwdCoord = new PasswordField();

    Label idCaptionAdd = new Label("ID");
    Label loginCaption = new Label("Login");
    Label pwdCaption = new Label("Password");

    idCaptionAdd.setSizeUndefined();
    idCoordAdd.setSizeUndefined();

    loginCaption.setSizeUndefined();
    loginCoord.setSizeUndefined();

    pwdCaption.setSizeUndefined();
    pwdCoord.setSizeUndefined();

    Button validateNewCoord = new Button("Validate");
    validateNewCoord.setClickShortcut(KeyCode.ENTER);
    validateNewCoord.setStyleName(ValoTheme.BUTTON_PRIMARY);

    GridLayout addCoordinatorLayout = new GridLayout(2, 4);
    addCoordinatorLayout.setSpacing(true);
    addCoordinatorLayout.setMargin(true);
    addCoordinatorLayout.setSizeFull();

    addCoordinatorLayout.addComponents(idCaptionAdd, idCoordAdd, loginCaption, loginCoord, pwdCaption,
            pwdCoord);

    addCoordinatorLayout.addComponent(validateNewCoord, 1, 3);

    addCoordinatorLayout.setComponentAlignment(idCaptionAdd, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(idCoordAdd, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(loginCaption, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(loginCoord, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(pwdCaption, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(pwdCoord, Alignment.MIDDLE_LEFT);

    addCoordPanel.setContent(addCoordinatorLayout);

    content.addComponents(controlLayout, coordOperationsLayout, messagesExternalLayout);
    content.setComponentAlignment(messagesExternalLayout, Alignment.TOP_CENTER);
    content.setComponentAlignment(controlLayout, Alignment.TOP_CENTER);
    content.setComponentAlignment(messagesExternalLayout, Alignment.TOP_CENTER);

    content.setExpandRatio(controlLayout, 20);
    content.setExpandRatio(coordOperationsLayout, 10);
    content.setExpandRatio(messagesExternalLayout, 28);

    Button addCoordinator = new Button("Add coordinator");
    Button deleteCoordinator = new Button("Delete coordinator");

    addCoordinator.addStyleName(ValoTheme.BUTTON_HUGE);
    deleteCoordinator.addStyleName(ValoTheme.BUTTON_HUGE);
    logoutBtn.addStyleName(ValoTheme.BUTTON_HUGE);

    VerticalLayout buttons = new VerticalLayout();

    buttons.setMargin(true);
    buttons.setSpacing(true);
    buttons.setSizeFull();

    buttons.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    controlPanel.setContent(buttons);

    buttons.addComponents(addCoordinator, deleteCoordinator, logoutBtn);

    /******* DELETE COORDINATOR PANEL BEGIN *********/
    Label idCaptionDel = new Label("ID");
    TextField idCoordDel = new TextField();

    Panel delCoordPanel = new Panel("Delete a coordinator");

    coordOperationsLayout.addComponent(delCoordPanel);
    delCoordPanel.setVisible(false);

    coordOperationsLayout.setComponentAlignment(delCoordPanel, Alignment.TOP_CENTER);
    delCoordPanel.setSizeUndefined();

    GridLayout delCoordinatorLayout = new GridLayout(2, 2);
    delCoordinatorLayout.setSpacing(true);
    delCoordinatorLayout.setMargin(true);
    delCoordinatorLayout.setSizeFull();

    Button deleteCoordBtn = new Button("Delete");
    deleteCoordBtn.setClickShortcut(KeyCode.ENTER);
    deleteCoordBtn.setStyleName(ValoTheme.BUTTON_PRIMARY);

    delCoordinatorLayout.addComponents(idCaptionDel, idCoordDel);

    delCoordinatorLayout.addComponent(deleteCoordBtn, 1, 1);

    delCoordinatorLayout.setComponentAlignment(idCaptionDel, Alignment.MIDDLE_LEFT);
    delCoordinatorLayout.setComponentAlignment(idCoordDel, Alignment.MIDDLE_LEFT);

    delCoordPanel.setContent(delCoordinatorLayout);
    /******* DELETE COORDINATOR PANEL END *********/

    /************************************************* MAIN BUTTONS LOGIC BEGIN *************************************************/

    addCoordinator.addClickListener(event -> {
        if (!addCoordPanel.isVisible()) {
            delCoordPanel.setVisible(false);
            addCoordPanel.setVisible(true);
            idCoordAdd.focus();
        } else
            addCoordPanel.setVisible(false);
    });

    deleteCoordinator.addClickListener(event -> {
        if (!delCoordPanel.isVisible()) {
            addCoordPanel.setVisible(false);
            delCoordPanel.setVisible(true);
            idCoordDel.focus();
        } else
            delCoordPanel.setVisible(false);
    });

    /************************************************* MAIN BUTTONS LOGIC END *************************************************/

    /************************************************* ADD COORDINATOR FORM LOGIC BEGIN *************************************************/
    validateNewCoord.addClickListener(event -> {

        String currentURL = Page.getCurrent().getLocation().toString();
        int strIndexCreator = currentURL.lastIndexOf(AdministratorLauncher.adminPageName);
        String iCrashURL = currentURL.substring(0, strIndexCreator);
        String googleShebang = "#!";
        String coordURL = iCrashURL + CoordinatorServlet.coordinatorsName + googleShebang;

        try {
            sys.oeAddCoordinator(new DtCoordinatorID(new PtString(idCoordAdd.getValue())),
                    new DtLogin(new PtString(loginCoord.getValue())),
                    new DtPassword(new PtString(pwdCoord.getValue())));

            // open new browser tab with the newly created coordinator console...
            // "_blank" instructs the browser to open a new tab instead of a new window...
            // unhappily not all browsers interpret it correctly,
            // some versions of some browsers might still open a new window instead (notably Firefox)!
            Page.getCurrent().open(coordURL + idCoordAdd.getValue(), "_blank");

        } catch (Exception e) {
            e.printStackTrace();
        }

        idCoordAdd.setValue("");
        loginCoord.setValue("");
        pwdCoord.setValue("");

        idCoordAdd.focus();
    });
    /************************************************* ADD COORDINATOR FORM LOGIC END *************************************************/
    /************************************************* DELETE COORDINATOR FORM LOGIC BEGIN *************************************************/
    deleteCoordBtn.addClickListener(event -> {
        IcrashSystem sys = IcrashSystem.getInstance();

        try {
            sys.oeDeleteCoordinator(new DtCoordinatorID(new PtString(idCoordDel.getValue())));
        } catch (Exception e) {
            e.printStackTrace();
        }

        idCoordDel.setValue("");
        idCoordDel.focus();
    });
    /************************************************* DELETE COORDINATOR FORM LOGIC END *************************************************/
}

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

License:Open Source License

private Component createMapLayout() {
    final Property<Double> scale = m_graphContainer.getScaleProperty();

    m_lastUpdatedTimeLabel = new LastUpdatedLabel();
    m_lastUpdatedTimeLabel.setImmediate(true);

    m_zoomLevelLabel.setHeight(20, Unit.PIXELS);
    m_zoomLevelLabel.setWidth(22, Unit.PIXELS);
    m_zoomLevelLabel.addStyleName("center-text");
    m_zoomLevelLabel.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override/*from   w w  w  .j  ava  2  s  . co  m*/
        public void textChange(FieldEvents.TextChangeEvent event) {
            try {
                int zoomLevel = Integer.parseInt(event.getText());
                setSemanticZoomLevel(zoomLevel);
            } catch (NumberFormatException e) {
                setSemanticZoomLevel(m_graphContainer.getSemanticZoomLevel());
            }

        }
    });

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

    final Slider slider = new Slider(0, 1);
    slider.setPropertyDataSource(scale);
    slider.setResolution(1);
    slider.setHeight("200px");
    slider.setOrientation(SliderOrientation.VERTICAL);

    slider.setImmediate(true);

    final NativeButton showFocusVerticesBtn = new NativeButton(FontAwesomeIcons.Icon.eye_open.variant());
    showFocusVerticesBtn.setDescription("Toggle Highlight Focus Nodes");
    showFocusVerticesBtn.setHtmlContentAllowed(true);
    showFocusVerticesBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (showFocusVerticesBtn.getCaption().equals(FontAwesomeIcons.Icon.eye_close.variant())) {
                showFocusVerticesBtn.setCaption(FontAwesomeIcons.Icon.eye_open.variant());
            } else {
                showFocusVerticesBtn.setCaption(FontAwesomeIcons.Icon.eye_close.variant());
            }
            m_topologyComponent.getState()
                    .setHighlightFocus(!m_topologyComponent.getState().isHighlightFocus());
            m_topologyComponent.updateGraph();
        }
    });

    final NativeButton magnifyBtn = new NativeButton();
    magnifyBtn.setHtmlContentAllowed(true);
    magnifyBtn.setCaption("<i class=\"" + FontAwesomeIcons.Icon.zoom_in.stylename() + "\" ></i>");
    magnifyBtn.setStyleName("icon-button");
    magnifyBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (slider.getValue() < 1) {
                slider.setValue(Math.min(1, slider.getValue() + 0.25));
            }
        }
    });

    final NativeButton demagnifyBtn = new NativeButton();
    demagnifyBtn.setHtmlContentAllowed(true);
    demagnifyBtn.setCaption("<i class=\"" + FontAwesomeIcons.Icon.zoom_out.stylename() + "\" ></i>");
    demagnifyBtn.setStyleName("icon-button");
    demagnifyBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (slider.getValue() != 0) {
                slider.setValue(Math.max(0, slider.getValue() - 0.25));
            }
        }
    });

    VerticalLayout sliderLayout = new VerticalLayout();
    sliderLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    sliderLayout.addComponent(magnifyBtn);
    sliderLayout.addComponent(slider);
    sliderLayout.addComponent(demagnifyBtn);

    m_szlOutBtn = new Button();
    m_szlOutBtn.setHtmlContentAllowed(true);
    m_szlOutBtn.setCaption(FontAwesomeIcons.Icon.arrow_down.variant());
    m_szlOutBtn.setDescription("Collapse Semantic Zoom Level");
    m_szlOutBtn.setEnabled(m_graphContainer.getSemanticZoomLevel() > 0);
    m_szlOutBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            int szl = m_graphContainer.getSemanticZoomLevel();
            if (szl > 0) {
                szl--;
                setSemanticZoomLevel(szl);
                saveHistory();
            }
        }
    });

    final Button szlInBtn = new Button();
    szlInBtn.setHtmlContentAllowed(true);
    szlInBtn.setCaption(FontAwesomeIcons.Icon.arrow_up.variant());
    szlInBtn.setDescription("Expand Semantic Zoom Level");
    szlInBtn.addClickListener(new ClickListener() {

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

    m_panBtn = new Button();
    m_panBtn.setIcon(FontAwesome.ARROWS);
    m_panBtn.setDescription("Pan Tool");
    m_panBtn.setStyleName("toolbar-button down");

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

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

    m_panBtn.addClickListener(new ClickListener() {

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

    final Button historyBackBtn = new Button(FontAwesomeIcons.Icon.arrow_left.variant());
    historyBackBtn.setHtmlContentAllowed(true);
    historyBackBtn.setDescription("Click to go back");
    historyBackBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            com.vaadin.ui.JavaScript.getCurrent().execute("window.history.back()");
        }
    });

    final Button historyForwardBtn = new Button(FontAwesomeIcons.Icon.arrow_right.variant());
    historyForwardBtn.setHtmlContentAllowed(true);
    historyForwardBtn.setDescription("Click to go forward");
    historyForwardBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            com.vaadin.ui.JavaScript.getCurrent().execute("window.history.forward()");
        }
    });

    m_searchBox = new SearchBox(m_serviceManager, new CommandManager.DefaultOperationContext(this,
            m_graphContainer, OperationContext.DisplayLocation.SEARCH));

    //History Button Layout
    HorizontalLayout historyButtonLayout = new HorizontalLayout();
    historyButtonLayout.setSpacing(true);
    historyButtonLayout.addComponent(historyBackBtn);
    historyButtonLayout.addComponent(historyForwardBtn);

    //Semantic Controls Layout
    HorizontalLayout semanticLayout = new HorizontalLayout();
    semanticLayout.setSpacing(true);
    semanticLayout.addComponent(szlInBtn);
    semanticLayout.addComponent(m_zoomLevelLabel);
    semanticLayout.addComponent(m_szlOutBtn);
    semanticLayout.setComponentAlignment(m_zoomLevelLabel, Alignment.MIDDLE_CENTER);

    VerticalLayout historyCtrlLayout = new VerticalLayout();
    historyCtrlLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    historyCtrlLayout.addComponent(historyButtonLayout);

    HorizontalLayout controlLayout = new HorizontalLayout();
    controlLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    controlLayout.addComponent(m_panBtn);
    controlLayout.addComponent(m_selectBtn);

    VerticalLayout semanticCtrlLayout = new VerticalLayout();
    semanticCtrlLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    semanticCtrlLayout.addComponent(semanticLayout);

    HorizontalLayout locationToolLayout = createLocationToolLayout();

    //Vertical Layout for all tools on right side
    VerticalLayout toollayout = new VerticalLayout();
    toollayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    toollayout.setSpacing(true);

    toollayout.addComponent(historyCtrlLayout);
    toollayout.addComponent(locationToolLayout);
    toollayout.addComponent(showFocusVerticesBtn);
    toollayout.addComponent(sliderLayout);
    toollayout.addComponent(controlLayout);
    toollayout.addComponent(semanticCtrlLayout);

    AbsoluteLayout mapLayout = new AbsoluteLayout();
    mapLayout.addComponent(m_topologyComponent, "top:0px; left: 0px; right: 0px; bottom: 0px;");
    mapLayout.addComponent(m_lastUpdatedTimeLabel, "top: 5px; right: 10px;");
    mapLayout.addComponent(toollayout, "top: 25px; right: 10px;");
    mapLayout.setSizeFull();

    m_infoPanel = new InfoPanel(m_searchBox, mapLayout);
    return m_infoPanel;
}

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 . jav  a 2 s  .  co 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();

            {/*w  w w.  j  a 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//from  w  w w.ja v a2  s  .c  o  m
 * @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.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 ww w .  j  av a 2 s . c om*/
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);
}

From source file:org.opennms.features.vaadin.pmatrix.ui.PmatrixApplication.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setWidth("-1px");
    layout.setHeight("-1px");
    layout.setDefaultComponentAlignment(Alignment.TOP_LEFT);
    layout.setMargin(true);//from   w w w  . j  a v a 2  s  .  c o m
    setContent(layout);

    //used to test that detach events are happening
    addDetachListener(new DetachListener() {
        @Override
        public void detach(DetachEvent event) {
            LOG.debug("Pmatrix UI instance detached:" + this);
        }
    });

    Component uiComponent = uiComponentFactory.getUiComponent(request);

    if (uiComponent == null) {

        StringBuilder sb = new StringBuilder(
                "Error: Cannot create the UI because the URL request parameters are not recognised<BR>\n"
                        + "you need to provide atleast '?" + UiComponentFactory.COMPONENT_REQUEST_PARAMETER
                        + "=" + UiComponentFactory.DEFAULT_COMPONENT_REQUEST_VALUE + "'<BR>\n"
                        + "Parameters passed in URL:<BR>\n");
        for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
            sb.append("parameter:'" + entry.getKey() + "' value:'");
            for (String s : entry.getValue()) {
                sb.append("{" + s + "}");
            }
            sb.append("'<BR>\n");
        }
        Label label = new Label();
        label.setWidth("600px");
        label.setContentMode(ContentMode.HTML);
        label.setValue(sb.toString());
        layout.addComponent(label);

    } else {
        layout.addComponent(uiComponent);

        // refresh interval to apply to the UI
        int pollInterval = uiComponentFactory.getRefreshRate();
        setPollInterval(pollInterval);

        // display poll interval in seconds
        DecimalFormat dformat = new DecimalFormat("##.##");
        Label label = new Label();
        label.setCaption("(refresh rate:" + dformat.format(pollInterval / 1000) + " seconds)");
        layout.addComponent(label);
    }

}