Example usage for com.vaadin.ui CssLayout addComponent

List of usage examples for com.vaadin.ui CssLayout addComponent

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:org.kani.Application.java

License:Apache License

private void loadProtectedResources() {
    String applicationTitle = getMessage("title");
    main = new Window(applicationTitle);
    mainLayout = (VerticalLayout) main.getContent();
    mainLayout.setMargin(false);// ww w .  j a  va 2s.co  m
    mainLayout.setStyleName("blue");
    setMainWindow(main);

    mainLayout.setSizeFull();
    mainLayout.addComponent(getMenu());

    HorizontalLayout header = new HorizontalLayout();

    header.addComponent(getHeader());
    header.addComponent(getToolbar());
    mainLayout.addComponent(header);

    CssLayout margin = new CssLayout();
    margin.setMargin(false, true, true, true);
    margin.setSizeFull();
    tabSheet = new TabSheet();
    tabSheet.setSizeFull();
    margin.addComponent(tabSheet);
    mainLayout.addComponent(margin);
    mainLayout.setExpandRatio(margin, 1);

    for (String viewKey : views.keySet()) {
        Object view = views.get(viewKey);
        String viewName = getMessage(viewKey, "title");
        Method createMethod;
        try {
            createMethod = view.getClass().getMethod("create", org.kani.Application.class);
            Component viewContent = (Component) createMethod.invoke(view, this);

            String viewIconPath = getMessage(viewKey, "icon");
            Resource viewIcon = new ClassResource(viewIconPath, this);

            tabSheet.addTab(viewContent, viewName, viewIcon);
        } catch (Exception e) {
            logger.log(Level.SEVERE, String.format("Could not initialize view %s", viewKey), e);
        }
    }
}

From source file:org.kani.Application.java

License:Apache License

private Layout getHeader() {
    HorizontalLayout header = new HorizontalLayout();
    header.setWidth("100%");
    header.setMargin(true);/*from ww w .  j a  v a 2s. co m*/
    header.setSpacing(true);

    CssLayout titleLayout = new CssLayout();

    String applicationTitle = getMessage("title");
    H1 title = new H1(applicationTitle);
    titleLayout.addComponent(title);

    String applicationDescription = getMessage("description");
    SmallText description = new SmallText(applicationDescription);
    description.setSizeUndefined();
    titleLayout.addComponent(description);
    titleLayout.addComponent(description);

    header.addComponent(titleLayout);

    return header;
}

From source file:org.kani.Application.java

License:Apache License

private Window getAboutDialog() {
    if (aboutWindow == null) {
        aboutWindow = new Window("About...");
        aboutWindow.setModal(true);// www  . jav  a  2  s .co  m
        aboutWindow.setWidth("400px");

        VerticalLayout layout = (VerticalLayout) aboutWindow.getContent();
        layout.setMargin(true);
        layout.setSpacing(true);
        layout.setStyleName("blue");

        CssLayout titleLayout = new CssLayout();
        H2 title = new H2("Dynamic Vaadin OSGi Demo");
        titleLayout.addComponent(title);
        SmallText description = new SmallText("<br>Copyright ?? and others.<br>"
                + "The icons are from the Silk icon set by Mark James<br>"
                + "<a href=\"http://www.famfamfam.com/lab/icons/silk/\">http://www.famfamfam.com/lab/icons/silk/</a>");
        description.setSizeUndefined();
        description.setContentMode(Label.CONTENT_XHTML);

        titleLayout.addComponent(description);
        aboutWindow.addComponent(titleLayout);

        Button close = new Button("Close", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                (aboutWindow.getParent()).removeWindow(aboutWindow);
            }

        });
        layout.addComponent(close);
        layout.setComponentAlignment(close, Alignment.MIDDLE_RIGHT);
    }
    return aboutWindow;
}

From source file:org.lucidj.browser.BrowserView.java

License:Apache License

