Example usage for com.vaadin.ui Window setWidth

List of usage examples for com.vaadin.ui Window setWidth

Introduction

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

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

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

License:Open Source License

@Override
public void menuBarUpdated(CommandManager commandManager) {
    if (m_menuBar != null) {
        m_rootLayout.removeComponent(m_menuBar);
    }/*from   www  . j a  v  a2s. c  om*/

    if (m_contextMenu != null) {
        m_contextMenu.detach();
    }

    m_menuBar = commandManager.getMenuBar(m_graphContainer, this);
    m_menuBar.setWidth(100, Unit.PERCENTAGE);
    // Set expand ratio so that extra space is not allocated to this vertical component
    if (m_showHeader) {
        m_rootLayout.addComponent(m_menuBar, 1);
    } else {
        m_rootLayout.addComponent(m_menuBar, 0);
    }

    m_contextMenu = commandManager
            .getContextMenu(new DefaultOperationContext(this, m_graphContainer, DisplayLocation.CONTEXTMENU));
    m_contextMenu.setAsContextMenuOf(this);

    // Add Menu Item to share the View with others
    m_menuBar.addItem("Share", FontAwesome.SHARE, new MenuBar.Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            // create the share link
            String fragment = getPage().getLocation().getFragment();
            String url = getPage().getLocation().toString().replace("#" + getPage().getLocation().getFragment(),
                    "");
            String shareLink = String.format("%s?%s=%s", url,
                    TopologyUIRequestHandler.PARAMETER_HISTORY_FRAGMENT, fragment);

            // Create the Window
            Window shareWindow = new Window();
            shareWindow.setCaption("Share Link");
            shareWindow.setModal(true);
            shareWindow.setClosable(true);
            shareWindow.setResizable(false);
            shareWindow.setWidth(400, Unit.PIXELS);

            TextArea shareLinkField = new TextArea();
            shareLinkField.setValue(shareLink);
            shareLinkField.setReadOnly(true);
            shareLinkField.setRows(3);
            shareLinkField.setWidth(100, Unit.PERCENTAGE);

            // Close Button
            Button close = new Button("Close");
            close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
            close.addClickListener(event -> shareWindow.close());

            // Layout for Buttons
            HorizontalLayout buttonLayout = new HorizontalLayout();
            buttonLayout.setMargin(true);
            buttonLayout.setSpacing(true);
            buttonLayout.setWidth("100%");
            buttonLayout.addComponent(close);
            buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT);

            // Content Layout
            VerticalLayout verticalLayout = new VerticalLayout();
            verticalLayout.setMargin(true);
            verticalLayout.setSpacing(true);
            verticalLayout.addComponent(
                    new Label("Please use the following link to share the current view with others."));
            verticalLayout.addComponent(shareLinkField);
            verticalLayout.addComponent(buttonLayout);

            shareWindow.setContent(verticalLayout);

            getUI().addWindow(shareWindow);
        }
    });

    updateMenuItems();
}

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

License:Open Source License

