Example usage for com.vaadin.ui CssLayout addStyleName

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

Introduction

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

Prototype

@Override
    public void addStyleName(String style) 

Source Link

Usage

From source file:org.opencms.ui.components.CmsUserInfo.java

License:Open Source License

/**
 * Creates the user image button.<p>
 *
 * @return the created button/* ww  w .j a  v  a2 s  . c om*/
 */
private Component createImageButton() {

    CssLayout layout = new CssLayout();
    layout.addStyleName(OpenCmsTheme.USER_IMAGE);
    Image userImage = new Image();
    userImage.setSource(new ExternalResource(OpenCms.getWorkplaceAppManager().getUserIconHelper()
            .getBigIconPath(A_CmsUI.getCmsObject(), m_user)));

    layout.addComponent(userImage);

    if (!CmsAppWorkplaceUi.isOnlineProject()) {
        CmsUploadButton uploadButton = createImageUploadButton(null, FontOpenCms.UPLOAD_SMALL, m_user,
                m_uploadListener);
        layout.addComponent(uploadButton);
        if (CmsUserIconHelper.hasUserImage(m_user)) {
            Button deleteButton = new Button(FontOpenCms.TRASH_SMALL);
            deleteButton.addClickListener(new ClickListener() {

                private static final long serialVersionUID = 1L;

                public void buttonClick(ClickEvent event) {

                    OpenCms.getWorkplaceAppManager().getUserIconHelper()
                            .deleteUserImage(A_CmsUI.getCmsObject());
                    m_context.updateUserInfo();

                }
            });
            layout.addComponent(deleteButton);
        }
    }

    return layout;
}

From source file:org.opencms.ui.sitemap.CmsLocaleComparePanel.java

License:Open Source License

/**
 * Initializes the locale comparison view.<p>
 *
 * @param id the structure id of the currrent sitemap root entry
 * @param initialComparisonLocale if not null, the initially selected ccomparison locale
 *
 * @throws CmsException if something goes wrong
 *//*from  ww  w .j  av  a2s  .c  o m*/
