Example usage for com.vaadin.ui HorizontalLayout addComponent

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

Introduction

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

Prototype

public void addComponent(Component c, int index) 

Source Link

Document

Adds a component into indexed position in this container.

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/*from ww  w . ja  va 2 s.  co  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:com.freebox.engeneering.application.web.common.ApplicationLayout.java

License:Apache License

/**
  * Initializes view layout when system enters 'initView' action state.
  */*from  ww  w.j  a  v a2  s  .  c  o m*/
  * @param event -  state event.
  */
public void initView(@SuppressWarnings("rawtypes") StateEvent event) {
    final HorizontalLayout content = new HorizontalLayout();
    content.setSizeFull();
    content.setStyleName("main-view");

    final HorizontalSplitPanel leftSplitPanel = new HorizontalSplitPanel();
    leftSplitPanel.setSplitPosition(20, Sizeable.Unit.PERCENTAGE);

    final ComponentContainer leftSideBar = createPlaceholder(StateLayout.LEFT_SIDE_BAR);
    leftSideBar.setSizeFull();
    content.addComponent(leftSideBar, 0);

    final VerticalLayout verticalLayoutContent = new VerticalLayout();
    verticalLayoutContent.setStyleName("freebox-view");
    verticalLayoutContent.addComponent(createPlaceholder(StateLayout.HEADER));
    verticalLayoutContent.setSpacing(true);
    final ComponentContainer layoutContent = createPlaceholder(StateLayout.CONTENT);
    layoutContent.setSizeFull();
    verticalLayoutContent.addComponent(layoutContent);
    verticalLayoutContent.setSizeFull();
    //verticalLayoutContent.addComponent(createPlaceholder(StateLayout.FOOTER));

    verticalLayoutContent.setExpandRatio(layoutContent, 8f);

    content.addComponent(verticalLayoutContent, 1);
    content.setExpandRatio(leftSideBar, 1.0f);
    content.setExpandRatio(verticalLayoutContent, 9f);

    setView(content);
}