public ToolbarPanel(final ToolbarPanelController controller) {
    addStyleName(Styles.TOOLBAR);//from w  w  w. j  av a2  s . c  om
    this.layoutManager = controller.getLayoutManager();

    final Property<Double> scale = controller.getScaleProperty();
    final Boolean[] eyeClosed = new Boolean[] { false };
    final Button showFocusVerticesBtn = new Button();
    showFocusVerticesBtn.setIcon(FontAwesome.EYE);
    showFocusVerticesBtn.setDescription("Toggle Highlight Focus Nodes");
    showFocusVerticesBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (eyeClosed[0]) {
                showFocusVerticesBtn.setIcon(FontAwesome.EYE);
            } else {
                showFocusVerticesBtn.setIcon(FontAwesome.EYE_SLASH);
            }
            eyeClosed[0] = !eyeClosed[0]; // toggle
            controller.toggleHighlightFocus();
        }
    });

    final Button magnifyBtn = new Button();
    magnifyBtn.setIcon(FontAwesome.PLUS);
    magnifyBtn.setDescription("Magnify");
    magnifyBtn.addClickListener(
            (Button.ClickListener) event -> scale.setValue(Math.min(1, scale.getValue() + 0.25)));

    final Button demagnifyBtn = new Button();
    demagnifyBtn.setIcon(FontAwesome.MINUS);
    demagnifyBtn.setDescription("Demagnify");
    demagnifyBtn.addClickListener(
            (Button.ClickListener) event -> scale.setValue(Math.max(0, scale.getValue() - 0.25)));

    m_szlOutBtn = new Button();
    m_szlOutBtn.setId("szlOutBtn");
    m_szlOutBtn.setIcon(FontAwesome.ANGLE_DOWN);
    m_szlOutBtn.setDescription("Decrease Semantic Zoom Level");
    m_szlOutBtn.setEnabled(controller.getSemanticZoomLevel() > 0);
    m_szlOutBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            int szl = controller.getSemanticZoomLevel();
            if (szl > 0) {
                setSemanticZoomLevel(controller, szl - 1);
                controller.saveHistory();
            }
        }
    });

    final Button szlInBtn = new Button();
    szlInBtn.setId("szlInBtn");
    szlInBtn.setIcon(FontAwesome.ANGLE_UP);
    szlInBtn.setDescription("Increase Semantic Zoom Level");
    szlInBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            setSemanticZoomLevel(controller, controller.getSemanticZoomLevel() + 1);
            controller.saveHistory();
        }
    });

    m_zoomLevelLabel.setId("szlInputLabel");

    m_panBtn = new Button();
    m_panBtn.setIcon(FontAwesome.ARROWS);
    m_panBtn.setDescription("Pan Tool");
    m_panBtn.addStyleName(Styles.SELECTED);

    m_selectBtn = new Button();
    m_selectBtn.setIcon(IonicIcons.ANDROID_EXPAND);
    m_selectBtn.setDescription("Selection Tool");
    m_selectBtn.setStyleName("toolbar-button");
    m_selectBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_selectBtn.addStyleName(Styles.SELECTED);
            m_panBtn.removeStyleName(Styles.SELECTED);
            controller.setActiveTool(ActiveTool.select);
        }
    });

    m_panBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_panBtn.addStyleName(Styles.SELECTED);
            m_selectBtn.removeStyleName(Styles.SELECTED);
            controller.setActiveTool(ActiveTool.pan);
        }
    });

    Button showAllMapBtn = new Button();
    showAllMapBtn.setId("showEntireMapBtn");
    showAllMapBtn.setIcon(FontAwesome.GLOBE);
    showAllMapBtn.setDescription("Show Entire Map");
    showAllMapBtn.addClickListener((Button.ClickListener) event -> controller.showAllMap());

    Button centerSelectionBtn = new Button();
    centerSelectionBtn.setIcon(FontAwesome.LOCATION_ARROW);
    centerSelectionBtn.setDescription("Center On Selection");
    centerSelectionBtn.addClickListener((Button.ClickListener) event -> controller.centerMapOnSelection());

    Button shareButton = new Button("", FontAwesome.SHARE_SQUARE_O);
    shareButton.setDescription("Share");
    shareButton.addClickListener((x) -> {
        // Create the share link
        String fragment = getUI().getPage().getLocation().getFragment();
        String url = getUI().getPage().getLocation().toString().replace("#" + fragment, "");
        String shareLink = String.format("%s?%s=%s", url, PARAMETER_HISTORY_FRAGMENT, fragment);

        // Create the Window
        Window shareWindow = new Window();
        shareWindow.setCaption("Share Link");
        shareWindow.setModal(true);
        shareWindow.setClosable(true);
        shareWindow.setResizable(false);
        shareWindow.setWidth(400, Sizeable.Unit.PIXELS);

        TextArea shareLinkField = new TextArea();
        shareLinkField.setValue(shareLink);
        shareLinkField.setReadOnly(true);
        shareLinkField.setRows(3);
        shareLinkField.setWidth(100, Sizeable.Unit.PERCENTAGE);

        // Close Button
        Button close = new Button("Close");
        close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
        close.addClickListener(event -> shareWindow.close());

        // Layout for Buttons
        HorizontalLayout buttonLayout = new HorizontalLayout();
        buttonLayout.setMargin(true);
        buttonLayout.setSpacing(true);
        buttonLayout.setWidth("100%");
        buttonLayout.addComponent(close);
        buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT);

        // Content Layout
        VerticalLayout verticalLayout = new VerticalLayout();
        verticalLayout.setMargin(true);
        verticalLayout.setSpacing(true);
        verticalLayout.addComponent(
                new Label("Please use the following link to share the current view with others."));
        verticalLayout.addComponent(shareLinkField);
        verticalLayout.addComponent(buttonLayout);

        shareWindow.setContent(verticalLayout);

        getUI().addWindow(shareWindow);
    });

    // Refresh Button
    Button refreshButton = new Button();
    refreshButton.setId("refreshNow");
    refreshButton.setIcon(FontAwesome.REFRESH);
    refreshButton.setDescription("Refresh Now");
    refreshButton.addClickListener((event) -> controller.refreshUI());

    // Layer Layout
    layerLayout = new VerticalLayout();
    layerLayout.setId("layerComponent");
    layerLayout.setSpacing(true);
    layerLayout.setMargin(true);

    // Layer Button
    layerButton = new Button();
    layerButton.setId("layerToggleButton");
    layerButton.setIcon(FontAwesome.BARS);
    layerButton.setDescription("Layers");
    layerButton.addClickListener((event) -> {
        boolean isCollapsed = layerButton.getStyleName().contains(Styles.EXPANDED);
        setLayerLayoutVisible(!isCollapsed);
    });

    // Save button
    layerSaveButton = new Button();
    layerSaveButton.setId("saveLayerButton");
    layerSaveButton.setIcon(FontAwesome.FLOPPY_O);
    layerSaveButton.addClickListener((event) -> controller.saveLayout());

    // Actual Layout for the Toolbar
    CssLayout contentLayout = new CssLayout();
    contentLayout.addStyleName("toolbar-component");
    contentLayout.addComponent(createGroup(szlInBtn, m_zoomLevelLabel, m_szlOutBtn));
    contentLayout.addComponent(
            createGroup(refreshButton, centerSelectionBtn, showAllMapBtn, layerButton, showFocusVerticesBtn));
    contentLayout.addComponent(createGroup(m_panBtn, m_selectBtn));
    contentLayout.addComponent(createGroup(magnifyBtn, demagnifyBtn));
    contentLayout.addComponent(createGroup(shareButton));
    contentLayout.addComponent(createGroup(layerSaveButton));

    // Toolbar
    addComponent(contentLayout);
}

