Example usage for com.vaadin.ui GridLayout setColumnExpandRatio

List of usage examples for com.vaadin.ui GridLayout setColumnExpandRatio

Introduction

In this page you can find the example usage for com.vaadin.ui GridLayout setColumnExpandRatio.

Prototype

public void setColumnExpandRatio(int columnIndex, float ratio) 

Source Link

Document

Sets the expand ratio of given column.

Usage

From source file:org.ikasan.dashboard.ui.topology.window.WiretapConfigurationWindow.java

License:BSD License

/**
  * Helper method to initialise this object.
  * //from   ww  w .  j  a v a 2  s. com
  * @param message
  */
protected void init() {
    setModal(true);
    setHeight("90%");
    setWidth("90%");

    GridLayout layout = new GridLayout(2, 10);
    layout.setSizeFull();
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.setColumnExpandRatio(0, .25f);
    layout.setColumnExpandRatio(1, .75f);

    Label wiretapLabel = new Label("Wiretap Configuration");
    wiretapLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(wiretapLabel);

    Label moduleNameLabel = new Label();
    moduleNameLabel.setContentMode(ContentMode.HTML);
    moduleNameLabel.setValue(VaadinIcons.ARCHIVE.getHtml() + " Module Name:");
    moduleNameLabel.setSizeUndefined();
    layout.addComponent(moduleNameLabel, 0, 1);
    layout.setComponentAlignment(moduleNameLabel, Alignment.MIDDLE_RIGHT);

    TextField moduleNameTextField = new TextField();
    moduleNameTextField.setRequired(true);
    moduleNameTextField.setValue(this.component.getFlow().getModule().getName());
    moduleNameTextField.setReadOnly(true);
    moduleNameTextField.setWidth("80%");
    layout.addComponent(moduleNameTextField, 1, 1);

    Label flowNameLabel = new Label();
    flowNameLabel.setContentMode(ContentMode.HTML);
    flowNameLabel.setValue(VaadinIcons.AUTOMATION.getHtml() + " Flow Name:");
    flowNameLabel.setSizeUndefined();
    layout.addComponent(flowNameLabel, 0, 2);
    layout.setComponentAlignment(flowNameLabel, Alignment.MIDDLE_RIGHT);

    TextField flowNameTextField = new TextField();
    flowNameTextField.setRequired(true);
    flowNameTextField.setValue(this.component.getFlow().getName());
    flowNameTextField.setReadOnly(true);
    flowNameTextField.setWidth("80%");
    layout.addComponent(flowNameTextField, 1, 2);

    Label componentNameLabel = new Label();
    componentNameLabel.setContentMode(ContentMode.HTML);
    componentNameLabel.setValue(VaadinIcons.COG.getHtml() + " Component Name:");
    componentNameLabel.setSizeUndefined();
    layout.addComponent(componentNameLabel, 0, 3);
    layout.setComponentAlignment(componentNameLabel, Alignment.MIDDLE_RIGHT);

    TextField componentNameTextField = new TextField();
    componentNameTextField.setRequired(true);
    componentNameTextField.setValue(this.component.getName());
    componentNameTextField.setReadOnly(true);
    componentNameTextField.setWidth("80%");
    layout.addComponent(componentNameTextField, 1, 3);

    Label errorCategoryLabel = new Label("Relationship:");
    errorCategoryLabel.setSizeUndefined();
    layout.addComponent(errorCategoryLabel, 0, 4);
    layout.setComponentAlignment(errorCategoryLabel, Alignment.MIDDLE_RIGHT);

    final ComboBox relationshipCombo = new ComboBox();
    //      relationshipCombo.addValidator(new StringLengthValidator(
    //               "An relationship must be selected!", 1, -1, false));
    relationshipCombo.setImmediate(false);
    relationshipCombo.setValidationVisible(false);
    relationshipCombo.setRequired(true);
    relationshipCombo.setRequiredError("A relationship must be selected!");
    relationshipCombo.setHeight("30px");
    relationshipCombo.setNullSelectionAllowed(false);
    layout.addComponent(relationshipCombo, 1, 4);
    relationshipCombo.addItem("before");
    relationshipCombo.setItemCaption("before", "Before");
    relationshipCombo.addItem("after");
    relationshipCombo.setItemCaption("after", "After");

    Label jobTypeLabel = new Label("Job Type:");
    jobTypeLabel.setSizeUndefined();
    layout.addComponent(jobTypeLabel, 0, 5);
    layout.setComponentAlignment(jobTypeLabel, Alignment.MIDDLE_RIGHT);

    final ComboBox jobTopCombo = new ComboBox();
    //      jobTopCombo.addValidator(new StringLengthValidator(
    //               "A job type must be selected!", 1, -1, false));
    jobTopCombo.setImmediate(false);
    jobTopCombo.setValidationVisible(false);
    jobTopCombo.setRequired(true);
    jobTopCombo.setRequiredError("A job type must be selected!");
    jobTopCombo.setHeight("30px");
    jobTopCombo.setNullSelectionAllowed(false);
    layout.addComponent(jobTopCombo, 1, 5);
    jobTopCombo.addItem("loggingJob");
    jobTopCombo.setItemCaption("loggingJob", "Logging Job");
    jobTopCombo.addItem("wiretapJob");
    jobTopCombo.setItemCaption("wiretapJob", "Wiretap Job");

    final Label timeToLiveLabel = new Label("Time to Live:");
    timeToLiveLabel.setSizeUndefined();
    timeToLiveLabel.setVisible(false);
    layout.addComponent(timeToLiveLabel, 0, 6);
    layout.setComponentAlignment(timeToLiveLabel, Alignment.MIDDLE_RIGHT);

    final TextField timeToLiveTextField = new TextField();
    timeToLiveTextField.setRequired(true);
    timeToLiveTextField.setValidationVisible(false);
    jobTopCombo.setRequiredError("A time to live value must be entered!");
    timeToLiveTextField.setVisible(false);
    timeToLiveTextField.setWidth("40%");
    layout.addComponent(timeToLiveTextField, 1, 6);

    jobTopCombo.addValueChangeListener(new ComboBox.ValueChangeListener() {

        /* (non-Javadoc)
         * @see com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin.data.Property.ValueChangeEvent)
         */
        @Override
        public void valueChange(ValueChangeEvent event) {
            String value = (String) event.getProperty().getValue();

            if (value.equals("wiretapJob")) {
                timeToLiveLabel.setVisible(true);
                timeToLiveTextField.setVisible(true);
            } else {
                timeToLiveLabel.setVisible(false);
                timeToLiveTextField.setVisible(false);
            }
        }

    });

    GridLayout buttonLayouts = new GridLayout(3, 1);
    buttonLayouts.setSpacing(true);

    Button saveButton = new Button("Save");
    saveButton.setStyleName(ValoTheme.BUTTON_SMALL);
    saveButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                relationshipCombo.validate();
                jobTopCombo.validate();

                if (timeToLiveTextField.isVisible()) {
                    timeToLiveTextField.validate();
                }
            } catch (InvalidValueException e) {
                relationshipCombo.setValidationVisible(true);
                relationshipCombo.markAsDirty();
                jobTopCombo.setValidationVisible(true);
                jobTopCombo.markAsDirty();

                if (timeToLiveTextField.isVisible()) {
                    timeToLiveTextField.setValidationVisible(true);
                    timeToLiveTextField.markAsDirty();
                }

                Notification.show("There are errors on the wiretap creation form!", Type.ERROR_MESSAGE);
                return;
            }

            createWiretap((String) relationshipCombo.getValue(), (String) jobTopCombo.getValue(),
                    timeToLiveTextField.getValue());
        }
    });

    Button cancelButton = new Button("Cancel");
    cancelButton.setStyleName(ValoTheme.BUTTON_SMALL);
    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            close();
        }
    });

    buttonLayouts.addComponent(saveButton);
    buttonLayouts.addComponent(cancelButton);

    layout.addComponent(buttonLayouts, 0, 7, 1, 7);
    layout.setComponentAlignment(buttonLayouts, Alignment.MIDDLE_CENTER);

    Panel paramPanel = new Panel();
    paramPanel.setStyleName("dashboard");
    paramPanel.setWidth("100%");
    paramPanel.setContent(layout);

    triggerTable = new Table();

    Label existingWiretapLabel = new Label("Existing Wiretaps");
    existingWiretapLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(existingWiretapLabel, 0, 8, 1, 8);

    layout.addComponent(triggerTable, 0, 9, 1, 9);
    layout.setComponentAlignment(triggerTable, Alignment.TOP_CENTER);

    this.triggerTable.setWidth("80%");
    this.triggerTable.setHeight(150, Unit.PIXELS);
    this.triggerTable.setCellStyleGenerator(new IkasanCellStyleGenerator());
    this.triggerTable.addStyleName(ValoTheme.TABLE_SMALL);
    this.triggerTable.addStyleName("ikasan");
    this.triggerTable.addContainerProperty("Job Type", String.class, null);
    this.triggerTable.addContainerProperty("Relationship", String.class, null);
    this.triggerTable.addContainerProperty("Trigger Parameters", String.class, null);
    this.triggerTable.addContainerProperty("", Button.class, null);

    refreshTriggerTable();

    GridLayout wrapper = new GridLayout(1, 1);
    wrapper.setMargin(true);
    wrapper.setSizeFull();
    wrapper.addComponent(paramPanel);

    this.setContent(wrapper);
}

