Example usage for com.vaadin.server ExternalResource ExternalResource

List of usage examples for com.vaadin.server ExternalResource ExternalResource

Introduction

In this page you can find the example usage for com.vaadin.server ExternalResource ExternalResource.

Prototype

public ExternalResource(String sourceURL) 

Source Link

Document

Creates a new download component for downloading directly from given URL.

Usage

From source file:org.bitpimp.VaadinCurrencyConverter.MyVaadinApplication.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    // Set the window or tab title
    getPage().setTitle("Yahoo Currency Converter");

    // Create the content root layout for the UI
    final FormLayout content = new FormLayout();
    content.setMargin(true);//  w ww . j  a  v  a 2 s. c o  m
    final Panel panel = new Panel(content);
    panel.setWidth("500");
    panel.setHeight("400");
    final VerticalLayout root = new VerticalLayout();
    root.addComponent(panel);
    root.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
    root.setSizeFull();
    root.setMargin(true);

    setContent(root);

    content.addComponent(new Embedded("",
            new ExternalResource("https://vaadin.com/vaadin-theme/images/vaadin/vaadin-logo-color.png")));
    content.addComponent(new Embedded("",
            new ExternalResource("http://images.wikia.com/logopedia/images/e/e4/YahooFinanceLogo.png")));

    // Display the greeting
    final Label heading = new Label("<b>Simple Currency Converter " + "Using YQL/Yahoo Finance Service</b>",
            ContentMode.HTML);
    heading.setWidth(null);
    content.addComponent(heading);

    // Build the set of fields for the converter form
    final TextField fromField = new TextField("From Currency", "AUD");
    fromField.setRequired(true);
    fromField.addValidator(new StringLengthValidator(CURRENCY_CODE_REQUIRED, 3, 3, false));
    content.addComponent(fromField);

    final TextField toField = new TextField("To Currency", "USD");
    toField.setRequired(true);
    toField.addValidator(new StringLengthValidator(CURRENCY_CODE_REQUIRED, 3, 3, false));
    content.addComponent(toField);

    final TextField resultField = new TextField("Result");
    resultField.setEnabled(false);
    content.addComponent(resultField);

    final TextField timeField = new TextField("Time");
    timeField.setEnabled(false);
    content.addComponent(timeField);

    final Button submitButton = new Button("Submit", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // Do the conversion
            final String result = converter.convert(fromField.getValue().toUpperCase(),
                    toField.getValue().toUpperCase());
            if (result != null) {
                resultField.setValue(result);
                timeField.setValue(new Date().toString());
            }
        }
    });
    content.addComponent(submitButton);

    // Configure the error handler for the UI
    UI.getCurrent().setErrorHandler(new DefaultErrorHandler() {
        @Override
        public void error(com.vaadin.server.ErrorEvent event) {
            // Find the final cause
            String cause = "<b>The operation failed :</b><br/>";
            Throwable th = Throwables.getRootCause(event.getThrowable());
            if (th != null)
                cause += th.getClass().getName() + "<br/>";

            // Display the error message in a custom fashion
            content.addComponent(new Label(cause, ContentMode.HTML));

            // Do the default error handling (optional)
            doDefault(event);
        }
    });
}

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 ww.jav a  2s  . c o 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.components.SPUIComponentProvider.java

License:Open Source License

/**
 * Method to create a link.//  w  w  w.j a  v  a  2 s . com
 *
 * @param id
 *            of the link
 * @param name
 *            of the link
 * @param resource
 *            path of the link
 * @param icon
 *            of the link
 * @param targetOpen
 *            specify how the link should be open (f. e. new windows =
 *            _blank)
 * @param style
 *            chosen style of the link. Might be {@code null} if no style
 *            should be used
 * @return a link UI component
 */
public static Link getLink(final String id, final String name, final String resource, final FontAwesome icon,
        final String targetOpen, final String style) {

    final Link link = new Link(name, new ExternalResource(resource));
    link.setId(id);
    link.setIcon(icon);
    link.setDescription(name);

    link.setTargetName(targetOpen);
    if (style != null) {
        link.setStyleName(style);
    }

    return link;

}

