Example usage for com.vaadin.ui Button setStyleName

List of usage examples for com.vaadin.ui Button setStyleName

Introduction

In this page you can find the example usage for com.vaadin.ui Button setStyleName.

Prototype

@Override
    public void setStyleName(String style) 

Source Link

Usage

From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardOverview.java

License:Open Source License

/**
 * Constructor for creating new instances.
 *
 * @param wallboardConfigView the {@link WallboardConfigView}
 *//*from  www . ja v a  2  s .  c  om*/
public WallboardOverview(WallboardConfigView wallboardConfigView) {
    /**
     * Setting the member fields
     */
    this.m_wallboardConfigView = wallboardConfigView;

    /**
     * Setting up the layout component
     */
    setSizeFull();
    setMargin(true);
    setSpacing(true);

    Label label = new Label("Overview");
    label.addStyleName("configuration-title");

    Button button = new Button("Help");
    button.setStyleName("small");
    button.setDescription("Display help and usage");

    button.addClickListener(new HelpClickListener(this, m_wallboardConfigView.getDashletSelector()));

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.addComponent(label);
    horizontalLayout.addComponent(button);
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);

    horizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    horizontalLayout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);

    addComponent(horizontalLayout);

    /**
     * Adding the table with the required {@link Table.ColumnGenerator} objects
     */
    m_table = new Table();
    m_table.setSizeFull();

    m_table.addGeneratedColumn("Edit", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            Button button = new Button("Edit");
            button.setDescription("Edit this Ops Board configuration");
            button.setStyleName("small");
            button.addClickListener(new Button.ClickListener() {
                public void buttonClick(Button.ClickEvent clickEvent) {
                    m_wallboardConfigView.openWallboardEditor((Wallboard) itemId);
                }
            });
            return button;
        }
    });

    m_table.addGeneratedColumn("Remove", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            Button button = new Button("Remove");
            button.setDescription("Delete this Ops Board configuration");
            button.setStyleName("small");
            button.addClickListener(new Button.ClickListener() {
                public void buttonClick(Button.ClickEvent clickEvent) {
                    m_wallboardConfigView.removeTab(((Wallboard) itemId).getTitle());
                    WallboardProvider.getInstance().removeWallboard((Wallboard) itemId);
                    refreshTable();
                }
            });
            return button;
        }
    });

    m_table.addGeneratedColumn("Preview", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            Button button = new Button("Preview");
            button.setDescription("Preview this Ops Board configuration");
            button.setStyleName("small");
            button.addClickListener(new PreviewClickListener(WallboardOverview.this, (Wallboard) itemId));
            return button;
        }
    });

    m_table.addGeneratedColumn("Default", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            CheckBox checkBox = new CheckBox();
            checkBox.setImmediate(true);
            checkBox.setDescription("Make this Ops Board configuration the default");

            final Wallboard wallboard = m_beanItemContainer.getItem(itemId).getBean();
            checkBox.setValue(wallboard.isDefault());

            checkBox.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                    boolean newValue = ((Boolean) valueChangeEvent.getProperty().getValue());

                    if (newValue) {
                        for (Wallboard wallboard1 : m_beanItemContainer.getItemIds()) {
                            wallboard1.setDefault(false);
                        }
                    }

                    wallboard.setDefault(newValue);

                    m_table.refreshRowCache();

                    WallboardProvider.getInstance().save();
                }
            });
            return checkBox;
        }
    });

    refreshTable();

    /**
     * Adding the table
     */
    addComponent(m_table);

    setExpandRatio(m_table, 1.0f);
}

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

License:Open Source License

/**
 * Returns a clickable glyph icon with the given {@link com.vaadin.ui.Button.ClickListener}.
 *
 * @param glyphIcon     the icon to be used
 * @param clickListener the listener/*from   ww  w  . jav  a2  s  . c o  m*/
 * @return the button instance
 */
protected Button getClickableIcon(String glyphIcon, Button.ClickListener clickListener) {
    Button button = new Button("<span class=\"" + glyphIcon + "\" aria-hidden=\"true\"></span>");
    button.setHtmlContentAllowed(true);
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addStyleName("icon");
    button.setEnabled(m_enabled);
    button.addClickListener(clickListener);
    return button;
}

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
 *///w ww  . j av  a  2s .  c  om
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.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewsConfigList.java

License:Open Source License

/**
 * Constructor for creating this component.
 *
 * @param surveillanceViewService the surveillance view service to be used
 *///w  w  w .  j  a va 2  s  . c  om