From source file:org.ikasan.dashboard.ui.topology.window.WiretapPayloadViewWindow.java

License:BSD License

protected Panel createWiretapDetailsPanel() {
    Panel errorOccurrenceDetailsPanel = new Panel();
    errorOccurrenceDetailsPanel.setSizeFull();
    errorOccurrenceDetailsPanel.setStyleName("dashboard");

    GridLayout layout = new GridLayout(2, 6);
    layout.setSizeFull();//from www.j a  va 2s. c om
    layout.setSpacing(true);
    layout.setColumnExpandRatio(0, 0.2f);
    layout.setColumnExpandRatio(1, 0.8f);

    Label wiretapDetailsLabel = new Label("Wiretap Details");
    wiretapDetailsLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(wiretapDetailsLabel);

    Label moduleNameLabel = new Label("Module Name:");
    moduleNameLabel.setSizeUndefined();

    layout.addComponent(moduleNameLabel, 0, 1);
    layout.setComponentAlignment(moduleNameLabel, Alignment.MIDDLE_RIGHT);

    TextField moduleName = new TextField();
    moduleName.setValue(this.wiretapEvent.getModuleName());
    moduleName.setReadOnly(true);
    moduleName.setWidth("80%");
    layout.addComponent(moduleName, 1, 1);

    Label flowNameLabel = new Label("Flow Name:");
    flowNameLabel.setSizeUndefined();

    layout.addComponent(flowNameLabel, 0, 2);
    layout.setComponentAlignment(flowNameLabel, Alignment.MIDDLE_RIGHT);

    TextField tf2 = new TextField();
    tf2.setValue(this.wiretapEvent.getFlowName());
    tf2.setReadOnly(true);
    tf2.setWidth("80%");
    layout.addComponent(tf2, 1, 2);

    Label componentNameLabel = new Label("Component Name:");
    componentNameLabel.setSizeUndefined();

    layout.addComponent(componentNameLabel, 0, 3);
    layout.setComponentAlignment(componentNameLabel, Alignment.MIDDLE_RIGHT);

    TextField tf3 = new TextField();
    tf3.setValue(this.wiretapEvent.getComponentName());
    tf3.setReadOnly(true);
    tf3.setWidth("80%");
    layout.addComponent(tf3, 1, 3);

    Label dateTimeLabel = new Label("Date/Time:");
    dateTimeLabel.setSizeUndefined();

    layout.addComponent(dateTimeLabel, 0, 4);
    layout.setComponentAlignment(dateTimeLabel, Alignment.MIDDLE_RIGHT);

    TextField tf4 = new TextField();
    tf4.setValue(new Date(this.wiretapEvent.getTimestamp()).toString());
    tf4.setReadOnly(true);
    tf4.setWidth("80%");
    layout.addComponent(tf4, 1, 4);

    Label eventIdLabel = new Label("Event Id:");
    eventIdLabel.setSizeUndefined();

    layout.addComponent(eventIdLabel, 0, 5);
    layout.setComponentAlignment(eventIdLabel, Alignment.MIDDLE_RIGHT);

    TextField tf5 = new TextField();
    tf5.setValue(((WiretapFlowEvent) wiretapEvent).getEventId());
    tf5.setReadOnly(true);
    tf5.setWidth("80%");
    layout.addComponent(tf5, 1, 5);

    GridLayout wrapperLayout = new GridLayout(1, 4);
    wrapperLayout.setWidth("100%");
    //      wrapperLayout.setMargin(true);
    //      wrapperLayout.setSizeFull();

    AceEditor editor = new AceEditor();
    editor.setCaption("Event");
    editor.setValue(this.wiretapEvent.getEvent());
    editor.setReadOnly(true);
    editor.setMode(AceMode.xml);
    editor.setTheme(AceTheme.eclipse);
    editor.setWidth("100%");
    editor.setHeight(550, Unit.PIXELS);

    //      HorizontalLayout formLayout = new HorizontalLayout();
    //      formLayout.setWidth("100%");
    //      formLayout.setHeight(120, Unit.PIXELS);
    //      formLayout.addComponent(layout);
    wrapperLayout.addComponent(layout, 0, 0);
    wrapperLayout.addComponent(editor, 0, 2);
    wrapperLayout.setComponentAlignment(editor, Alignment.TOP_LEFT);

    errorOccurrenceDetailsPanel.setContent(wrapperLayout);
    return errorOccurrenceDetailsPanel;
}