public void initialize(CmsUUID id, Locale initialComparisonLocale) throws CmsException {

    removeAllComponents();
    CmsObject cms = A_CmsUI.getCmsObject();
    CmsResource res = cms.readResource(id);
    m_currentRoot = res;
    CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(res.getRootPath());

    Locale rootLocale = OpenCms.getLocaleManager().getDefaultLocale(cms, res);
    m_rootLocale = rootLocale;
    Locale mainLocale = site.getMainTranslationLocale(null);
    List<Locale> secondaryLocales = site.getSecondaryTranslationLocales();

    List<Locale> possibleLocaleSelections = getMainLocaleSelectOptions(cms, res, mainLocale, secondaryLocales);
    m_rootLocaleSelector = new ComboBox();
    m_rootLocaleSelector.addStyleName("o-sitemap-localeselect");
    m_rootLocaleSelector.setNullSelectionAllowed(false);
    for (Locale selectableLocale : possibleLocaleSelections) {
        m_rootLocaleSelector.addItem(selectableLocale);
        m_rootLocaleSelector.setItemIcon(selectableLocale, FontOpenCms.SPACE);
        m_rootLocaleSelector.setItemCaption(selectableLocale,
                selectableLocale.getDisplayName(A_CmsUI.get().getLocale()));
    }
    m_rootLocaleSelector.setItemIcon(mainLocale, MAIN_LOCALE_ICON);
    m_rootLocaleSelector.setValue(m_rootLocale);
    m_rootLocaleSelector.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void valueChange(ValueChangeEvent event) {

            if (!m_handlingLocaleChange) {
                m_handlingLocaleChange = true;
                try {
                    Locale newLocale = (Locale) (event.getProperty().getValue());
                    switchToLocale(newLocale);
                } catch (Exception e) {
                    LOG.error(e.getLocalizedMessage(), e);
                    CmsErrorDialog.showErrorDialog(e);
                } finally {
                    m_handlingLocaleChange = false;
                }
            }
        }
    });

    m_comparisonLocaleSelector = new ComboBox();
    m_comparisonLocaleSelector.addStyleName("o-sitemap-localeselect");
    m_comparisonLocaleSelector.setNullSelectionAllowed(false);

    List<Locale> comparisonLocales = getComparisonLocales();
    Locale selectedComparisonLocale = null;
    for (Locale comparisonLocale : comparisonLocales) {
        m_comparisonLocaleSelector.addItem(comparisonLocale);
        m_comparisonLocaleSelector.setItemIcon(comparisonLocale, FontOpenCms.SPACE);
        m_comparisonLocaleSelector.setItemCaption(comparisonLocale,
                comparisonLocale.getDisplayName(A_CmsUI.get().getLocale()));
        if ((selectedComparisonLocale == null) && !comparisonLocale.equals(m_rootLocale)) {
            selectedComparisonLocale = comparisonLocale;
        }
        if ((initialComparisonLocale != null) && comparisonLocale.equals(initialComparisonLocale)
                && !comparisonLocale.equals(m_rootLocale)) {
            // if an initial comparison locale is given, it should have priority over the first comparison locale
            selectedComparisonLocale = comparisonLocale;
        }

    }
    m_comparisonLocale = selectedComparisonLocale;
    m_comparisonLocaleSelector.setValue(selectedComparisonLocale);
    m_comparisonLocaleSelector.setItemIcon(mainLocale, MAIN_LOCALE_ICON);

    m_comparisonLocaleSelector.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void valueChange(ValueChangeEvent event) {

            if (!m_handlingLocaleChange) {
                m_handlingLocaleChange = true;
                try {
                    Locale locale = (Locale) (event.getProperty().getValue());
                    if (m_rootLocale.equals(locale)) {
                        Locale oldComparisonLocale = m_comparisonLocale;
                        if (getLocaleGroup().getResourcesByLocale().keySet().contains(oldComparisonLocale)) {
                            m_comparisonLocale = locale;
                            switchToLocale(oldComparisonLocale);
                            updateLocaleWidgets();
                        } else {
                            Notification.show(CmsVaadinUtils.getMessageText(
                                    Messages.GUI_LOCALECOMPARE_CANNOT_SWITCH_COMPARISON_LOCALE_0));
                            m_comparisonLocaleSelector.setValue(oldComparisonLocale);
                        }
                    } else {
                        m_comparisonLocale = locale;
                        updateLocaleWidgets();
                        initTree(m_currentRoot);
                    }

                } catch (Exception e) {
                    LOG.error(e.getLocalizedMessage(), e);
                    CmsErrorDialog.showErrorDialog(e);
                } finally {
                    m_handlingLocaleChange = false;
                }
            }
        }
    });

    CssLayout localeSelectors = new CssLayout();
    localeSelectors.addStyleName(OpenCmsTheme.SITEMAP_LOCALE_BAR);

    m_rootLocaleSelector.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_MAIN_LOCALE_0));
    m_comparisonLocaleSelector
            .setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_COMPARISON_LOCALE_0));

    localeSelectors.setWidth("100%");
    localeSelectors.addComponent(m_rootLocaleSelector);
    localeSelectors.addComponent(m_comparisonLocaleSelector);
    // localeSelectors.setComponentAlignment(wrapper2, Alignment.MIDDLE_RIGHT);

    setSpacing(true);
    addComponent(localeSelectors);
    addComponent(m_treeContainer);
    m_treeContainer.setWidth("100%");
    initTree(res);
}

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  . java  2s. c o m
    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.opennms.features.topology.app.internal.ui.ToolbarPanel.java

License:Open Source License

private CssLayout createGroup(Component... components) {
    CssLayout group = new CssLayout();
    group.addStyleName("toolbar-component-group");
    group.setSizeFull();/*www. j  av a 2s .  c o  m*/
    for (Component eachComponent : components) {
        eachComponent.setPrimaryStyleName("toolbar-group-item");
        group.addComponent(eachComponent);
    }
    return group;
}

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

License:Apache License

/**
 * Sample content with simple table (disabled as table is so broken in
 * Vaadin 7). To get table work you probably need some special timer.
 * /*from   ww w  .j a v a  2s  .  co m*/
 * @return
 */
// private ComponentContainer createPanelContentC() {
// VerticalLayout layout = new VerticalLayout();
// layout.setWidth("100%");
// layout.setMargin(true);
// layout.setSpacing(true);
//
// Label label = new Label ("Table is quite broken in Vaadin 7?");
// layout.addComponent(label);
//
// Table table = new Table();
// table.setWidth("400px");
// table.setHeight("500px");
// table.addContainerProperty("Name", String.class, "");
// table.addContainerProperty("Phone Number", String.class, "");
// table.addItem(new Object[] { "Matti Meiklinen", "555 234 2344" },
// "Matti");
// table.addItem(new Object[] { "Donald Duck", "555 332 7782" }, "Donald");
//
// layout.addComponent(table);
//
// return layout;
// }

private ComponentContainer createPanelContentD() {
    CssLayout layout = new CssLayout();
    layout.addStyleName("demo-panel-d");
    layout.setWidth("100%");
    layout.setHeight("100%");

    Image image = new Image();
    image.setSource(new ThemeResource("images/meme.jpg"));
    image.addStyleName("demo-meme");
    layout.addComponent(image);

    return layout;
}

From source file:org.vaadin.notifique.Notifique.java

License:Apache License