From source file:org.vaadin.addon.ewopener.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    EnhancedBrowserWindowOpener opener1 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true);
    Button button1 = new Button("Click me");
    button1.addClickListener(e -> {//from   w w  w  . ja v a2s.co m
        opener1.open(generateResource());
    });
    opener1.extend(button1);

    EnhancedBrowserWindowOpener opener4 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true);
    Button button4 = new Button("Nothing to open here");
    button4.addClickListener(e -> {
        opener4.open((Resource) null);
    });
    opener4.extend(button4);

    Button button2 = new Button("Click me");
    button2.addClickListener(e -> {
        EnhancedBrowserWindowOpener.extendOnce(button2).open(generateResource());
    });

    Button button3 = new Button("Click me");
    EnhancedBrowserWindowOpener opener3 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true)
            .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(button3);
    button3.addClickListener(opener3::open);

    Link link = new Link("Click me", null);
    new EnhancedBrowserWindowOpener().clientSide(true)
            .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(link);

    Link link2 = new Link("Click me", null);
    new EnhancedBrowserWindowOpener().clientSide(true)
            .withGeneratedContent("myFileName.txt", this::generateContent, resource -> {
                resource.setCacheTime(0);
                resource.setFilename("runtimeFileName-" + Instant.now().getEpochSecond() + ".txt");
            }).doExtend(link2);

    EnhancedBrowserWindowOpener opener5 = new EnhancedBrowserWindowOpener(
            new ClassResource(DemoUI.class, "static.txt"));
    CssLayout hiddenComponent = new MCssLayout().withWidth("0").withHeight("0");
    opener5.extend(hiddenComponent);
    CompletableFuture.runAsync(this::doSomeLongProcessing).thenRun(() -> getUI().access(opener5::open));

    table = new Table("Select items to download",
            new BeanItemContainer<>(DummyService.Person.class, DummyService.data()));
    table.setImmediate(true);
    table.setVisibleColumns("name", "age");
    table.setColumnHeaders("Name", "Age");
    table.setWidth("100%");
    table.setPageLength(20);
    table.setMultiSelectMode(MultiSelectMode.DEFAULT);
    table.setMultiSelect(true);
    table.setSelectable(true);

    final MyPopupContent popupContent = new MyPopupContent();
    Button popupButton = new Button("Open modal", event -> {
        Window window = new Window("Test", popupContent);
        window.setWidth(40, Sizeable.Unit.PERCENTAGE);
        window.setHeight(200, Sizeable.Unit.PIXELS);
        window.setModal(true);
        window.setDraggable(false);
        window.setResizable(false);
        window.center();
        getUI().addWindow(window);
    });

    MenuBar.Command cmd = selectedItem -> Notification.show("Item clicked",
            "Item is " + selectedItem.getDescription(), Notification.Type.TRAY_NOTIFICATION);
    MenuBar menuBar = new MenuBar();
    menuBar.setSizeFull();
    EnhancedBrowserWindowOpener opener6 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-serverside.txt", this::generateContent)
            .popupBlockerWorkaround(true);
    EnhancedBrowserWindowOpener opener7 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-clientside-1.txt", this::generateContent).clientSide(true);
    EnhancedBrowserWindowOpener opener8 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-clientside-2.txt", this::generateContent).clientSide(true);
    MenuBar.MenuItem menuItem = menuBar.addItem("Download from Menu (Client side)", selectedItem -> {
        System.out.println("OK, Invoked");
    });
    MenuBar.MenuItem subMenu = menuBar.addItem("Sub menu", null);
    subMenu.addItem("Item 1", cmd);
    subMenu.addItem("Item 2", cmd);
    MenuBar.MenuItem subItem = subMenu.addItem("Download (client side)", cmd);
    MenuBar.MenuItem subItem2 = subMenu.addItem("Download (server side)", selectedItem -> opener6.open());
    opener7.doExtend(menuBar, menuItem);
    opener6.doExtend(menuBar, subItem2);
    opener8.doExtend(menuBar, subItem);

    // Show it in the middle of the screen
    final Layout layout = new MVerticalLayout(
            new MLabel("Enhanced Window Opener Demo").withStyleName(ValoTheme.LABEL_COLORED,
                    ValoTheme.LABEL_H1),
            new MHorizontalLayout().add(table, 1)
                    .add(new MCssLayout(menuBar, readMarkdown("code_menu.md").withFullWidth(),
                            new MVerticalLayout(readMarkdown("code1.md"), button1)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code2.md"), button2)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code7.md"), button3)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code5.md"), link)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code6.md"), link2)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code3.md"), button4)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code8.md"), popupButton)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code4.md"), hiddenComponent)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false))
                                            .withFullWidth().withStyleName("demo-samples"),
                            5)
                    .withFullWidth()).withFullWidth().withMargin(true);

    setContent(layout);

}

