Example usage for com.vaadin.ui VerticalLayout setMargin

List of usage examples for com.vaadin.ui VerticalLayout setMargin

Introduction

In this page you can find the example usage for com.vaadin.ui VerticalLayout setMargin.

Prototype

@Override
    public void setMargin(boolean enabled) 

Source Link

Usage

From source file:com.mycompany.project.components.GroupDetails.java

public GroupDetails() {
    //        setCaption("Contact Details");

    VerticalLayout mainVLayout = new VerticalLayout();
    mainVLayout.setMargin(true);
    mainVLayout.setSpacing(true);/*  ww w  .  j  av a 2 s  .c  o m*/

    setContent(mainVLayout);
    tfName.setSizeFull();
    mainVLayout.addComponent(tfName);

    Button btnUpdate = new Button("Update");
    mainVLayout.addComponent(btnUpdate);

    btnUpdate.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            //invoke business logic
            BusinessLogic bl = ((MyVaadinUI) getUI()).getBusinessLogic();

            String name = tfName.getValue();

            boolean success = bl.updateGroup(selectedGroupId, name);
            if (success) {
                load(selectedGroupId);
                Notification.show("Success", "Group updated", Notification.Type.TRAY_NOTIFICATION);
            } else {
                Notification.show("Error", "\nSomething bad happened", Notification.Type.ERROR_MESSAGE);
            }
        }
    });

    GroupDetails.this.setVisible(false);
}

From source file:com.mycompany.project.components.NewContactForm.java

public NewContactForm() {

    VerticalLayout mainVLayout = new VerticalLayout();
    mainVLayout.setMargin(true);
    mainVLayout.setSpacing(true);/*  w  ww. j a v a2s.  c  o m*/
    mainVLayout.addStyleName(boostrap.Forms.FORM.styleName());
    setContent(mainVLayout);

    // field properties
    tfName.setSizeFull();
    tfPhone.setSizeFull();
    tfemail.setSizeFull();

    tfName.focus();

    mainVLayout.addComponent(tfName);
    mainVLayout.addComponent(tfPhone);
    mainVLayout.addComponent(tfemail);

    Button btnSave = new Button("Guardar");
    mainVLayout.addComponent(btnSave);

    btnSave.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            // get hold of the business logic

            String name = tfName.getValue();
            String phone = tfPhone.getValue();
            String email = tfemail.getValue();

            BusinessLogic bl = ((MyVaadinUI) getUI()).getBusinessLogic();
            String newContactId = bl.saveNewContact(name, phone, email);

            if (newContactId != null) {
                //saved successfully
                Notification.show("Success", name + " saved", Notification.Type.TRAY_NOTIFICATION);
                //reset fields
                resetFields();
            } else {
                //something bad happened
                Notification.show("Error", "\nContact could not be saved", Notification.Type.ERROR_MESSAGE);
            }
        }
    });
}

From source file:com.mycompany.project.components.NewGroupForm.java

public NewGroupForm() {

    VerticalLayout mainVLayout = new VerticalLayout();
    mainVLayout.setMargin(true);
    mainVLayout.setSpacing(true);//from   w ww.  ja  v a2s  . c o m

    setContent(mainVLayout);

    // field properties
    tfName.setSizeFull();

    mainVLayout.addComponent(tfName);

    Button btnSave = new Button("Save");
    mainVLayout.addComponent(btnSave);

    btnSave.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            // get hold of the business logic

            String name = tfName.getValue();

            BusinessLogic bl = ((MyVaadinUI) getUI()).getBusinessLogic();
            String newGroupId = bl.saveNewGroup(name);

            if (newGroupId != null) {
                //saved successfully
                Notification.show("Success", name + " saved", Notification.Type.TRAY_NOTIFICATION);
                resetFields();
            } else {
                //something bad happened
                Notification.show("Error", "\nGroup could not be saved", Notification.Type.ERROR_MESSAGE);
            }
        }
    });
}

From source file:com.mycompany.project.views.ContactsView.java