private void build_toolbar() {
    current_toolbar = new CssLayout();

    CssLayout local_toolbar = new CssLayout();
    current_toolbar.addComponent(local_toolbar);

    CssLayout navigation = new CssLayout();
    navigation.addStyleName("v-component-group");
    navigation.addStyleName("ui-toolbar-spacer");
    createButton(navigation, "prev-smartbox", FontAwesome.CHEVRON_LEFT, null, ShortcutAction.KeyCode.ARROW_UP,
            ShortcutAction.ModifierKey.CTRL);
    createButton(navigation, "next-smartbox", FontAwesome.CHEVRON_RIGHT, null,
            ShortcutAction.KeyCode.ARROW_DOWN, ShortcutAction.ModifierKey.CTRL);
    local_toolbar.addComponent(navigation);

    createButton(local_toolbar, "save", FontAwesome.SAVE).addStyleName("ui-toolbar-spacer");
    //        createButton (local_toolbar, "test", FontAwesome.MAGIC)
    //            .addStyleName("ui-toolbar-spacer");
    //        createButton (local_toolbar, "test2", FontAwesome.FLASK)
    //                .addStyleName("ui-toolbar-spacer");

    CssLayout edition = new CssLayout();
    edition.addStyleName("v-component-group");
    edition.addStyleName("ui-toolbar-spacer");
    createButton(edition, "undo-cell-edit", FontAwesome.UNDO, "Undo");
    createButton(edition, "redo-cell-edit", FontAwesome.REPEAT, null);
    createButton(edition, "delete-cell", FontAwesome.TRASH_O, null);
    local_toolbar.addComponent(edition);

    CssLayout view_controls = new CssLayout();
    view_controls.addStyleName("v-component-group");
    view_controls.addStyleName("ui-toolbar-spacer");
    createButton(view_controls, VM_NOTEBOOK,
            new ExternalResource("vaadin://~/Browser_libraries/notebook-view.png"));
    createButton(view_controls, VM_SINGLE, new ExternalResource("vaadin://~/Browser_libraries/single-view.png"),
            null, ShortcutAction.KeyCode.INSERT, ShortcutAction.ModifierKey.CTRL);
    local_toolbar.addComponent(view_controls);

    // TODO: CTRL+ENTER => RUN AND SKIP TO NEXT
    // TODO: SELECTION + SHIFT+ENTER => RUN ONLY SELECTED STATEMENTS

    final Button source_view = new Button();
    source_view.setId("output");
    source_view.addStyleName("ui-toolbar-spacer");
    source_view.setHtmlContentAllowed(true);
    String ico = "<path class=\"path1\" d=\"M1088 128h-64v-64c0-35.2-28.8-64-64-64h-896c-35.2 0-64 28.8-64 64v768c0 35.2 28.8 64 64 64h64v64c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64v-768c0-35.2-28.8-64-64-64zM128 192v640h-63.886c-0.040-0.034-0.082-0.076-0.114-0.116v-767.77c0.034-0.040 0.076-0.082 0.114-0.114h895.77c0.040 0.034 0.082 0.076 0.116 0.116v63.884h-768c-35.2 0-64 28.8-64 64v0zM1088 959.884c-0.034 0.040-0.076 0.082-0.116 0.116h-895.77c-0.040-0.034-0.082-0.076-0.114-0.116v-767.77c0.034-0.040 0.076-0.082 0.114-0.114h895.77c0.040 0.034 0.082 0.076 0.116 0.116v767.768z\"></path>\n"
            + "<path class=\"path2\" d=\"M960 352c0 53.020-42.98 96-96 96s-96-42.98-96-96 42.98-96 96-96 96 42.98 96 96z\"></path>\n"
            + "<path class=\"path3\" d=\"M1024 896h-768v-128l224-384 256 320h64l224-192z\"></path>";
    source_view.setCaption(/*from w  w  w . j a  va2  s  .  co m*/
            "<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1152 1024\">"
                    + ico + "</svg>");
    source_view.addStyleName("tiny");
    source_view.addStyleName("toolbar");
    source_view.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            handle_button_click(source_view);
        }
    });
    local_toolbar.addComponent(source_view);

    //        Button output_view = new Button ();
    //        output_view.setHtmlContentAllowed(true);
    //        String ico2 = "<path d=\"M249.649 792.806l-107.776 166.4 11.469 54.426 54.272-11.622 107.725-166.298c-11.469-6.144-22.835-12.698-33.843-19.968-11.162-7.219-21.811-14.95-31.846-22.938zM705.943 734.694c0.717-1.485 1.178-3.123 1.843-4.71 2.714-5.99 5.12-11.981 7.066-18.278 0.307-1.126 0.461-2.253 0.819-3.277 1.997-6.963 3.686-13.824 5.018-20.89 0-0.358 0-0.614 0-1.075 9.984-59.853-7.424-126.618-47.258-186.931l56.832-87.757c65.485 8.346 122.112-8.141 149.35-50.278 47.258-72.858-10.24-194.15-128.256-271.002-118.118-76.902-252.058-80.128-299.213-7.373-27.341 42.189-19.354 100.71 15.002 157.338l-56.934 87.757c-71.117-11.93-139.059-0.819-189.594 32.768-0.307 0.102-0.666 0.205-0.87 0.41-5.888 3.994-11.622 8.397-16.998 13.005-0.87 0.717-1.894 1.382-2.611 2.099-5.018 4.301-9.523 9.114-13.875 13.926-1.024 1.229-2.458 2.304-3.43 3.584-5.427 6.195-10.445 12.749-14.848 19.712-70.861 109.21-10.394 274.483 134.81 369.101 145.306 94.618 320.512 82.637 391.219-26.573 4.454-6.912 8.55-14.131 11.93-21.555zM664.215 224.845c-45.414-29.542-67.584-76.134-49.408-104.243 18.125-28.006 69.683-26.726 114.995 2.816 45.517 29.542 67.482 76.237 49.408 104.243s-69.53 26.726-114.995-2.816z\"></path>";
    //        output_view.setCaption("<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1024 1024\">" + ico2 + "</svg>");
    //        output_view.addStyleName("tiny");
    //        view_controls.addComponent (output_view);
    //
    //        Button run = new Button ();
    //        run.setHtmlContentAllowed(true);
    //        String ico3 = "<path class=\"path1\" d=\"M192 128l640 384-640 384z\"></path>";
    //        run.setCaption("<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1024 1024\">" + ico3 + "</svg>");
    //        run.addStyleName("tiny");
    //        view_controls.addComponent (run);

}