/**
 * Create a new item into the queue. It is not visible until added with
 *///from  ww  w.java 2  s. c o m
protected Message createMessage(final Component component, String style) {

    final Message m = new Message();

    // Wrap to a CssLayout (this is needed for styling and sizing correctly)
    CssLayout css = new CssLayout();
    css.setWidth("100%");
    css.setStyleName(Notifique.STYLE_ITEM);
    css.addStyleName(style != null ? style : Styles.MESSAGE);
    css.addComponent(component);

    // Wrap component into an animator
    m.component = component;
    m.animatedContent = css;

    return m;
}

From source file:org.vaadin.spring.samples.navigation.NavigationUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout root = new VerticalLayout();
    root.setSizeFull();/*from  w  w w  .  j  a  v  a 2 s.c  om*/
    root.setMargin(true);
    root.setSpacing(true);
    setContent(root);

    final CssLayout navigationBar = new CssLayout();
    navigationBar.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    navigationBar.addComponent(createNavigationButton("Prototype Scoped View", PrototypeScopedView.VIEW_NAME));
    navigationBar.addComponent(createNavigationButton("UI Scoped View", UIScopedView.VIEW_NAME));
    navigationBar.addComponent(createNavigationButton("View Scoped View", ViewScopedView.VIEW_NAME));
    navigationBar.addComponent(createNavigationButton("Access Control", AccessControlView.VIEW_NAME));
    root.addComponent(navigationBar);

    final Panel viewContainer = new Panel();
    viewContainer.setSizeFull();
    root.addComponent(viewContainer);
    root.setExpandRatio(viewContainer, 1.0f);

    viewProvider.setAccessDeniedViewClass(AccessDeniedView.class);

    Navigator navigator = new Navigator(this, viewContainer);
    navigator.setErrorView(new ErrorView()); // You can still create the error view yourself if you want to.
    navigator.addProvider(viewProvider);
}

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

License:Apache License

private Component buildLabels() {
    CssLayout labels = new CssLayout();
    labels.addStyleName("labels");

    Label welcome = new Label("Welcome");
    welcome.setSizeUndefined();/*from w  ww .ja va 2s  .c om*/
    welcome.addStyleName(ValoTheme.LABEL_H4);
    welcome.addStyleName(ValoTheme.LABEL_COLORED);
    labels.addComponent(welcome);

    Label title = new Label("Security-Sample");
    title.setSizeUndefined();
    title.addStyleName(ValoTheme.LABEL_H3);
    title.addStyleName(ValoTheme.LABEL_LIGHT);
    labels.addComponent(title);
    return labels;
}

From source file:org.vaadin.spring.sidebar.components.ValoSideBar.java

License:Apache License

@Override
protected CssLayout createCompositionRoot() {
    CssLayout layout = new CssLayout();
    layout.addStyleName(ValoTheme.MENU_PART);
    if (largeIcons) {
        layout.addStyleName(ValoTheme.MENU_PART_LARGE_ICONS);
    }/*from  ww w. ja  va2s . c  om*/
    layout.setWidth(null);
    layout.setHeight("100%");
    if (logo != null) {
        layout.addComponent(logo);
    }
    if (headerLayout != null) {
        layout.addComponent(headerLayout);
    }
    return layout;
}

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

License:Apache License

private Component createPostControl(final Method setter, final List<Post> posts) throws Exception {
    if (posts == null || posts.isEmpty()) {
        final Label label = new Label(getNameForCheckBox(setter));
        label.setEnabled(false);//from  w w  w .j  a  v a2  s  .  c o  m
        return label;
    }

    Component content = new CustomComponent() {
        {
            final CssLayout root = new CssLayout();
            root.addStyleName("postselect-content");
            root.addStyleName(setter.getName());
            setCompositionRoot(root);
            root.setWidth("100%");
            setWidth("400px");

            root.addComponent(new Label(setter.getName()));

            for (final Post post : posts) {
                final Method getter = getGetterFrom(setter);
                final boolean getterValue = (Boolean) getter.invoke(authorizationService, post.getId());

                final String authorName = post.getAuthor().getDisplayedName();

                String postBody = post.getBodyRaw();
                if (postBody.length() > 20) {
                    postBody = postBody.substring(0, 20);
                }

                final CheckBox checkbox = new CheckBox(authorName + " :: " + postBody);
                checkbox.setValue(getterValue);
                checkbox.addValueChangeListener(new PostCheckboxListener(post, setter));
                checkbox.setImmediate(true);
                checkbox.setWidth("100%");
                root.addComponent(checkbox);
            }
        }
    };
    final PopupView popup = new PopupView(getNameForCheckBox(setter), content);
    popup.setHideOnMouseOut(false);
    popup.setHeight(30.0f, Unit.PIXELS);
    return popup;
}