public ContactsView() {

    VerticalLayout mainVLayout = new VerticalLayout();
    mainVLayout.setMargin(true);
    mainVLayout.setSpacing(true);/*from ww  w  . j a v a 2 s .  com*/

    setContent(mainVLayout);

    // view header
    Label header = new Label("<div align=\"center\" style=\"font-size:12pt;\">Contactos</div>");
    header.setContentMode(ContentMode.HTML);

    mainVLayout.addComponent(header);

    // set window properties
    window.setWidth("400px");
    window.setCaption("Nuevo Contacto");
    window.setModal(true);
    window.setContent(newContactForm);

    // add new cotact button
    Button btnNew = new Button("Agregar Nuevo Contacto");
    mainVLayout.addComponent(btnNew);

    // clicking the button should display the NewContactForm
    btnNew.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (window.getParent() == null) {
                getUI().addWindow(window);
            }

        }
    });

    //add a horozontal layout - left has a table, right has a ContactDetail component
    HorizontalLayout hLayout = new HorizontalLayout();
    hLayout.setSizeFull();
    hLayout.setSpacing(true);

    mainVLayout.addComponent(hLayout);

    //add a table

    table.setWidth("600px");
    table.setImmediate(true);
    hLayout.addComponent(table);

    // how does table get its data
    beanContainer.setBeanIdProperty("id");
    table.setContainerDataSource(beanContainer);

    //set columns
    final Object[] NATURAL_COL_ORDER = new Object[] { "name", "phone", "email" };
    final String[] COL_HEADERS_ENGLISH = new String[] { "Name", "Phone", "Email" };

    table.setSelectable(true);
    table.setColumnCollapsingAllowed(true);
    table.setRowHeaderMode(RowHeaderMode.INDEX);
    table.setVisibleColumns(NATURAL_COL_ORDER);
    table.setColumnHeaders(COL_HEADERS_ENGLISH);

    // selecting a table row should enable/disale the ContactDetails component
    table.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            String contactId = (String) table.getValue();
            contactDetails.setContactId(contactId);
        }
    });

    //add a ContactDetails component

    //        contactDetails.setWidth("500px");
    hLayout.addComponent(contactDetails);

    // let the table fill the entire remaining width
    hLayout.setExpandRatio(contactDetails, 1);

}

From source file:com.mycompany.project.views.GroupsView.java

public GroupsView() {

    VerticalLayout mainVLayout = new VerticalLayout();
    mainVLayout.setMargin(true);
    mainVLayout.setSpacing(true);//from w  w w .  jav a2s .c o m

    setContent(mainVLayout);

    // view header
    Label header = new Label("<div align=\"center\" style=\"font-size:12pt;\">Grupos</div>");
    header.setContentMode(ContentMode.HTML);

    mainVLayout.addComponent(header);

    // set window properties
    window.setWidth("400px");
    window.setCaption("New Group");
    window.setModal(true);
    window.setContent(newGroupForm);

    // add new cotact button
    Button btnNew = new Button("Add New Group");
    mainVLayout.addComponent(btnNew);

    // clicking the button should display the NewContactForm
    btnNew.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (window.getParent() == null) {
                getUI().addWindow(window);
            }

        }
    });

    //add a horozontal layout - left has a table, right has a ContactDetail component
    HorizontalLayout hLayout = new HorizontalLayout();
    hLayout.setSizeFull();
    hLayout.setSpacing(true);

    mainVLayout.addComponent(hLayout);

    //add a table

    table.setWidth("600px");
    table.setImmediate(true);
    hLayout.addComponent(table);

    // how does table get its data
    beanContainer.setBeanIdProperty("id");
    table.setContainerDataSource(beanContainer);

    //set columns
    final Object[] NATURAL_COL_ORDER = new Object[] { "name" };
    final String[] COL_HEADERS_ENGLISH = new String[] { "Name" };

    table.setSelectable(true);
    table.setColumnCollapsingAllowed(true);
    table.setRowHeaderMode(RowHeaderMode.INDEX);
    table.setVisibleColumns(NATURAL_COL_ORDER);
    table.setColumnHeaders(COL_HEADERS_ENGLISH);

    // selecting a table row should enable/disale the ContactDetails component
    table.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            String groupId = (String) table.getValue();
            groupDetails.setGroupId(groupId);
        }
    });

    //add a ContactDetails component

    //        contactDetails.setWidth("500px");
    hLayout.addComponent(groupDetails);

    // let the table fill the entire remaining width
    hLayout.setExpandRatio(groupDetails, 1);
}

From source file:com.mymita.vaadlets.demo.AddonDemoApplication.java

License:Apache License

private static VerticalLayout createStackTraceLabel(final Exception e) {
    final VerticalLayout vl = new VerticalLayout();
    vl.setMargin(true);
    vl.addComponent(new Label("<h1>Error</h1>", Label.CONTENT_XHTML));
    final StringWriter buf = new StringWriter();
    e.printStackTrace(new PrintWriter(buf));
    vl.addComponent(new Label(buf.toString(), Label.CONTENT_PREFORMATTED));
    return vl;//from w  ww.j  ava  2  s  .co  m
}

From source file:com.naoset.framework.frontend.component.profile.CustomerPanelView.java