From source file:org.lucidj.html_renderer.HtmlRenderer.java

License:Apache License

private void init_toolbar() {
    editor_toolbar = new CssLayout();

    CssLayout group = new CssLayout();
    group.addStyleName("v-component-group");

    Button output_view = new Button();
    output_view.setHtmlContentAllowed(true);
    String ico2 = "<path d=\"M249.649 792.806l-107.776 166.4 11.469 54.426 54.272-11.622 107.725-166.298c-11.469-6.144-22.835-12.698-33.843-19.968-11.162-7.219-21.811-14.95-31.846-22.938zM705.943 734.694c0.717-1.485 1.178-3.123 1.843-4.71 2.714-5.99 5.12-11.981 7.066-18.278 0.307-1.126 0.461-2.253 0.819-3.277 1.997-6.963 3.686-13.824 5.018-20.89 0-0.358 0-0.614 0-1.075 9.984-59.853-7.424-126.618-47.258-186.931l56.832-87.757c65.485 8.346 122.112-8.141 149.35-50.278 47.258-72.858-10.24-194.15-128.256-271.002-118.118-76.902-252.058-80.128-299.213-7.373-27.341 42.189-19.354 100.71 15.002 157.338l-56.934 87.757c-71.117-11.93-139.059-0.819-189.594 32.768-0.307 0.102-0.666 0.205-0.87 0.41-5.888 3.994-11.622 8.397-16.998 13.005-0.87 0.717-1.894 1.382-2.611 2.099-5.018 4.301-9.523 9.114-13.875 13.926-1.024 1.229-2.458 2.304-3.43 3.584-5.427 6.195-10.445 12.749-14.848 19.712-70.861 109.21-10.394 274.483 134.81 369.101 145.306 94.618 320.512 82.637 391.219-26.573 4.454-6.912 8.55-14.131 11.93-21.555zM664.215 224.845c-45.414-29.542-67.584-76.134-49.408-104.243 18.125-28.006 69.683-26.726 114.995 2.816 45.517 29.542 67.482 76.237 49.408 104.243s-69.53 26.726-114.995-2.816z\"></path>";
    output_view.setCaption(//  w w w  . j a  v  a  2 s .com
            "<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1024 1024\">"
                    + ico2 + "</svg>");
    output_view.addStyleName("tiny");
    group.addComponent(output_view);

    output_view.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            show_hide_rich_text();
        }
    });

    Button run = new Button();
    run.setHtmlContentAllowed(true);
    String ico3 = "<path class=\"path1\" d=\"M192 128l640 384-640 384z\"></path>";
    run.setCaption(
            "<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1024 1024\">"
                    + ico3 + "</svg>");
    run.addStyleName("tiny");
    group.addComponent(run);

    run.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            render_html_from_rich_text();
        }
    });

    run.addShortcutListener(new AbstractField.FocusShortcut(run, ShortcutAction.KeyCode.ENTER,
            ShortcutAction.ModifierKey.SHIFT) {
        @Override
        public void handleAction(Object sender, Object target) {
            render_html_from_rich_text();
        }
    });

    editor_toolbar.addComponent(group);
}