From source file:org.eclipse.hawkbit.ui.components.SPUIComponentProvider.java

License:Open Source License

/**
 * Generates help/documentation links from within management UI.
 *
 * @param i18n//from w ww . ja  va2  s.com
 *            the i18n
 * @param uri
 *            to documentation site
 *
 * @return generated link
 */
public static Link getHelpLink(final VaadinMessageSource i18n, final String uri) {

    final Link link = new Link("", new ExternalResource(uri));
    link.setTargetName("_blank");
    link.setIcon(FontAwesome.QUESTION_CIRCLE);
    link.setDescription(i18n.getMessage("tooltip.documentation.link"));
    return link;

}

From source file:org.esn.esobase.view.MainView.java

private void buildHeader() {
    headerLayout.setMargin(false);//  w  w  w  .  j  a va  2  s .  c o m
    headerLayout.setSpacing(false);
    headerLayout.setWidth(100f, Unit.PERCENTAGE);
    headerLayout.addComponent(loginLabel, 7, 0);
    ExternalResource resource = new ExternalResource("j_spring_security_logout");
    logoutLink.setResource(resource);
    logoutLink.setCaption("");
    headerLayout.addComponent(logoutLink, 8, 0);
}

From source file:org.esn.esobase.view.tab.QuestTranslateTab.java

