Example usage for com.vaadin.ui CheckBox CheckBox

List of usage examples for com.vaadin.ui CheckBox CheckBox

Introduction

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

Prototype

public CheckBox(String caption, boolean initialState) 

Source Link

Document

Creates a new checkbox with a caption and a set initial state.

Usage

From source file:org.lucidj.vaadinui.Login.java

License:Apache License

@Override // LoginForm
protected Component createContent(TextField userNameField, PasswordField passwordField, Button loginButton) {
    // Save the predefined components
    this.userNameField = userNameField;
    this.passwordField = passwordField;
    this.loginButton = loginButton;

    // Make LoginForm container full-screen
    setSizeFull();/*from   w ww .  j  a va 2  s.c  o  m*/

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();
    layout.addStyleName("login-wallpaper");

    final VerticalLayout loginPanel = new VerticalLayout();
    loginPanel.setSizeUndefined();
    loginPanel.setMargin(true);
    loginPanel.setSpacing(true);
    Responsive.makeResponsive(loginPanel);
    loginPanel.addStyleName("card");

    //--------
    // HEADER
    //--------

    final HorizontalLayout labels = new HorizontalLayout();
    labels.setWidth("100%");

    final Label title = new Label("<h3><strong>LucidJ</strong> Console</h3>", ContentMode.HTML);
    labels.addComponent(title);
    labels.setExpandRatio(title, 1);

    loginPanel.addComponent(labels);

    //--------
    // FIELDS
    //--------

    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.addStyleName("fields");

    userNameField.setImmediate(true);
    userNameField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);
    final ShortcutListener username_enter_listener = new ShortcutListener("Next field (Tab)",
            ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object o, Object o1) {
            passwordField.setValue("");
            passwordField.focus();
        }
    };
    userNameField.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
            show_default_message();

            int new_username_length = textChangeEvent.getText().length();

            // Check for autofill
            if (userNameField.isEmpty() && new_username_length > 1 && !userNameField_filling) {
                // This is autofill
                userNameField.removeShortcutListener(username_enter_listener);
                userNameField.setCursorPosition(new_username_length);
                userNameField.setSelectionRange(0, new_username_length);
            } else {
                userNameField_filling = true;
                passwordField.setValue("");
                userNameField.addShortcutListener(username_enter_listener);
            }
        }
    });
    userNameField.addFocusListener(new FieldEvents.FocusListener() {
        @Override
        public void focus(FieldEvents.FocusEvent focusEvent) {
            // Cursor on username, Enter jump to password
            loginButton.removeClickShortcut();
            userNameField.addShortcutListener(username_enter_listener);
        }
    });
    userNameField.addBlurListener(new FieldEvents.BlurListener() {
        @Override
        public void blur(FieldEvents.BlurEvent blurEvent) {
            // Cursor on password or elsewhere, enter submits
            userNameField.removeShortcutListener(username_enter_listener);
            loginButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
        }
    });

    passwordField.setImmediate(true);
    passwordField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);
    passwordField.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
            show_default_message();
        }
    });

    loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    loginButton.setDisableOnClick(true);

    fields.addComponents(userNameField, passwordField, loginButton);
    fields.setComponentAlignment(loginButton, Alignment.BOTTOM_LEFT);

    loginPanel.addComponent(fields);

    //--------
    // FOOTER
    //--------

    loginPanel.addComponent(new CheckBox("Remember me", true));

    loginPanel.addComponent(message_label);
    show_default_message();

    layout.addComponent(loginPanel);
    layout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
    return (layout);
}