From source file:org.lucidj.markdown_renderer.MarkdownRenderer.java

License:Apache License

private void init_toolbar() {
    editor_toolbar = new CssLayout();

    CssLayout group = new CssLayout();
    group.addStyleName("v-component-group");

    Button output_view = new Button();
    output_view.setHtmlContentAllowed(true);
    String ico2 = "<path d=\"M249.649 792.806l-107.776 166.4 11.469 54.426 54.272-11.622 107.725-166.298c-11.469-6.144-22.835-12.698-33.843-19.968-11.162-7.219-21.811-14.95-31.846-22.938zM705.943 734.694c0.717-1.485 1.178-3.123 1.843-4.71 2.714-5.99 5.12-11.981 7.066-18.278 0.307-1.126 0.461-2.253 0.819-3.277 1.997-6.963 3.686-13.824 5.018-20.89 0-0.358 0-0.614 0-1.075 9.984-59.853-7.424-126.618-47.258-186.931l56.832-87.757c65.485 8.346 122.112-8.141 149.35-50.278 47.258-72.858-10.24-194.15-128.256-271.002-118.118-76.902-252.058-80.128-299.213-7.373-27.341 42.189-19.354 100.71 15.002 157.338l-56.934 87.757c-71.117-11.93-139.059-0.819-189.594 32.768-0.307 0.102-0.666 0.205-0.87 0.41-5.888 3.994-11.622 8.397-16.998 13.005-0.87 0.717-1.894 1.382-2.611 2.099-5.018 4.301-9.523 9.114-13.875 13.926-1.024 1.229-2.458 2.304-3.43 3.584-5.427 6.195-10.445 12.749-14.848 19.712-70.861 109.21-10.394 274.483 134.81 369.101 145.306 94.618 320.512 82.637 391.219-26.573 4.454-6.912 8.55-14.131 11.93-21.555zM664.215 224.845c-45.414-29.542-67.584-76.134-49.408-104.243 18.125-28.006 69.683-26.726 114.995 2.816 45.517 29.542 67.482 76.237 49.408 104.243s-69.53 26.726-114.995-2.816z\"></path>";
    output_view.setCaption(//from  www  .  j a va  2s  . c  om
            "<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1024 1024\">"
                    + ico2 + "</svg>");
    output_view.addStyleName("tiny");
    group.addComponent(output_view);

    output_view.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            show_hide_rich_text();
        }
    });

    Button run = new Button();
    run.setHtmlContentAllowed(true);
    String ico3 = "<path class=\"path1\" d=\"M192 128l640 384-640 384z\"></path>";
    run.setCaption(
            "<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1024 1024\">"
                    + ico3 + "</svg>");
    run.addStyleName("tiny");
    group.addComponent(run);

    run.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            render_html_from_markdown();
        }
    });

    run.addShortcutListener(new AbstractField.FocusShortcut(run, ShortcutAction.KeyCode.ENTER,
            ShortcutAction.ModifierKey.SHIFT) {
        @Override
        public void handleAction(Object sender, Object target) {
            render_html_from_markdown();
        }
    });

    editor_toolbar.addComponent(group);
}