public SurveillanceViewsConfigList(SurveillanceViewService surveillanceViewService) {
    /**
     * set the fields
     */
    this.m_surveillanceViewService = surveillanceViewService;

    /**
     * Loading the config
     */
    reloadSurveillanceViews();

    /**
     * Setting up the layout component
     */
    setSizeFull();
    setMargin(true);
    setSpacing(true);

    Label label = new Label("Surveillance View Configurations");
    label.addStyleName("configuration-title");

    /*
    Button button = new Button("Help");
    button.setStyleName("small");
    button.setDescription("Display help and usage");
    */

    /**
     * button.addClickListener(new HelpClickListener(this, m_wallboardConfigView.getDashletSelector()));
     */

    Button addButton = new Button("Add");
    addButton.setStyleName("small");
    addButton.setDescription("Add surveillance view configuration");

    addButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            String newName;
            int i = 0;

            do {
                i++;
                newName = "Untitled #" + i;
            } while (SurveillanceViewProvider.getInstance().containsView(newName));

            View view = new View();
            view.setName(newName);

            getUI().addWindow(new SurveillanceViewConfigurationWindow(m_surveillanceViewService, view,
                    new SurveillanceViewConfigurationWindow.SaveActionListener() {
                        @Override
                        public void save(View view) {
                            m_beanItemContainer.addItem(view);

                            SurveillanceViewProvider.getInstance().getSurveillanceViewConfiguration().getViews()
                                    .add(view);
                            SurveillanceViewProvider.getInstance().save();

                            ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Data saved",
                                    "Surveillance View");

                            m_table.refreshRowCache();
                            m_table.sort(new Object[] { "name" }, new boolean[] { true });
                        }
                    }));
        }
    });

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.addComponent(label);
    // horizontalLayout.addComponent(button);
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);

    horizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    // horizontalLayout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);

    addComponent(horizontalLayout);

    addComponent(addButton);

    /**
     * Adding the table with the required {@link com.vaadin.ui.Table.ColumnGenerator} objects
     */
    m_table = new Table();

    m_table.setContainerDataSource(m_beanItemContainer);
    m_table.setSizeFull();
    m_table.sort(new Object[] { "name" }, new boolean[] { true });

    m_table.addGeneratedColumn("Edit", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            Button button = new Button("Edit");
            button.setDescription("Edit this Surveillance View configuration");
            button.setStyleName("small");
            button.addClickListener(new Button.ClickListener() {
                public void buttonClick(Button.ClickEvent clickEvent) {
                    getUI().addWindow(new SurveillanceViewConfigurationWindow(m_surveillanceViewService,
                            m_beanItemContainer.getItem(itemId).getBean(),
                            new SurveillanceViewConfigurationWindow.SaveActionListener() {
                                @Override
                                public void save(View view) {
                                    View oldView = m_beanItemContainer.getItem(itemId).getBean();

                                    m_beanItemContainer.removeItem(itemId);
                                    m_beanItemContainer.addItem(view);

                                    SurveillanceViewProvider.getInstance().replaceView(oldView, view);

                                    SurveillanceViewProvider.getInstance().save();
                                    ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Data saved",
                                            "Surveillance view");

                                    m_table.refreshRowCache();
                                    m_table.sort(new Object[] { "name" }, new boolean[] { true });
                                }
                            }));
                }
            });
            return button;
        }
    }

    );

    m_table.addGeneratedColumn("Remove", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            Button button = new Button("Remove");
            button.setDescription("Delete this Surveillance View configuration");
            button.setStyleName("small");
            button.addClickListener(new Button.ClickListener() {
                public void buttonClick(Button.ClickEvent clickEvent) {
                    SurveillanceViewProvider.getInstance().removeView((View) itemId);
                    m_beanItemContainer.removeItem(itemId);
                }
            });
            return button;
        }
    });

    m_table.addGeneratedColumn("Preview", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            Button button = new Button("Preview");
            button.setDescription("Preview this Surveillance View configuration");
            button.setStyleName("small");

            button.addClickListener(new PreviewClickListener(m_surveillanceViewService,
                    SurveillanceViewsConfigList.this, (View) itemId));

            return button;
        }
    }

    );

    m_table.addGeneratedColumn("Default", new Table.ColumnGenerator() {
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            CheckBox checkBox = new CheckBox();
            checkBox.setImmediate(true);
            checkBox.setDescription("Make this Surveillance View configuration the default");

            final View view = m_beanItemContainer.getItem(itemId).getBean();

            checkBox.setValue(SurveillanceViewProvider.getInstance().getSurveillanceViewConfiguration()
                    .getDefaultView().equals(view.getName()));

            checkBox.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                    boolean newValue = ((Boolean) valueChangeEvent.getProperty().getValue());

                    if (newValue) {
                        SurveillanceViewProvider.getInstance().getSurveillanceViewConfiguration()
                                .setDefaultView(view.getName());
                    }

                    m_table.refreshRowCache();

                    SurveillanceViewProvider.getInstance().save();

                    ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Data saved",
                            "Default surveillance view");
                }
            });
            return checkBox;
        }
    }

    );

    m_table.setVisibleColumns(new Object[] { "name", "Edit", "Remove", "Preview", "Default" });
    m_table.setColumnHeader("name", "Name");

    /**
     * Adding the table
     */
    addComponent(m_table);

    setExpandRatio(m_table, 1.0f);
}