From source file:org.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewConfigurationWindow.java

License:Open Source License

/**
 * The constructor for instantiating this component.
 *
 * @param surveillanceViewService the surveillance view service to be used
 * @param view                    the view to edit
 * @param saveActionListener      the save action listener
 *//*from   w ww. j  av a2 s  .  c  o m*/
public SurveillanceViewConfigurationWindow(final SurveillanceViewService surveillanceViewService,
        final View view, final SaveActionListener saveActionListener) {
    /**
     * Setting the title
     */
    super("Surveillance view configuration");

    /**
     * Setting the modal and size properties
     */
    setModal(true);
    setClosable(false);
    setResizable(false);
    setWidth(80, Sizeable.Unit.PERCENTAGE);
    setHeight(75, Sizeable.Unit.PERCENTAGE);

    /**
     * Title field
     */
    final TextField titleField = new TextField();
    titleField.setValue(view.getName());
    titleField.setImmediate(true);
    titleField.setCaption("Title");
    titleField.setDescription("Title of this surveillance view");
    titleField.setWidth(25, Unit.PERCENTAGE);

    /**
     * Adding simple validator
     */
    titleField.addValidator(new AbstractStringValidator("Please use an unique name for the surveillance view") {
        @Override
        protected boolean isValidValue(String string) {
            if ("".equals(string.trim())) {
                return false;
            }
            if (SurveillanceViewProvider.getInstance().containsView(string) && !view.getName().equals(string)) {
                return false;
            }
            return true;
        }
    });

    /**
     * Refresh seconds field setup and validator
     */
    final TextField refreshSecondsField = new TextField();
    refreshSecondsField.setValue(String.valueOf(view.getRefreshSeconds()));
    refreshSecondsField.setImmediate(true);
    refreshSecondsField.setCaption("Refresh seconds");
    refreshSecondsField.setDescription("Refresh duration in seconds");

    refreshSecondsField.addValidator(new AbstractStringValidator("Only numbers allowed here") {
        @Override
        protected boolean isValidValue(String s) {
            int number;
            try {
                number = Integer.parseInt(s);
            } catch (NumberFormatException numberFormatException) {
                return false;
            }
            return (number >= 0);
        }
    });

    /**
     * Columns table
     */
    final Table columnsTable = new Table();

    columnsTable.setSortEnabled(false);
    columnsTable.setWidth(25, Unit.PERCENTAGE);

    final BeanItemContainer<ColumnDef> columns = new BeanItemContainer<ColumnDef>(ColumnDef.class,
            view.getColumns());

    final Map<ColumnDef, Integer> columnOrder = new HashMap<>();

    int c = 0;
    for (ColumnDef columnDef : view.getColumns()) {
        columnOrder.put(columnDef, c++);
    }

    columnsTable.setContainerDataSource(columns);

    columnsTable.setVisibleColumns("label");
    columnsTable.setColumnHeader("label", "Columns");
    columnsTable.setColumnExpandRatio("label", 1.0f);
    columnsTable.setSelectable(true);
    columnsTable.setMultiSelect(false);

    /**
     * Create custom sorter
     */
    columns.setItemSorter(new DefaultItemSorter() {
        @Override
        public int compare(Object o1, Object o2) {
            if (o1 == null) {
                if (o2 == null) {
                    return 0;
                } else {
                    return -1;
                }
            }
            if (o2 == null) {
                return 1;
            }

            if (columnOrder.get(o1).intValue() == columnOrder.get(o2).intValue()) {
                return 0;
            } else {
                if (columnOrder.get(o1).intValue() > columnOrder.get(o2).intValue()) {
                    return 1;
                } else {
                    return -1;
                }
            }
        }
    });

    /**
     * Adding the buttons...
     */
    final Button columnsAddButton = new Button("Add");
    columnsAddButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService,
                    columnsTable.getItemIds(), new ColumnDef(),
                    new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() {
                        @Override
                        public void save(Def def) {
                            columns.addItem((ColumnDef) def);
                            columnOrder.put((ColumnDef) def, columnOrder.size());

                            columns.sort(new Object[] { "label" }, new boolean[] { true });
                            columnsTable.refreshRowCache();
                        }
                    }));
        }
    });

    columnsAddButton.setEnabled(true);
    columnsAddButton.setStyleName("small");
    columnsAddButton.setDescription("Add column");
    columnsAddButton.setEnabled(true);

    final Button columnsEditButton = new Button("Edit");
    columnsEditButton.setEnabled(true);
    columnsEditButton.setStyleName("small");
    columnsEditButton.setDescription("Edit column");
    columnsEditButton.setEnabled(false);

    columnsEditButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService,
                    columnsTable.getItemIds(), (ColumnDef) columnsTable.getValue(),
                    new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() {
                        @Override
                        public void save(Def def) {
                            ColumnDef columnToBeReplaced = (ColumnDef) columnsTable.getValue();
                            int index = columnOrder.get(columnToBeReplaced);

                            columns.removeItem(columnToBeReplaced);
                            columnOrder.remove(columnToBeReplaced);

                            columns.addItem((ColumnDef) def);
                            columnOrder.put((ColumnDef) def, index);

                            columns.sort(new Object[] { "label" }, new boolean[] { true });
                            columnsTable.refreshRowCache();
                        }
                    }));
        }
    });

    final Button columnsRemoveButton = new Button("Remove");
    columnsRemoveButton.setEnabled(true);
    columnsRemoveButton.setStyleName("small");
    columnsRemoveButton.setDescription("Remove column");
    columnsRemoveButton.setEnabled(false);

    columnsRemoveButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            ColumnDef columnDef = (ColumnDef) columnsTable.getValue();
            if (columnDef != null) {
                columnsTable.unselect(columnDef);
                columns.removeItem(columnDef);
            }

            columnsTable.refreshRowCache();
        }
    });

    final Button columnUpButton = new Button();
    columnUpButton.setStyleName("small");
    columnUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png"));
    columnUpButton.setDescription("Move this a column entry one position up");
    columnUpButton.setEnabled(false);

    columnUpButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            ColumnDef columnDef = (ColumnDef) columnsTable.getValue();
            if (columnDef != null) {
                int columnDefIndex = columnOrder.get(columnDef);

                ColumnDef columnDefToSwap = null;

                for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) {
                    if (entry.getValue().intValue() == columnDefIndex - 1) {
                        columnDefToSwap = entry.getKey();
                        break;
                    }
                }

                if (columnDefToSwap != null) {
                    columnsTable.unselect(columnDef);
                    columnOrder.remove(columnDef);
                    columnOrder.remove(columnDefToSwap);
                    columnOrder.put(columnDef, columnDefIndex - 1);
                    columnOrder.put(columnDefToSwap, columnDefIndex);

                    columns.sort(new Object[] { "label" }, new boolean[] { true });
                    columnsTable.refreshRowCache();
                    columnsTable.select(columnDef);
                }

            }
        }
    });

    final Button columnDownButton = new Button();
    columnDownButton.setStyleName("small");
    columnDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png"));
    columnDownButton.setDescription("Move this a column entry one position down");
    columnDownButton.setEnabled(false);

    columnDownButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            ColumnDef columnDef = (ColumnDef) columnsTable.getValue();
            if (columnDef != null) {
                int columnDefIndex = columnOrder.get(columnDef);

                ColumnDef columnDefToSwap = null;

                for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) {
                    if (entry.getValue().intValue() == columnDefIndex + 1) {
                        columnDefToSwap = entry.getKey();
                        break;
                    }
                }

                if (columnDefToSwap != null) {
                    columnsTable.unselect(columnDef);
                    columnOrder.remove(columnDef);
                    columnOrder.remove(columnDefToSwap);
                    columnOrder.put(columnDef, columnDefIndex + 1);
                    columnOrder.put(columnDefToSwap, columnDefIndex);

                    columns.sort(new Object[] { "label" }, new boolean[] { true });
                    columnsTable.refreshRowCache();
                    columnsTable.select(columnDef);
                }
            }
        }
    });

    columnsTable.setSizeFull();

    columnUpButton.setSizeFull();
    columnDownButton.setSizeFull();
    columnsAddButton.setSizeFull();
    columnsEditButton.setSizeFull();
    columnsRemoveButton.setSizeFull();

    columnsTable.setImmediate(true);

    /**
     * ...and a listener
     */
    columnsTable.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            boolean somethingSelected = (columnsTable.getValue() != null);
            columnsRemoveButton.setEnabled(somethingSelected);
            columnsEditButton.setEnabled(somethingSelected);
            columnsAddButton.setEnabled(true);
            columnUpButton
                    .setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() > 0);
            columnDownButton.setEnabled(somethingSelected
                    && columnOrder.get(columnsTable.getValue()).intValue() < columnOrder.size() - 1);
        }
    });

    /**
     * Rows table
     */
    final Table rowsTable = new Table();

    rowsTable.setSortEnabled(false);
    rowsTable.setWidth(25, Unit.PERCENTAGE);

    final BeanItemContainer<RowDef> rows = new BeanItemContainer<RowDef>(RowDef.class, view.getRows());

    final Map<RowDef, Integer> rowOrder = new HashMap<>();

    int r = 0;
    for (RowDef rowDef : view.getRows()) {
        rowOrder.put(rowDef, r++);
    }

    rowsTable.setContainerDataSource(rows);

    rowsTable.setVisibleColumns("label");
    rowsTable.setColumnHeader("label", "Rows");
    rowsTable.setColumnExpandRatio("label", 1.0f);
    rowsTable.setSelectable(true);
    rowsTable.setMultiSelect(false);

    /**
     * Create custom sorter
     */
    rows.setItemSorter(new DefaultItemSorter() {
        @Override
        public int compare(Object o1, Object o2) {
            if (o1 == null) {
                if (o2 == null) {
                    return 0;
                } else {
                    return -1;
                }
            }
            if (o2 == null) {
                return 1;
            }

            if (rowOrder.get(o1).intValue() == rowOrder.get(o2).intValue()) {
                return 0;
            } else {
                if (rowOrder.get(o1).intValue() > rowOrder.get(o2).intValue()) {
                    return 1;
                } else {
                    return -1;
                }
            }
        }
    });

    /**
     * Adding the buttons...
     */
    final Button rowsAddButton = new Button("Add");
    rowsAddButton.setEnabled(true);
    rowsAddButton.setStyleName("small");
    rowsAddButton.setDescription("Add row");
    rowsAddButton.setEnabled(true);

    rowsAddButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService,
                    rowsTable.getItemIds(), new RowDef(),
                    new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() {
                        @Override
                        public void save(Def def) {
                            rows.addItem((RowDef) def);
                            rowOrder.put((RowDef) def, rowOrder.size());

                            rows.sort(new Object[] { "label" }, new boolean[] { true });
                            rowsTable.refreshRowCache();
                        }
                    }));
        }
    });

    final Button rowsEditButton = new Button("Edit");
    rowsEditButton.setEnabled(true);
    rowsEditButton.setStyleName("small");
    rowsEditButton.setDescription("Edit row");
    rowsEditButton.setEnabled(false);

    rowsEditButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService,
                    rowsTable.getItemIds(), (RowDef) rowsTable.getValue(),
                    new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() {
                        @Override
                        public void save(Def def) {
                            RowDef rowToBeReplaced = (RowDef) rowsTable.getValue();
                            int index = rowOrder.get(rowToBeReplaced);

                            rows.removeItem(rowToBeReplaced);
                            rowOrder.remove(rowToBeReplaced);

                            rows.addItem((RowDef) def);
                            rowOrder.put((RowDef) def, index);

                            rows.sort(new Object[] { "label" }, new boolean[] { true });
                            rowsTable.refreshRowCache();
                        }
                    }));
        }
    });

    final Button rowsRemoveButton = new Button("Remove");
    rowsRemoveButton.setEnabled(true);
    rowsRemoveButton.setStyleName("small");
    rowsRemoveButton.setDescription("Remove row");
    rowsRemoveButton.setEnabled(false);

    rowsRemoveButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            RowDef rowDef = (RowDef) rowsTable.getValue();
            if (rowDef != null) {
                rowsTable.unselect(rowDef);
                rows.removeItem(rowDef);
            }

            rowsTable.refreshRowCache();
        }
    });

    final Button rowUpButton = new Button();
    rowUpButton.setStyleName("small");
    rowUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png"));
    rowUpButton.setDescription("Move this a row entry one position up");
    rowUpButton.setEnabled(false);

    rowUpButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            RowDef rowDef = (RowDef) rowsTable.getValue();
            if (rowDef != null) {
                int rowDefIndex = rowOrder.get(rowDef);

                RowDef rowDefToSwap = null;

                for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) {
                    if (entry.getValue().intValue() == rowDefIndex - 1) {
                        rowDefToSwap = entry.getKey();
                        break;
                    }
                }

                if (rowDefToSwap != null) {
                    rowsTable.unselect(rowDef);
                    rowOrder.remove(rowDef);
                    rowOrder.remove(rowDefToSwap);
                    rowOrder.put(rowDef, rowDefIndex - 1);
                    rowOrder.put(rowDefToSwap, rowDefIndex);

                    rows.sort(new Object[] { "label" }, new boolean[] { true });
                    rowsTable.refreshRowCache();
                    rowsTable.select(rowDef);
                }
            }
        }
    });

    final Button rowDownButton = new Button();
    rowDownButton.setStyleName("small");
    rowDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png"));
    rowDownButton.setDescription("Move this a row entry one position down");
    rowDownButton.setEnabled(false);

    rowDownButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            RowDef rowDef = (RowDef) rowsTable.getValue();
            if (rowDef != null) {
                int rowDefIndex = rowOrder.get(rowDef);

                RowDef rowDefToSwap = null;

                for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) {
                    if (entry.getValue().intValue() == rowDefIndex + 1) {
                        rowDefToSwap = entry.getKey();
                        break;
                    }
                }

                if (rowDefToSwap != null) {
                    rowsTable.unselect(rowDef);
                    rowOrder.remove(rowDef);
                    rowOrder.remove(rowDefToSwap);
                    rowOrder.put(rowDef, rowDefIndex + 1);
                    rowOrder.put(rowDefToSwap, rowDefIndex);

                    rows.sort(new Object[] { "label" }, new boolean[] { true });
                    rowsTable.refreshRowCache();
                    rowsTable.select(rowDef);
                }
            }
        }
    });

    rowsTable.setSizeFull();

    rowUpButton.setSizeFull();
    rowDownButton.setSizeFull();
    rowsAddButton.setSizeFull();
    rowsEditButton.setSizeFull();
    rowsRemoveButton.setSizeFull();

    rowsTable.setImmediate(true);

    /**
     * ...and a listener
     */
    rowsTable.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            boolean somethingSelected = (rowsTable.getValue() != null);
            rowsRemoveButton.setEnabled(somethingSelected);
            rowsEditButton.setEnabled(somethingSelected);
            rowsAddButton.setEnabled(true);
            rowUpButton.setEnabled(somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() > 0);
            rowDownButton.setEnabled(
                    somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() < rowOrder.size() - 1);
        }
    });

    /**
     * Create form layouts...
     */
    FormLayout baseFormLayout = new FormLayout();
    baseFormLayout.addComponent(titleField);
    baseFormLayout.addComponent(refreshSecondsField);

    FormLayout columnTableFormLayout = new FormLayout();
    columnTableFormLayout.addComponent(columnsAddButton);
    columnTableFormLayout.addComponent(columnsEditButton);
    columnTableFormLayout.addComponent(columnsRemoveButton);
    columnTableFormLayout.addComponent(columnUpButton);
    columnTableFormLayout.addComponent(columnDownButton);

    FormLayout rowTableFormLayout = new FormLayout();
    rowTableFormLayout.addComponent(rowsAddButton);
    rowTableFormLayout.addComponent(rowsEditButton);
    rowTableFormLayout.addComponent(rowsRemoveButton);
    rowTableFormLayout.addComponent(rowUpButton);
    rowTableFormLayout.addComponent(rowDownButton);

    /**
     * Adding the different {@link com.vaadin.ui.FormLayout} instances to a {@link com.vaadin.ui.GridLayout}
     */
    baseFormLayout.setMargin(true);
    columnTableFormLayout.setMargin(true);
    rowTableFormLayout.setMargin(true);

    GridLayout gridLayout = new GridLayout();
    gridLayout.setSizeFull();
    gridLayout.setColumns(4);
    gridLayout.setRows(1);
    gridLayout.setMargin(true);

    gridLayout.addComponent(rowsTable);
    gridLayout.addComponent(rowTableFormLayout);
    gridLayout.addComponent(columnsTable);
    gridLayout.addComponent(columnTableFormLayout);

    gridLayout.setColumnExpandRatio(1, 0.5f);
    gridLayout.setColumnExpandRatio(2, 1.0f);
    gridLayout.setColumnExpandRatio(3, 0.5f);
    gridLayout.setColumnExpandRatio(4, 1.0f);

    /**
     * Creating the vertical layout...
     */
    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.addComponent(baseFormLayout);
    verticalLayout.addComponent(gridLayout);

    /**
     * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons
     */
    HorizontalLayout horizontalLayout = new HorizontalLayout();

    horizontalLayout.setMargin(true);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);

    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing properties");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    horizontalLayout.addComponent(cancel);
    horizontalLayout.setExpandRatio(cancel, 1);
    horizontalLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");

    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (!titleField.isValid()) {
                ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please use an unique title",
                        Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (!refreshSecondsField.isValid()) {
                ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error",
                        "Please enter a valid number in the \"Refresh seconds\" field",
                        Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (columns.getItemIds().isEmpty() || rows.getItemIds().isEmpty()) {
                ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error",
                        "You must define at least one row category and one column category",
                        Notification.Type.ERROR_MESSAGE);
                return;
            }

            View finalView = new View();

            for (ColumnDef columnDef : columns.getItemIds()) {
                finalView.getColumns().add(columnDef);
            }

            for (RowDef rowDef : rows.getItemIds()) {
                finalView.getRows().add(rowDef);
            }

            finalView.setName(titleField.getValue());
            finalView.setRefreshSeconds(Integer.parseInt(refreshSecondsField.getValue()));

            saveActionListener.save(finalView);

            close();
        }
    });

    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    horizontalLayout.addComponent(ok);

    verticalLayout.addComponent(horizontalLayout);

    setContent(verticalLayout);
}

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