From source file:org.lucidj.smartbox_renderer.SmartBoxRenderer.java

License:Apache License

private void init_toolbar() {
    cell_toolbar = new CssLayout();

    CssLayout group = new CssLayout();
    group.addStyleName("v-component-group");
    group.addStyleName("ui-toolbar-spacer");

    Button run = new Button();
    run.setHtmlContentAllowed(true);/* www  .  ja v  a 2s . com*/
    String ico3 = "<path class=\"path1\" d=\"M192 128l640 384-640 384z\"></path>";
    run.setCaption(
            "<svg style=\"fill: currentColor; width: 1.5em; margin-top:0.3em;\" viewBox=\"0 0 1024 1024\">"
                    + ico3 + "</svg>");
    run.addStyleName("tiny");
    group.addComponent(run);

    run.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            source.fireEvent(this, "run");
        }
    });

    run.addShortcutListener(new ShortcutListener("Run", ShortcutAction.KeyCode.ENTER,
            new int[] { ShortcutAction.ModifierKey.CTRL }) {
        @Override
        public void handleAction(Object sender, Object target) {
            // The shortcuts (while active on toolbar) are global, however for
            // Ctrl+Enter this becomes counter-intuitive. This way, we filter
            // it to avoid running things from outside the edition field.
            if (target == commands) {
                source.fireEvent(this, "run");
            }
        }
    });

    Button stop = new Button();
    stop.setIcon(FontAwesome.STOP);
    stop.addStyleName("tiny");
    group.addComponent(stop);

    stop.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            source.fireEvent(this, "stop");
        }
    });

    cell_toolbar.addComponent(group);
}

From source file:org.lucidj.ui.gauss.GaussUI.java

License:Apache License