From source file:org.processbase.ui.bpm.generator.GeneratedWindow.java

License:Open Source License

private Button getButton(Widget widget) {
    Button component = new Button(widget.getLabel());
    component.addListener((Button.ClickListener) this);
    if (widget.isLabelButton()) {
        component.setStyleName(Reindeer.BUTTON_LINK);
    }//  w  ww. ja va 2  s  . c om
    return component;
}

From source file:org.processbase.ui.core.template.DefaultConfirmDialogFactory.java

License:Open Source License

public ConfirmDialog create(final String caption, final String message, final String okCaption,
        final String cancelCaption) {

    // Create a confirm dialog
    final ConfirmDialog confirm = new ConfirmDialog();
    confirm.setCaption(caption != null ? caption : DEFAULT_CAPTION);

    // Close listener implementation
    confirm.addListener(new Window.CloseListener() {

        private static final long serialVersionUID = 1971800928047045825L;

        public void windowClose(CloseEvent ce) {
            confirm.setConfirmed(false);
            if (confirm.getListener() != null) {
                confirm.getListener().onClose(confirm);
            }//from w ww .  ja v a  2  s .c  o  m
        }
    });

    // Create content
    VerticalLayout c = (VerticalLayout) confirm.getContent();
    c.setSizeFull();
    c.setSpacing(true);

    // Panel for scrolling lengthty messages.
    Panel scroll = new Panel(new VerticalLayout());
    scroll.setScrollable(true);
    c.addComponent(scroll);
    scroll.setWidth("100%");
    scroll.setHeight("100%");
    scroll.setStyleName(Reindeer.PANEL_LIGHT);
    c.setExpandRatio(scroll, 1f);

    // Always HTML, but escape
    Label text = new Label("", Label.CONTENT_RAW);
    scroll.addComponent(text);
    confirm.setMessageLabel(text);
    confirm.setMessage(message);

    HorizontalLayout buttons = new HorizontalLayout();
    c.addComponent(buttons);
    buttons.setSpacing(true);

    buttons.setHeight(format(BUTTON_HEIGHT) + "em");
    buttons.setWidth("100%");
    Label spacer = new Label("");
    buttons.addComponent(spacer);
    spacer.setWidth("100%");
    buttons.setExpandRatio(spacer, 1f);

    final Button cancel = new Button(cancelCaption != null ? cancelCaption : DEFAULT_CANCEL_CAPTION);
    cancel.setData(false);
    cancel.setClickShortcut(KeyCode.ESCAPE, null);
    buttons.addComponent(cancel);
    buttons.setComponentAlignment(cancel, Alignment.MIDDLE_RIGHT);
    confirm.setCancelButton(cancel);

    final Button ok = new Button(okCaption != null ? okCaption : DEFAULT_OK_CAPTION);
    ok.setData(true);
    ok.setClickShortcut(KeyCode.ENTER, null);
    ok.setStyleName(Reindeer.BUTTON_DEFAULT);
    ok.focus();
    buttons.addComponent(ok);
    buttons.setComponentAlignment(ok, Alignment.MIDDLE_RIGHT);
    confirm.setOkButton(ok);

    // Create a listener for buttons
    Button.ClickListener cb = new Button.ClickListener() {
        private static final long serialVersionUID = 3525060915814334881L;

        public void buttonClick(ClickEvent event) {
            // Copy the button date to window for passing through either
            // "OK" or "CANCEL"
            confirm.setConfirmed(event.getButton() == ok);

            // This has to be invoked as the window.close
            // event is not fired when removed.
            if (confirm.getListener() != null) {
                confirm.getListener().onClose(confirm);
            }
            confirm.close();

        }

    };
    cancel.addListener(cb);
    ok.addListener(cb);

    // Approximate the size of the dialog
    double[] dim = getDialogDimensions(message, ConfirmDialog.CONTENT_TEXT_WITH_NEWLINES);
    confirm.setWidth(format(dim[0]) + "em");
    confirm.setHeight(format(dim[1]) + "em");
    confirm.setResizable(false);

    return confirm;
}

