Example usage for com.vaadin.ui HorizontalLayout setMargin

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

Introduction

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

Prototype

@Override
    public void setMargin(boolean enabled) 

Source Link

Usage

From source file:org.sensorhub.ui.GenericConfigFormBuilder.java

License:Mozilla Public License

@SuppressWarnings("serial")
@Override/*from   w  ww.j av a2  s.c  om*/
public FormLayout buildForm(final FieldGroup fieldGroup) {
    reset();
    FormLayout form = new FormLayout();

    // add widget for each visible attribute
    for (Object propId : fieldGroup.getUnboundPropertyIds()) {
        Property<?> prop = fieldGroup.getItemDataSource().getItemProperty(propId);

        if (prop instanceof ContainerProperty) {
            String label = ((ContainerProperty) prop).getLabel();
            if (label == null)
                label = getPrettyName((String) propId);

            /*Table table = new Table();
            table.setCaption(label);
            table.setSizeFull();
            table.setPageLength(5);
            table.setHeight(50, Unit.POINTS);
            table.setSelectable(true);
            table.setEditable(true);
            table.setColumnReorderingAllowed(false);
            table.setContainerDataSource(((ContainerProperty)prop).getValue());
            table.setBuffered(true);
            table.setStyleName(Runo.TABLE_SMALL);
            otherWidgets.add(table);*/

            if (!((ContainerProperty) prop).getValue().getItemIds().isEmpty()) {
                Object firstItemId = ((ContainerProperty) prop).getValue().getItemIds().iterator().next();
                FieldGroup newFieldGroup = new FieldGroup(
                        ((ContainerProperty) prop).getValue().getItem(firstItemId));
                FormLayout subform = new GenericConfigFormBuilder().buildForm(newFieldGroup);
                subform.setCaption(label);
                otherWidgets.add(subform);
            }
        } else {
            Field<?> field = null;

            try {
                String label = null;
                if (prop instanceof FieldProperty)
                    label = ((FieldProperty) prop).getLabel();
                if (label == null)
                    label = getPrettyName((String) propId);
                field = fieldGroup.buildAndBind(label, propId);
            } catch (Exception e) {
                System.err.println("No UI generator for field " + propId);
                continue;
            }

            //Property<?> prop = field.getPropertyDataSource();            
            customizeField((String) propId, prop, field);

            if (field instanceof Label)
                labels.add(field);
            else if (field instanceof TextField)
                textBoxes.add(field);
            else if (field instanceof CheckBox)
                checkBoxes.add(field);
            else
                otherWidgets.add(field);
        }
    }

    // add all widgets
    for (Field<?> w : labels)
        form.addComponent(w);
    for (Field<?> w : textBoxes)
        form.addComponent(w);
    for (Field<?> w : checkBoxes)
        form.addComponent(w);
    for (Component w : otherWidgets)
        form.addComponent(w);

    // add save button
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100.0f, Unit.PERCENTAGE);
    //buttonsLayout.setSizeFull();
    buttonsLayout.setMargin(true);
    buttonsLayout.setSpacing(true);
    form.addComponent(buttonsLayout);

    Button saveButton = new Button("Save");
    saveButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                fieldGroup.commit();
            } catch (CommitException e) {
                e.printStackTrace();
            }
        }
    });
    buttonsLayout.addComponent(saveButton);
    //buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_CENTER);

    // add cancel button
    Button cancelButton = new Button("Cancel");
    cancelButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            fieldGroup.discard();
        }
    });
    buttonsLayout.addComponent(cancelButton);
    //buttonsLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER);

    return form;
}

From source file:org.universAAL.ucc.windows.LicenceWindow.java