private void initToolbarArea() {
    hToolbarArea.setStyleName("ui-toolbar-area");
    hToolbarArea.setSizeUndefined();/*from w  w  w  . ja va 2 s. c om*/
    hToolbarArea.setWidth("100%");

    CssLayout home_buttons = new CssLayout();
    home_buttons.setStyleName("ui-toolbar-area-home");
    home_buttons.setWidth(get_default_left_panel_width(), Sizeable.Unit.PIXELS);
    home_buttons.setId("_home_buttons");

    final Button toggle_menu = new Button();
    toggle_menu.setWidth(3, Unit.EM);
    toggle_menu.setIcon(FontAwesome.CHEVRON_DOWN);
    toggle_menu.addStyleName("tiny");
    toggle_menu.addStyleName("link");
    toggle_menu.addStyleName("ui-toolbar-spacer");
    toggle_menu.addStyleName("ui-toggle-button");
    toggle_menu.setId("_toggle_menu");
    home_buttons.addComponent(toggle_menu);

    toggle_menu.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            if (!hsMenuContents.isLocked()) {
                default_left_panel_width_px = (int) hsMenuContents.getSplitPosition();
                acMenu.setVisible(false);
                hsMenuContents.setMinSplitPosition(0, Unit.PIXELS);
                hsMenuContents.setSplitPosition(0, Sizeable.Unit.PIXELS);
                toggle_menu.setIcon(FontAwesome.CHEVRON_RIGHT);
                hsMenuContents.setLocked(true);
            } else {
                hsMenuContents.setLocked(false);
                acMenu.setVisible(true);
                hsMenuContents.setMinSplitPosition(MIN_LEFT_PANEL_WIDTH_PX, Unit.PIXELS);
                hsMenuContents.setSplitPosition(get_default_left_panel_width(), Unit.PIXELS);
                toggle_menu.setIcon(FontAwesome.CHEVRON_DOWN);
            }
        }
    });

    final Button home = new Button("Home");
    home.setIcon(FontAwesome.HOME);
    home.addStyleName("tiny");
    home.addStyleName("ui-toolbar-spacer");
    home.addStyleName("ui-toggle-button");
    home.setId("_home");
    home_buttons.addComponent(home);

    home.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            navigator.navigateTo("home");
        }
    });

    final Button new_button = new Button("New");
    new_button.setIcon(FontAwesome.EDIT);
    new_button.addStyleName("tiny");
    new_button.addStyleName("primary");
    new_button.addStyleName("ui-toggle-button");
    new_button.setId("_new");
    home_buttons.addComponent(new_button);
    new_button.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            navigator.navigateTo("new");
        }
    });

    hToolbarArea.addComponent(home_buttons);

    hToolbarPlaceholder = new CssLayout();
    hToolbarPlaceholder.setSizeFull();
    hToolbarArea.addComponent(hToolbarPlaceholder);
    hToolbarArea.setExpandRatio(hToolbarPlaceholder, 1.0f);

    final Button eject_view = new Button();
    eject_view.setIcon(FontAwesome.EXTERNAL_LINK);
    eject_view.addStyleName("tiny");
    eject_view.addStyleName("link");
    eject_view.addStyleName("ui-toggle-button");
    eject_view.setId("_eject_view");
    hToolbarArea.addComponent(eject_view);

    eject_view.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            Notification.show("Not implemented", Notification.Type.HUMANIZED_MESSAGE);
        }
    });

    toggle_sidebar = new Button();
    toggle_sidebar.setWidth(3, Unit.EM);
    toggle_sidebar.addStyleName("tiny");
    toggle_sidebar.addStyleName("link");
    toggle_sidebar.addStyleName("ui-toolbar-spacer");
    toggle_sidebar.addStyleName("ui-toggle-button");
    toggle_sidebar.setId("_toggle_sidebar");
    hToolbarArea.addComponent(toggle_sidebar);

    toggle_sidebar.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            show_sidebar(!sidebar_visible());
        }
    });
}

From source file:org.lucidj.vaadinui.BaseVaadinUI.java

License:Apache License

