List of usage examples for com.vaadin.server ResourceReference create
public static ResourceReference create(Resource resource, ClientConnector connector, String key)
From source file:com.haulmont.cuba.web.toolkit.ui.renderers.CubaImageRenderer.java
License:Apache License
@Override public JsonValue encode(String value) { Resource resource = null;/* w w w .j a v a 2 s. c o m*/ if (value != null) { if (value.startsWith("file:") || value.startsWith("jar:") || value.contains("icon:")) { throw new IllegalArgumentException( "ImageRenderer only supports ExternalResource and ThemeResource"); } if (value.startsWith("http") || value.startsWith("https")) { try { resource = new ExternalResource(new URL(value)); } catch (MalformedURLException e) { throw new RuntimeException("Unable to parse url for value", e); } } else { if (value.startsWith("theme://")) { value = value.substring("theme://".length()); } resource = new VersionedThemeResource(value); } } return encode(ResourceReference.create(resource, this, null), URLReference.class); }
From source file:com.haulmont.cuba.web.widgets.addons.contextmenu.ContextMenu.java
License:Apache License
private List<MenuItemState> convertItemsToState(List<MenuItem> items) { if (items == null || items.size() == 0) { return null; }/*from w w w .j a v a 2 s . c o m*/ List<MenuItemState> state = new ArrayList<>(); for (MenuItem item : items) { MenuItemState menuItemState = new MenuItemState(); if (!item.isVisible()) { continue; } menuItemState.id = item.getId(); menuItemState.text = item.getText(); menuItemState.checkable = item.isCheckable(); menuItemState.checked = item.isChecked(); menuItemState.description = item.getDescription(); menuItemState.enabled = item.isEnabled(); menuItemState.separator = item.isSeparator(); menuItemState.icon = ResourceReference.create(item.getIcon(), this, ""); menuItemState.styleName = item.getStyleName(); menuItemState.childItems = convertItemsToState(item.getChildren()); state.add(menuItemState); } return state; }
From source file:com.haulmont.cuba.web.widgets.renderers.CubaImageRenderer.java
License:Apache License
@Override public JsonValue encode(String value) { Resource resource = null;//from w ww . ja v a 2s.co m if (value != null) { if (value.startsWith("file:") || value.startsWith("jar:") || value.contains("icon:")) { throw new IllegalArgumentException( "ImageRenderer only supports ExternalResource and ThemeResource"); } if (value.startsWith("http") || value.startsWith("https")) { try { resource = new ExternalResource(new URL(value)); } catch (MalformedURLException e) { throw new RuntimeException("Unable to parse url for value", e); } } else { if (value.startsWith("theme://")) { value = value.substring("theme://".length()); } resource = ((EnhancedUI) getUI()).createVersionedResource(value); } } return encode(ResourceReference.create(resource, this, null), URLReference.class); }
From source file:org.azrul.langkuik.framework.customtype.attachment.AttachmentCustomTypeUICreator.java
@Override public Component createUIForForm(final C currentBean, final Class<? extends CustomType> attachmentClass, final String pojoFieldName, final BeanView beanView, final DataAccessObject<C> conatainerClassDao, final DataAccessObject<? extends CustomType> customTypeDao, final RelationManagerFactory relationManagerFactory, final Configuration config, final ComponentState componentState, final Window window) { final FormLayout form = new FormLayout(); final DataAccessObject<AttachmentCustomType> attachmentDao = ((DataAccessObject<AttachmentCustomType>) customTypeDao); final Collection<AttachmentCustomType> attachments = attachmentDao.find(currentBean, pojoFieldName, null, true, 0, Integer.parseInt(config.get("uploadCountLimit"))); final WebEntityItemContainer attachmentIC = new WebEntityItemContainer(attachmentClass); if (!attachments.isEmpty()) { attachmentIC.addAll(attachments); }//from ww w . j av a 2 s.c om final ListSelect attachmentList = new ListSelect("", attachmentIC); createAtachmentList(attachmentList, attachments, config, beanView, form); final String relativePath = currentBean.getClass().getCanonicalName() + File.separator + conatainerClassDao.getIdentifierValue(currentBean); final String fullPath = config.get("attachmentRepository") + File.separator + relativePath; MyUploadHandler<C> uploadFinishHandler = new MyUploadHandler<>(currentBean, Integer.parseInt(config.get("uploadCountLimit").trim()), pojoFieldName, fullPath, relativePath, attachmentList, attachmentIC, customTypeDao, attachmentClass, relationManagerFactory); //File upload/download/delete buttons HorizontalLayout attachmentButtons = new HorizontalLayout(); attachmentButtons.setSpacing(true); UploadStateWindow uploadStateWindow = new UploadStateWindow(); MultiFileUpload fileUpload = new MultiFileUpload(uploadFinishHandler, uploadStateWindow); uploadFinishHandler.setFileUpload(fileUpload); fileUpload.getSmartUpload().setEnabled(true); fileUpload.getSmartUpload().setMaxFileSize(Integer.parseInt(config.get("uploadSizeLimit").trim())); fileUpload.getSmartUpload().setUploadButtonCaptions("Upload files", "Upload files"); fileUpload.getSmartUpload().setId("Upload files"); fileUpload.setId("Upload files2"); Button deleteAttachmentBtn = new Button("Delete file", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Collection<AttachmentCustomType> attachments = (Collection<AttachmentCustomType>) attachmentList .getValue(); if (!attachments.isEmpty()) { customTypeDao.unlinkAndDelete(attachments, currentBean, pojoFieldName, relationManagerFactory.create(currentBean.getClass(), attachmentClass)); Collection<AttachmentCustomType> a = attachmentDao.find(currentBean, pojoFieldName, null, true, 0, Integer.parseInt(config.get("uploadCountLimit"))); attachmentIC.removeAllItems(); attachmentIC.addAll(a); attachmentIC.refreshItems(); } } }); deleteAttachmentBtn.setId(deleteAttachmentBtn.getCaption()); Button downloadAttachmentBtn = new Button("Download file", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Collection<AttachmentCustomType> attachments = (Collection<AttachmentCustomType>) attachmentList .getValue(); if (!attachments.isEmpty()) { AttachmentCustomType attachment = attachments.iterator().next(); final String fullPath = config.get("attachmentRepository") + File.separator + attachment.getRelativeLocation() + File.separator + attachment.getFileName(); FileResource res = new FileResource(new File(fullPath)); beanView.setViewResource("DOWNLOAD", res); ResourceReference rr = ResourceReference.create(res, beanView, "DOWNLOAD"); Page.getCurrent().open(rr.getURL(), null); } } }); downloadAttachmentBtn.setId(downloadAttachmentBtn.getCaption()); Button closeWindowBtn = new Button("Close", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { window.close(); } }); closeWindowBtn.setId(closeWindowBtn.getCaption()); if (componentState.equals(ComponentState.EDITABLE)) { attachmentButtons.addComponent(fileUpload); attachmentButtons.addComponent(deleteAttachmentBtn); } if (componentState.equals(ComponentState.EDITABLE) || componentState.equals(ComponentState.READ_ONLY)) { attachmentButtons.addComponent(downloadAttachmentBtn); } attachmentButtons.addComponent(closeWindowBtn); form.addComponent(attachmentButtons); form.setMargin(true); //beanView.addComponent(form); return form; }
From source file:org.azrul.langkuik.framework.customtype.attachment.AttachmentCustomTypeUICreator.java
private void createAtachmentList(final ListSelect attachmentList, final Collection<? extends CustomType> attachments, final Configuration config, final BeanView view, final FormLayout form) { attachmentList.setHeight(attachments.size() + 2, Sizeable.Unit.EM); attachmentList.setMultiSelect(true); VerticalLayout attachmentListCont = new VerticalLayout(); attachmentListCont.setCaption("Attachments"); attachmentListCont.addComponent(attachmentList); attachmentListCont.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { @Override//from ww w . ja v a 2s. c om public void layoutClick(LayoutEvents.LayoutClickEvent event) { if (event.getClickedComponent() == null) { return; } if (event.getClickedComponent().equals(attachmentList)) { Collection<AttachmentCustomType> attachments = (Collection<AttachmentCustomType>) attachmentList .getValue(); if (!attachments.isEmpty()) { AttachmentCustomType attachment = attachments.iterator().next(); final String fullPath = config.get("attachmentRepository") + File.separator + attachment.getRelativeLocation() + File.separator + attachment.getFileName(); FileResource res = new FileResource(new File(fullPath)); view.setViewResource("DOWNLOAD", res); ResourceReference rr = ResourceReference.create(res, view, "DOWNLOAD"); Page.getCurrent().open(rr.getURL(), null); } } } }); form.addComponent(attachmentListCont); }
From source file:org.jumpmind.metl.ui.views.deploy.EditAgentPanel.java
License:Open Source License
protected void exportConfiguration() { final String export = context.getConfigurationService().export(agent); StreamSource ss = new StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { try { return new ByteArrayInputStream(export.getBytes()); } catch (Exception e) { log.error("Failed to export configuration", e); CommonUiUtils.notify("Failed to export configuration.", Type.ERROR_MESSAGE); return null; }/*from www.java 2 s .c om*/ } }; String datetime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); StreamResource resource = new StreamResource(ss, String.format("%s-config-%s.sql", agent.getName().toLowerCase().replaceAll(" ", "-"), datetime)); final String KEY = "export"; setResource(KEY, resource); Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null); }