Example usage for com.vaadin.ui Label setValue

List of usage examples for com.vaadin.ui Label setValue

Introduction

In this page you can find the example usage for com.vaadin.ui Label setValue.

Prototype

public void setValue(String value) 

Source Link

Document

Sets the text to be shown in the label.

Usage

From source file:org.adho.dhconvalidator.ui.DHConvalidatorExample.java

@Override
protected void init(VaadinRequest request) {
    try {// w w w.ja v  a 2s .  c o  m
        Messages.setLocaleProvider(VaadinSessionLocaleProvider.INSTANCE);

        VerticalLayout content = new VerticalLayout();
        content.setMargin(true);
        content.setSpacing(true);

        setContent(content);

        HeaderPanel headerPanel = new HeaderPanel(null);
        headerPanel.getBackLink().setVisible(false);

        content.addComponent(headerPanel);

        // prepare downloader for input file
        Button btGetInputfile = new Button(Messages.getString("DHConvalidatorExample.btInputCaption"));
        content.addComponent(btGetInputfile);

        FileDownloader inputFileDownloader = new FileDownloader(new StreamResource(new StreamSource() {

            @Override
            public InputStream getStream() {
                return Thread.currentThread().getContextClassLoader().getResourceAsStream(
                        "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.odt");
            }
        }, "1_Digital_Humanities.odt"));
        inputFileDownloader.extend(btGetInputfile);

        // prepare downloader for output file
        Button btGetOutputfile = new Button(
                Messages.getString("DHConvalidatorExample.btConversionResultCaption"));
        content.addComponent(btGetOutputfile);

        FileDownloader outputFileDownloader = new FileDownloader(new StreamResource(new StreamSource() {

            @Override
            public InputStream getStream() {
                return Thread.currentThread().getContextClassLoader().getResourceAsStream(
                        "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.dhc");
            }
        }, "1_Digital_Humanities.dhc"));
        outputFileDownloader.extend(btGetOutputfile);

        // setup visual feedback
        Label preview = new Label("", ContentMode.HTML);
        preview.addStyleName("tei-preview");
        preview.setWidth("800px");

        content.addComponent(preview);
        content.setComponentAlignment(preview, Alignment.MIDDLE_CENTER);

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        IOUtils.copy(Thread.currentThread().getContextClassLoader().getResourceAsStream(
                "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.html"), buffer);

        preview.setValue(buffer.toString("UTF-8"));

        Page.getCurrent().setTitle(Messages.getString("DHConvalidatorExample.title"));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.adho.dhconvalidator.ui.LoginResultPanel.java

/**
 * Setup UI.//ww  w.jav a 2s. c o m
 *
 * @param errorMessage
 */
private void initComponents(String errorMessage) {
    logoutLink = new LogoutLink();
    logoutLink.setVisible(false);

    User user = (User) VaadinSession.getCurrent().getAttribute(SessionStorageKey.USER.name());

    // if authencication has been successful we open up a new tab to show the DHConvalidator
    // services
    btContinue = new Button(Messages.getString("LoginResultPanel.continue"));
    new BrowserWindowOpener(DHConvalidatorServices.class).extend(btContinue);

    btRetry = new Button(Messages.getString("LoginResultPanel.retry"));
    btRetry.setVisible(false);

    Label infoLabel = new Label("", ContentMode.HTML);
    if (errorMessage != null) {
        infoLabel.setValue(Messages.getString("LoginResultPanel.authenticationFailure", errorMessage));
        btContinue.setVisible(false);
        btRetry.setVisible(true);
    } else {
        infoLabel.setValue(
                Messages.getString("LoginResultPanel.greeting", user.getFirstName(), user.getLastName()));
        logoutLink.setVisible(true);
    }

    addCenteredComponent(logoutLink, Alignment.TOP_RIGHT);
    addCenteredComponent(infoLabel);
    addCenteredComponent(btContinue);
    addCenteredComponent(btRetry);
}

From source file:org.agocontrol.site.viewlet.dashboard.BuildingControlPanel.java

License:Apache License

/**
 * Default constructor./* w  ww.j  a  va 2 s  .  c o m*/
 */
public BuildingControlPanel() {
    site = ((AgoControlSiteUI) UI.getCurrent()).getSite();
    siteContext = site.getSiteContext();
    entityManager = siteContext.getObject(EntityManager.class);

    layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.setSizeFull();
    layout.setStyleName(Reindeer.LAYOUT_WHITE);

    final Label title = new Label("Control Panel");
    title.setIcon(getSite().getIcon("inventory"));
    title.setStyleName(Reindeer.LABEL_H2);
    layout.addComponent(title);
    layout.setExpandRatio(title, 0);

    elementLayout = new VerticalLayout();
    elementLayout.setSpacing(true);
    elementLayout.setMargin(false);
    layout.addComponent(elementLayout);
    layout.setExpandRatio(elementLayout, 1);

    roomIcon = site.getIcon("room");
    deviceIcon = site.getIcon("device");
    temperatureIcon = site.getIcon("temperature");
    brightnessIcon = site.getIcon("brightness");
    humidityIcon = site.getIcon("humidity");
    eventIcon = site.getIcon("event");

    setCompositionRoot(layout);

    // the Refresher polls automatically
    final Refresher refresher = new Refresher();
    refresher.setRefreshInterval(200);
    refresher.addListener(new Refresher.RefreshListener() {
        @Override
        public void refresh(final Refresher refresher) {
            while (!recordsQueue.isEmpty()) {
                final List<Record> records = recordsQueue.remove();
                if (records.size() > 0) {
                    final Record record = records.get(0);
                    final RecordSet recordSet = record.getRecordSet();
                    final Element element = recordSet.getElement();

                    final GridLayout recordsLayout = recordsLayouts.get(element.getElementId());
                    if (recordsLayout == null) {
                        continue;
                    }

                    final int columnIndex = recordSet.getType().ordinal();
                    final int rowIndex = 0;
                    if (recordsLayout.getComponent(columnIndex, rowIndex) != null) {
                        continue;
                    }

                    final VerticalLayout recordLayout = new VerticalLayout();
                    recordLayout.setSpacing(true);
                    final Resource recordIcon;
                    switch (recordSet.getType()) {
                    case TEMPERATURE:
                        recordIcon = temperatureIcon;
                        break;
                    case BRIGHTNESS:
                        recordIcon = brightnessIcon;
                        break;
                    case HUMIDITY:
                        recordIcon = humidityIcon;
                        break;
                    default:
                        recordIcon = eventIcon;
                        break;
                    }

                    final Embedded embedded = new Embedded(null, recordIcon);
                    recordLayout.addComponent(embedded);
                    recordLayout.setExpandRatio(embedded, 0.1f);
                    embedded.setWidth(32, Unit.PIXELS);
                    embedded.setHeight(32, Unit.PIXELS);

                    final Label label = new Label();
                    recordLayout.addComponent(label);
                    recordLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);

                    final String recordUnit = recordSet.getUnit();
                    final String displayUnit = DisplayValueConversionUtil.getDisplayUnit(recordSet.getType(),
                            recordUnit);

                    final double displayValue = DisplayValueConversionUtil.convertValue(recordSet.getType(),
                            recordUnit, displayUnit, record.getValue());

                    final String displayValueString = DisplayValueConversionUtil.formatDouble(displayValue);

                    label.setValue(displayValueString + " " + displayUnit);
                    label.setDescription(record.getCreated().toString());

                    recordsLayout.addComponent(recordLayout, columnIndex, rowIndex);
                }
            }
        }
    });
    addExtension(refresher);

}

From source file:org.agocontrol.site.viewlet.dashboard.BuildingControlPanel.java

License:Apache License

/**
 * Invoked when view is entered.//  www .  j  a v a2 s.co  m
 * @param parameters the parameters
 */
public final synchronized void enter(final String parameters) {
    if (recordReaderThread != null) {
        recordReaderExitRequested = true;
        recordReaderThread.interrupt();
        try {
            recordReaderThread.join();
        } catch (final InterruptedException e) {
            LOGGER.debug("Record reader thread death wait interrupted.");
        }
    }
    elementLayout.removeAllComponents();
    recordsLayouts.clear();
    recordsQueue.clear();
    recordReaderExitRequested = false;

    final Company company = siteContext.getObject(Company.class);
    if (company == null || parameters == null || parameters.length() == 0) {
        return;
    }

    final String buildingId = parameters;
    final List<Element> elements = ElementDao.getElements(entityManager, company);

    boolean started = false;
    for (final Element element : elements) {
        if (element.getElementId().equals(buildingId)) {
            started = true;
            continue;
        }
        if (!started) {
            continue;
        }
        if (element.getTreeDepth() == 0) {
            break;
        }

        final HorizontalLayout elementLayout = new HorizontalLayout();
        this.elementLayout.addComponent(elementLayout);
        elementLayout.setSpacing(true);

        final Resource elementIcon;
        switch (element.getType()) {
        case ROOM:
            elementIcon = roomIcon;
            break;
        case DEVICE:
            elementIcon = deviceIcon;
            break;
        default:
            elementIcon = deviceIcon;
            break;
        }

        final Embedded embedded = new Embedded(null, elementIcon);
        elementLayout.addComponent(embedded);
        elementLayout.setExpandRatio(embedded, 0.1f);
        embedded.setWidth(32, Unit.PIXELS);
        embedded.setHeight(32, Unit.PIXELS);

        final Label label = new Label();
        elementLayout.addComponent(label);
        elementLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
        label.setValue(element.toString());

        final GridLayout recordLayout = new GridLayout();
        recordLayout.setSpacing(true);
        recordLayout.setColumns(4);
        recordLayout.setRows(1);

        this.elementLayout.addComponent(recordLayout);
        recordsLayouts.put(element.getElementId(), recordLayout);

    }

    recordReaderThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                final EntityManager threadEntityManager = ((EntityManagerFactory) getSite().getSiteContext()
                        .getObject(EntityManagerFactory.class)).createEntityManager();
                for (final Element element : elements) {
                    final List<RecordSet> recordSets = RecordSetDao.getRecordSets(threadEntityManager, element);
                    if (recordsLayouts.containsKey(element.getElementId())) {
                        for (final RecordSet recordSet : recordSets) {
                            recordsQueue.put(RecordDao.getRecords(threadEntityManager, recordSet, 1));
                            if (recordReaderExitRequested) {
                                break;
                            }
                        }
                    }
                }

                Thread.sleep(10);
            } catch (InterruptedException e) {
            }
        }
    });
    recordReaderThread.start();

}