private void initSystemToolbar() {
    desktop_canvas.setSizeFull();/*from  w  w w  . j ava 2s . c o  m*/
    desktop_canvas.setWidth("100%");

    ui_header = new HorizontalLayout();
    {
        ui_header.setStyleName("ui-header-area");
        ui_header.setWidth(100, Sizeable.Unit.PERCENTAGE);
        ui_header.setHeightUndefined();
        ui_header.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

        Label logo = new Label("&nbsp;", ContentMode.HTML);
        {
            logo.addStyleName("ui-header-logo");
            logo.setWidth(default_sidebar_width_pixels, Sizeable.Unit.PIXELS);
        }
        ui_header.addComponent(logo);

        HorizontalLayout header_components = new HorizontalLayout();
        {
            header_components.setWidth(100, com.vaadin.server.Sizeable.Unit.PERCENTAGE);
            header_components.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
            header_components.setSpacing(true);

            // Search component
            CssLayout search_component = new CssLayout();
            {
                search_component.setWidth(100, com.vaadin.server.Sizeable.Unit.PERCENTAGE);
                search_component.setWidthUndefined();
                search_component.addStyleName("v-component-group");
                search_component.addStyleName("ui-header-search");
                final ComboBox search_text = new ComboBox();
                {
                    search_text.setInputPrompt("Search or paste URL...");
                    //combo.setContainerDataSource(StringGenerator.generateContainer(200, false));
                    search_text.setNullSelectionAllowed(true);
                    search_text.setTextInputAllowed(true);
                    search_text.setNewItemsAllowed(true);
                    //combo.select(combo.getItemIds().iterator().next());
                    //combo.setItemCaptionPropertyId(StringGenerator.CAPTION_PROPERTY);
                    //combo.setItemIconPropertyId(StringGenerator.ICON_PROPERTY);

                    // TODO: SOMEDAY DISCOVER HOW TO EXPAND THIS GROUPED COMPONENT, AND THE CURE FOR CANCER
                    search_text.setWidth("480px");
                    search_text.addStyleName("invisible-focus");
                    search_text.addValueChangeListener(new Property.ValueChangeListener() {
                        @Override
                        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                            String search_args = (String) search_text.getValue();

                            if (search_args != null) {
                                fireEvent("search", search_text.getValue());
                                value_change_button_quirk = true;
                            }
                        }
                    });

                    // Handles the Enter key by activating on focus and deactivating on blur
                    final ShortcutListener handle_enter = new ShortcutListener("Enter",
                            ShortcutAction.KeyCode.ENTER, null) {
                        @Override
                        public void handleAction(Object o, Object o1) {
                            value_change_button_quirk = false;
                            fireEvent("search", search_text.getValue());
                        }
                    };

                    search_text.addFocusListener(new FieldEvents.FocusListener() {
                        @Override
                        public void focus(FieldEvents.FocusEvent focusEvent) {
                            if (nested_focus_blur_bug_count++ == 0) {
                                search_text.addShortcutListener(handle_enter);
                            }
                        }
                    });

                    search_text.addBlurListener(new FieldEvents.BlurListener() {
                        @Override
                        public void blur(FieldEvents.BlurEvent blurEvent) {
                            if (--nested_focus_blur_bug_count == 0) {
                                search_text.removeShortcutListener(handle_enter);
                            }
                        }
                    });

                }
                search_component.addComponent(search_text);

                Button search_button = new Button();
                {
                    search_button.setIcon(FontAwesome.SEARCH);
                    search_button.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent clickEvent) {
                            if (!value_change_button_quirk) {
                                fireEvent("search", search_text.getValue());
                            }
                            value_change_button_quirk = false;
                        }
                    });
                    search_button.addStyleName("invisible-focus");
                }
                search_component.addComponent(search_button);
            }
            header_components.addComponent(search_component);

            // User component
            user_component = new HorizontalLayout();
            {
                user_component.setStyleName("ui-header-user");
                user_component.setWidthUndefined();
            }
            header_components.addComponent(user_component);

            // I swear someday I'll learn CSS, AFTER implementing my own distributed
            // operating system with augmented reality interface and a machine learning kernel,
            // all written in Z80 assembly, as a preparation for the task.
            Label spacer = new Label();
            spacer.setWidthUndefined();
            header_components.addComponent(spacer);

            // Search expands
            header_components.setExpandRatio(search_component, 1.0f);
        }
        ui_header.addComponent(header_components);
        ui_header.setExpandRatio(header_components, 1.0f);
    }

    desktop_canvas.addComponent(ui_header);
    desktop_canvas.addComponent(empty_desktop);
    desktop_canvas.setExpandRatio(empty_desktop, 1.0f);
    setContent(desktop_canvas);
}

From source file:org.lunifera.example.vaadin.databinding.DatabindingDemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    VaadinObservables.getRealm(getUI());

    CssLayout layout = new CssLayout();
    layout.setSizeFull();/*from www  .j  a v a  2s  .c  om*/
    setContent(layout);

    TabSheet tabsheet = new TabSheet();
    tabsheet.setSizeFull();
    tabsheet.addTab(new ValueBindings(), "Value bindings");
    tabsheet.addTab(new SelectionBindings(), "Selection bindings");
    tabsheet.addTab(new LocaleBindings(), "Locales combo");
    try {
        tabsheet.addTab(new ECViewVerticalLayout(), "ECView Vertical");
        tabsheet.addTab(new ECViewHorizontalLayout(), "ECView Horizontal");
        tabsheet.addTab(new ECViewGridLayout(), "ECView Gridlayout");
        tabsheet.addTab(new ECViewTabSheet(), "ECView Tabsheet");
        tabsheet.addTab(new ECViewDatabinding(), "ECView Bindings");
    } catch (ContextException e) {
        e.printStackTrace();
    }
    layout.addComponent(tabsheet);
}