License:Mozilla Public License

protected Panel newPanel(String title) {
    Panel panel = new Panel(title);
    GridLayout layout = new GridLayout(2, 2);
    layout.setWidth(100.0f, Unit.PERCENTAGE);
    layout.setMargin(true);/*from w  ww  . j  a  va 2  s.c o m*/
    layout.setSpacing(true);
    layout.setColumnExpandRatio(0, 0.2f);
    layout.setColumnExpandRatio(1, 0.8f);
    layout.setDefaultComponentAlignment(Alignment.TOP_LEFT);
    panel.setContent(layout);
    return panel;
}

From source file:org.vaadin.addons.sitekit.site.FixedWidthView.java

License:Apache License

/**
 * {@inheritDoc}/*from w  w  w  . j av a2  s  . co  m*/
 */
@Override
protected void initializeComponents() {
    final int columnCount = 5;
    final int rowCount = 3;

    final GridLayout layout = this;
    layout.setMargin(true);
    layout.setColumns(columnCount);
    layout.setRows(rowCount);
    layout.setColumnExpandRatio(0, MARGIN_COLUMN_EXPAND_RATIO);
    layout.setColumnExpandRatio(MARGIN_COLUMN_RIGTH_INDEX, MARGIN_COLUMN_EXPAND_RATIO);
    layout.setRowExpandRatio(1, 1.0f);
    layout.setSizeFull();
    layout.setMargin(false);
    layout.setSpacing(true);

    final AbstractComponent logoComponent = getComponent("logo");
    logoComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS);
    layout.addComponent(logoComponent, 1, 0);

    final AbstractComponent navigationComponent = getComponent("navigation");
    navigationComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS);
    navigationComponent.setHeight(NAVIGATION_HEIGHT, Unit.PIXELS);
    layout.addComponent(navigationComponent, 1, 1);

    final AbstractComponent headerComponent = getComponent("header");
    headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    headerComponent.setSizeFull();
    layout.addComponent(headerComponent, 2, 0);

    final AbstractComponent contentComponent = getComponent("content");
    contentComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    contentComponent.setSizeFull();
    layout.addComponent(contentComponent, 2, 1);

    final AbstractComponent footerComponent = getComponent("footer");
    headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    layout.addComponent(footerComponent, 2, 2);
}