From source file:org.lunarray.model.generation.vaadin.render.factories.table.vaadin.components.CheckboxColumnGenerator.java

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override//ww  w . j ava2 s.c  o m
public Object generateCell(final Table source, final Object itemId, final Object columnId) {
    Validate.notNull(itemId, "Item id may not be null.");
    final OutputPropertyStrategy<P, E> strategy = this.getOutputPropertyStrategy();
    final RelationDescriptor relationProperty = strategy.getProperty().adapt(RelationDescriptor.class);
    Object result = null;
    String format = null;
    if (strategy.hasPresentationProperty()) {
        format = strategy.getPresentationProperty().getFormat();
    }
    if (CheckUtil.isNull(relationProperty)) {
        final CheckBox tmpCheckbox = new CheckBox("", new TableModelProperty<P, E>(strategy.getConverterTool(),
                this.getOutputPropertyStrategy().getProperty(), (E) itemId, format, strategy.getModel()));
        tmpCheckbox.setReadOnly(true);
        result = tmpCheckbox;
    } else {
        final PropertyDescriptor<Object, P> displayProperty = (PropertyDescriptor<Object, P>) this
                .resolveDisplayProperty();
        try {
            final CheckBox tmpCheckbox = new CheckBox("",
                    new TableModelProperty<Object, P>(strategy.getConverterTool(), displayProperty,
                            strategy.getProperty().getValue((E) itemId), format, strategy.getModel()));
            tmpCheckbox.setReadOnly(true);
            result = tmpCheckbox;
        } catch (final ValueAccessException e) {
            CheckboxColumnGenerator.LOGGER.warn("Could not access value.", e);
            result = itemId.toString();
        }
    }
    CheckboxColumnGenerator.LOGGER.debug("Resolved for item {} and column {}: {}", itemId, columnId, result);
    return result;
}

From source file:org.ops4j.pax.vaadin.samples.complex.app.MyComplexVaadinApplication.java

License:Apache License

@Override
public void init() {

    // TODO CHECK WHY THEME RENDERING IS TOO SLOW
    // setTheme("table");

    window = new Window("My Complex Vaadin Application");
    setMainWindow(window);/*  w ww .  ja  v  a2s .c o m*/

    final VerticalLayout layout = new VerticalLayout();
    final Table table = new Table("The Pax projects");
    table.addStyleName("multirowlabels");

    // Define two columns for the built-in container
    table.addContainerProperty("Code", String.class, null);
    table.addContainerProperty("Description", String.class, null);
    table.addContainerProperty("Creation Date", Date.class, null);
    // table.addContainerProperty("Edit", CheckBox.class, null);

    // Add a row the hard way
    Object newItemId = table.addItem();
    Item row1 = table.getItem(newItemId);
    row1.getItemProperty("Code").setValue("pax-vaadin");
    row1.getItemProperty("Description").setValue("OSGI vaadin project");
    //row1.getItemProperty("Creation date").setValue(new Date());

    // Add a few other rows using shorthand addItem()
    table.addItem(new Object[] { "pax-cdi", "pax cdi project", new Date() }, 2);
    table.addItem(new Object[] { "pax-logging", "pax logging project", new Date() }, 3);
    table.addItem(new Object[] { "pax-runner", "osgi runner tool", new Date() }, 4);
    table.addItem(new Object[] { "pax-web", "pax web project", new Date() }, 5);
    table.addItem(new Object[] { "pax-jdbc", "pax jdbc project", new Date() }, 6);

    // Allow selecting
    table.setSelectable(true);

    // Put the table in editable mode
    table.setEditable(false);

    // Reordering
    table.setColumnReorderingAllowed(true);

    // Allow switching to non-editable mode
    final CheckBox editable = new CheckBox("Table is editable", false);
    editable.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 6291942958587745232L;

        public void valueChange(ValueChangeEvent event) {
            table.setEditable((Boolean) editable.getValue());
        }
    });
    editable.setImmediate(true);
    layout.addComponent(editable);

    // Handle selection changes
    table.addListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                layout.addComponent(new Label("Selected item id " + event.getProperty().getValue().toString()));
            } else // Item deselected
            {
                layout.addComponent(new Label("Nothing selected"));
            }
        }
    });

    // Set Table Size
    table.setPageLength(table.size());

    layout.addComponent(table);
    window.addComponent(layout);

    IndexedContainer container = new IndexedContainer();
    container.addContainerProperty("foo", String.class, null);
    container.addContainerProperty("bar", String.class, null);
    container.addContainerProperty("baz", String.class, null);
    for (int i = 0; i < 100; i++) {
        Item item = container.addItem(i);
        item.getItemProperty("foo").setValue("foo " + i);
        item.getItemProperty("bar").setValue("bar");
        item.getItemProperty("baz").setValue("baz");
    }
    PagedTable pagedTable = new PagedTable("footable");
    pagedTable.setContainerDataSource(container);
    pagedTable.setPageLength(15);
    window.addComponent(pagedTable);
    window.addComponent(pagedTable.createControls());
    setMainWindow(window);

}

From source file:org.processbase.ui.bpm.admin.ActivityWindow.java

License:Open Source License