public QuestTranslateTab(DBService service_) {
    this.setSizeFull();
    this.setSpacing(false);
    this.setMargin(false);
    this.service = service_;
    QuestChangeListener questChangeListener = new QuestChangeListener();
    FilterChangeListener filterChangeListener = new FilterChangeListener();
    questListlayout = new HorizontalLayout();
    questListlayout.setWidth(100f, Unit.PERCENTAGE);
    questListlayout.setSpacing(false);//from   w w w  .  j  a  v  a2 s  .co  m
    questListlayout.setMargin(false);
    locationTable = new ComboBox("?");
    locationTable.setPageLength(30);
    locationTable.setScrollToSelectedItem(true);
    locationTable.setWidth(100f, Unit.PERCENTAGE);
    locationTable.addValueChangeListener(filterChangeListener);
    locationTable.setDataProvider(new ListDataProvider<>(locations));
    questTable = new ComboBox("?");
    questTable.setWidth(100f, Unit.PERCENTAGE);
    questTable.setPageLength(15);
    questTable.setScrollToSelectedItem(true);

    questTable.setWidth(100f, Unit.PERCENTAGE);
    questTable.addValueChangeListener(questChangeListener);
    questTable.setDataProvider(new ListDataProvider<>(questList));
    questListlayout.addComponent(questTable);
    FormLayout locationAndQuestLayout = new FormLayout(locationTable, questTable);
    locationAndQuestLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    locationAndQuestLayout.setSizeFull();
    questListlayout.addComponent(locationAndQuestLayout);
    translateStatus = new ComboBoxMultiselect("? ",
            Arrays.asList(TRANSLATE_STATUS.values()));
    translateStatus.setClearButtonCaption("?");
    translateStatus.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            LoadFilters();
            LoadContent();
        }
    });
    noTranslations = new CheckBox("?  ?");
    noTranslations.setValue(Boolean.FALSE);
    noTranslations.addValueChangeListener(filterChangeListener);
    emptyTranslations = new CheckBox("?  ");
    emptyTranslations.setValue(Boolean.FALSE);
    emptyTranslations.addValueChangeListener(filterChangeListener);
    HorizontalLayout checkBoxlayout = new HorizontalLayout(noTranslations, emptyTranslations);
    checkBoxlayout.setSpacing(false);
    checkBoxlayout.setMargin(false);
    translatorBox = new ComboBox("");
    translatorBox.setPageLength(15);
    translatorBox.setScrollToSelectedItem(true);
    translatorBox.setDataProvider(new ListDataProvider<SysAccount>(service.getSysAccounts()));
    translatorBox.addValueChangeListener(filterChangeListener);
    refreshButton = new Button("");
    refreshButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            LoadFilters();
            LoadContent();
        }
    });
    countLabel = new Label();
    searchField = new TextField("?? ?");
    searchField.setSizeFull();
    searchField.addValueChangeListener(filterChangeListener);

    FormLayout filtersLayout = new FormLayout(translateStatus, translatorBox, checkBoxlayout, searchField);
    filtersLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    filtersLayout.setSizeFull();
    questListlayout.addComponent(filtersLayout);
    questListlayout.addComponent(refreshButton);
    questListlayout.addComponent(countLabel);
    questListlayout.setExpandRatio(locationAndQuestLayout, 0.4f);
    questListlayout.setExpandRatio(filtersLayout, 0.4f);
    questListlayout.setExpandRatio(refreshButton, 0.1f);
    questListlayout.setExpandRatio(countLabel, 0.1f);
    questListlayout.setHeight(105f, Unit.PIXELS);
    this.addComponent(questListlayout);
    infoLayout = new VerticalLayout();
    infoLayout.setSizeFull();
    infoLayout.setSpacing(false);
    infoLayout.setMargin(false);
    tabSheet = new TabSheet();
    tabSheet.setSizeFull();
    nameLayout = new VerticalLayout();
    nameLayout.setSizeFull();
    nameHLayout = new HorizontalLayout();
    nameHLayout.setSizeFull();
    nameHLayout.setSpacing(false);
    nameHLayout.setMargin(false);
    nameLayout = new VerticalLayout();
    nameLayout.setSizeFull();
    nameLayout.setSpacing(false);
    nameLayout.setMargin(false);
    questNameEnArea = new TextArea("?");
    questNameEnArea.setSizeFull();
    questNameEnArea.setRows(1);
    questNameEnArea.setReadOnly(true);
    questNameRuArea = new TextArea("? Ru");
    questNameRuArea.setSizeFull();
    questNameRuArea.setRows(1);
    questNameRuArea.setReadOnly(true);
    questNameRawEnArea = new TextArea("?  ");
    questNameRawEnArea.setSizeFull();
    questNameRawEnArea.setRows(1);
    questNameRawEnArea.setReadOnly(true);
    questNameRawRuArea = new TextArea("?   Ru");
    questNameRawRuArea.setSizeFull();
    questNameRawRuArea.setRows(1);
    questNameRawRuArea.setReadOnly(true);
    nameLayout.addComponents(questNameEnArea, questNameRuArea, questNameRawEnArea, questNameRawRuArea);
    nameHLayout.addComponent(nameLayout);
    nameTranslateLayout = new VerticalLayout();
    nameTranslateLayout.setSizeFull();
    nameTranslateLayout.setSpacing(false);
    nameTranslateLayout.setMargin(false);
    nameHLayout.addComponent(nameTranslateLayout);
    infoLayout.addComponent(nameHLayout);
    descriptionLayout = new VerticalLayout();
    descriptionLayout.setSizeFull();
    descriptionHLayout = new HorizontalLayout();
    descriptionHLayout.setSizeFull();
    descriptionHLayout.setSpacing(false);
    descriptionHLayout.setMargin(false);
    descriptionLayout = new VerticalLayout();
    descriptionLayout.setSizeFull();
    descriptionLayout.setSpacing(false);
    descriptionLayout.setMargin(false);
    questDescriptionEnArea = new TextArea("?");
    questDescriptionEnArea.setSizeFull();
    questDescriptionEnArea.setRows(4);
    questDescriptionEnArea.setReadOnly(true);
    questDescriptionRuArea = new TextArea("? Ru");
    questDescriptionRuArea.setSizeFull();
    questDescriptionRuArea.setRows(4);
    questDescriptionRuArea.setReadOnly(true);
    questDescriptionRawEnArea = new TextArea("?  ");
    questDescriptionRawEnArea.setSizeFull();
    questDescriptionRawEnArea.setRows(4);
    questDescriptionRawEnArea.setReadOnly(true);
    questDescriptionRawRuArea = new TextArea("?   Ru");
    questDescriptionRawRuArea.setSizeFull();
    questDescriptionRawRuArea.setRows(4);
    questDescriptionRawRuArea.setReadOnly(true);
    descriptionLayout.addComponents(questDescriptionEnArea, questDescriptionRuArea, questDescriptionRawEnArea,
            questDescriptionRawRuArea);
    descriptionHLayout.addComponent(descriptionLayout);
    descriptionTranslateLayout = new VerticalLayout();
    descriptionTranslateLayout.setSizeFull();
    descriptionTranslateLayout.setSpacing(false);
    descriptionTranslateLayout.setMargin(false);
    descriptionHLayout.addComponent(descriptionTranslateLayout);
    infoLayout.addComponent(descriptionHLayout);
    tabSheet.addTab(infoLayout, "?");
    stepsLayout = new VerticalLayout();
    stepsLayout.setSizeFull();
    stepsLayout.setSpacing(false);
    stepsLayout.setMargin(false);
    stepsData = new TreeData();
    stepsGrid = new TreeGrid(new TreeDataProvider(stepsData));
    stepsGrid.setSelectionMode(Grid.SelectionMode.NONE);
    stepsGrid.setRowHeight(250);
    stepsGrid.setHeaderVisible(false);
    stepsGrid.setSizeFull();
    stepsGrid.setItemCollapseAllowedProvider(new ItemCollapseAllowedProvider() {
        @Override
        public boolean test(Object item) {
            return false;
        }
    });
    stepsGrid.addColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            if (source instanceof QuestStep) {
                return "?";
            }
            if (source instanceof QuestDirection) {
                return " - " + ((QuestDirection) source).getDirectionType().name();
            }
            return null;
        }
    }).setId("rowType").setCaption("").setWidth(132).setStyleGenerator(rowStyleGenerator);
    stepsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestStep) {

                QuestStep step = (QuestStep) source;
                if (step.getTextEn() != null && !step.getTextEn().isEmpty()) {
                    TextArea textEnArea = new TextArea("?  ");
                    textEnArea.setValue(step.getTextEn());
                    textEnArea.setReadOnly(true);
                    textEnArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnArea);
                }
                if (step.getTextRu() != null && !step.getTextRu().isEmpty()) {
                    TextArea textRuArea = new TextArea("  ");
                    textRuArea.setValue(step.getTextRu());
                    textRuArea.setReadOnly(true);
                    textRuArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textRuArea);
                }
            } else if (source instanceof QuestDirection) {
                QuestDirection d = (QuestDirection) source;
                if (d.getTextEn() != null && !d.getTextEn().isEmpty()) {
                    TextArea textEnArea = new TextArea("?  ");
                    textEnArea.setValue(d.getTextEn());
                    textEnArea.setRows(2);
                    textEnArea.setReadOnly(true);
                    textEnArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnArea);
                }
                if (d.getTextRu() != null && !d.getTextRu().isEmpty()) {
                    TextArea textRuArea = new TextArea("  ");
                    textRuArea.setValue(d.getTextRu());
                    textRuArea.setRows(2);
                    textRuArea.setReadOnly(true);
                    textRuArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textRuArea);
                }

            }
            return result;
        }
    }).setId("ingameText").setStyleGenerator(rowStyleGenerator);
    stepsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestStep) {

                QuestStep step = (QuestStep) source;
                if (step.getSheetsJournalEntry() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(step.getSheetsJournalEntry().getTextEn());
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (step.getSheetsJournalEntry().getTextRu() != null && !step.getSheetsJournalEntry()
                            .getTextRu().equals(step.getSheetsJournalEntry().getTextEn())) {
                        TextArea textRuRawArea = new TextArea("    "
                                + step.getSheetsJournalEntry().getTranslator());
                        textRuRawArea.setValue(step.getSheetsJournalEntry().getTextRu());
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);//, "  " 
                    }
                }

            } else if (source instanceof QuestDirection) {
                QuestDirection d = (QuestDirection) source;
                if (d.getSheetsQuestDirection() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(d.getSheetsQuestDirection().getTextEn());
                    textEnRawArea.setRows(2);
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (d.getSheetsQuestDirection().getTextRu() != null && !d.getSheetsQuestDirection()
                            .getTextRu().equals(d.getSheetsQuestDirection().getTextEn())) {
                        TextArea textRuRawArea = new TextArea("    "
                                + d.getSheetsQuestDirection().getTranslator());
                        textRuRawArea.setValue(d.getSheetsQuestDirection().getTextRu());
                        textRuRawArea.setRows(2);
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);
                    }
                }
            }
            return result;
        }
    }).setId("rawText").setStyleGenerator(rowStyleGenerator);
    stepsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            Panel panel = new Panel();
            panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
            panel.setWidth(100f, Unit.PERCENTAGE);
            panel.setHeight(245f, Unit.PIXELS);
            final VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestStep) {

                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestStep step = (QuestStep) source;
                list.addAll(step.getSheetsJournalEntry().getTranslatedTexts());

                if (list != null) {
                    for (TranslatedText t : list) {
                        result.addComponent(new TranslationCell(t));
                        accounts.add(t.getAuthor());
                    }
                }
                if (!accounts.contains(SpringSecurityHelper.getSysAccount())
                        && step.getSheetsJournalEntry() != null
                        && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                    final TranslatedText translatedText = new TranslatedText();
                    translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                    translatedText.setSpreadSheetsJournalEntry(step.getSheetsJournalEntry());
                    Button addTranslation = new Button(" ",
                            FontAwesome.PLUS_SQUARE);
                    addTranslation.addClickListener(new Button.ClickListener() {

                        @Override
                        public void buttonClick(Button.ClickEvent event) {

                            if (translatedText.getSpreadSheetsJournalEntry() != null) {
                                translatedText.getSpreadSheetsJournalEntry().getTranslatedTexts()
                                        .add(translatedText);
                            }
                            result.addComponent(new TranslationCell(translatedText));
                            event.getButton().setVisible(false);
                        }
                    });
                    result.addComponent(addTranslation);
                }
            } else if (source instanceof QuestDirection) {
                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestDirection d = (QuestDirection) source;
                list.addAll(d.getSheetsQuestDirection().getTranslatedTexts());

                if (list != null) {
                    for (TranslatedText t : list) {
                        result.addComponent(new TranslationCell(t));
                        accounts.add(t.getAuthor());
                    }
                }
                if (!accounts.contains(SpringSecurityHelper.getSysAccount())
                        && d.getSheetsQuestDirection() != null
                        && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                    final TranslatedText translatedText = new TranslatedText();
                    translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                    translatedText.setSpreadSheetsQuestDirection(d.getSheetsQuestDirection());
                    Button addTranslation = new Button(" ");
                    addTranslation.addClickListener(new Button.ClickListener() {

                        @Override
                        public void buttonClick(Button.ClickEvent event) {

                            if (translatedText.getSpreadSheetsQuestDirection() != null) {
                                translatedText.getSpreadSheetsQuestDirection().getTranslatedTexts()
                                        .add(translatedText);
                            }
                            result.addComponent(new TranslationCell(translatedText));
                            event.getButton().setVisible(false);
                        }
                    });
                    result.addComponent(addTranslation);
                }
            }
            panel.setContent(result);
            return panel;
        }
    }).setId("translation").setStyleGenerator(rowStyleGenerator);
    stepsGrid.setColumns("rowType", "ingameText", "rawText", "translation");
    stepsLayout.addComponent(stepsGrid);
    tabSheet.addTab(stepsLayout, "");
    itemsGrid = new Grid(new ListDataProvider(itemList));
    itemsGrid.setSelectionMode(Grid.SelectionMode.NONE);
    itemsGrid.setRowHeight(250);
    itemsGrid.setHeaderVisible(false);
    itemsGrid.setSizeFull();
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                QuestItem item = (QuestItem) source;
                if (item.getName() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(item.getName().getTextEn());
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (item.getName().getTextRu() != null
                            && !item.getName().getTextRu().equals(item.getName().getTextEn())) {
                        TextArea textRuRawArea = new TextArea(
                                " ?    "
                                        + item.getName().getTranslator());
                        textRuRawArea.setValue(item.getName().getTextRu());
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);//, "  " 
                    }
                }

            }
            return result;
        }
    }).setId("rawName");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                QuestItem item = (QuestItem) source;
                if (item.getDescription() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(item.getDescription().getTextEn());
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (item.getDescription().getTextRu() != null
                            && !item.getDescription().getTextRu().equals(item.getDescription().getTextEn())) {
                        TextArea textRuRawArea = new TextArea(
                                " ??    "
                                        + item.getDescription().getTranslator());
                        textRuRawArea.setValue(item.getDescription().getTextRu());
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);//, "  " 
                    }
                }

            }
            return result;
        }
    }).setId("rawDescription");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            Panel panel = new Panel();
            panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
            panel.setWidth(100f, Unit.PERCENTAGE);
            panel.setHeight(245f, Unit.PIXELS);
            final VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestItem item = (QuestItem) source;
                if (item.getName() != null) {
                    String text = item.getName().getTextEn();
                    list.addAll(item.getName().getTranslatedTexts());

                    if (list != null) {
                        for (TranslatedText t : list) {
                            result.addComponent(new TranslationCell(t));
                            accounts.add(t.getAuthor());
                        }
                    }
                    if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && text != null
                            && !text.isEmpty() && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                        final TranslatedText translatedText = new TranslatedText();
                        translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                        translatedText.setSpreadSheetsItemName(item.getName());
                        Button addTranslation = new Button(" ",
                                FontAwesome.PLUS_SQUARE);
                        addTranslation.addClickListener(new Button.ClickListener() {

                            @Override
                            public void buttonClick(Button.ClickEvent event) {

                                if (translatedText.getSpreadSheetsItemName() != null) {
                                    translatedText.getSpreadSheetsItemName().getTranslatedTexts()
                                            .add(translatedText);
                                }
                                result.addComponent(new TranslationCell(translatedText));
                                event.getButton().setVisible(false);
                            }
                        });
                        result.addComponent(addTranslation);
                    }
                }
            }
            panel.setContent(result);
            return panel;
        }
    }).setId("nameTranslation");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            Panel panel = new Panel();
            panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
            panel.setWidth(100f, Unit.PERCENTAGE);
            panel.setHeight(245f, Unit.PIXELS);
            final VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestItem item = (QuestItem) source;
                if (item.getDescription() != null) {
                    String text = item.getDescription().getTextEn();
                    list.addAll(item.getDescription().getTranslatedTexts());

                    if (list != null) {
                        for (TranslatedText t : list) {
                            result.addComponent(new TranslationCell(t));
                            accounts.add(t.getAuthor());
                        }
                    }
                    if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && text != null
                            && !text.isEmpty() && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                        final TranslatedText translatedText = new TranslatedText();
                        translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                        translatedText.setSpreadSheetsItemDescription(item.getDescription());
                        Button addTranslation = new Button(" ",
                                FontAwesome.PLUS_SQUARE);
                        addTranslation.addClickListener(new Button.ClickListener() {

                            @Override
                            public void buttonClick(Button.ClickEvent event) {

                                if (translatedText.getSpreadSheetsItemDescription() != null) {
                                    translatedText.getSpreadSheetsItemDescription().getTranslatedTexts()
                                            .add(translatedText);
                                }
                                result.addComponent(new TranslationCell(translatedText));
                                event.getButton().setVisible(false);
                            }
                        });
                        result.addComponent(addTranslation);
                    }
                }
            }
            panel.setContent(result);
            return panel;
        }
    }).setId("descriptionTranslation");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setMargin(new MarginInfo(true, false, false, false));
            result.setSpacing(false);
            if (source instanceof QuestItem) {
                GSpreadSheetsItemName name = ((QuestItem) source).getName();
                if (name.getIcon() != null) {
                    Image image = new Image(null, new ExternalResource(
                            "https://elderscrolls.net" + name.getIcon().replaceAll(".dds", ".png")));
                    result.addComponent(image);
                    return result;
                }
            }
            return result;
        }
    }).setId("icon").setWidth(95);
    itemsGrid.setColumns("icon", "rawName", "nameTranslation", "rawDescription", "descriptionTranslation");
    tabSheet.addTab(itemsGrid, "");
    this.addComponent(tabSheet);
    this.setExpandRatio(tabSheet, 1f);
    GridScrollExtension stepsScrollExtension = new GridScrollExtension(stepsGrid);
    GridScrollExtension itemsScrollExtension = new GridScrollExtension(itemsGrid);
    new NoAutcompleteComboBoxExtension(locationTable);
    new NoAutcompleteComboBoxExtension(questTable);
    new NoAutcompleteComboBoxExtension(translatorBox);
    LoadFilters();
}