From source file:org.vaadin.addons.sitekit.viewlet.administrator.user.UserFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout layout = new GridLayout(2, 3);
    layout.setSizeFull();/*from   ww w  . j a  v a 2  s .c o  m*/
    layout.setMargin(false);
    layout.setSpacing(true);
    layout.setRowExpandRatio(1, 1f);
    layout.setColumnExpandRatio(1, 1f);
    setViewContent(layout);

    editor = new ValidatingEditor(SiteFields.getFieldDescriptors(User.class));
    editor.setCaption("User");
    editor.addListener((ValidatingEditorStateListener) this);
    editor.setWidth("380px");
    layout.addComponent(editor, 0, 1);

    final List<FieldDescriptor> childFieldDescriptors = SiteFields.getFieldDescriptors(GroupMember.class);
    final List<FilterDescriptor> childFilterDescriptors = new ArrayList<FilterDescriptor>();
    childContainer = new EntityContainer<GroupMember>(entityManager, GroupMember.class, "groupMemberId", 1000,
            true, false, false);
    childContainer.getQueryView().getQueryDefinition().setDefaultSortState(
            new String[] { "user.firstName", "user.lastName" }, new boolean[] { true, true });

    ContainerUtil.addContainerProperties(childContainer, childFieldDescriptors);

    final Table childTable = new FormattingTable();
    childGrid = new Grid(childTable, childContainer);
    childGrid.setFields(childFieldDescriptors);
    childGrid.setFilters(childFilterDescriptors);

    childTable.setColumnCollapsed("created", true);

    layout.addComponent(childGrid, 1, 1);

    final HorizontalLayout editorButtonLayout = new HorizontalLayout();
    editorButtonLayout.setSpacing(true);
    layout.addComponent(editorButtonLayout, 0, 2);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    editorButtonLayout.addComponent(saveButton);
    saveButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.commit();
            entityManager.getTransaction().begin();
            try {

                if (user.getPasswordHash() != null) {
                    final int hashSize = 64;
                    if (user.getPasswordHash().length() != hashSize) {
                        final byte[] passwordAndSaltBytes = (user.getEmailAddress() + ":"
                                + user.getPasswordHash()).getBytes(Charset.forName("UTF-8"));
                        try {
                            final MessageDigest md = MessageDigest.getInstance("SHA-256");
                            final byte[] passwordAndSaltDigest = md.digest(passwordAndSaltBytes);
                            user.setPasswordHash(StringUtil.toHexString(passwordAndSaltDigest));
                        } catch (NoSuchAlgorithmException e) {
                            e.printStackTrace();
                        }
                    }
                }
                // UserLogic.updateUser(user,
                // UserDao.getGroupMembers(entityManager, user));
                user = entityManager.merge(user);
                entityManager.persist(user);
                entityManager.getTransaction().commit();
                editor.setItem(new BeanItem<User>(user), false);
                //entityManager.detach(user);
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + user, t);
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    editorButtonLayout.addComponent(discardButton);
    discardButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.discard();
        }
    });

    childListButtonLayout = new HorizontalLayout();
    childListButtonLayout.setSpacing(true);
    childListButtonLayout.setSizeUndefined();
    layout.addComponent(childListButtonLayout, 1, 0);

    final Button addButton = getSite().getButton("add");
    childListButtonLayout.addComponent(addButton);
    addButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final GroupMember userElement = new GroupMember();
            userElement.setUser(user);
            userElement.setCreated(new Date());
            final UserGroupMemberFlowlet userGroupMemberFlowlet = getFlow()
                    .forward(UserGroupMemberFlowlet.class);
            userGroupMemberFlowlet.edit(userElement, true);
        }
    });

    final Button removeButton = getSite().getButton("remove");
    childListButtonLayout.addComponent(removeButton);
    removeButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            childContainer.removeItem(childGrid.getSelectedItemId());
            childContainer.commit();
        }
    });

}