public void initUI() throws ParticipantNotFoundException, ProcessNotFoundException, VariableNotFoundException,
        InstanceNotFoundException, ActivityNotFoundException, Exception {
    setContent(layout);//from  www  . j a va 2 s  .c  o  m
    setCaption(ProcessbaseApplication.getCurrent().getPbMessages().getString("defaultTaskWindowCaption2") + " "
            + lightActivity.getActivityName());

    try {
        processDefinition = ProcessbaseApplication.getCurrent().getBpmModule()
                .getProcessDefinition(lightActivity.getProcessDefinitionUUID());
        if (lightActivity.isTask()) {
            task = ProcessbaseApplication.getCurrent().getBpmModule().getTaskInstance(lightActivity.getUUID());
        }
        dfds = ProcessbaseApplication.getCurrent().getBpmModule()
                .getProcessDataFields(lightActivity.getProcessDefinitionUUID());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    closeBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnClose"), this);
    reassignBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnReassign"),
            this);
    unAssignBtn = new CheckBox(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnUnassign"),
            this);
    assignBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnAssign"), this);
    candidatesList = new ListSelect(
            ProcessbaseApplication.getCurrent().getPbMessages().getString("candidates"));
    groupList = new ListSelect(ProcessbaseApplication.getCurrent().getPbMessages().getString("actorsGroups"));
    variablesTable = new Table(
            ProcessbaseApplication.getCurrent().getPbMessages().getString("processVariables"));

    tabSheet.addListener((TabSheet.SelectedTabChangeListener) this);
    tabSheet.setSizeFull();
    if (task != null) {
        addParticipantInfo();
        participantLayout.setSizeFull();
        tabSheet.addTab(participantLayout,
                ProcessbaseApplication.getCurrent().getPbMessages().getString("taskPerformer"), null);
    }
    try {
        addVariablesInfo();
        variablesLayout.setSizeFull();
        tabSheet.addTab(variablesLayout,
                ProcessbaseApplication.getCurrent().getPbMessages().getString("processVariables"), null);
        addStateInfo();
        stateLayout.setSizeFull();
        tabSheet.addTab(stateLayout,
                ProcessbaseApplication.getCurrent().getPbMessages().getString("taskStateUpdates"), null);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    tabSheet.setStyleName(Reindeer.TABSHEET_MINIMAL);

    buttons.setSpacing(true);
    buttons.setMargin(true);
    buttons.addComponent(closeBtn);
    buttons.setComponentAlignment(closeBtn, Alignment.MIDDLE_RIGHT);
    buttons.setWidth("100%");

    VerticalLayout vl = new VerticalLayout();
    vl.setMargin(true);
    vl.addComponent(tabSheet);
    layout.setFirstComponent(vl);
    layout.setSplitPosition(87);
    layout.setMargin(false);
    layout.setSecondComponent(buttons);
    layout.setStyleName(Reindeer.SPLITPANEL_SMALL);

    setWidth("800px");
    setHeight("600px");
    setModal(true);
    setResizable(false);
}

From source file:org.processbase.ui.bpm.admin.ProcessDefinitionWindow.java

License:Open Source License

public void initUI() {
    try {//  w w  w  .ja va  2s  .  c  om
        String caption = processDefinition.getLabel() != null ? processDefinition.getLabel()
                : processDefinition.getName();
        setCaption(caption + " (v." + processDefinition.getVersion() + ")");
        VerticalLayout layout = (VerticalLayout) this.getContent();
        layout.setMargin(true);
        layout.setSpacing(true);
        layout.setStyleName(Reindeer.LAYOUT_WHITE);

        v1.setMargin(true, false, false, false);
        v1.setSizeFull();

        if (processDefinition.getLabel() != null) {
            Label pdLabel = new Label("<b>" + processDefinition.getLabel() + "</b>");
            pdLabel.setContentMode(Label.CONTENT_XHTML);
            v1.addComponent(pdLabel);
        }

        if (processDefinition.getDescription() != null) {
            Label pdDescription = new Label(processDefinition.getDescription());
            pdDescription.setContentMode(Label.CONTENT_XHTML);
            v1.addComponent(pdDescription);
            v1.setExpandRatio(pdDescription, 1);
        }

        tabSheet.addTab(v1, ProcessbaseApplication.getCurrent().getPbMessages().getString("tabDescription"),
                null);

        activitiesTable.setSizeFull();

        v2.setMargin(false, false, false, false);
        v2.addComponent(activitiesTable);
        v2.setSizeFull();
        tabSheet.addTab(v2, ProcessbaseApplication.getCurrent().getPbMessages().getString("tabCustomUI"), null);

        // prepare membership
        prepareTableMembership();
        addBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnAdd"), this);
        addBtn.setStyleName(Runo.BUTTON_SMALL);
        v3.setMargin(false, false, false, false);
        v3.setSpacing(true);
        v3.addComponent(addBtn);
        v3.setComponentAlignment(addBtn, Alignment.MIDDLE_RIGHT);
        v3.addComponent(tableMembership);
        v3.setSizeFull();
        tabSheet.addTab(v3, ProcessbaseApplication.getCurrent().getPbMessages().getString("processAccess"),
                null);
        refreshTableMembership();

        tabSheet.setStyleName(Reindeer.TABSHEET_MINIMAL);
        tabSheet.setSizeFull();
        tabSheet.addListener((TabSheet.SelectedTabChangeListener) this);
        layout.addComponent(tabSheet);
        layout.setExpandRatio(tabSheet, 1);

        closeBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnClose"), this);
        applyBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnSaveCustomUI"),
                this);
        saveAccessBtn = new Button(
                ProcessbaseApplication.getCurrent().getPbMessages().getString("btnSaveProcessAccess"), this);
        deleteAllBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnDeleteAll"),
                this);
        deleteInstancesBtn = new Button(
                ProcessbaseApplication.getCurrent().getPbMessages().getString("btnDeleteInstances"), this);
        downloadBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnDownload"),
                this);
        enableBtn = new CheckBox(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnEnable"),
                this);
        archiveBtn = new Button(ProcessbaseApplication.getCurrent().getPbMessages().getString("btnArchive"),
                this);

        deleteAllBtn.setDescription(
                ProcessbaseApplication.getCurrent().getPbMessages().getString("deleteProcessDefinition"));
        buttons.addButton(deleteAllBtn);
        buttons.setComponentAlignment(deleteAllBtn, Alignment.MIDDLE_RIGHT);
        deleteInstancesBtn.setDescription(
                ProcessbaseApplication.getCurrent().getPbMessages().getString("deleteProcessInstances"));
        buttons.addButton(deleteInstancesBtn);
        buttons.setComponentAlignment(deleteInstancesBtn, Alignment.MIDDLE_RIGHT);

        Label expand = new Label("");
        buttons.addComponent(expand);
        buttons.setExpandRatio(expand, 1);

        enableBtn.setValue(processDefinition.getState().equals(ProcessState.ENABLED));
        buttons.addButton(enableBtn);
        buttons.setComponentAlignment(enableBtn, Alignment.MIDDLE_RIGHT);

        buttons.addButton(archiveBtn);
        buttons.setComponentAlignment(archiveBtn, Alignment.MIDDLE_RIGHT);

        applyBtn.setVisible(false);
        buttons.addButton(applyBtn);
        buttons.setComponentAlignment(applyBtn, Alignment.MIDDLE_RIGHT);
        buttons.addButton(saveAccessBtn);
        saveAccessBtn.setVisible(false);
        buttons.setComponentAlignment(saveAccessBtn, Alignment.MIDDLE_RIGHT);
        buttons.addButton(closeBtn);
        buttons.setComponentAlignment(closeBtn, Alignment.MIDDLE_RIGHT);
        buttons.setMargin(false);
        buttons.setHeight("30px");
        buttons.setWidth("100%");
        layout.addComponent(buttons);
        layout.setWidth("800px");
        layout.setHeight("400px");
        setResizable(false);
        setModal(true);

        //        activitiesTable.addContainerProperty("activityUUID", String.class, null, "UUID", null, null);
        //        activitiesTable.setColumnWidth("activityUUID", 0);
        activitiesTable.addContainerProperty("activityLabel", String.class, null,
                ProcessbaseApplication.getCurrent().getPbMessages().getString("tableCaptionActivityName"), null,
                null);
        activitiesTable.addContainerProperty("url", String.class, null,
                ProcessbaseApplication.getCurrent().getPbMessages().getString("tabCaptionTaskURL"), null, null);
        activitiesTable.setColumnWidth("url", 300);
        activitiesTable.setTableFieldFactory(new PbTableFieldFactory());
        activitiesTable.setEditable(true);
        activitiesTable.setImmediate(true);

        refreshTable();
    } catch (Exception ex) {
        ex.printStackTrace();
        showError(ex.getMessage());
    }
}