From source file:org.geant.sat.ui.MainView.java

License:BSD License

/** {@inheritDocs}. */
@SuppressWarnings("rawtypes")
@Override//from w w  w .  j  a  v a 2  s.  co m
public void enter(ViewChangeEvent event) {
    if (MENU_ENTITIES.equals(event.getParameters())) {
        workPanel.setContent(new EntityListViewer((MainUI) getUI()));
        return;
    }
    if (MENU_SURVEYS.equals(event.getParameters())) {
        workPanel.setContent(new SurveyViewer((MainUI) getUI()));
        return;
    }
    if (MENU_USERS.equals(event.getParameters())) {
        workPanel.setContent(new UserListViewer((MainUI) getUI()));
        return;
    }
    if (MENU_PROFILE.equals(event.getParameters())) {
        workPanel.setContent(new ProfileViewer((MainUI) getUI(), ((MainUI) getUI()).getUser().getDetails()));
        return;
    }
    if (MENU_ABOUT.equals(event.getParameters())) {
        workPanel.setContent(new AboutViewer());
        return;
    }
    if (MENU_LIMESURVEY.equals(event.getParameters())) {
        final String hostUrl = getBaseUrl(((MainUI) getUI()).getPage().getLocation());
        log.debug("Using the following baseUrl: {}", hostUrl);
        final String limesurveyPath = ((MainUI) getUI()).getLimesurveyPath();
        log.debug("The limesurvey path is {}", limesurveyPath);
        final BrowserFrame browserFrame = new BrowserFrame("Browser",
                new ExternalResource(hostUrl + limesurveyPath + "admin/"));
        browserFrame.setHeight("100%");
        browserFrame.setWidth("100%");
        workPanel.setContent(browserFrame);
        return;
    }
    workPanel.setContent(new AboutViewer());
    return;

}