From source file:ro.zg.netcell.vaadin.action.OpenGroupsActionHandler.java

License:Apache License

protected void centerWindow(Window w, OpenGroupsApplication app) {
    WebBrowser wb = app.getAppContext().getBrowser();
    float width = (float) (wb.getScreenWidth() * 0.9);
    float height = (float) (wb.getScreenHeight() * 0.6);

    w.setHeight(height, Sizeable.UNITS_PIXELS);
    w.setWidth(width, Sizeable.UNITS_PIXELS);
    w.setPositionX((int) ((wb.getScreenWidth() - width) / 2));
    w.setPositionY((int) ((wb.getScreenHeight() - height) / 6));
}

From source file:rs.superb.apps.inventory.components.UI.clients.mol.AccordionMenu.java

private void createTabs(String[] mainMenuItems) {
    for (String mainMenuItem : mainMenuItems) {
        VerticalLayout vl = new VerticalLayout();
        vl.setMargin(true);/*from  w  ww  . ja v a2 s .  c om*/
        vl.setSpacing(true);
        vl.setCaption(mainMenuItem);
        addComponent(vl);

        for (Button subMenuButton : mainMenu.get(mainMenuItem)) {
            subMenuButton.setStyleName(BUTTON_STYLE1);
            subMenuButton.setWidth("80%");
            subMenuButton.setHeight("90px");

            vl.addComponent(subMenuButton);
            vl.setComponentAlignment(subMenuButton, Alignment.MIDDLE_CENTER);
        }

        subMenuButtons0.get(0).addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                Window w = new Window("Click" + subMenuButtons0.get(0).getCaption());
                w.setWidth(66, Unit.PERCENTAGE);
                w.setHeight(66, Unit.PERCENTAGE);
                w.center();
                UI.getCurrent().addWindow(w);
            }
        });
        subMenuButtons0.get(1).addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                UI.getCurrent().getNavigator().navigateTo(GodPopis_View.VIEW_ID);
            }
        });
    }
}

From source file:ru.codeinside.gses.webui.executor.ArchiveFactory.java

License:Mozilla Public License

static Window createFormWindow(Component su, ActivityImpl ac, String id) {
    VerticalLayout content = new VerticalLayout();
    content.setMargin(true);/* ww w .j  ava2s  . c om*/
    content.addComponent(su);
    Window window = new Window();
    window.setWidth(800 + 50, Sizeable.UNITS_PIXELS);
    window.setHeight(600 + 100, Sizeable.UNITS_PIXELS);
    window.center();
    window.setContent(content);
    window.setCaption(" ? " + ac.getId() + "  ? #" + id);
    if (su instanceof JsonFormIntegration || su instanceof ExpandRequired) {
        content.setSizeFull();
        content.setExpandRatio(su, 1f);
    } else {
        window.setResizable(false); //  ?  
    }
    return window;
}