From source file:org.vaadin.addons.javaee.table.BooleanColumnGenerator.java

License:Apache License

@Override
public Component generateCell(Table source, Object itemId, Object columnId) {
    Property<?> prop = source.getItem(itemId).getItemProperty(columnId);
    CheckBox checkBox = new CheckBox(null, prop);
    checkBox.setId(source.getId() + ":" + itemId + ":" + columnId);
    checkBox.setImmediate(true);/*from w  w w . jav a 2 s . c o m*/
    checkBox.setBuffered(false);
    if (source.isEditable()) {
        checkBox.setReadOnly(false);
    } else {
        checkBox.setReadOnly(true);
    }
    return checkBox;
}

From source file:org.vaadin.miki.widgets.ItemGridUI.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//  ww  w.  java2s  .  c  om
protected void init(VaadinRequest request) {

    this.primary.addContainerProperty("text", String.class, "");
    this.primary.addContainerProperty("number", Integer.class, 0);
    this.primary.addContainerProperty("bool", Boolean.class, false);

    for (int zmp1 = 0; zmp1 < 15; zmp1++) {
        Item item = this.primary.addItem(zmp1);
        item.getItemProperty("text").setValue("number " + zmp1);
        item.getItemProperty("number").setValue(zmp1 * 3);
        item.getItemProperty("bool").setValue((zmp1 % 3) == 1);
    }

    this.secondary.addContainerProperty("caption", String.class, "default");
    this.secondary.addContainerProperty("price", Double.class, 1.99);

    for (int zmp1 = 5; zmp1 < 60; zmp1 += 3) {
        Item item = this.secondary.addItem(zmp1);
        item.getItemProperty("caption").setValue("this is item with id " + zmp1);
        item.getItemProperty("price").setValue(1.0 / zmp1);
    }

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    this.setContent(layout);

    final ItemGrid grid = new ItemGrid();
    grid.setContainerDataSource(this.primary);

    grid.setItemComponentGenerator(this.generator);

    layout.addComponent(grid);

    Slider slider = new Slider(1, 20);
    slider.setCaption("Select number of columns:");
    slider.setValue(new Double(grid.getColumnCount()));
    slider.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 20140509;

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            Object number = event.getProperty().getValue();
            if (number != null)
                grid.setColumnCount((int) Math.round((Double) number));
        }
    });
    slider.setSizeFull();
    layout.addComponent(slider);

    CheckBox selectable = new CheckBox("Selectable?", grid.isSelectable());
    selectable.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 20140510;

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            grid.setSelectable((Boolean) event.getProperty().getValue());
        }
    });

    layout.addComponent(selectable);

    CheckBox nullSelection = new CheckBox("Null selection allowed?", grid.isNullSelectionAllowed());
    nullSelection.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 20140512;

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            grid.setNullSelectionAllowed((Boolean) event.getProperty().getValue());
        }
    });
    layout.addComponent(nullSelection);

    CheckBox multiSelection = new CheckBox("Multiple selection allowed?", grid.isMultiSelect());
    multiSelection.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 20140512;

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            grid.setMultiSelect((Boolean) event.getProperty().getValue());
        }
    });
    layout.addComponent(multiSelection);

    CheckBox defaultGenerator = new CheckBox("Use ItemGrid's default component generator?");
    defaultGenerator.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 20140513;

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if ((Boolean) event.getProperty().getValue())
                grid.setItemComponentGenerator(null);
            else
                grid.setItemComponentGenerator(ItemGridUI.this.generator);
        }
    });
    layout.addComponent(defaultGenerator);

    ListSelect container = new ListSelect("Container data source", Arrays.asList(this.primary, this.secondary));
    container.setNullSelectionAllowed(false);
    container.setItemCaption(this.primary, "Primary container");
    container.setItemCaption(this.secondary, "Backup container");
    container.select(this.primary);
    container.setImmediate(true);
    container.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 20140514;

        @Override
        public void valueChange(ValueChangeEvent event) {
            grid.setContainerDataSource((Container) event.getProperty().getValue());
        }
    });
    layout.addComponent(container);

    Button addItem = new Button("Add item to current container", new Button.ClickListener() {

        private static final long serialVersionUID = 20140515;

        @Override
        public void buttonClick(ClickEvent event) {
            grid.getContainerDataSource().addItem(grid.getContainerDataSource().size() + 0.5);
        }
    });
    layout.addComponent(addItem);

}