From source file:org.asi.ui.pagedtable.PagedTable.java

License:Apache License

public HorizontalLayout createControls(PagedControlConfig config) {
    Label itemsPerPageLabel = new Label(config.getItemsPerPage(), ContentMode.HTML);
    itemsPerPageLabel.setSizeUndefined();
    final ComboBox itemsPerPageSelect = new ComboBox();

    for (Integer i : config.getPageLengths()) {
        itemsPerPageSelect.addItem(i);/*from   w  ww  .  j av  a 2 s.  c  o  m*/
        itemsPerPageSelect.setItemCaption(i, String.valueOf(i));
    }
    itemsPerPageSelect.setImmediate(true);
    itemsPerPageSelect.setNullSelectionAllowed(false);
    itemsPerPageSelect.setWidth(null);
    itemsPerPageSelect.addValueChangeListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -2255853716069800092L;

        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            setPageLength((Integer) event.getProperty().getValue());
        }
    });
    if (itemsPerPageSelect.containsId(getPageLength())) {
        itemsPerPageSelect.select(getPageLength());
    } else {
        itemsPerPageSelect.select(itemsPerPageSelect.getItemIds().iterator().next());
    }
    Label pageLabel = new Label(config.getPage(), ContentMode.HTML);
    final TextField currentPageTextField = new TextField();
    currentPageTextField.setValue(String.valueOf(getCurrentPage()));
    currentPageTextField.setConverter(new StringToIntegerConverter() {
        @Override
        protected NumberFormat getFormat(Locale locale) {
            NumberFormat result = super.getFormat(UI.getCurrent().getLocale());
            result.setGroupingUsed(false);
            return result;
        }
    });
    Label separatorLabel = new Label("&nbsp;/&nbsp;", ContentMode.HTML);
    final Label totalPagesLabel = new Label(String.valueOf(getTotalAmountOfPages()), ContentMode.HTML);
    currentPageTextField.setStyleName(Reindeer.TEXTFIELD_SMALL);
    currentPageTextField.setImmediate(true);
    currentPageTextField.addValueChangeListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -2255853716069800092L;

        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            if (currentPageTextField.isValid() && currentPageTextField.getValue() != null) {
                int page = Integer.valueOf(String.valueOf(currentPageTextField.getValue()));
                setCurrentPage(page);
            }
        }
    });
    pageLabel.setWidth(null);
    currentPageTextField.setColumns(3);
    separatorLabel.setWidth(null);
    totalPagesLabel.setWidth(null);

    HorizontalLayout controlBar = new HorizontalLayout();
    HorizontalLayout pageSize = new HorizontalLayout();
    HorizontalLayout pageManagement = new HorizontalLayout();
    final Button first = new Button(config.getFirst(), new Button.ClickListener() {
        private static final long serialVersionUID = -355520120491283992L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            setCurrentPage(0);
        }
    });
    final Button previous = new Button(config.getPrevious(), new Button.ClickListener() {
        private static final long serialVersionUID = -355520120491283992L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            previousPage();
        }
    });
    final Button next = new Button(config.getNext(), new Button.ClickListener() {
        private static final long serialVersionUID = -1927138212640638452L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            nextPage();
        }
    });
    final Button last = new Button(config.getLast(), new Button.ClickListener() {
        private static final long serialVersionUID = -355520120491283992L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            setCurrentPage(getTotalAmountOfPages());
        }
    });
    first.setStyleName(Reindeer.BUTTON_LINK);
    previous.setStyleName(Reindeer.BUTTON_LINK);
    next.setStyleName(Reindeer.BUTTON_LINK);
    last.setStyleName(Reindeer.BUTTON_LINK);

    itemsPerPageLabel.addStyleName("pagedtable-itemsperpagecaption");
    itemsPerPageSelect.addStyleName("pagedtable-itemsperpagecombobox");
    pageLabel.addStyleName("pagedtable-pagecaption");
    currentPageTextField.addStyleName("pagedtable-pagefield");
    separatorLabel.addStyleName("pagedtable-separator");
    totalPagesLabel.addStyleName("pagedtable-total");
    first.addStyleName("pagedtable-first");
    previous.addStyleName("pagedtable-previous");
    next.addStyleName("pagedtable-next");
    last.addStyleName("pagedtable-last");

    itemsPerPageLabel.addStyleName("pagedtable-label");
    itemsPerPageSelect.addStyleName("pagedtable-combobox");
    pageLabel.addStyleName("pagedtable-label");
    currentPageTextField.addStyleName("pagedtable-label");
    separatorLabel.addStyleName("pagedtable-label");
    totalPagesLabel.addStyleName("pagedtable-label");
    first.addStyleName("pagedtable-button");
    previous.addStyleName("pagedtable-button");
    next.addStyleName("pagedtable-button");
    last.addStyleName("pagedtable-button");

    pageSize.addComponent(itemsPerPageLabel);
    pageSize.addComponent(itemsPerPageSelect);
    pageSize.setComponentAlignment(itemsPerPageLabel, Alignment.MIDDLE_LEFT);
    pageSize.setComponentAlignment(itemsPerPageSelect, Alignment.MIDDLE_LEFT);
    pageSize.setSpacing(true);
    pageManagement.addComponent(first);
    pageManagement.addComponent(previous);
    pageManagement.addComponent(pageLabel);
    pageManagement.addComponent(currentPageTextField);
    pageManagement.addComponent(separatorLabel);
    pageManagement.addComponent(totalPagesLabel);
    pageManagement.addComponent(next);
    pageManagement.addComponent(last);
    pageManagement.setComponentAlignment(first, Alignment.MIDDLE_LEFT);
    pageManagement.setComponentAlignment(previous, Alignment.MIDDLE_LEFT);
    pageManagement.setComponentAlignment(pageLabel, Alignment.MIDDLE_LEFT);
    pageManagement.setComponentAlignment(currentPageTextField, Alignment.MIDDLE_LEFT);
    pageManagement.setComponentAlignment(separatorLabel, Alignment.MIDDLE_LEFT);
    pageManagement.setComponentAlignment(totalPagesLabel, Alignment.MIDDLE_LEFT);
    pageManagement.setComponentAlignment(next, Alignment.MIDDLE_LEFT);
    pageManagement.setComponentAlignment(last, Alignment.MIDDLE_LEFT);
    pageManagement.setWidth(null);
    pageManagement.setSpacing(true);
    controlBar.addComponent(pageSize);
    controlBar.addComponent(pageManagement);
    controlBar.setComponentAlignment(pageManagement, Alignment.MIDDLE_CENTER);
    controlBar.setWidth(100, Sizeable.Unit.PERCENTAGE);
    controlBar.setExpandRatio(pageSize, 1);

    if (container != null) {
        first.setEnabled(container.getStartIndex() > 0);
        previous.setEnabled(container.getStartIndex() > 0);
        next.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength());
        last.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength());
    }

    addListener(new PageChangeListener() {
        private boolean inMiddleOfValueChange;

        @Override
        public void pageChanged(PagedTableChangeEvent event) {
            if (!inMiddleOfValueChange) {
                inMiddleOfValueChange = true;
                first.setEnabled(container.getStartIndex() > 0);
                previous.setEnabled(container.getStartIndex() > 0);
                next.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength());
                last.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength());
                currentPageTextField.setValue(String.valueOf(getCurrentPage()));
                totalPagesLabel.setValue(Integer.toString(getTotalAmountOfPages()));
                itemsPerPageSelect.setValue(getPageLength());
                inMiddleOfValueChange = false;
            }
        }
    });
    return controlBar;
}