From source file:org.vaadin.addons.sitekit.viewlet.user.UserAccountFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout layout = new GridLayout(1, 3);
    layout.setSizeFull();//  w  ww .ja  va2  s  .  c  o m
    layout.setMargin(false);
    layout.setSpacing(true);
    layout.setRowExpandRatio(1, 1f);
    layout.setColumnExpandRatio(1, 1f);
    setViewContent(layout);

    editor = new ValidatingEditor(SiteFields.getFieldDescriptors(User.class));
    editor.setCaption("User");
    editor.addListener((ValidatingEditorStateListener) this);
    editor.setWidth("380px");
    layout.addComponent(editor, 0, 1);

    final HorizontalLayout editorButtonLayout = new HorizontalLayout();
    editorButtonLayout.setSpacing(true);
    layout.addComponent(editorButtonLayout, 0, 2);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    editorButtonLayout.addComponent(saveButton);
    saveButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.commit();
            entityManager.getTransaction().begin();
            try {

                if (user.getPasswordHash() != null) {
                    final int hashSize = 64;
                    if (user.getPasswordHash().length() != hashSize) {
                        final byte[] passwordAndSaltBytes = (user.getEmailAddress() + ":"
                                + user.getPasswordHash()).getBytes(Charset.forName("UTF-8"));
                        try {
                            final MessageDigest md = MessageDigest.getInstance("SHA-256");
                            final byte[] passwordAndSaltDigest = md.digest(passwordAndSaltBytes);
                            user.setPasswordHash(StringUtil.toHexString(passwordAndSaltDigest));
                        } catch (NoSuchAlgorithmException e) {
                            e.printStackTrace();
                        }
                    }
                }
                // UserLogic.updateUser(user,
                // UserDao.getGroupMembers(entityManager, user));
                user = entityManager.merge(user);
                entityManager.persist(user);
                entityManager.getTransaction().commit();
                editor.setItem(new BeanItem<User>(user), false);
                entityManager.detach(user);
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + user, t);
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    editorButtonLayout.addComponent(discardButton);
    discardButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.discard();
        }
    });

}