From source file:org.vaadin.spring.samples.navigation.AccessControlView.java

License:Apache License

private CheckBox createViewCheckbox(String caption, final String viewName) {
    final CheckBox checkBox = new CheckBox(caption, true);
    checkBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override/*  ww w  .j  a v a2s.c  o m*/
        public void valueChange(Property.ValueChangeEvent event) {
            if (checkBox.getValue()) {
                allowedViews.add(viewName);
            } else {
                allowedViews.remove(viewName);
            }
        }
    });
    return checkBox;
}

From source file:org.vaadin.tori.component.AuthoringComponent.java

License:Apache License

private Component buildButtons() {
    HorizontalLayout result = new HorizontalLayout();
    result.addStyleName("buttonslayout");
    result.setWidth(100.0f, Unit.PERCENTAGE);
    result.setSpacing(true);/*from ww w . j a  v a  2  s  .  co  m*/
    result.setMargin(true);
    postButton = new Button("Post Reply", new Button.ClickListener() {

        @Override
        public void buttonClick(final ClickEvent event) {
            if (editor.getValue().trim().isEmpty()) {
                postButton.setEnabled(true);
            } else {
                listener.submit(editor.getValue(), attachments, followCheckbox.getValue());
            }
        }
    });
    postButton.setDisableOnClick(true);
    result.addComponent(postButton);

    attach = buildAttachUpload();
    result.addComponent(attach);
    followCheckbox = new CheckBox("Follow topic after posting", true);
    result.addComponent(followCheckbox);
    result.setComponentAlignment(followCheckbox, Alignment.MIDDLE_RIGHT);

    result.setExpandRatio(attach, 1.0f);
    result.setExpandRatio(followCheckbox, 1.0f);

    return result;
}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.form.SecurityPermissionsForm.java

