List of usage examples for com.vaadin.ui Image Image
public Image()
From source file:edu.kit.dama.ui.admin.AdminUIMainView.java
License:Apache License
private void setupHeader(boolean landingPage, String landingObjectId) { if (!landingPage) { String repositoryName = DataManagerSettings.getSingleton() .getStringProperty(DataManagerSettings.GENERAL_REPOSITORY_NAME, "Repository"); title = new Label("<h1>" + repositoryName + " Administration</h1><h5>Build " + readVersion() + "</h5>", ContentMode.HTML); title.setDescription("Click to return to main page."); title.setWidth("50%"); title.addStyleName("title"); title.addStyleName("myclickablecomponent"); logo = new Image(); String logoUrl;/* w w w .j av a 2s .com*/ try { logoUrl = new URL(DataManagerSettings.getSingleton().getStringProperty( DataManagerSettings.GENERAL_REPOSITORY_LOGO_URL, "http://datamanager.kit.edu/dama/logo_default.png")).toString(); } catch (MalformedURLException ex) { logoUrl = URI.create("http://datamanager.kit.edu/dama/logo_default.png").toString(); } logo.setSource(new ExternalResource(logoUrl)); header = new HorizontalLayout(logo, title); header.setComponentAlignment(logo, Alignment.MIDDLE_CENTER); header.setComponentAlignment(title, Alignment.MIDDLE_CENTER); } else { title = new Label( "<h1>Landing Page for Object #" + landingObjectId + "</h1><h5>Build " + readVersion() + "</h5>", ContentMode.HTML); title.setWidth("50%"); title.addStyleName("title"); title.addStyleName("myclickablecomponent"); logo = new Image(); String logoUrl; try { logoUrl = new URL(DataManagerSettings.getSingleton().getStringProperty( DataManagerSettings.GENERAL_REPOSITORY_LOGO_URL, "http://datamanager.kit.edu/dama/logo_default.png")).toString(); } catch (MalformedURLException ex) { logoUrl = URI.create("http://datamanager.kit.edu/dama/logo_default.png").toString(); } logo.setSource(new ExternalResource(logoUrl)); header = new HorizontalLayout(logo, title); header.setComponentAlignment(logo, Alignment.MIDDLE_CENTER); header.setComponentAlignment(title, Alignment.MIDDLE_CENTER); } }
From source file:edu.kit.dama.ui.repo.components.EntryRenderPanel.java
License:Apache License
/** * Build the main layout of the representation of one digital object. * * @param pContext The authorization context used to decide whether special * administrative features are available or not. *//*from ww w. j a va 2 s .c o m*/ private void buildMainLayout(IAuthorizationContext pContext) { //check if the object could be obtained or not, e.g. due to missing permissions. If not, show an error message. if (ERROR_PLACEHOLDER.equals(object.getLabel())) { Label warnLabel = new Label("<h3>Failed to obtain entry with identifier '" + object.getDigitalObjectIdentifier() + "' from database.</h3>", ContentMode.HTML); final Button cleanup = new Button("Cleanup"); cleanup.setDescription("Click to remove object from search index."); cleanup.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { cleanup.setEnabled(false); new Notification("Information", "Cleanup not implemented, yet.", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); } }); if (pContext.getRoleRestriction().atLeast(Role.ADMINISTRATOR)) { //show cleanup button mainLayout = new HorizontalLayout(warnLabel, cleanup); } else { //no cleanup available mainLayout = new HorizontalLayout(warnLabel); } mainLayout.setSizeFull(); return; } //initialize image field typeImage = new Image(); typeImage.setSizeFull(); setImage(object); //initialize title label/field titleField = UIUtils7.factoryTextField(null, "dc:title"); titleField.addStyleName("basic_title"); titleLabel = new Label("dc:title"); titleLabel.setWidth("100%"); titleLabel.addStyleName("basic_title"); //initialize creator label if (object.getUploader() != null) { creatorLabel = new Label(StringUtils.abbreviate(object.getUploader().getFullname(), 100)); creatorLabel.setEnabled(true); } else { creatorLabel = new Label("dc:creator"); creatorLabel.setEnabled(false); } creatorLabel.setWidth("100%"); creatorLabel.addStyleName("basic_left"); //initialize creation label if (object.getStartDate() != null) { creationLabel = new Label(new SimpleDateFormat().format(object.getStartDate())); creationLabel.setEnabled(true); } else { creationLabel = new Label("dc:date"); creationLabel.setEnabled(false); } creationLabel.setWidth("100%"); //initialize identifier label objectIdLabel = new Label(StringUtils.abbreviate(object.getDigitalObjectIdentifier(), 100)); objectIdLabel.setWidth("100%"); //initialize description label/area descriptionLabel = new Label("dc:description"); descriptionArea = UIUtils7.factoryTextArea(null, "dc:description"); descriptionArea.setHeight("50px"); descriptionLabel.setHeight("50px"); descriptionLabel.setWidth("100%"); //action buttons downloadButton = new NativeButton("Download"); downloadButton.setIcon(new ThemeResource("img/32x32/download.png")); downloadButton.setStyleName(BaseTheme.BUTTON_LINK); downloadButton.setDescription("Download the data of this digital object."); downloadButton.setWidth("100%"); shareButton = new NativeButton("Share"); shareButton.setIcon(new ThemeResource("img/16x16/share.png")); shareButton.setStyleName(BaseTheme.BUTTON_LINK); shareButton.setDescription("Share this digital object."); Role eligibleRole = Role.GUEST; if (parent.getParentUI().isUserLoggedIn()) { //obtain role only if a user is logged in and we are not in ingest mode. //Otherwise, the dummy context of MyVaadinUI would be used and will cause unwanted access. try { //Determine eligible role of currently logged in user eligibleRole = ResourceServiceLocal.getSingleton().getGrantRole(object.getSecurableResourceId(), parent.getParentUI().getAuthorizationContext().getUserId(), AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) { LOGGER.warn("Failed to determine eligable role for context " + parent.getParentUI().getAuthorizationContext() + ". Continue with GUEST permissions.", ex); } } //Update share button depending on role. Only possessing the role MANAGER (being the owner) entitles to share an object. if (eligibleRole.atLeast(Role.MANAGER)) { shareButton.setEnabled(true); shareButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (parent != null) { parent.showSharingPopup(object); } } }); } else { shareButton.setEnabled(false); shareButton.setDescription("Only the object owner is allowed to change sharing information."); } editButton = new NativeButton("Edit Metadata"); editButton.setIcon(new ThemeResource("img/16x16/edit.png")); editButton.setStyleName(BaseTheme.BUTTON_LINK); editButton.setDescription("Edit this digital object's metadata."); //Update edit button depending on role. If the object is shared with or owned by the logged in user, editing will be allowed. if (eligibleRole.atLeast(Role.MEMBER)) { editButton.setEnabled(true); editButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { switchEditMode(); } }); } else { editButton.setEnabled(false); editButton.setDescription( "Only the object owner and users the object is shared with are allowed to change metadata information."); } starButton = new NativeButton("Favorite"); starButton.setImmediate(true); starButton.setIcon(new ThemeResource("img/16x16/unstarred.png")); starButton.setStyleName(BaseTheme.BUTTON_LINK); starButton.setDescription("Add/remove digital object to/from favorites."); //Update star button depending on role. If the object is shared with or owned by the logged in user, "star'ing" will be allowed. if (eligibleRole.atLeast(Role.MEMBER)) { starButton.setEnabled(true); starButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext()); try { DigitalObjectType favoriteType = mdm .findSingleResult("SELECT t FROM DigitalObjectType t WHERE t.identifier='" + MyVaadinUI.FAVORITE_TYPE_IDENTIFIER + "' AND t.typeDomain='" + MyVaadinUI.FAVORITE_TYPE_DOMAIN + "'", DigitalObjectType.class); if (DigitalObjectTypeHelper.isTypeAssignedToObject(object, favoriteType, AuthorizationContext.factorySystemContext())) { //remove favorite status DigitalObjectTypeHelper.removeTypeFromObject(object, favoriteType, AuthorizationContext.factorySystemContext()); starButton.setIcon(new ThemeResource("img/16x16/unstarred.png")); new Notification("Information", "Successfully removed favorite tag from object " + object.getDigitalObjectIdentifier() + ".", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); } else { //assign favorite status DigitalObjectTypeHelper.assignTypeToObject(object, favoriteType, AuthorizationContext.factorySystemContext()); starButton.setIcon(new ThemeResource("img/16x16/starred.png")); new Notification("Information", "Successfully added favorite tag to object " + object.getDigitalObjectIdentifier() + ".", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); } } catch (Exception e) { LOGGER.error("Failed to change 'favorite' status of digital object.", e); new Notification("Warning", "Failed to update favorite status.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); } } }); } else { starButton.setEnabled(false); starButton.setDescription( "Only the object owner and users the object is shared with are allowed to change the favorite state."); } dcLayout = new UIUtils7.GridLayoutBuilder(3, 5).addComponent(titleLabel, 0, 0, 2, 1) .addComponent(creationLabel, 2, 0, 1, 1).addComponent(creatorLabel, 0, 1, 3, 1) .addComponent(objectIdLabel, 0, 2, 3, 1).fill(descriptionLabel, 0, 3).getLayout(); dcLayout.setSizeFull(); Button.ClickListener saveCancelButtonListener = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (saveEditButton.equals(event.getButton())) { //do save IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext()); try { String title = titleField.getValue(); String description = descriptionArea.getValue(); Investigation investigation = object.getInvestigation(); boolean wasError = false; if (description != null && description.length() <= 1024 && investigation != null) { if (!description.equals(investigation.getDescription())) { investigation.setDescription(description); //store investigation mdm.save(investigation); } } else { LOGGER.warn( "Failed to commit updated description '{}'. Either length is exceeded or investigation '{}' is null.", description, investigation); wasError = true; } //store object if (title != null && title.length() >= 3 && title.length() <= 255) { if (!title.equals(object.getLabel())) { //store object object.setLabel(title); object = mdm.save(object); } } else { LOGGER.warn("Failed to commit updated title '{}'. Length is invalid (3<=l<=255).", title); wasError = true; } if (wasError) { new Notification("Warning", "Failed to update title and/or description. See logfile for details.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); } //As there is not automatic sync between database and search index the entry has to be reindexed at this point in order //to keep both systems consistent. However, changes taking place in between are lost. LOGGER.debug("Object committed to database. Updating index."); ElasticsearchHelper.indexEntry(object); } catch (UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to commit changes.", ex); new Notification("Warning", "Failed to commit changes. See logfile for details.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); } finally { mdm.close(); } } //do cancel/reload and switch back to read-mode reset(); switchEditMode(); } }; //save/cancel buttons saveEditButton = new NativeButton("Commit Update"); saveEditButton.setIcon(new ThemeResource("img/16x16/save.png")); saveEditButton.setStyleName(BaseTheme.BUTTON_LINK); saveEditButton.setDescription("Save changes to this digital object's metadata."); saveEditButton.addClickListener(saveCancelButtonListener); cancelEditButton = new NativeButton("Cancel Update"); cancelEditButton.setIcon(new ThemeResource("img/16x16/cancel.png")); cancelEditButton.setStyleName(BaseTheme.BUTTON_LINK); cancelEditButton.setDescription("Withdraw all changes to this digital object's metadata."); cancelEditButton.addClickListener(saveCancelButtonListener); //default action layout Label spacerMiscActionLayout = new Label(); miscActionLayout = new HorizontalLayout(editButton, shareButton, starButton, spacerMiscActionLayout); miscActionLayout.setWidth("100%"); miscActionLayout.setHeight("18px"); miscActionLayout.setSpacing(false); miscActionLayout.setMargin(false); miscActionLayout.setExpandRatio(spacerMiscActionLayout, .9f); //edit action layout Label spacerEditActionLayout = new Label(); editActionLayout = new HorizontalLayout(saveEditButton, cancelEditButton, spacerEditActionLayout); editActionLayout.setWidth("100%"); editActionLayout.setHeight("18px"); editActionLayout.setSpacing(false); editActionLayout.setMargin(false); editActionLayout.setExpandRatio(spacerEditActionLayout, .9f); //divider generation Label dividerTop = new Label(); dividerTop.setHeight("5px"); dividerTop.addStyleName("horizontal-line"); dividerTop.setWidth("90%"); Label dividerBottom = new Label(); dividerBottom.setHeight("5px"); dividerBottom.addStyleName("horizontal-line"); dividerBottom.setWidth("90%"); Label dividerLeft = new Label(); dividerLeft.addStyleName("vertical-line"); dividerLeft.setWidth("5px"); dividerLeft.setHeight("90%"); Label dividerRight = new Label(); dividerRight.addStyleName("vertical-line"); dividerRight.setWidth("5px"); dividerRight.setHeight("90%"); //build content layout HorizontalLayout contentLayout = new HorizontalLayout(typeImage, dividerLeft, dcLayout, dividerRight, downloadButton); contentLayout.setSizeFull(); contentLayout.setSpacing(true); contentLayout.setComponentAlignment(typeImage, Alignment.TOP_RIGHT); contentLayout.setComponentAlignment(dividerLeft, Alignment.MIDDLE_CENTER); contentLayout.setComponentAlignment(dcLayout, Alignment.MIDDLE_CENTER); contentLayout.setComponentAlignment(dividerRight, Alignment.MIDDLE_CENTER); contentLayout.setComponentAlignment(downloadButton, Alignment.BOTTOM_CENTER); contentLayout.setExpandRatio(typeImage, .1f); contentLayout.setExpandRatio(dcLayout, .8f); contentLayout.setExpandRatio(downloadButton, .1f); //build main layout mainLayout = new VerticalLayout(dividerTop, contentLayout, dividerBottom, miscActionLayout); mainLayout.setExpandRatio(dividerTop, .05f); mainLayout.setComponentAlignment(dividerTop, Alignment.TOP_LEFT); mainLayout.setExpandRatio(contentLayout, .80f); mainLayout.setExpandRatio(dividerBottom, .05f); mainLayout.setComponentAlignment(dividerBottom, Alignment.BOTTOM_RIGHT); mainLayout.setExpandRatio(miscActionLayout, .1f); mainLayout.setSpacing(true); mainLayout.setMargin(true); mainLayout.addStyleName("basic"); mainLayout.setWidth("100%"); mainLayout.setHeight("185px"); //do reset to load title and description reset(); LOGGER.debug("Layout successfully build up."); }
From source file:edu.nps.moves.mmowgli.modules.actionplans.MediaSubWindow.java
License:Open Source License
private Component buildCenter(Resource res) { Image img = new Image(); img.setSource(res); return img; }
From source file:edu.nps.moves.mmowgliMobile.ui.CardRenderer2.java
License:Open Source License
public void setMessage(FullEntryView2 mView, ListEntry message, ListView2 messageList, AbstractOrderedLayout layout) {/* w w w .ja v a 2 s.co m*/ Object key = HSess.checkInit(); CardListEntry wc = (CardListEntry) message; Card c = wc.getCard(); CardType typ = c.getCardType(); layout.removeAllComponents(); layout.setSpacing(true); VerticalLayout cardLay = new VerticalLayout(); cardLay.addStyleName("m-card-render"); cardLay.setWidth("98%"); //100%"); cardLay.setSpacing(true); layout.addComponent(cardLay); HorizontalLayout horl = new HorizontalLayout(); horl.addStyleName("m-card-header"); String stl = CardStyler.getCardBaseStyle(typ); horl.addStyleName(stl); horl.addStyleName(CardStyler.getCardTextColorOverBaseStyle(typ)); horl.setMargin(true); horl.setWidth("100%"); Label lbl = new Label(typ.getTitle());//c.getText()); horl.addComponent(lbl); lbl = new Label("" + getPojoId(message)); lbl.addStyleName("m-text-align-right"); horl.addComponent(lbl); cardLay.addComponent(horl); horl = new HorizontalLayout(); horl.setWidth("100%"); horl.setMargin(true); cardLay.addComponent(horl); lbl = new Label(c.getText()); horl.addComponent(lbl); horl = new HorizontalLayout(); horl.addStyleName("m-card-footer"); horl.setMargin(true); horl.setWidth("100%"); horl.addComponent(lbl = new Label("")); lbl.setWidth("5px"); Image img = new Image(); img.setSource(mediaLocator.locate(c.getAuthor().getAvatar().getMedia())); img.setWidth("30px"); img.setHeight("30px"); horl.addComponent(img); // horl.addComponent(lbl=new Label(c.getAuthorName())); // lbl.setWidth("100%"); // lbl.addStyleName("m-text-align-center"); // horl.setComponentAlignment(lbl, Alignment.MIDDLE_CENTER); // horl.setExpandRatio(lbl, 1.0f); Button authButt = new MyButton(c.getAuthorName(), c, mView); authButt.setStyleName(BaseTheme.BUTTON_LINK); authButt.setWidth("100%"); horl.addComponent(authButt); horl.setComponentAlignment(authButt, Alignment.MIDDLE_CENTER); horl.setExpandRatio(authButt, 1.0f); horl.addComponent(lbl = new HtmlLabel(formatter.format(message.getTimestamp()))); lbl.setWidth("115px"); ; lbl.addStyleName("m-text-align-right"); horl.setComponentAlignment(lbl, Alignment.MIDDLE_CENTER); cardLay.addComponent(horl); // lbl = new Hr(); // layout.addComponent(lbl); lbl = new Label("Child Cards"); layout.addComponent(lbl); lbl.addStyleName("m-text-center"); // lbl = new Hr(); // layout.addComponent(lbl); horl = new HorizontalLayout(); horl.setSpacing(true); horl.setMargin(true); horl.setWidth("100%"); layout.addComponent(horl); horl.addComponent( makeChildGroupButton("Expand", (CardListEntry) message, CardType.getExpandTypeTL(), messageList)); horl.addComponent( makeChildGroupButton("Counter", (CardListEntry) message, CardType.getCounterTypeTL(), messageList)); horl.addComponent( makeChildGroupButton("Adapt", (CardListEntry) message, CardType.getAdaptTypeTL(), messageList)); horl.addComponent( makeChildGroupButton("Explore", (CardListEntry) message, CardType.getExploreTypeTL(), messageList)); HSess.checkClose(key); }
From source file:edu.nps.moves.mmowgliMobile.ui.UserRenderer2.java
License:Open Source License
public void setMessage(FullEntryView2 mView, ListEntry message, ListView2 messageList, AbstractOrderedLayout layout) {/*from w ww .j av a 2s. c o m*/ // messageList can be null if coming in from ActionPlan Object key = HSess.checkInit(); UserListEntry wu = (UserListEntry) message; User u = wu.getUser(); layout.removeAllComponents(); HorizontalLayout hlay = new HorizontalLayout(); layout.addComponent(hlay); hlay.addStyleName("m-userview-top"); hlay.setWidth("100%"); hlay.setMargin(true); hlay.setSpacing(true); Image img = new Image(); img.addStyleName("m-ridgeborder"); img.setSource(mediaLocator.locate(u.getAvatar().getMedia())); img.setWidth("90px"); img.setHeight("90px"); hlay.addComponent(img); hlay.setComponentAlignment(img, Alignment.MIDDLE_CENTER); Label lab; hlay.addComponent(lab = new Label()); lab.setWidth("5px"); VerticalLayout vlay = new VerticalLayout(); vlay.setSpacing(true); hlay.addComponent(vlay); hlay.setComponentAlignment(vlay, Alignment.MIDDLE_LEFT); vlay.setWidth("100%"); hlay.setExpandRatio(vlay, 1.0f); HorizontalLayout horl = new HorizontalLayout(); horl.setSpacing(false); vlay.addComponent(horl); vlay.setComponentAlignment(horl, Alignment.BOTTOM_LEFT); horl.addComponent(lab = new Label("name")); lab.addStyleName("m-user-top-label"); //light-text"); horl.addComponent(lab = new HtmlLabel(" " + u.getUserName())); lab.addStyleName("m-user-top-value"); horl = new HorizontalLayout(); horl.setSpacing(false); vlay.addComponent(horl); vlay.setComponentAlignment(horl, Alignment.TOP_LEFT); horl.addComponent(lab = new Label("level")); lab.addStyleName("m-user-top-label"); //light-text"); Level lev = u.getLevel(); if (u.isGameMaster()) { Level l = Level.getLevelByOrdinal(Level.GAME_MASTER_ORDINAL, HSess.get()); if (l != null) lev = l; } horl.addComponent(lab = new HtmlLabel(" " + lev.getDescription())); lab.addStyleName("m-user-top-value"); GridLayout gLay = new GridLayout(); // gLay.setHeight("155px"); // won't size properly gLay.setMargin(true); gLay.addStyleName("m-userview-mid"); gLay.setColumns(2); gLay.setRows(11); gLay.setSpacing(true); gLay.setWidth("100%"); gLay.setColumnExpandRatio(1, 1.0f); layout.addComponent(gLay); addRow(gLay, "user ID:", "" + getPojoId(message)); addRow(gLay, "location:", u.getLocation()); addRow(gLay, "expertise:", u.getExpertise()); addRow(gLay, "affiliation:", u.getAffiliation()); addRow(gLay, "date registered:", formatter.format(u.getRegisterDate())); gLay.addComponent(new Hr(), 0, 5, 1, 5); Container cntr = new CardsByUserContainer<Card>(u); // expects ThreadLocal session to be setup numCards = cntr.size(); addRow(gLay, "cards played:", "" + numCards); cntr = new ActionPlansByUserContainer<Card>(u); // expects ThreadLocal session to be setup numAps = cntr.size(); addRow(gLay, "action plans:", "" + numAps); gLay.addComponent(new Hr(), 0, 8, 1, 8); addRow(gLay, "exploration points:", "" + u.getBasicScore()); addRow(gLay, "innovation points:", "" + u.getInnovationScore()); cardListener = new CardLis(u, mView); apListener = new AppLis(u, mView); layout.addComponent(makeButtons()); HSess.checkClose(key); }
From source file:eu.eco2clouds.portal.component.PictureWindow.java
License:Apache License
private void render() { VerticalLayout content = new VerticalLayout(); content.setSpacing(true);//from w w w.ja v a 2 s. c o m content.setMargin(true); content.setSizeFull(); Image image = new Image(); //image.setSource(new ThemeResource("img/applicationsample.png")); image.setSource(new FileResource( new File(Configuration.propertiesDir + File.separator + "sample_applicationprofile.png"))); //image.setHeight("300px"); content.addComponent(image); Button btnClose = new Button("Close"); btnClose.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { close(); } }); content.addComponent(btnClose); content.setExpandRatio(image, 1.0f); content.setComponentAlignment(btnClose, Alignment.BOTTOM_CENTER); this.setContent(content); this.setHeight("450px"); this.setWidth("900px"); this.center(); this.setModal(true); }
From source file:fi.semantum.strategia.Updates.java
License:Open Source License
private static void updateQueryGrid(final Main main, final FilterState state) { main.gridPanelLayout.removeAllComponents(); main.gridPanelLayout.setMargin(false); final List<String> keys = state.reportColumns; if (keys.isEmpty()) { Label l = new Label("Kysely ei tuottanut yhtn tulosta."); l.addStyleName(ValoTheme.LABEL_BOLD); l.addStyleName(ValoTheme.LABEL_HUGE); main.gridPanelLayout.addComponent(l); return;/* w w w .ja va 2 s .c o m*/ } final IndexedContainer container = new IndexedContainer(); for (String key : keys) { container.addContainerProperty(key, String.class, ""); } rows: for (Map<String, ReportCell> map : state.report) { Object item = container.addItem(); for (String key : keys) if (map.get(key) == null) continue rows; for (Map.Entry<String, ReportCell> entry : map.entrySet()) { @SuppressWarnings("unchecked") com.vaadin.data.Property<String> p = container.getContainerProperty(item, entry.getKey()); p.setValue(entry.getValue().get()); } } HorizontalLayout hl = new HorizontalLayout(); hl.setWidth("100%"); final TextField filter = new TextField(); filter.addStyleName(ValoTheme.TEXTFIELD_TINY); filter.setInputPrompt("rajaa hakutuloksia - kirjoitetun sanan tulee lyty rivin teksteist"); filter.setWidth("100%"); final Image clipboard = new Image(); clipboard.setSource(new ThemeResource("page_white_excel.png")); clipboard.setHeight("24px"); clipboard.setWidth("24px"); hl.addComponent(filter); hl.setExpandRatio(filter, 1.0f); hl.setComponentAlignment(filter, Alignment.BOTTOM_CENTER); hl.addComponent(clipboard); hl.setComponentAlignment(clipboard, Alignment.BOTTOM_CENTER); hl.setExpandRatio(clipboard, 0.0f); main.gridPanelLayout.addComponent(hl); main.gridPanelLayout.setExpandRatio(hl, 0f); filter.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 3033918399018888150L; @Override public void valueChange(ValueChangeEvent event) { container.removeAllContainerFilters(); container.addContainerFilter(new QueryFilter(filter.getValue(), true, false)); } }); AbsoluteLayout abs = new AbsoluteLayout(); abs.setSizeFull(); final Grid queryGrid = new Grid(container); queryGrid.setSelectionMode(SelectionMode.NONE); queryGrid.setHeightMode(HeightMode.CSS); queryGrid.setHeight("100%"); queryGrid.setWidth("100%"); for (String key : keys) { Column col = queryGrid.getColumn(key); col.setExpandRatio(1); } abs.addComponent(queryGrid); OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() { private static final long serialVersionUID = 981769438054780731L; File f; Date date = new Date(); @Override public InputStream getStream() { String uuid = UUID.randomUUID().toString(); File printing = new File(Main.baseDirectory(), "printing"); f = new File(printing, uuid + ".xlsx"); Workbook w = new XSSFWorkbook(); Sheet sheet = w.createSheet("Sheet1"); Row header = sheet.createRow(0); for (int i = 0; i < keys.size(); i++) { Cell cell = header.createCell(i); cell.setCellValue(keys.get(i)); } int row = 1; rows: for (Map<String, ReportCell> map : state.report) { for (String key : keys) if (map.get(key) == null) continue rows; Row r = sheet.createRow(row++); int column = 0; for (int i = 0; i < keys.size(); i++) { Cell cell = r.createCell(column++); ReportCell rc = map.get(keys.get(i)); cell.setCellValue(rc.getLong()); } } try { FileOutputStream s = new FileOutputStream(f); w.write(s); s.close(); } catch (Exception e) { e.printStackTrace(); } try { return new FileInputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } throw new IllegalStateException(); } @Override public void onRequest() { // TODO Auto-generated method stub } @Override public long getFileSize() { return f.length(); } @Override public String getFileName() { return "Strategiakartta_" + Utils.dateString(date) + ".xlsx"; } }); dl.getResource().setCacheTime(0); dl.extend(clipboard); main.gridPanelLayout.addComponent(abs); main.gridPanelLayout.setExpandRatio(abs, 1f); }
From source file:info.magnolia.ui.form.field.component.AbstractBaseItemContentPreviewComponent.java
License:Open Source License
@Override public Component refreshContentPreview(Item item) { Image thumbnail = new Image(); String path = imageProvider.getPortraitPath(((JcrItemAdapter) item).getItemId()); if (StringUtils.isNotBlank(path)) { thumbnail = new Image("", new ExternalResource(path)); thumbnail.addStyleName("file-preview-area"); }//from w ww . ja v a2s. c o m return thumbnail; }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar la foto/*from w w w.j a va 2s . co m*/ * * */ private void uploadFoto() { // Create a sub-window and set the content Window subWindow = new Window("My photo"); subWindow.setWidth("475px"); FormLayout f = new FormLayout(); f.setMargin(true); Label e = new Label(); Image image = new Image(); class MyUploader implements Upload.Receiver, Upload.SucceededListener { File file; public File getFile() { return file; } public OutputStream receiveUpload(String fileName, String mimeType) { // Create and return a file output stream System.out.println("receiveUpload(" + fileName + "," + mimeType + ")"); FileOutputStream os = null; if (fileName != null && !"".equals(fileName)) { long id = fileId++; String extension = ".tmp"; if (fileName == null || "".equals(fileName.trim())) fileName = "" + id + extension; if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")); } File temp = null; try { temp = File.createTempFile(fileName, extension); os = new FileOutputStream(file = temp); } catch (IOException e) { e.printStackTrace(); } } return os; } public void uploadSucceeded(Upload.SucceededEvent event) { // Show the uploaded file in the image viewer image.setSource(new FileResource(file)); System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")"); } public FileLocator getFileLocator() throws IOException { String extension = ".tmp"; String fileName = file.getName(); if (file.getName() == null || "".equals(file.getName().trim())) fileName = "" + getId(); if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_"); } java.io.File temp = (System.getProperty("tmpdir") == null) ? java.io.File.createTempFile(fileName, extension) : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension); System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); System.out.println("Temp file : " + temp.getAbsolutePath()); if (System.getProperty("tmpdir") == null || !temp.exists()) { System.out.println("writing temp file to " + temp.getAbsolutePath()); Files.copy(file, temp); } else { System.out.println("temp file already exists"); } String baseUrl = System.getProperty("tmpurl"); URL url = null; try { if (baseUrl == null) { url = file.toURI().toURL(); } else url = new URL(baseUrl + "/" + file.getName()); } catch (MalformedURLException e) { e.printStackTrace(); } return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath()); } } ; MyUploader receiver = new MyUploader(); Upload upload = new Upload(null, receiver); //upload.setImmediateMode(false); upload.addSucceededListener(receiver); f.addComponent(image); f.addComponent(upload); f.addComponent(e); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Changing photo..."); try { FileLocator loc = receiver.getFileLocator(); io.mateu.ui.core.client.app.MateuUI.getBaseService() .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setPhoto(loc.getUrl()); foto = (getApp().getUserData().getPhoto() != null) ? new ExternalResource(getApp().getUserData().getPhoto()) : new ClassResource("profile-pic-300px.jpg"); subWindow.close(); refreshSettings(); } }); } catch (IOException e1) { e1.printStackTrace(); io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage()); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); upload.focus(); }
From source file:me.uni.emuseo.view.common.helpers.ImagePreviewWindow.java
License:Open Source License
public ImagePreviewWindow(String url) { setSizeUndefined();// w w w.j a v a2s .co m setWidth(400, Unit.PIXELS); setHeight(360, Unit.PIXELS); windowLayout = new VerticalLayout(); if (url != null) { Image image = new Image(); image.setSource(new ExternalResource(url)); image.setSizeFull(); windowLayout.addComponent(image); } // buildButtons(); // windowLayout.addComponent(buttonLayout); setContent(windowLayout); setModal(true); }