From source file:org.vaadin.johannesh.jfokus2012.touchkit.view.ShowContactView.java

License:Open Source License

private void buildLayout() {
    layout = new CssLayout();
    layout.addStyleName("show-contact-view");
    layout.setWidth("100%");

    VerticalComponentGroup infoGroup = new VerticalComponentGroup("");
    infoGroup.setWidth("100%");

    Component label;/*  ww w . j  a va 2s . c  o  m*/
    Property p;

    p = item.getItemProperty(ContactUtils.PROPERTY_COMPANY);
    label = new Label(new ContactUtils.CompanyPropertyFormatter(p));
    label.setCaption(ContactUtils.formatFieldCaption(ContactUtils.PROPERTY_COMPANY));
    infoGroup.addComponent(label);

    p = item.getItemProperty(ContactUtils.PROPERTY_MOBILE);
    label = new Label(p);
    label.setCaption(ContactUtils.formatFieldCaption(ContactUtils.PROPERTY_MOBILE));
    infoGroup.addComponent(label);

    p = item.getItemProperty(ContactUtils.PROPERTY_EMAIL);
    label = new Label(p);
    label.setCaption(ContactUtils.formatFieldCaption(ContactUtils.PROPERTY_EMAIL));
    infoGroup.addComponent(label);

    Embedded picture = new Embedded("", new ThemeResource("icon/picture.png"));
    picture.setWidth("57px");
    picture.setHeight("57px");

    Label firstName = new Label(item.getItemProperty(ContactUtils.PROPERTY_FIRST_NAME));
    firstName.addStyleName("strong-name");

    Label lastName = new Label(item.getItemProperty(ContactUtils.PROPERTY_LAST_NAME));
    lastName.addStyleName("strong-name");

    GridLayout nameLayout = new GridLayout(2, 2);
    nameLayout.setWidth("100%");
    nameLayout.setSpacing(true);
    nameLayout.setMargin(true, true, false, true);
    nameLayout.setColumnExpandRatio(1, 1.0f);
    nameLayout.addComponent(picture, 0, 0, 0, 1);
    nameLayout.addComponent(firstName, 1, 0);
    nameLayout.addComponent(lastName, 1, 1);
    nameLayout.setComponentAlignment(firstName, Alignment.MIDDLE_LEFT);
    nameLayout.setComponentAlignment(lastName, Alignment.MIDDLE_LEFT);

    final Favourite favourite = new Favourite();
    favourite.setImmediate(true);
    favourite.setReadOnly(true);
    favourite.setIcon(new ThemeResource("icon/favourite.png"));
    favourite.setPropertyDataSource(item.getItemProperty(ContactUtils.PROPERTY_FAVOURITE));

    layout.addComponent(nameLayout);
    layout.addComponent(favourite);
    layout.addComponent(infoGroup);

    Button editButton = new Button("Edit");
    editButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            getNavigationManager().navigateTo(new EditContactView(item));
        }
    });
    setRightComponent(editButton);
    setContent(layout);
}