License:Open Source License

private void handleRoleSelectionChange(ComboBox roleSelect, final FormLayout permissionsLayout,
        final JPAContainer<? extends Role> roles, final Map<String, Permission> permissionsMap) {
    roleSelect.addValueChangeListener(new Property.ValueChangeListener() {

        private Map<CheckBox, Permission> permissionCbsMap;

        @Override/*w w w  .  j a v a  2s .c  om*/
        public void valueChange(Property.ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                this.createRolePermissionsForm(event);
            }
        }

        private void createRolePermissionsForm(Property.ValueChangeEvent event) throws NumberFormatException {
            this.permissionCbsMap = new HashMap<>();
            permissionsLayout.removeAllComponents();

            Long itemId = Long.parseLong(event.getProperty().getValue().toString());
            Role selectedRole = roles.getItem(itemId).getEntity();
            final GrantedAuthoritySid sid = new GrantedAuthoritySid(selectedRole.getName());

            for (String permissionName : permissionsMap.keySet()) {
                CheckBox permissionCb = this.createPermissionCheckbox(permissionName, sid);
                permissionsLayout.addComponent(permissionCb);
            }

            Button savePermissions = this.createSaveButton(sid);
            permissionsLayout.addComponent(savePermissions);
        }

        private CheckBox createPermissionCheckbox(String permissionName, final GrantedAuthoritySid sid) {
            CheckBox permissionCb = new CheckBox(permissionName,
                    acl.isGranted(subject, permissionsMap.get(permissionName), sid));
            this.permissionCbsMap.put(permissionCb, permissionsMap.get(permissionName));
            return permissionCb;
        }

        private Button createSaveButton(final GrantedAuthoritySid sid) {
            Button savePermissions = new Button(t("core.save"), FontAwesome.FLOPPY_O);
            savePermissions.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    for (CheckBox permissionCb : permissionCbsMap.keySet()) {
                        if (permissionCb.getValue()) {
                            acl.grant(subject, permissionCbsMap.get(permissionCb), sid);
                        } else {
                            acl.revoke(subject, permissionCbsMap.get(permissionCb), sid);
                        }
                    }
                    Notification.show(t("core.security.management.permision.update.success"));
                }
            });
            return savePermissions;
        }
    });
}