From source file:org.bubblecloud.ilves.comment.CommentListComponent.java

License:Open Source License

public void refresh() {

    final String contextPath = VaadinService.getCurrentRequest().getContextPath();
    final Site site = Site.getCurrent();

    final Company company = site.getSiteContext().getObject(Company.class);
    final EntityManager entityManager = site.getSiteContext().getObject(EntityManager.class);

    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<Comment> commentCriteriaQuery = builder.createQuery(Comment.class);
    final Root<Comment> commentRoot = commentCriteriaQuery.from(Comment.class);
    commentCriteriaQuery.where(builder.and(builder.equal(commentRoot.get("owner"), company),
            builder.equal(commentRoot.get("dataId"), contextPath)));
    commentCriteriaQuery.orderBy(builder.asc(commentRoot.get("created")));

    final TypedQuery<Comment> commentTypedQuery = entityManager.createQuery(commentCriteriaQuery);
    final List<Comment> commentList = commentTypedQuery.getResultList();

    final Panel panel = new Panel(site.localize("panel-comments"));
    setCompositionRoot(panel);//from w  ww . j av a2 s  .c  o  m

    final GridLayout gridLayout = new GridLayout(3, commentList.size() + 1);
    panel.setContent(gridLayout);
    gridLayout.setSpacing(true);
    gridLayout.setMargin(true);
    gridLayout.setColumnExpandRatio(0, 0.0f);
    gridLayout.setColumnExpandRatio(1, 0.1f);
    gridLayout.setColumnExpandRatio(2, 0.9f);

    final Label authorHeaderLabel = new Label();
    authorHeaderLabel.setStyleName(ValoTheme.LABEL_BOLD);
    authorHeaderLabel.setValue(site.localize("column-header-author"));
    gridLayout.addComponent(authorHeaderLabel, 0, 0, 1, 0);

    final Label commentHeaderLabel = new Label();
    commentHeaderLabel.setStyleName(ValoTheme.LABEL_BOLD);
    commentHeaderLabel.setValue(site.localize("column-header-comment"));
    gridLayout.addComponent(commentHeaderLabel, 2, 0);

    for (int i = 0; i < commentList.size(); i++) {
        final Comment comment = commentList.get(i);

        final Link authorImageLink = GravatarUtil.getGravatarImageLink(comment.getAuthor().getEmailAddress());
        gridLayout.addComponent(authorImageLink, 0, i + 1);

        final Label authorLabel = new Label();
        final String authorName = comment.getAuthor().getFirstName();
        authorLabel.setValue(authorName);
        gridLayout.addComponent(authorLabel, 1, i + 1);

        final Label messageLabel = new Label();
        messageLabel.setValue(comment.getMessage());
        gridLayout.addComponent(messageLabel, 2, i + 1);
    }

}