From source file:qbic.vaadincomponents.SelectFileComponent.java

License:Open Source License

public SelectFileComponent(String mainCaption, String info, String sourceCaption, String destinationCaption,
        BeanItemContainer<?> source, BeanItemContainer<?> destination) {
    setCaption(mainCaption);/*from   w  w  w  . ja va 2s. com*/

    VerticalLayout files = new VerticalLayout();
    files.setSpacing(true);

    // info label
    Label rawFilesInfo = new Label(info);
    rawFilesInfo.addStyleName(ValoTheme.LABEL_COLORED);
    files.addComponent(rawFilesInfo);
    files.setWidth("100%");

    // available files in openbis
    available = new Grid(source);
    available.setCaption(sourceCaption);
    available.setSelectionMode(SelectionMode.MULTI);

    // selected files for anaylsis
    selected = new Grid(destination);

    if (mainCaption.equals("Raw files")) {
        available.removeColumn("fullPath");
        available.removeColumn("openbisCode");
    }

    else if (mainCaption.equals("")) {
        available.removeColumn("name");
        available.removeColumn("path");
        selected.removeColumn("name");
        selected.removeColumn("path");
    }

    selected.setCaption(destinationCaption);
    selected.setSelectionMode(SelectionMode.MULTI);

    for (Grid.Column col : available.getColumns()) {
        col.setWidthUndefined();
    }

    // selectedFiles.set
    // buttons to add or remove files
    VerticalLayout buttons = new VerticalLayout();
    toLeft = new Button();
    toLeft.setIcon(FontAwesome.ARROW_LEFT);

    toRight = new Button();
    toRight.setIcon(FontAwesome.ARROW_RIGHT);
    buttons.addComponent(toRight);
    buttons.addComponent(toLeft);

    GridLayout grids = new GridLayout(3, 1);
    grids.setWidth("100%");

    // grids.setSpacing(true);
    grids.addComponent(available, 0, 0);

    available.setWidth("100%");
    grids.addComponent(buttons, 1, 0);
    grids.addComponent(selected, 2, 0);
    grids.setColumnExpandRatio(0, 0.45f);
    grids.setColumnExpandRatio(1, 0.029f);
    grids.setColumnExpandRatio(2, 0.45f);
    grids.setSpacing(false);
    grids.setComponentAlignment(buttons, com.vaadin.ui.Alignment.MIDDLE_CENTER);

    selected.setWidth("100%");

    files.addComponent(grids);

    this.setCompositionRoot(files);
    files.setMargin(new MarginInfo(true, true, true, false));
    this.setWidth("100%");

}

From source file:uk.q3c.krail.testapp.view.GridViewBase.java

License:Apache License

@Override
protected void doBuild() {
    Label label = new Label("This is the " + this.getClass().getSimpleName());
    label.setHeight("100px");
    GridLayout grid = new GridLayout(3, 3);

    grid.addComponent(label, 1, 1);/*from w  w  w.  j  a v a 2 s  .  c o m*/
    grid.setSizeFull();
    grid.setColumnExpandRatio(0, 0.33f);
    grid.setColumnExpandRatio(1, 0.33f);
    grid.setColumnExpandRatio(2, 0.33f);

    grid.setRowExpandRatio(0, 0.4f);
    grid.setRowExpandRatio(1, 0.2f);
    grid.setRowExpandRatio(2, 0.4f);

    label.setSizeFull();
    setRootComponent(grid);

}