List of usage examples for com.vaadin.ui Image markAsDirty
@Override public void markAsDirty()
From source file:com.adonis.ui.menu.Menu.java
private void createViewButtonWithEditableImage(final String name, String caption, String nameImage) { Button button = new Button(caption, new ClickListener() { @Override//from ww w . jav a2 s. c o m public void buttonClick(ClickEvent event) { navigator.navigateTo(name); } }); button.setPrimaryStyleName(ValoTheme.BUTTON_FRIENDLY); // button.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); FileReader.createDirectoriesFromCurrent(getInitialPath()); final Image image = new Image("", new ThemeResource("img/" + nameImage)); try { FileReader.copyFile(VaadinUtils.getResourcePath(nameImage), VaadinUtils.getInitialPath() + File.separator + nameImage); image.setSource(new FileResource(new File(VaadinUtils.getInitialPath() + File.separator + nameImage))); } catch (IOException e) { e.printStackTrace(); image.setSource(new ThemeResource("img/" + nameImage)); } // image.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setPrimaryStyleName(ValoTheme.MENU_ITEM); horizontalLayout.addComponents(image, button); image.addClickListener(new MouseEvents.ClickListener() { @Override public void click(MouseEvents.ClickEvent event) { uploadFieldImage = new UploadField(); uploadFieldImage.setAcceptFilter("image/*"); uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.FailedListener() { @Override public void uploadFailed(com.vaadin.v7.ui.Upload.FailedEvent event) { uploadFieldImage.clearDefaulLayout(); horizontalLayout.removeComponent(uploadFieldImage); } private static final long serialVersionUID = 1L; }); horizontalLayout.addComponent(uploadFieldImage, 2); uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.SucceededListener() { @Override public void uploadSucceeded(com.vaadin.v7.ui.Upload.SucceededEvent event) { File file = (File) uploadFieldImage.getValue(); try { showUploadedImage(uploadFieldImage, image, file.getName(), nameImage); } catch (IOException e) { e.printStackTrace(); } uploadFieldImage.clearDefaulLayout(); horizontalLayout.removeComponent(uploadFieldImage); } }); uploadFieldImage.setFieldType(UploadField.FieldType.FILE); horizontalLayout.markAsDirty(); // image.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); image.setVisible(false); image.markAsDirty(); horizontalLayout.addComponent(image, 0); } }); button.setVisible(true); image.setVisible(true); menuItemsLayout.addComponents(horizontalLayout); viewButtons.put(name, button); }
From source file:org.vaadin.easyuploads.ImagePreviewField.java
License:Apache License
@Override protected void updateDisplayComponent() { try {/*w ww . j a va 2s .c o m*/ Image image = (Image) display; // check if upload is an image if (getValue() != null && ImageIO.read(new ByteArrayInputStream(getValue())) != null) { // Update the image according to // https://vaadin.com/book/vaadin7/-/page/components.embedded.html SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String filename = df.format(new Date()) + getLastFileName(); StreamResource resource = new StreamResource(new ImageSource(getValue()), filename); resource.setCacheTime(0); image.setSource(resource); image.setVisible(true); } else { image.setVisible(false); image.setSource(null); setValue(null); } image.markAsDirty(); if (display.getParent() == null) { getRootLayout().addComponent(display); } } catch (IOException e) { e.printStackTrace(); } }