From source file:org.bubblecloud.ilves.site.view.valo.DefaultValoView.java

License:Apache License

private CssLayout buildMenu() {

    final HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setWidth("100%");
    topLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    topLayout.addStyleName("valo-menu-title");
    menu.addComponent(topLayout);//from  w  w  w.j  av a2s. co  m

    final Button showMenu = new Button("Menu", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (menu.getStyleName().contains("valo-menu-visible")) {
                menu.removeStyleName("valo-menu-visible");
            } else {
                menu.addStyleName("valo-menu-visible");
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(ValoTheme.BUTTON_SMALL);
    showMenu.addStyleName("valo-menu-toggle");
    showMenu.setIcon(FontAwesome.LIST);
    menu.addComponent(showMenu);

    final Label title = new Label("<h3>" + Site.getCurrent().localize(getViewVersion().getTitle()) + "</h3>",
            ContentMode.HTML);
    title.setSizeUndefined();
    topLayout.addComponent(title);
    topLayout.setExpandRatio(title, 1);

    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");

    final String user = Site.getCurrent().getSecurityProvider().getUser();
    final String userMenuCaption;
    final Resource userMenuIcon;
    if (user == null) {
        userMenuCaption = Site.getCurrent().localize("page-link-login");
        userMenuIcon = new ThemeResource("ilves_logo.png");
    } else {
        final URL gravatarUrl = GravatarUtil.getGravatarUrl(user, 64);
        userMenuIcon = new ExternalResource(gravatarUrl);
        userMenuCaption = ((SecurityProviderSessionImpl) Site.getCurrent().getSecurityProvider())
                .getUserFromSession().getFirstName();
    }

    final MenuBar.MenuItem settingsItem = settings.addItem(userMenuCaption, userMenuIcon, null);
    if (user != null) {
        settingsItem.addItem(Site.getCurrent().localize("page-link-account"), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                UI.getCurrent().getNavigator().navigateTo("account");
            }
        });
        settingsItem.addSeparator();
        settingsItem.addItem(Site.getCurrent().localize("button-logout"), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                LoginService.logout(Site.getCurrent().getSiteContext());
                final Company company = Site.getCurrent().getSiteContext().getObject(Company.class);
                getUI().getPage().setLocation(company.getUrl());
                getSession().getSession().invalidate();
                getSession().close();
            }
        });
    } else {
        settingsItem.addItem(Site.getCurrent().localize("page-link-login"), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                UI.getCurrent().getNavigator().navigateTo("login");
            }
        });
    }
    menu.addComponent(settings);

    menuItemsLayout.setPrimaryStyleName("valo-menuitems");
    menu.addComponent(menuItemsLayout);

    final Site site = Site.getCurrent();
    final NavigationVersion navigationVersion = site.getCurrentNavigationVersion();

    for (final String pageName : navigationVersion.getRootPages()) {
        final ViewVersion pageVersion = site.getCurrentViewVersion(pageName);
        if (pageVersion == null) {
            throw new SiteException("Unknown page: " + pageName);
        }
        if (pageVersion.getViewerRoles().length > 0) {
            boolean roleMatch = false;
            for (final String role : pageVersion.getViewerRoles()) {
                if (site.getSecurityProvider().getRoles().contains(role)) {
                    roleMatch = true;
                    break;
                }
            }
            if (!roleMatch) {
                continue;
            }
        }

        if (navigationVersion.hasChildPages(pageName)) {

            final String localizedPageName = pageVersion.isDynamic() ? pageName
                    : site.localize("page-link-" + pageName);

            final Label label = new Label(localizedPageName, ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);

            final List<String> childPages = navigationVersion.getChildPages(pageName);
            for (final String childPage : childPages) {
                addMenuLink(navigationVersion, childPage);
            }

            label.setValue(
                    label.getValue() + " <span class=\"valo-menu-badge\">" + childPages.size() + "</span>");
        } else {
            addMenuLink(navigationVersion, pageName);
        }
    }

    return menu;
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadConfirmationWindow.java