public Component buildCustomerPanel(Customer customer) {

    VerticalLayout content = new VerticalLayout();

    content.addComponent(builtData());// w  ww.  j  av  a 2s .co m
    content.setSizeFull();
    content.setMargin(new MarginInfo(true, false, false, false));

    return content;
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create delete tab in the accordion./*  ww w.  j a  v  a2 s  . com*/
 * 
 * @return the component.
 */
@SuppressWarnings("serial")
private final AbstractComponent createDelete() {

    /* root layout */
    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();
    layout.setMargin(true);
    layout.setSpacing(true);

    final Label label = new Label("Deleting a device can be done, only if it is de-activated.");
    layout.addComponent(label);
    label.setWidth(null);
    layout.setComponentAlignment(label, Alignment.MIDDLE_CENTER);

    final Button deleteButton = new Button("Delete");

    layout.addComponent(deleteButton);
    layout.setComponentAlignment(deleteButton, Alignment.BOTTOM_CENTER);

    deleteButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                final DeviceDeleteWindow deleteWindow = new DeviceDeleteWindow(model.getItemUuid());
                deleteWindow.add(model);
            } catch (final Exception e) {
                LOGGER.error("Can not delete device: ", e);
            }
        }
    });
    return layout;
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create the component to take a snapshot.
 * /*from  www  .j  ava 2  s .co  m*/
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createTakeSnap() {

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(true);

    final FormLayout takeSnapLayout = new FormLayout();
    takeSnapLayout.setMargin(true);
    takeSnapLayout.setImmediate(true);
    takeSnapLayout.setWidth(null);
    layout.addComponent(takeSnapLayout);
    layout.setComponentAlignment(takeSnapLayout, Alignment.MIDDLE_CENTER);

    // Enter name
    final TextField vvrName = new TextField("Name", "");
    takeSnapLayout.addComponent(vvrName);

    // take button
    final Button take = new Button("Take snapshot");
    layout.addComponent(take);
    layout.setComponentAlignment(take, Alignment.MIDDLE_CENTER);

    take.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                model.takeDeviceSnapshot(vvrName.getValue());
                Notification.show("New snapshot created", Notification.Type.TRAY_NOTIFICATION);
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("Snapshot not taken: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return layout;
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create the component to activate/deactivate a device.
 * //  w  w  w  .  j  a  v  a 2s. co  m
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createActivate() {

    final VerticalLayout rootlayout = new VerticalLayout();
    rootlayout.setMargin(true);
    rootlayout.setSpacing(true);

    final OptionGroup activate = new OptionGroup("Select an option: ");
    rootlayout.addComponent(activate);
    rootlayout.setComponentAlignment(activate, Alignment.MIDDLE_CENTER);

    activate.setNullSelectionAllowed(false);
    activate.setHtmlContentAllowed(true);
    activate.setImmediate(true);
    activate.addItem(DEACTIVATE);
    activate.addItem(RWACTIVATE);
    activate.addItem(ROACTIVATE);

    final boolean isActivated = model.isDeviceActive();
    if (isActivated) {
        final boolean isReadOnly = model.isDeviceReadOnly();
        if (isReadOnly) {
            activate.select(ROACTIVATE);
            // rw is not authorized, deactivate first
            activate.setItemEnabled(RWACTIVATE, false);
        } else {
            activate.select(RWACTIVATE);
            // ro is not authorized, deactivate first
            activate.setItemEnabled(ROACTIVATE, false);
        }
    } else {
        activate.select(DEACTIVATE);
    }

    activate.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            final String valueString = String.valueOf(event.getProperty().getValue());

            if (valueString.equals(DEACTIVATE)) {
                final String action = DEACTIVATE;

                // Run activation in background
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.deActivateDevice();
                    }

                    @Override
                    public void postProcessing() {
                        activate.setItemEnabled(RWACTIVATE, true);
                        activate.setItemEnabled(ROACTIVATE, true);
                        updateAttributes();
                        Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION);
                    }
                });

            } else if (valueString.equals(RWACTIVATE)) {
                final String action = RWACTIVATE;
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.activateDeviceRW();
                    }

                    @Override
                    public void postProcessing() {
                        // ro is not authorized, deactivate first
                        activate.setItemEnabled(ROACTIVATE, false);
                        updateAttributes();
                        Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION);
                    }
                });
            } else if (valueString.equals(ROACTIVATE)) {
                final String action = ROACTIVATE;
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.activateDeviceRO();
                    }

                    @Override
                    public void postProcessing() {
                        // rw is not authorized, deactivate first
                        activate.setItemEnabled(RWACTIVATE, false);
                        updateAttributes();
                        Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION);
                    }
                });
            }

        }
    });

    return rootlayout;
}