List of usage examples for com.vaadin.ui Label addStyleName
@Override public void addStyleName(String style)
From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java
private void addRow(GroupInterestProfile profile, boolean included, String value, boolean isAdmin) { GridLayout tagLayout = new GridLayout(2, 1); tagLayout.setWidth("100%"); Label labelTagName = new Label(value, ContentMode.HTML); labelTagName.setWidth("100%"); labelTagName.addStyleName(ValoTheme.LABEL_H3); labelTagName.addStyleName(ValoTheme.LABEL_NO_MARGIN); tagLayout.addComponent(labelTagName); tagLayout.setComponentAlignment(labelTagName, Alignment.MIDDLE_LEFT); if (isAdmin) { Button buttonDeleteTag = new Button(VaadinIcons.TRASH); buttonDeleteTag.addStyleName(ValoTheme.BUTTON_DANGER); buttonDeleteTag.addClickListener(ev -> { profile.getTags().remove(value); if (included) { includedTagsLayouts.get(profile).removeComponent(tagLayout); } else { excludedTagsLayouts.get(profile).removeComponent(tagLayout); }//from w w w . j ava2 s. c o m }); tagLayout.addComponent(buttonDeleteTag); tagLayout.setComponentAlignment(buttonDeleteTag, Alignment.MIDDLE_RIGHT); } tagLayout.setWidth("100%"); tagLayout.setColumnExpandRatio(0, 5); tagLayout.setSpacing(true); tagLayout.setMargin(false); if (included) { if (isAdmin) { includedTagsLayouts.get(profile).addComponent(tagLayout, 2); } else { includedTagsLayouts.get(profile).addComponent(tagLayout, 1); } } else { if (isAdmin) { excludedTagsLayouts.get(profile).addComponent(tagLayout, 2); } else { excludedTagsLayouts.get(profile).addComponent(tagLayout, 1); } } }
From source file:dhbw.clippinggorilla.userinterface.windows.ManageSourcesWindow.java
public void refreshSources() { sourcesLayout.removeAllComponents(); SourceUtils.getSources().stream().sorted((s1, s2) -> s1.getName().compareToIgnoreCase(s2.getName())) .forEach(source -> {/* w ww . j a v a 2 s . com*/ try { GridLayout sourceLayout = new GridLayout(4, 1); sourceLayout.setSizeFull(); Image sourceLogo = new Image(); URL url = source.getLogo(); if (url != null) { sourceLogo.setSource(new ExternalResource(url)); } sourceLogo.setWidth("150px"); VerticalLayout sourceText = new VerticalLayout(); sourceText.setSizeFull(); Label labelHeadLine = new Label( source.getCategory().getIcon().getHtml() + " " + source.getName(), ContentMode.HTML); labelHeadLine.addStyleName(ValoTheme.LABEL_H2); Label labelDescription = new Label(source.getDescription(), ContentMode.HTML); labelDescription.addStyleName(ValoTheme.LABEL_SMALL); labelDescription.setWidth("100%"); sourceText.setMargin(false); sourceText.addComponents(labelHeadLine, labelDescription); Button buttonEdit = new Button(VaadinIcons.EDIT); buttonEdit.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonEdit.addClickListener( ce -> UI.getCurrent().addWindow(NewSourceWindow.createEditMode(source))); Button buttonDelete = new Button(VaadinIcons.TRASH); buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER); buttonDelete.addClickListener(ce -> { sourcesLayout.removeComponent(sourceLayout); sourceLayouts.remove(source.getName().toLowerCase().replaceAll(" ", "") .replaceAll("-", "").replaceAll("_", "")); SourceUtils.removeSource(source); }); sourceLayout.addComponents(sourceLogo, sourceText, buttonEdit, buttonDelete); sourceLayout.setComponentAlignment(sourceLogo, Alignment.MIDDLE_CENTER); sourceLayout.setComponentAlignment(buttonEdit, Alignment.MIDDLE_CENTER); sourceLayout.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER); sourceLayout.setColumnExpandRatio(1, 5); sourceLayout.setSpacing(true); sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "") .replaceAll("_", ""), sourceLayout); sourcesLayout.addComponent(sourceLayout); } catch (Exception e) { Log.error("Skipping Source! ", e); } }); }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
public Component getFirstStage() { Label header = new Label(Language.get(Word.RSS)); header.addStyleName(ValoTheme.LABEL_H1); FormLayout forms = new FormLayout(); forms.setSizeFull();/*from w ww.j a v a 2s. c o m*/ TextField rssField = new TextField(Language.get(Word.RSS)); rssField.setWidth("750px"); forms.addComponents(rssField); Runnable cancel = () -> close(); Runnable next = () -> validateFirstStage(rssField.getValue()); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.addComponents(header, forms, getFooter(cancel, next)); windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER); return windowLayout; }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
/** * If no value present, choose a empty string * * @param title/*from w ww .java2 s .c o m*/ * @param link * @param description * @param language * @param imageUrl * @return */ private Component getSecondStage(Source s) { Label header = new Label(Language.get(Word.SOURCE)); header.addStyleName(ValoTheme.LABEL_H1); FormLayout forms = new FormLayout(); forms.setSizeFull(); TextField textFieldId = new TextField(Language.get(Word.ID)); textFieldId.setEnabled(false); textFieldId.setValue(s.getId()); textFieldId.setWidth("750px"); TextField textFieldName = new TextField(Language.get(Word.NAME)); textFieldName.setValue(s.getName()); textFieldName.setWidth("750px"); TextField textFieldDescription = new TextField(Language.get(Word.DESCRIPTION)); textFieldDescription.setValue(s.getDescription()); textFieldDescription.setWidth("750px"); TextField textFieldURL = new TextField(Language.get(Word.URL)); if (s.getUrl() != null) { textFieldURL.setValue(s.getUrl().toExternalForm()); } textFieldURL.setWidth("750px"); ComboBox<Category> comboBoxCategories = new ComboBox<>(Language.get(Word.CATEGORY), EnumSet.allOf(Category.class)); comboBoxCategories.setItemCaptionGenerator(c -> c.getName()); comboBoxCategories.setItemIconGenerator(c -> c.getIcon()); comboBoxCategories.setEmptySelectionAllowed(false); comboBoxCategories.setTextInputAllowed(false); comboBoxCategories.setWidth("375px"); if (s.getCategory() != null) { comboBoxCategories.setSelectedItem(s.getCategory()); } ComboBox<Locale> comboBoxLanguage = new ComboBox<>(Language.get(Word.LANGUAGE), getLanguages()); comboBoxLanguage.setItemCaptionGenerator(l -> l.getDisplayLanguage(VaadinSession.getCurrent().getLocale())); comboBoxLanguage.setEmptySelectionAllowed(false); comboBoxLanguage.setWidth("375px"); if (!s.getLanguage().isEmpty()) { Locale selected = new Locale(s.getLanguage()); comboBoxLanguage.setSelectedItem(selected); } Locale loc = VaadinSession.getCurrent().getLocale(); Map<String, Locale> countries = getCountries(); List<Locale> locales = countries.values().parallelStream() .sorted((l1, l2) -> l1.getDisplayCountry(loc).compareTo(l2.getDisplayCountry(loc))) .collect(Collectors.toList()); ComboBox<Locale> comboBoxCountry = new ComboBox<>(Language.get(Word.COUNTRY), locales); comboBoxCountry.setItemCaptionGenerator(l -> l.getDisplayCountry(VaadinSession.getCurrent().getLocale())); comboBoxCountry.setItemIconGenerator(l -> FamFamFlags.fromLocale(l)); comboBoxCountry.setEmptySelectionAllowed(false); comboBoxCountry.setWidth("375px"); if (!s.getCountry().isEmpty()) { comboBoxCountry.setSelectedItem(countries.getOrDefault(s.getCountry(), Locale.ROOT)); } Image imageLogo = new Image(Language.get(Word.LOGO)); TextField textFieldLogo = new TextField(Language.get(Word.LOGO_URL)); if (s.getLogo() != null) { textFieldLogo.setValue(s.getLogo().toExternalForm()); imageLogo.setSource(new ExternalResource(s.getLogo())); } textFieldLogo.addValueChangeListener(ce -> imageLogo.setSource(new ExternalResource(ce.getValue()))); textFieldLogo.setWidth("750px"); if (imageLogo.getHeight() > 125) { imageLogo.setHeight("125px"); } forms.addComponents(textFieldId, textFieldName, textFieldDescription, textFieldURL, comboBoxCategories, comboBoxLanguage, comboBoxCountry, textFieldLogo, imageLogo); Runnable cancel = () -> close(); Runnable next = () -> validateSecondStage(s, textFieldId.getValue(), textFieldName.getValue(), textFieldURL.getValue(), textFieldDescription.getValue(), comboBoxCategories.getSelectedItem().orElse(null), comboBoxLanguage.getSelectedItem().orElse(Locale.ROOT), comboBoxCountry.getSelectedItem().orElse(Locale.ROOT), textFieldLogo.getValue()); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.addComponents(header, forms, getFooter(cancel, next)); windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER); return windowLayout; }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
public Component getThirdStage(Source s) { Label header = new Label(Language.get(Word.CRAWLER)); header.addStyleName(ValoTheme.LABEL_H1); Crawler crawler;/*from w w w . ja v a 2 s .co m*/ if (s.getCrawler() != null) { crawler = s.getCrawler(); } else { crawler = new Crawler(s); s.setCrawler(crawler); } GridLayout mainGrid = new GridLayout(2, 2); mainGrid.setSizeFull(); mainGrid.setSpacing(true); FormLayout layoutForms = new FormLayout(); //Exclude or Include RadioButtonGroup<Boolean> radios = new RadioButtonGroup<>(); radios.setItems(true, false); radios.setItemCaptionGenerator(b -> b ? Language.get(Word.INCLUDE_TAGS) : Language.get(Word.EXCLUDE_TAGS)); radios.setItemIconGenerator(b -> b ? VaadinIcons.CHECK : VaadinIcons.CLOSE); radios.setSelectedItem(true); radios.addValueChangeListener(event -> include = event.getValue()); //By Class CssLayout addByClassGroup = new CssLayout(); addByClassGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldAddByClass = new TextField(); textFieldAddByClass.setWidth("465px"); Button buttonAddByClass = new Button(VaadinIcons.PLUS); buttonAddByClass.addClickListener(e -> { crawler.addByClass(textFieldAddByClass.getValue(), include); refreshList(mainGrid, crawler); textFieldAddByClass.clear(); }); addByClassGroup.addComponents(textFieldAddByClass, buttonAddByClass); addByClassGroup.setCaption(Language.get(Word.BYCLASS)); //ByTag CssLayout addByTagGroup = new CssLayout(); addByTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldAddByTag = new TextField(); Button buttonAddByTag = new Button(VaadinIcons.PLUS); textFieldAddByTag.setWidth("465px"); buttonAddByTag.addClickListener(e -> { crawler.addByTag(textFieldAddByTag.getValue(), include); refreshList(mainGrid, crawler); textFieldAddByTag.clear(); }); addByTagGroup.addComponents(textFieldAddByTag, buttonAddByTag); addByTagGroup.setCaption(Language.get(Word.BYTAG)); //ByID CssLayout addByIDGroup = new CssLayout(); addByIDGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldAddByID = new TextField(); textFieldAddByID.setWidth("465px"); Button buttonAddByID = new Button(VaadinIcons.PLUS); buttonAddByID.addClickListener(e -> { crawler.addByID(textFieldAddByID.getValue(), include); refreshList(mainGrid, crawler); textFieldAddByID.clear(); }); addByIDGroup.addComponents(textFieldAddByID, buttonAddByID); addByIDGroup.setCaption(Language.get(Word.BYID)); //ByAttribute CssLayout addByAttributeGroup = new CssLayout(); addByAttributeGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldAddByAttributeKey = new TextField(); textFieldAddByAttributeKey.setWidth("233px"); TextField textFieldAddByAttributeValue = new TextField(); textFieldAddByAttributeValue.setWidth("232px"); Button buttonAddByAttribute = new Button(VaadinIcons.PLUS); buttonAddByAttribute.addClickListener(e -> { crawler.addByAttribute(textFieldAddByAttributeKey.getValue(), textFieldAddByAttributeValue.getValue(), include); refreshList(mainGrid, crawler); textFieldAddByAttributeKey.clear(); textFieldAddByAttributeValue.clear(); }); addByAttributeGroup.addComponents(textFieldAddByAttributeKey, textFieldAddByAttributeValue, buttonAddByAttribute); addByAttributeGroup.setCaption(Language.get(Word.BYATTRIBUTEVALUE)); layoutForms.addComponents(radios, addByClassGroup, addByTagGroup, addByIDGroup, addByAttributeGroup); mainGrid.addComponent(layoutForms); Label labelResult = new Label(); Panel panelResult = new Panel(labelResult); labelResult.setWidth("100%"); panelResult.setWidth("100%"); panelResult.setHeight("175px"); mainGrid.addComponent(panelResult, 0, 1, 1, 1); Button buttonTestURL = new Button(); buttonTestURL.setIcon(VaadinIcons.EXTERNAL_LINK); buttonTestURL.setCaption(Language.get(Word.OPEN_LINK)); Button buttonTest = new Button(Language.get(Word.TEST), VaadinIcons.CLIPBOARD_CHECK); buttonTest.addClickListener(ce -> { Article a = CrawlerUtils.executeRandom(crawler); labelResult.setValue(a.getBody()); if (reg != null) { reg.remove(); } reg = buttonTestURL .addClickListener(cev -> UI.getCurrent().getPage().open(a.getUrl(), "_blank", false)); }); refreshList(mainGrid, crawler); Runnable cancel = () -> close(); Runnable next = () -> validateThirdStage(s); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.addComponents(header, mainGrid, getFooter(cancel, next, buttonTest, buttonTestURL)); windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER); windowLayout.setExpandRatio(mainGrid, 5); windowLayout.setWidth("1250px"); return windowLayout; }
From source file:edu.cornell.qatarmed.planrnaseq.BrowseAndAnnotate.java
public void initLayout() { /* Root of the user interface component tree is set */ VerticalLayout mainLayout = new VerticalLayout(); Label titleLabel = new Label("<span style=\"color:rgb(255,255,255)\">MetaRNA-Seq: An interactive " + "tool to browse and annotate RNA-Seq meta-data</span>", ContentMode.HTML); titleLabel.addStyleName("maintitle"); HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); mainLayout.addComponent(titleLabel); mainLayout.addComponent(splitPanel); setContent(mainLayout);/*from w w w .ja va2s . com*/ splitPanel.setSizeFull(); mainLayout.setSizeFull(); mainLayout.setExpandRatio(splitPanel, 1); /* Build the component tree */ // VerticalLayout leftLayout = new VerticalLayout(); // moved this to class level as it is been accessed by other function VerticalSplitPanel rightSplitPanel = new VerticalSplitPanel(); // VerticalSplitPanel leftSplitPanel = new VerticalSplitPanel(); splitPanel.addComponent(leftLayout); splitPanel.addComponent(rightSplitPanel); VerticalLayout rightTopLayout = new VerticalLayout(); // rightTopLayout.addComponent(rightTopForm); rightTopTabsheet.setSizeFull(); rightTopLayout.addComponent(rightTopTabsheet); rightTopTabsheet.addTab(startHelpLayout, "Start Help"); StartHelp sh = new StartHelp(); startHelpLayout.addComponent(sh); rightTopTabsheet.addTab(rightTopForm, "Study Details"); rightTopTabsheet.addTab(rightTopAnnotationForm, "Annotate"); rightTopLayout.setSizeFull(); rightSplitPanel.addComponent(rightTopLayout); HorizontalSplitPanel rightBottomLayout = new HorizontalSplitPanel(); // HorizontalLayout rightBottomLayout = new HorizontalLayout(); VerticalLayout rightBottomLeftLayout = new VerticalLayout(); VerticalLayout rightBottomRightLayout = new VerticalLayout(); rightBottomLayout.addComponent(rightBottomLeftLayout); rightBottomLayout.addComponent(rightBottomRightLayout); // rightBottomLayout.setExpandRatio(rightBottomLeftLayout, 1); // rightBottomLayout.setExpandRatio(rightBottomRightLayout, 3); rightBottomLayout.setSplitPosition(30f, Unit.PERCENTAGE); rightBottomLayout.setSizeFull(); rightBottomTabsheet.setSizeFull(); rightSplitPanel.addComponent(rightBottomLayout); splitPanel.setSplitPosition(50f, Unit.PERCENTAGE); //HorizontalLayout leftTopLayout = new HorizontalLayout(); // moved this to class level as it is been accessed by other function leftLayout.addComponent(leftTopLayout); leftTopLayout.addComponent(searchField); leftTopLayout.addComponent(searchButton); leftTopLayout.addComponent(slowSearchButton); leftTopLayout.addComponent(guidedSearchButton); leftTopLayout.setWidth("100%"); searchField.setWidth("100%"); leftTopLayout.setExpandRatio(searchField, 1); leftLayout.addComponent(bioprojectSummaryTable); // leftLayout.setExpandRatio(searchField, 0); leftLayout.setExpandRatio(bioprojectSummaryTable, 1); bioprojectSummaryTable.setSizeFull(); /* Set the contents in the left of the split panel to use all the space */ leftLayout.setSizeFull(); rightBottomLeftLayout.addComponent(tree); rightBottomRightLayout.addComponent(rightBottomTabsheet); rightBottomTabsheet.addTab(myform, "Details of selected Item"); myform.setSizeFull(); VerticalLayout rbTabBiosampleSummaryLayout = new VerticalLayout(); // Right bottom Biosample Summary // rightBottomTabsheet.addTab(rbTabBiosampleSummaryLayout, "All Biosamples"); rbTabBiosampleSummaryLayout.addComponent(biosampleSummaryTable); rbTabBiosampleSummaryLayout.setSizeFull(); initDataAndSubcomponent(); rightTopLayout.setSizeFull(); rightBottomRightLayout.setSizeFull(); }
From source file:edu.kit.dama.ui.admin.administration.user.MembershipRoleEditorWindow.java
License:Apache License
/** * Get the memberships table.//from ww w .j ava2 s .c o m * * @return The memberships table. */ private Table getMembershipsTable() { if (membershipsTable == null) { String id = "membershipsTable"; LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ..."); membershipsTable = new Table(); membershipsTable.setId(DEBUG_ID_PREFIX + id); membershipsTable.setSizeFull(); membershipsTable.setSelectable(true); membershipsTable.setMultiSelect(true); IndexedContainer c = new IndexedContainer(); c.addContainerProperty(NAME_COLUMN_ID, String.class, null); c.addContainerProperty(ROLE_COLUMN_ID, Role.class, null); c.addContainerProperty(INFO_COLUMN_ID, String.class, null); membershipsTable.setContainerDataSource(c); membershipsTable.setColumnHeader(NAME_COLUMN_ID, "Group Name"); membershipsTable.setColumnHeader(ROLE_COLUMN_ID, "Role"); membershipsTable.setColumnHeader(INFO_COLUMN_ID, "Info"); membershipsTable.addGeneratedColumn(ROLE_COLUMN_ID, (Table source, Object itemId, Object columnId) -> { Role role = (Role) source.getContainerDataSource().getContainerProperty(itemId, columnId) .getValue(); Label cellContent = new Label(); if (role != null && role.moreThan(Role.NO_ACCESS)) { cellContent.addStyleName(CSSTokenContainer.GREEN_BOLD_CENTERED_LABEL); cellContent.setValue(role.toString()); } else if (role != null && !role.moreThan(Role.NO_ACCESS)) { cellContent.addStyleName(CSSTokenContainer.RED_BOLD_CENTERED_LABEL); cellContent.setValue(role.toString()); } else { cellContent.addStyleName(CSSTokenContainer.ORANGE_BOLD_CENTERED_LABEL); cellContent.setValue("NO MEMBER"); } return cellContent; }); membershipsTable.addGeneratedColumn(INFO_COLUMN_ID, (Table source, Object itemId, Object columnId) -> { String value = (String) source.getContainerDataSource().getContainerProperty(itemId, columnId) .getValue(); Label cellContent = new Label(); cellContent.addStyleName(CSSTokenContainer.RED_BOLD_CENTERED_LABEL); if (value != null) { cellContent.setValue("!"); cellContent.setDescription(value); } else { cellContent.setValue(""); cellContent.setDescription(null); } return cellContent; }); } return membershipsTable; }
From source file:edu.kit.dama.ui.admin.administration.usergroup.GroupMembershipEditorWindow.java
License:Apache License
private Table getMembersTable() { if (membersTable == null) { String id = "membersTable"; LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ..."); membersTable = new Table(); membersTable.setId(DEBUG_ID_PREFIX + id); membersTable.setSizeFull();/* w w w . j av a2 s .co m*/ membersTable.setSelectable(true); membersTable.setMultiSelect(true); IndexedContainer c = new IndexedContainer(); c.addContainerProperty(NAME_COLUMN_ID, String.class, null); c.addContainerProperty(ROLE_COLUMN_ID, Role.class, null); c.addContainerProperty(INFO_COLUMN_ID, String.class, null); membersTable.setContainerDataSource(c); membersTable.setColumnHeader(NAME_COLUMN_ID, "User Name"); membersTable.setColumnHeader(ROLE_COLUMN_ID, "Role"); membersTable.setColumnHeader(INFO_COLUMN_ID, "Info"); membersTable.addGeneratedColumn(ROLE_COLUMN_ID, (Table source, Object itemId, Object columnId) -> { Role role = (Role) source.getContainerDataSource().getContainerProperty(itemId, columnId) .getValue(); Label cellContent = new Label(); if (role != null && role.moreThan(Role.NO_ACCESS)) { cellContent.addStyleName(CSSTokenContainer.GREEN_BOLD_CENTERED_LABEL); cellContent.setValue(role.toString()); } else if (role != null && !role.moreThan(Role.NO_ACCESS)) { cellContent.addStyleName(CSSTokenContainer.RED_BOLD_CENTERED_LABEL); cellContent.setValue(role.toString()); } else { cellContent.addStyleName(CSSTokenContainer.ORANGE_BOLD_CENTERED_LABEL); cellContent.setValue("NO MEMBER"); } return cellContent; }); membersTable.addGeneratedColumn(INFO_COLUMN_ID, (Table source, Object itemId, Object columnId) -> { String value = (String) source.getContainerDataSource().getContainerProperty(itemId, columnId) .getValue(); Label cellContent = new Label(); cellContent.addStyleName(CSSTokenContainer.RED_BOLD_CENTERED_LABEL); if (value != null) { cellContent.setValue("!"); cellContent.setDescription(value); } else { cellContent.setValue(""); cellContent.setDescription(null); } return cellContent; }); } return membersTable; }
From source file:edu.kit.dama.ui.admin.LandingPageComponent.java
License:Apache License
public final void update(DigitalObject object, boolean privileged) { if (object == null) { UIUtils7.GridLayoutBuilder builder = new UIUtils7.GridLayoutBuilder(1, 1); builder.fill(new Label("Access to digital object not permitted."), 0, 0); mainLayout = builder.getLayout(); mainLayout.setMargin(true);/*from w ww . j ava 2 s. c o m*/ mainLayout.setSpacing(true); mainLayout.setStyleName("landing"); HorizontalLayout hLayout = new HorizontalLayout(mainLayout); hLayout.setSizeFull(); hLayout.setComponentAlignment(mainLayout, Alignment.MIDDLE_CENTER); setCompositionRoot(hLayout); } else { final TextField oidField = new TextField(); Button searchButton = new Button("Search"); Button metsButton = new Button("METS"); final Button dcButton = new Button("DublinCore"); Button dataButton = new Button("Download"); VerticalLayout metadataDownloadButtons = new VerticalLayout(dcButton, metsButton); UIUtils7.GridLayoutBuilder builder = new UIUtils7.GridLayoutBuilder(3, 6); StreamResource metsResource = new StreamResource(() -> { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); MetsBuilder.init(object).createMinimalMetsDocument(UserData.WORLD_USER).write(bout); return new ByteArrayInputStream(bout.toByteArray()); } catch (Exception ex) { LOGGER.error("Failed to provide METS document.", ex); UIComponentTools.showError( "Failed to initialize METS document for download. Cause: " + ex.getMessage()); return null; } }, object.getDigitalObjectIdentifier() + ".mets.xml"); StreamResource dcResource = new StreamResource(() -> { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DublinCoreHelper.writeDublinCoreDocument(object, UserData.WORLD_USER, bout); return new ByteArrayInputStream(bout.toByteArray()); } catch (ParserConfigurationException ex) { LOGGER.error("Failed to provide DC document.", ex); UIComponentTools .showError("Failed to initialize DC document for download. Cause: " + ex.getMessage()); return null; } }, object.getDigitalObjectIdentifier() + ".dc.xml"); StreamResource dataResource = new StreamResource(() -> { IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext()); try { IAuthorizationContext ctx = new AuthorizationContext(new UserId(Constants.WORLD_USER_ID), new GroupId(Constants.WORLD_USER_ID), Role.GUEST); if (accessGranted(object, ctx) || accessGranted(object, UIHelper.getSessionContext())) { Response response = new PublicDownloadHandler().prepareStream(object); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return (InputStream) response.getEntity(); } else { LOGGER.error("Preparation of the public download for object " + object.getDigitalObjectIdentifier() + " returned status " + response.getStatus() + ". Aborting."); } } throw new IOException("Public access not available."); } catch (IOException ex) { LOGGER.error( "Failed to provide data stream for object " + object.getDigitalObjectIdentifier() + ".", ex); UIComponentTools.showError( "Failed to initialize data stream for public download. Probably, the digital object is not publicly available."); return null; } }, object.getDigitalObjectIdentifier() + ".zip"); Map<String, String> dcElementMap = new HashMap<>(); try { dcElementMap = DublinCoreHelper.createDublinCoreElementMap(object, UserData.WORLD_USER); } catch (ParserConfigurationException ex) { LOGGER.error( "Failed to create DC metadata for object with id " + object.getDigitalObjectIdentifier(), ex); } oidField.setValue(object.getDigitalObjectIdentifier()); FileDownloader metsDownloader = new FileDownloader(metsResource); metsDownloader.extend(metsButton); FileDownloader dcDownloader = new FileDownloader(dcResource); dcDownloader.extend(dcButton); FileDownloader dataDownloader = new FileDownloader(dataResource); dataDownloader.extend(dataButton); oidField.setSizeFull(); searchButton.setWidth("128px"); searchButton.addClickListener((Button.ClickEvent event) -> { String oid = oidField.getValue(); Page.getCurrent().setLocation( URI.create(UIHelper.getWebAppUrl().toString() + "?landing&oid=" + oid).toString()); }); dcButton.setWidth("128px"); metsButton.setWidth("128px"); dataButton.setWidth("128px"); metadataDownloadButtons.setComponentAlignment(dcButton, Alignment.TOP_LEFT); metadataDownloadButtons.setComponentAlignment(metsButton, Alignment.TOP_LEFT); //build layout Label oidLabel = new Label("<u>Object Id</u>", ContentMode.HTML); builder.fillRow(oidLabel, 0, 0, 1); oidLabel.addStyleName("myboldcaption"); builder.addComponent(oidField, 0, 1, 2, 1).addComponent(searchButton, 2, 1); Label dcMetadataLabel = new Label("<u>DC Metadata</u>", ContentMode.HTML); builder.fillRow(dcMetadataLabel, 0, 2, 1); dcMetadataLabel.addStyleName("myboldcaption"); Set<Map.Entry<String, String>> entries = dcElementMap.entrySet(); Table dcTable = new Table(); dcTable.setPageLength(entries.size() + 1); dcTable.addContainerProperty("dc:key", String.class, "-"); dcTable.addContainerProperty("dc:value", String.class, "-"); entries.forEach((entry) -> { Object newItemId = dcTable.addItem(); Item row1 = dcTable.getItem(newItemId); row1.getItemProperty("dc:key").setValue(entry.getKey()); row1.getItemProperty("dc:value").setValue(entry.getValue()); }); dcTable.setWidth("640px"); dcTable.addStyleName("myboldcaption"); builder.addComponent(dcTable, 0, 3, 2, 1); builder.addComponent(metadataDownloadButtons, 2, 3, 1, 1); builder.fillRow(new Label("<u>Data Access</u>", ContentMode.HTML), 0, 4, 1); long bytes = DataOrganizationUtils.getAssociatedDataSize(object.getDigitalObjectId()); String formatted = AbstractFile.formatSize(bytes); Label oidDownloadLabel = new Label( object.getDigitalObjectIdentifier() + ".zip (approx. " + formatted + ")"); oidDownloadLabel.addStyleName("myboldcaption"); builder.addComponent(oidDownloadLabel, 0, 5, 2, 1); builder.addComponent(dataButton, 2, 5, 1, 1); mainLayout = builder.getLayout(); mainLayout.setRowExpandRatio(0, .1f); mainLayout.setRowExpandRatio(1, .1f); mainLayout.setRowExpandRatio(2, .6f); mainLayout.setRowExpandRatio(3, .1f); mainLayout.setRowExpandRatio(4, .1f); mainLayout.setColumnExpandRatio(0, .1f); mainLayout.setColumnExpandRatio(1, .8f); mainLayout.setColumnExpandRatio(2, .1f); } mainLayout.setMargin(true); mainLayout.setSpacing(true); mainLayout.setStyleName("landing"); HorizontalLayout hLayout = new HorizontalLayout(mainLayout); hLayout.setSizeFull(); hLayout.setComponentAlignment(mainLayout, Alignment.MIDDLE_CENTER); setCompositionRoot(hLayout); }
From source file:edu.kit.dama.ui.admin.LoginInformationBar.java
License:Apache License
/** * Add a help entry to the provided layout. * * @param pId The id of the item to which the help belongs. * @param pHelpText The help text./*from ww w. j av a 2 s .c om*/ * @param pTargetLayout The layout where the help will be added to. */ private void addHelpItem(String pId, String pHelpText, AbsoluteLayout pTargetLayout) { Label item = new Label(pHelpText, ContentMode.HTML); item.setId(pId + "_help"); item.setHeight("48px"); item.addStyleName("invisible"); item.addStyleName("help-left"); pTargetLayout.addComponent(item); }