From source file:org.generationcp.breeding.manager.listimport.EmbeddedGermplasmListDetailComponent.java

License:Open Source License

@Override
public void afterPropertiesSet() throws Exception {
    setMargin(false);//from www .j a  v a  2 s. c  o m
    setSpacing(true);
    setWidth("800px");

    Tool tool = null;
    try {
        tool = workbenchDataManager.getToolWithName(ToolName.germplasm_list_browser.toString());
    } catch (MiddlewareQueryException qe) {
        LOG.error("QueryException", qe);
    }

    ExternalResource listBrowserLink = null;
    if (tool == null) {
        listBrowserLink = new ExternalResource(
                "http://localhost:18080/GermplasmStudyBrowser/main/germplasmlist-" + listId);
    } else {
        listBrowserLink = new ExternalResource(
                tool.getPath().replace("germplasmlist/", "germplasmlist-") + listId);
    }

    VerticalLayout layoutForList = new VerticalLayout();
    layoutForList.setMargin(false);
    layoutForList.setSpacing(false);

    BrowserFrame listInfoPage = new BrowserFrame("", listBrowserLink);
    listInfoPage.setSizeFull();
    layoutForList.setHeight("550px");
    layoutForList.addComponent(listInfoPage);

    GermplasmImportButtonClickListener listener = new GermplasmImportButtonClickListener(this);
    /*
    exportButton = new Button();
    exportButton.setData(EXPORT_BUTTON_ID);
    exportButton.addListener(listener);
    */
    makeImportButton = new Button();
    makeImportButton.setData(NEW_IMPORT_BUTTON_ID);
    makeImportButton.addListener(listener);

    HorizontalLayout buttonArea = new HorizontalLayout();
    buttonArea.setMargin(true);
    buttonArea.setSpacing(true);
    buttonArea.addComponent(makeImportButton);

    addComponent(layoutForList);
    addComponent(buttonArea);
    setComponentAlignment(buttonArea, Alignment.BOTTOM_RIGHT);
}