License:Open Source License

private static Label getWarningLabel() {
    final Label warningIconLabel = new Label();
    warningIconLabel.addStyleName(ValoTheme.LABEL_SMALL);
    warningIconLabel.setHeightUndefined();
    warningIconLabel.setContentMode(ContentMode.HTML);
    warningIconLabel.setValue(FontAwesome.WARNING.getHtml());
    warningIconLabel.addStyleName("warningLabel");
    warningIconLabel.setVisible(false);/*from  w ww.  j a va 2  s .c  o  m*/
    return warningIconLabel;
}

From source file:org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable.java

License:Open Source License

private VerticalLayout createSoftModuleLayout(final SoftwareModuleType swModType,
        final DistributionSet distributionSet, final Set<SoftwareModule> alreadyAssignedSwModules) {
    final VerticalLayout verticalLayout = new VerticalLayout();
    for (final SoftwareModule sw : alreadyAssignedSwModules) {
        if (swModType.getKey().equals(sw.getType().getKey())) {
            final HorizontalLayout horizontalLayout = new HorizontalLayout();
            horizontalLayout.setSizeFull();
            final Label softwareModule = HawkbitCommonUtil.getFormatedLabel("");
            final Button reassignSoftModule = SPUIComponentProvider.getButton(sw.getName(), "", "", "", true,
                    FontAwesome.TIMES, SPUIButtonStyleNoBorder.class);
            reassignSoftModule/*from   ww w . j  a v a  2s.c  o m*/
                    .addClickListener(event -> unassignSW(event, distributionSet, alreadyAssignedSwModules));
            final String softwareModNameVersion = HawkbitCommonUtil.getFormattedNameVersion(sw.getName(),
                    sw.getVersion());
            softwareModule.setValue(softwareModNameVersion);
            softwareModule.setDescription(softwareModNameVersion);
            softwareModule.setId(sw.getName() + "-label");
            horizontalLayout.addComponent(softwareModule);
            horizontalLayout.setExpandRatio(softwareModule, 1F);
            if (isUnassignSoftModAllowed && permissionChecker.hasUpdateRepositoryPermission()
                    && !isTargetAssigned
                    && (isSoftModAvaiableForSoftType(alreadyAssignedSwModules, swModType))) {
                horizontalLayout.addComponent(reassignSoftModule);
            }
            verticalLayout.addComponent(horizontalLayout);
        }

    }

    return verticalLayout;
}

From source file:org.eclipse.hawkbit.ui.distributions.dstable.DistributionSetDetails.java

License:Open Source License

private static VerticalLayout createSoftwareModuleLayout(final String softwareModuleName) {
    final VerticalLayout verticalLayout = new VerticalLayout();
    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSizeFull();//from w w  w. ja  va 2 s .  co  m
    final Label softwareModule = HawkbitCommonUtil.getFormatedLabel("");
    softwareModule.setValue(softwareModuleName);
    softwareModule.setDescription(softwareModuleName);
    softwareModule.setId(softwareModuleName + "-label");
    horizontalLayout.addComponent(softwareModule);
    horizontalLayout.setExpandRatio(softwareModule, 1F);
    verticalLayout.addComponent(horizontalLayout);
    return verticalLayout;
}