Example usage for com.vaadin.ui HorizontalLayout markAsDirty

List of usage examples for com.vaadin.ui HorizontalLayout markAsDirty

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout markAsDirty.

Prototype

@Override
    public void markAsDirty() 

Source Link

Usage

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/* ww  w.  j  a  va2s  . 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);
}