From source file:org.inakirj.imagerulette.screens.DiceGallerySetupView.java

License:Open Source License

/**
 * Adds the row./*from   ww  w  .j  a  va  2s.c om*/
 */
public void addRow(String urlEntry) {
    DiceItem itemCreated = new DiceItem();
    Button validateButton = new Button();
    validateButton.setIcon(FontAwesome.CHECK_CIRCLE_O);
    validateButton.addClickListener(e -> validateUrl(itemCreated));
    itemCreated.setValidateImg(validateButton);
    Image imgRow = null;
    String url = null;
    if (urlEntry != null) {
        StringTokenizer urlEntryTokenizer = new StringTokenizer(urlEntry, " ");
        url = urlEntryTokenizer.nextToken();
        ExternalResource resource = new ExternalResource(url);
        imgRow = new Image("", resource);
        itemCreated.setId(getNextId());
    } else {
        imgRow = new Image("", null);
    }
    imgRow.addStyleName("dice-image");
    imgRow.addStyleName("dice-align-center");
    itemCreated.setImg(imgRow);
    TextField textRow = new TextField();
    textRow.addStyleName("url-style");
    if (url != null) {
        textRow.setValue(url);
        validateButton.setIcon(FontAwesome.CHECK_CIRCLE);
    }
    itemCreated.setUrl(textRow);
    if (urlEntry != null) {
        itemCreated.getUrl().setEnabled(false);
    }
    itemCreated.setValid(imgRow != null);

    Button deleteButton = new Button();
    deleteButton.setIcon(FontAwesome.TRASH);
    itemCreated.setDeleteImg(deleteButton);
    deleteButton.addClickListener(e -> deleteUrl(itemCreated));

    newDataSource.addBean(itemCreated);
    hasReachLimitImages = newDataSource.size() == TOTAL_URL_LIMIT;
}

From source file:org.inakirj.imagerulette.screens.DiceGallerySetupView.java

License:Open Source License

/**
 * Validate url./*from  w w  w . j a v a 2s .  com*/
 *
 * @param itemCreated
 *            the item created
 */
private void validateUrl(DiceItem item) {
    boolean isValid = false;
    String urlInput = item.getUrl().getValue();
    if (urlInput != null && ImageUtils.isValidImageURI(urlInput)) {
        Image imgRow = null;
        if (urlInput != null) {
            ExternalResource resource = new ExternalResource(urlInput);
            imgRow = new Image("", resource);
            imgRow.addStyleName("dice-image");
            isValid = true;
            CookieManager cm = new CookieManager();
            cm.saveAllURLs(newDataSource.getItemIds().stream().map(di -> di.getUrl().getValue())
                    .collect(Collectors.toList()));
        }
        item.setImg(imgRow);
    }
    item.setValid(isValid);
    if (isValid) {
        item.getUrl().setEnabled(false);
    }
    newDataSource.sort(propertyIds, ascendingIds);
}