From source file:org.processbase.ui.servlet.MainWindow.java

License:Open Source License

Layout getHeader() {
    HorizontalLayout header = new HorizontalLayout();
    header.setWidth("100%");
    header.setMargin(false);//  w w w.j  av  a2s  . c om
    header.setSpacing(true);

    ThemeResource themeResource = new ThemeResource("icons/processbase.png");
    Embedded logo = new Embedded();
    logo.setSource(themeResource);
    logo.setType(Embedded.TYPE_IMAGE);

    header.addComponent(logo);
    header.setExpandRatio(logo, 1.0f);

    Label helloUser = new Label("Welcome, " + user.getFirstName() + " " + user.getLastName());
    //        helloUser.setStyleName(Runo.LABEL_H2);
    header.addComponent(helloUser);
    header.setComponentAlignment(helloUser, Alignment.MIDDLE_RIGHT);
    header.setExpandRatio(helloUser, 1.0f);

    Button profile = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnProfile"),
            new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    openProfileWindow();
                }
            });
    profile.setStyleName(Runo.BUTTON_LINK);
    header.addComponent(profile);
    header.setComponentAlignment(profile, Alignment.MIDDLE_RIGHT);

    Button logout = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnLogout"),
            new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    openLogoutWindow();
                }
            });
    logout.setStyleName(Runo.BUTTON_LINK);
    header.addComponent(logout);
    header.setComponentAlignment(logout, Alignment.MIDDLE_RIGHT);

    return header;
}

From source file:org.processbase.ui.servlet.MainWindow.java

License:Open Source License

void openLogoutWindow() {
    Window logout = new Window(((PbApplication) getApplication()).getPbMessages().getString("btnLogout"));
    logout.setModal(true);//from ww  w . j a va  2 s  .  co m
    //        logout.setStyleName(Reindeer.WINDOW_BLACK);
    logout.setWidth("260px");
    logout.setResizable(false);
    logout.setClosable(false);
    logout.setDraggable(false);
    logout.setCloseShortcut(KeyCode.ESCAPE, null);

    Label helpText = new Label("Are you sure you want to log out?", Label.CONTENT_XHTML);
    logout.addComponent(helpText);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    Button yes = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnLogout"),
            new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    WebApplicationContext applicationContext = (WebApplicationContext) getApplication()
                            .getContext();
                    getApplication().close();
                    applicationContext.getHttpSession().invalidate();
                }
            });
    yes.setStyleName(Reindeer.BUTTON_DEFAULT);
    yes.focus();
    buttons.addComponent(yes);
    Button no = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnCancel"),
            new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    removeWindow(event.getButton().getWindow());
                }
            });
    buttons.addComponent(no);

    logout.addComponent(buttons);
    ((VerticalLayout) logout.getContent()).setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
    ((VerticalLayout) logout.getContent()).setSpacing(true);

    addWindow(logout);
}

From source file:org.ripla.web.demo.widgets.views.ButtonWidgetsView.java

License:Open Source License