public LicenceWindow(UccUI app, ArrayList<License> licenses, AALService aal, UAPP installApp)
        throws IOException {
    res = ResourceBundle.getBundle(base);
    setCaption(res.getString("license.capt"));
    this.app = app;
    this.installingApplication = installApp;
    modus = Arrays.asList(new String[] { res.getString("agree.radio"), res.getString("dontAgree.radio") });
    vl = new VerticalLayout();
    vl.setSizeFull();//from   w  w  w . j  a va2  s  .  co  m
    vl.setSpacing(true);
    vl.setMargin(true);
    hp = new HorizontalSplitPanel();
    hp.setSplitPosition(150, Sizeable.UNITS_PIXELS);
    hp.setStyleName(Reindeer.SPLITPANEL_SMALL);
    hp.setLocked(true);

    hp.setSizeFull();
    tree = new Tree();
    tree.setImmediate(true);
    tree.setNullSelectionAllowed(true);
    tree.setNewItemsAllowed(false);
    for (License l : licenses) {
        tree.addItem(l.getAppName());
        tree.setChildrenAllowed(l.getAppName(), true);
        tree.expandItemsRecursively(l.getAppName());
        for (File f : l.getLicense()) {
            tree.addItem(f.getName());
            tree.setParent(f.getName(), l.getAppName());
            tree.setChildrenAllowed(f.getName(), false);
        }
    }
    if (licenses.size() > 0) {
        tree.select(licenses.get(0).getLicense().get(0).getName());
    }
    Panel panel = new Panel();
    panel.setHeight("400px");
    VerticalLayout layout = (VerticalLayout) panel.getContent();
    layout.setSpacing(true);
    layout.setMargin(true);
    for (License l : licenses) {
        if (l.getSlaList().size() > 0) {
            for (File slaFile : l.getSlaList()) {
                FileReader fr = new FileReader(slaFile);
                // SLA makes problems
                BufferedReader reader = new BufferedReader(fr);
                String line = null;
                while ((line = reader.readLine()) != null) {
                    panel.addComponent(new Label(line));
                }
            }
        } else if (l.getLicense().size() > 0) {
            for (File lFile : l.getLicense()) {
                FileReader fr = new FileReader(lFile);
                BufferedReader reader = new BufferedReader(fr);
                String line = null;
                while ((line = reader.readLine()) != null) {
                    panel.addComponent(new Label(line));
                }
            }
        }
    }
    hp.setFirstComponent(tree);
    vl.addComponent(panel);
    setContent(hp);
    op = new OptionGroup("", modus);
    op.setNullSelectionAllowed(false);
    op.select(res.getString("dontAgree.radio"));
    op.setImmediate(true);
    vl.addComponent(op);
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.setMargin(true);
    cancel = new Button(res.getString("cancel.button"));
    go = new Button(res.getString("finish.button"));
    go.setEnabled(false);
    hl.addComponent(cancel);
    hl.addComponent(go);
    vl.addComponent(hl);
    vl.setComponentAlignment(hl, Alignment.BOTTOM_RIGHT);
    setWidth("700px");
    setHeight("600px");
    setModal(true);
    center();
    hp.setSecondComponent(vl);
    setClosable(false);
    lic = new LicenseController(app, this, licenses, aal, installingApplication);
    tree.addListener(lic);
    op.addListener(lic);
}

From source file:org.universAAL.ucc.windows.LicenceWindow.java

public void createSecondComponent(Panel p) {
    modus = Arrays.asList(new String[] { res.getString("agree.radio"), res.getString("dontAgree.radio") });
    vl = new VerticalLayout();
    vl.setSizeFull();//from w  ww.ja  v a  2  s.  c o  m
    vl.setSpacing(true);
    vl.setMargin(true);
    p.setHeight("400px");
    VerticalLayout layout = (VerticalLayout) p.getContent();
    layout.setSpacing(true);
    layout.setMargin(true);
    vl.addComponent(p);
    op = new OptionGroup("", modus);
    op.setNullSelectionAllowed(false);
    op.select(res.getString("dontAgree.radio"));
    op.setImmediate(true);
    vl.addComponent(op);
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.setMargin(true);
    cancel = new Button(res.getString("cancel.button"));
    go = new Button(res.getString("finish.button"));
    cancel.addListener((Button.ClickListener) lic);
    go.addListener((Button.ClickListener) lic);
    go.setEnabled(false);
    hl.addComponent(cancel);
    hl.addComponent(go);
    vl.addComponent(hl);
    vl.setComponentAlignment(hl, Alignment.BOTTOM_RIGHT);
    op.addListener(lic);
    hp.setSecondComponent(vl);

}

From source file:org.vaadin.addon.itemlayout.demo.client.ui.ItemLayoutDemoUI.java

License:Open Source License

private Component initItemGridExamples() {
    // Layout to show examples
    final HorizontalLayout example = new HorizontalLayout();
    example.addComponent(new Label("Demo for ItemGrid"));

    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setMargin(true);
    example.addComponent(horizontalLayout);

    final ItemGrid itemGrid = buildDefaultItemGrid();
    itemGrid.addItemClickListener(buildClickListener());

    final OptionGroup sample = buildSelectableOption();
    sample.addValueChangeListener(buildValueChangeListener(itemGrid));
    horizontalLayout.addComponent(sample);
    horizontalLayout.addComponent(itemGrid);
    return example;
}