public ButtonWidgetsView() {
    super();//from  ww w.  j a  v  a  2  s . c o  m

    final IMessages lMessages = Activator.getMessages();
    final VerticalLayout lLayout = initLayout(lMessages, "widgets.title.page.button"); //$NON-NLS-1$

    lLayout.addComponent(getSubtitle(lMessages.getMessage("widgets.view.button.subtitle.button"))); //$NON-NLS-1$
    final Button lButton = new Button(lMessages.getMessage("widgets.view.button.label.save")); //$NON-NLS-1$
    lButton.setDescription(lMessages.getMessage("widgets.view.button.descr.normal")); //$NON-NLS-1$
    lButton.addClickListener(new Listener(lMessages.getMessage("widgets.view.button.feedback.normal"))); //$NON-NLS-1$
    lLayout.addComponent(lButton);

    lLayout.addComponent(getSubtitle(lMessages.getMessage("widgets.view.button.label.image"))); //$NON-NLS-1$
    final Button lButton2 = new Button(lMessages.getMessage("widgets.view.button.label.save")); //$NON-NLS-1$
    lButton2.setIcon(new ThemeResource("../runo/icons/16/ok.png")); //$NON-NLS-1$
    lButton2.setDescription(lMessages.getMessage("widgets.view.button.label.image")); //$NON-NLS-1$
    lButton2.addClickListener(new Listener(lMessages.getMessage("widgets.view.button.feedback.image"))); //$NON-NLS-1$
    lLayout.addComponent(lButton2);

    lLayout.addComponent(getSubtitle(lMessages.getMessage("widgets.view.button.subtitle.disable"))); //$NON-NLS-1$
    lLayout.addComponent(new Label(lMessages.getMessage("widgets.view.button.label.disable"))); //$NON-NLS-1$
    final Button lButton3 = new Button(lMessages.getMessage("widgets.view.button.label.click")); //$NON-NLS-1$
    lButton3.setDisableOnClick(true);
    lButton3.setDescription(lMessages.getMessage("widgets.view.button.descr.disable")); //$NON-NLS-1$
    lButton3.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent inEvent) {
            try {
                Thread.sleep(3000);
            } catch (final InterruptedException exc) {
            }
            Notification.show(lMessages.getMessage("widgets.view.button.feedback.disable"),
                    Notification.Type.TRAY_NOTIFICATION);
            inEvent.getButton().setEnabled(true);
        }
    });
    lLayout.addComponent(lButton3);

    lLayout.addComponent(getSubtitle(lMessages.getMessage("widgets.view.button.subtitle.link"))); //$NON-NLS-1$
    final Button lButton4 = new Button(lMessages.getMessage("widgets.view.button.label.click")); //$NON-NLS-1$
    lButton4.setStyleName(BaseTheme.BUTTON_LINK);
    lButton4.addClickListener(new Listener(lMessages.getMessage("widgets.view.button.feedback.link"))); //$NON-NLS-1$
    lLayout.addComponent(new Label(lMessages.getMessage("widgets.view.button.label.link"))); //$NON-NLS-1$
    lLayout.addComponent(lButton4);

    lLayout.addComponent(getSubtitle(lMessages.getMessage("widgets.view.button.subtitle.check"))); //$NON-NLS-1$
    lLayout.addComponent(new Label(lMessages.getMessage("widgets.view.button.label.check"))); //$NON-NLS-1$
    final CheckBox lCheckbox = new CheckBox(lMessages.getMessage("widgets.view.button.label.click")); //$NON-NLS-1$
    lCheckbox.setImmediate(true);
    lCheckbox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent inEvent) {
            Notification.show(lMessages.getMessage("widgets.view.button.feedback.check"),
                    Notification.Type.TRAY_NOTIFICATION);

        }
    });
    lLayout.addComponent(lCheckbox);
}

From source file:org.ripla.web.internal.menu.ContextMenuManager.java

License:Open Source License

/**
 * Method to render the context menu./*  ww  w.  ja v a2  s  .c o  m*/
 * 
 * @param inMenuSetName
 *            String the fully qualified ID of the context menu
 * @param inUser
 *            {@link User} the user instance, might be evaluated to check
 *            the conditions
 * @param inAuthorization
 *            {@link Authorization} the authorization instance, will be
 *            evaluate to check the conditions
 * @param inParameters
 *            {@link ParameterObject} the generic parameter object with
 *            parameters that could be evaluated to check the conditions
 * @param inControllerClass
 *            Class&lt;? extends IPluggable> the active controller class
 * @return {@link Component} the component that displays the rendered
 *         context menu
 */
public Component renderContextMenu(final String inMenuSetName, final User inUser,
        final Authorization inAuthorization, final ParameterObject inParameters,
        final Class<? extends IPluggable> inControllerClass) {
    final VerticalLayout outContextMenu = new VerticalLayout();
    outContextMenu.setMargin(true);
    outContextMenu.setStyleName("ripla-contextmenu"); //$NON-NLS-1$

    final ContextMenuSet lContextMenuSet = contextMenus.get(inMenuSetName);
    if (lContextMenuSet == null) {
        return outContextMenu;
    }

    for (final ContextMenuItem lItem : lContextMenuSet.getContextMenuItems()) {
        if (lItem.checkConditions(inUser, inAuthorization, inParameters)) {
            final Button lContextMenuLink = new Button(lItem.getCaption()); // NOPMD
            lContextMenuLink.setStyleName(BaseTheme.BUTTON_LINK);
            lContextMenuLink.addStyleName("ripla-contextmenu-item");
            lContextMenuLink.setSizeUndefined();
            final Class<? extends IPluggable> lControllerClass = lItem.getControllerClass();
            if (lControllerClass.equals(inControllerClass)) {
                lContextMenuLink.addStyleName("active");
            }
            lContextMenuLink.addClickListener(new ContextMenuListener( // NOPMD
                    lControllerClass));
            outContextMenu.addComponent(lContextMenuLink);
        }
    }

    return outContextMenu;
}