Example usage for com.vaadin.ui Button setEnabled

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

Introduction

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

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:org.s23m.cell.editor.semanticdomain.ui.components.layout.AdminFormLayout.java

License:Mozilla Public License

private void init() {
    setMargin(true);//from  w  w  w.jav  a 2 s  .c  o m
    final String lblMsg = STATUS_MSG_SERVER_INACTIVE;//RepositoryClientServer.getInstance().isRepositoryServerRunning() ? STATUS_MSG_SERVER_ACTIVE : STATUS_MSG_SERVER_INACTIVE;
    final Label lblStatus = new Label(lblMsg);
    addComponent(lblStatus);

    final HorizontalLayout buttonBarLayout = new HorizontalLayout();
    buttonBarLayout.setSpacing(true);
    buttonBarLayout.setHeight(BUTTON_BAR_HEIGHT);

    final HorizontalLayout checkinBarLayout = new HorizontalLayout();
    checkinBarLayout.setSpacing(true);
    checkinBarLayout.setHeight(BUTTON_BAR_HEIGHT);

    final Button okBtn = new Button("Start Repository Client", new Button.ClickListener() {
        public void buttonClick(final ClickEvent event) {
            try {
                if (!RepositoryClientServer.getInstance().isRepositoryServerRunning()) {
                    RepositoryClientServer.getInstance().start();
                    lblStatus.setValue(STATUS_MSG_SERVER_ACTIVE);
                }
            } catch (final Throwable th) {
                lblStatus.setValue(th);
            }
        }
    });

    final Button stopBtn = new Button("Stop Repository Client", new Button.ClickListener() {
        public void buttonClick(final ClickEvent event) {
            try {
                if (RepositoryClientServer.getInstance().isRepositoryServerRunning()) {
                    RepositoryClientServer.getInstance().stop();
                    lblStatus.setValue(STATUS_MSG_SERVER_INACTIVE);
                }
            } catch (final Throwable th) {
                lblStatus.setValue(th);
            }
        }
    });

    buttonBarLayout.addComponent(okBtn);
    buttonBarLayout.addComponent(stopBtn);
    buttonBarLayout.setComponentAlignment(stopBtn, Alignment.TOP_RIGHT);

    final Button checkInButton = new Button("Do initial check-in", new Button.ClickListener() {
        public void buttonClick(final ClickEvent event) {
            try {
                S23MKernel.completeCellKernelInitialization();
                CellPlatform.instantiateFeature();
                //org.s23m.cell.test.artifactinstantiation.Test.main(null);
                final ArtefactContainer container = ObjectFactoryHolder.getInstance().createArtefactContainer();
                container.setContentType(SerializationType.IN_MEMORY_PERSISTENCE.name());
                client.put(container);
                lblStatus.setValue("Initial check-in done.");
            } catch (final Throwable th) {
                lblStatus.setValue(th);
            }
        }
    });

    checkInButton.setEnabled(true);
    checkinBarLayout.addComponent(checkInButton);
    addComponent(buttonBarLayout);
    addComponent(checkinBarLayout);
}

From source file:org.tylproject.vaadin.addon.datanav.AbstractButtonBar.java

License:Apache License

protected void enable(Button... btns) {
    for (Button btn : btns)
        btn.setEnabled(true);
}

From source file:org.tylproject.vaadin.addon.datanav.AbstractButtonBar.java

License:Apache License

protected void disable(Button... btns) {
    for (Button btn : btns)
        btn.setEnabled(false);
}

From source file:org.vaadin.addons.filterbuilder.FilterBuilderUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    getPage().setTitle("FilterBuilder demo");

    HorizontalSplitPanel content = new HorizontalSplitPanel();
    content.setSizeFull();/*from w  w  w. j a  v  a 2s.c o  m*/

    // Left pane
    leftPane = new VerticalLayout();
    {
        leftPane.setSizeFull();
        leftPane.setMargin(true);
        leftPane.setSpacing(true);

        filterField = new TextField();
        filterField.setInputPrompt("Write your filter here");
        filterField.setIcon(FontAwesome.SEARCH);
        filterField.addStyleName("filter-field inline-icon");
        filterField.setWidth(100, Unit.PERCENTAGE);
        filterField.setTextChangeEventMode(TextField.TextChangeEventMode.LAZY);
        filterField.setTextChangeTimeout(1000);
        filterField.addTextChangeListener(this);
        leftPane.addComponent(filterField);

        filterLabel = new Label();
        filterLabel.setWidth(100, Unit.PERCENTAGE);

        try {
            dataSource = new BeanItemContainer<>(TestCaseBean.class, TestCaseBean.loadMockData());
            dataSource.removeContainerProperty("address");
            dataSource.addNestedContainerProperty("address.country");
            dataSource.addNestedContainerProperty("address.city");
            dataSource.addNestedContainerProperty("address.street");
            dataSource.addNestedContainerProperty("address.address");
        } catch (Exception e) {
            logger.error("Could not load mock data");
        }
        table = new Table(null, dataSource);
        table.setSizeFull();
        table.setVisibleColumns("id", "firstName", "lastName", "jobTitle", "dob", "salary", "address.country",
                "address.city", "address.street", "address.address", "unemployed");
        table.setSelectable(true);
        leftPane.addComponent(table);
        leftPane.setExpandRatio(table, 1);

    }
    content.setFirstComponent(leftPane);

    // Right pane
    rightPane = new TabSheet();
    {
        rightPane.setSizeFull();

        VerticalLayout lastUsedFiltersPane = new VerticalLayout();
        lastUsedFiltersPane.setSizeFull();
        lastUsedFiltersPane.setMargin(true);
        lastUsedFiltersPane.setSpacing(true);
        lastUsedFilters = new IndexedContainer();
        lastUsedFilters.addContainerProperty("filter", String.class, null);
        lastUsedFiltersTable = new Table();
        lastUsedFiltersTable.setSizeFull();
        lastUsedFiltersTable.setContainerDataSource(lastUsedFilters);
        lastUsedFiltersTable.setSortEnabled(false);
        lastUsedFiltersTable.setSelectable(true);
        lastUsedFiltersTable.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
        lastUsedFiltersTable.addItemClickListener(this);

        final Button removeFilterButton = new Button("Remove", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                if (lastUsedFiltersTable.getValue() != null) {
                    lastUsedFilters.removeItem(lastUsedFiltersTable.getValue());
                    lastUsedFiltersTable.setValue(null);
                }
            }
        });
        removeFilterButton.setEnabled(false);
        lastUsedFiltersTable.addValueChangeListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                removeFilterButton.setEnabled(lastUsedFiltersTable.getValue() != null);
            }
        });
        lastUsedFiltersPane.addComponents(lastUsedFiltersTable, removeFilterButton);
        lastUsedFiltersPane.setExpandRatio(lastUsedFiltersTable, 1);
        rightPane.addTab(lastUsedFiltersPane).setCaption("Last used filters");

        VerticalLayout dateFormatsPane = new VerticalLayout();
        dateFormatsPane.setMargin(true);
        dateFormats = new IndexedContainer();
        dateFormats.addContainerProperty("format", String.class, null);
        for (SimpleDateFormat dateFormat : FilterBuilder.DATE_FORMATS) {
            final Item item = dateFormats.addItem(dateFormat.toPattern());
            item.getItemProperty("format").setValue(dateFormat.toPattern());
        }
        dateFormatsTable = new Table();
        dateFormatsTable.setWidth(100, Unit.PERCENTAGE);
        dateFormatsTable.setContainerDataSource(dateFormats);
        dateFormatsTable.setSortEnabled(false);
        dateFormatsTable.setSelectable(true);
        dateFormatsTable.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
        dateFormatsPane.addComponent(dateFormatsTable);
        rightPane.addTab(dateFormatsPane).setCaption("Known date formats");
    }
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    content.setSecondComponent(rightPane);
    content.setSplitPosition(80, Unit.PERCENTAGE);

    setContent(content);
    logger.debug("UI initialized");
}

From source file:org.vaadin.addons.sitekit.example.FeedbackViewlet.java

License:Apache License

/**
 * Default constructor./*from www . ja v a2s . c o  m*/
 */
public FeedbackViewlet() {

    final List<FieldDescriptor> fieldDescriptors = FieldSetDescriptorRegister.getFieldSetDescriptor("feedback")
            .getFieldDescriptors();

    editor = new ValidatingEditor(fieldDescriptors);

    final Button submitButton = new Button(getSite().localize("button-submit"));
    submitButton.addClickListener(new ClickListener() {
        /** The default serial version ID. */
        private static final long serialVersionUID = 1L;

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

            final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
            final Company company = getSite().getSiteContext().getObject(Company.class);

            try {

                Notification.show(getSite().localize("message-feedback-submit-success"),
                        Notification.Type.HUMANIZED_MESSAGE);

            } catch (final Exception e) {
                LOGGER.error("Error adding user.", e);
                Notification.show(getSite().localize("message-feedback-submit-error"),
                        Notification.Type.WARNING_MESSAGE);
            }
            reset();
        }
    });

    editor.addListener(new ValidatingEditorStateListener() {
        @Override
        public void editorStateChanged(final ValidatingEditor source) {
            if (source.isValid()) {
                submitButton.setEnabled(true);
            } else {
                submitButton.setEnabled(false);
            }
        }
    });

    reset();

    final HorizontalLayout titleLayout = new HorizontalLayout();
    titleLayout.setMargin(new MarginInfo(true, false, true, false));
    titleLayout.setSpacing(true);
    final Embedded titleIcon = new Embedded(null, getSite().getIcon("view-icon-feedback"));
    titleIcon.setWidth(32, Unit.PIXELS);
    titleIcon.setHeight(32, Unit.PIXELS);
    titleLayout.addComponent(titleIcon);
    final Label titleLabel = new Label("<h1>" + getSite().localize("view-feedback") + "</h1>",
            ContentMode.HTML);
    titleLayout.addComponent(titleLabel);

    final VerticalLayout panel = new VerticalLayout();
    panel.addComponent(titleLayout);
    panel.addComponent(editor);
    panel.addComponent(submitButton);
    panel.setSpacing(true);
    panel.setMargin(true);

    final Panel mainLayout = new Panel();
    mainLayout.setStyleName(Reindeer.PANEL_LIGHT);
    mainLayout.setContent(panel);

    setCompositionRoot(mainLayout);

}

From source file:org.vaadin.addons.sitekit.viewlet.anonymous.login.ForgotPasswordFlowlet.java

License:Apache License

@Override
public void initialize() {
    pinProperty = new ObjectProperty<String>(null, String.class);
    emailAddressProperty = new ObjectProperty<String>(null, String.class);

    final List<FieldDescriptor> fieldDescriptors = new ArrayList<FieldDescriptor>();

    fieldDescriptors.add(new FieldDescriptor("pin", getSite().localize("input-password-reset-pin"),
            TextField.class, null, 150, null, String.class, null, true, true, true));
    fieldDescriptors.add(new FieldDescriptor("emailAddress", getSite().localize("input-email-address"),
            TextField.class, null, 150, null, String.class, null, false, true, true)
                    .addValidator(new EmailValidator("Email address is not valid.")));

    editor = new ValidatingEditor(fieldDescriptors);

    final Button resetPasswordButton = new Button(getSite().localize("button-reset-password"));
    resetPasswordButton.addListener(new ClickListener() {
        /** The default serial version ID. */
        private static final long serialVersionUID = 1L;

        @Override//from   ww  w .  jav a  2s  . c om
        public void buttonClick(final ClickEvent event) {
            editor.commit();
            final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
            final Company company = getSite().getSiteContext().getObject(Company.class);

            final User user = UserDao.getUser(entityManager, company, (String) emailAddressProperty.getValue());
            if (user == null) {
                Notification.show(getSite().localize("message-user-email-address-not-registered"),
                        Notification.Type.WARNING_MESSAGE);
                return;
            }

            final List<EmailPasswordReset> emailPasswordResets = UserDao
                    .getEmailPasswordResetByEmailAddress(entityManager, user);
            final Date now = new Date();

            for (final EmailPasswordReset emailPasswordReset : emailPasswordResets) {
                if (now.getTime() - emailPasswordReset.getCreated().getTime() < 24 * 60 * 60 * 1000) {
                    Notification.show(getSite().localize("message-password-reset-email-already-sent"),
                            Notification.Type.ERROR_MESSAGE);
                    return;
                } else {
                    entityManager.getTransaction().begin();
                    try {
                        entityManager.remove(emailPasswordReset);
                        entityManager.getTransaction().commit();
                    } catch (final Exception e) {
                        if (entityManager.getTransaction().isActive()) {
                            entityManager.getTransaction().rollback();
                        }
                        throw new SiteException("Error removing old email password reset.", e);
                    }
                }
            }

            try {
                final String pin = (String) pinProperty.getValue();
                final byte[] pinAndSaltBytes = (user.getEmailAddress() + ":" + pin).getBytes("UTF-8");
                final MessageDigest md = MessageDigest.getInstance("SHA-256");
                final byte[] pinAndSaltDigest = md.digest(pinAndSaltBytes);

                final EmailPasswordReset emailPasswordReset = new EmailPasswordReset();
                emailPasswordReset.setUser(user);
                emailPasswordReset.setPinHash(StringUtil.toHexString(pinAndSaltDigest));
                emailPasswordReset.setCreated(now);

                entityManager.getTransaction().begin();
                try {
                    entityManager.persist(emailPasswordReset);
                    entityManager.getTransaction().commit();
                } catch (final Exception e) {
                    if (entityManager.getTransaction().isActive()) {
                        entityManager.getTransaction().rollback();
                    }
                    throw new SiteException("Error saving email password reset", e);
                }

                final String url = company.getUrl() + "#!reset/" + emailPasswordReset.getEmailPasswordResetId();

                final Thread emailThread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        EmailUtil.send(PropertiesUtil.getProperty("site", "smtp-host"), user.getEmailAddress(),
                                company.getSupportEmailAddress(), "Password Reset Link",
                                "Password reset has been requested for your user account."
                                        + "You can perform the reset using the following link: " + url);
                    }
                });
                emailThread.start();

                Notification.show(
                        getSite().localize("message-password-reset-email-sent")
                                + getSite().localize("message-your-password-reset-pin-is") + pin,
                        Notification.Type.WARNING_MESSAGE);

                final HttpServletRequest request = ((VaadinServletRequest) VaadinService.getCurrentRequest())
                        .getHttpServletRequest();
                LOGGER.info("Password reset email sent to " + user.getEmailAddress() + " (IP: "
                        + request.getRemoteHost() + ":" + request.getRemotePort() + ")");

                getFlow().back();
            } catch (final Exception e) {
                LOGGER.error("Error preparing password reset.", e);
                Notification.show(getSite().localize("message-password-reset-prepare-error"),
                        Notification.TYPE_WARNING_MESSAGE);
            }
            reset();
        }
    });

    editor.addListener(new ValidatingEditorStateListener() {
        @Override
        public void editorStateChanged(final ValidatingEditor source) {
            if (source.isValid()) {
                resetPasswordButton.setEnabled(true);
            } else {
                resetPasswordButton.setEnabled(false);
            }
        }
    });

    reset();

    final VerticalLayout panel = new VerticalLayout();
    panel.addComponent(editor);
    panel.addComponent(resetPasswordButton);
    panel.setSpacing(true);

    final HorizontalLayout mainLayout = new HorizontalLayout();
    mainLayout.addComponent(panel);

    setViewContent(mainLayout);
}

From source file:org.vaadin.addons.sitekit.viewlet.anonymous.login.RegisterFlowlet.java

License:Apache License

@Override
public void initialize() {
    originalPasswordProperty = new ObjectProperty<String>(null, String.class);
    verifiedPasswordProperty = new ObjectProperty<String>(null, String.class);

    final List<FieldDescriptor> fieldDescriptors = new ArrayList<FieldDescriptor>();

    final PasswordValidator passwordValidator = new PasswordValidator(getSite(), originalPasswordProperty,
            "password2");

    //fieldDescriptors.addAll(SiteFields.getFieldDescriptors(Customer.class));

    for (final FieldDescriptor fieldDescriptor : SiteFields.getFieldDescriptors(Customer.class)) {
        if (fieldDescriptor.getId().equals("adminGroup")) {
            continue;
        }//from www . j  a v  a  2s  . c  o m
        if (fieldDescriptor.getId().equals("memberGroup")) {
            continue;
        }
        if (fieldDescriptor.getId().equals("created")) {
            continue;
        }
        if (fieldDescriptor.getId().equals("modified")) {
            continue;
        }
        fieldDescriptors.add(fieldDescriptor);
    }

    //fieldDescriptors.remove(fieldDescriptors.size() - 1);
    //fieldDescriptors.remove(fieldDescriptors.size() - 1);
    fieldDescriptors
            .add(new FieldDescriptor("password1", getSite().localize("input-password"), PasswordField.class,
                    null, 150, null, String.class, null, false, true, true).addValidator(passwordValidator));
    fieldDescriptors.add(new FieldDescriptor("password2", getSite().localize("input-password-verification"),
            PasswordField.class, null, 150, null, String.class, null, false, true, true)
                    .addValidator(new PasswordVerificationValidator(getSite(), originalPasswordProperty)));

    editor = new ValidatingEditor(fieldDescriptors);
    passwordValidator.setEditor(editor);

    final Button registerButton = new Button(getSite().localize("button-register"));
    registerButton.addListener(new ClickListener() {
        /** The default serial version ID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            editor.commit();
            customer.setCreated(new Date());
            customer.setModified(customer.getCreated());
            final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
            final Company company = getSite().getSiteContext().getObject(Company.class);

            final PostalAddress invoicingAddress = new PostalAddress();
            final PostalAddress deliveryAddress = new PostalAddress();
            customer.setInvoicingAddress(invoicingAddress);
            customer.setDeliveryAddress(deliveryAddress);

            if (UserDao.getUser(entityManager, company, customer.getEmailAddress()) != null) {
                Notification.show(getSite().localize("message-user-email-address-registered"),
                        Notification.Type.WARNING_MESSAGE);
                return;
            }

            final HttpServletRequest request = ((VaadinServletRequest) VaadinService.getCurrentRequest())
                    .getHttpServletRequest();

            try {
                final byte[] passwordAndSaltBytes = (customer.getEmailAddress() + ":"
                        + ((String) originalPasswordProperty.getValue())).getBytes("UTF-8");
                final MessageDigest md = MessageDigest.getInstance("SHA-256");
                final byte[] passwordAndSaltDigest = md.digest(passwordAndSaltBytes);

                customer.setOwner(company);
                final User user = new User(company, customer.getFirstName(), customer.getLastName(),
                        customer.getEmailAddress(), customer.getPhoneNumber(),
                        StringUtil.toHexString(passwordAndSaltDigest));

                if (UserDao.getGroup(entityManager, company, "user") == null) {
                    UserDao.addGroup(entityManager, new Group(company, "user", "Default user group."));
                }

                UserDao.addUser(entityManager, user, UserDao.getGroup(entityManager, company, "user"));
                CustomerDao.saveCustomer(entityManager, customer);
                UserDao.addGroupMember(entityManager, customer.getAdminGroup(), user);
                UserDao.addGroupMember(entityManager, customer.getMemberGroup(), user);

                final String url = company.getUrl() + "#!validate/" + user.getUserId();

                final Thread emailThread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        EmailUtil.send(PropertiesUtil.getProperty("site", "smtp-host"), user.getEmailAddress(),
                                company.getSupportEmailAddress(), "Email Validation",
                                "Please validate your email by browsing to this URL: " + url);
                    }
                });
                emailThread.start();

                LOGGER.info("User registered " + user.getEmailAddress() + " (IP: " + request.getRemoteHost()
                        + ":" + request.getRemotePort() + ")");
                Notification.show(getSite().localize("message-registration-success"),
                        Notification.Type.HUMANIZED_MESSAGE);

                getFlow().back();
            } catch (final Exception e) {
                LOGGER.error("Error adding user. (IP: " + request.getRemoteHost() + ":"
                        + request.getRemotePort() + ")", e);
                Notification.show(getSite().localize("message-registration-error"),
                        Notification.TYPE_WARNING_MESSAGE);
            }
            reset();
        }
    });

    editor.addListener(new ValidatingEditorStateListener() {
        @Override
        public void editorStateChanged(final ValidatingEditor source) {
            if (source.isValid()) {
                registerButton.setEnabled(true);
            } else {
                registerButton.setEnabled(false);
            }
        }
    });

    reset();

    final VerticalLayout panel = new VerticalLayout();
    panel.addComponent(editor);
    panel.addComponent(registerButton);
    panel.setSpacing(true);

    final HorizontalLayout mainLayout = new HorizontalLayout();
    mainLayout.addComponent(panel);

    setViewContent(mainLayout);
}

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

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDefinitions = SiteFields.getFieldDescriptors(Customer.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();
    filterDefinitions.add(new FilterDescriptor("companyName", "companyName", "Company Name", new TextField(),
            101, "=", String.class, ""));
    filterDefinitions.add(new FilterDescriptor("lastName", "lastName", "Last Name", new TextField(), 101, "=",
            String.class, ""));

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    entityContainer = new EntityContainer<Customer>(entityManager, true, false, false, Customer.class, 1000,
            new String[] { "companyName", "lastName" }, new boolean[] { false, false }, "customerId");

    for (final FieldDescriptor fieldDefinition : fieldDefinitions) {
        entityContainer.addContainerProperty(fieldDefinition.getId(), fieldDefinition.getValueType(),
                fieldDefinition.getDefaultValue(), fieldDefinition.isReadOnly(), fieldDefinition.isSortable());
    }/*  w ww.j  a  va2 s.  c  om*/

    final GridLayout gridLayout = new GridLayout(1, 6);
    gridLayout.setRowExpandRatio(0, 0.0f);
    gridLayout.setRowExpandRatio(1, 0.0f);
    gridLayout.setRowExpandRatio(2, 0.0f);
    gridLayout.setRowExpandRatio(3, 0.0f);
    gridLayout.setRowExpandRatio(4, 0.0f);
    gridLayout.setRowExpandRatio(5, 1.0f);

    gridLayout.setSizeFull();
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(4, 1f);
    setViewContent(gridLayout);

    final HorizontalLayout userAccountTitle = new HorizontalLayout();
    userAccountTitle.setMargin(new MarginInfo(false, false, false, false));
    userAccountTitle.setSpacing(true);
    final Embedded userAccountTitleIcon = new Embedded(null, getSite().getIcon("view-icon-user"));
    userAccountTitleIcon.setWidth(32, UNITS_PIXELS);
    userAccountTitleIcon.setHeight(32, UNITS_PIXELS);
    userAccountTitle.addComponent(userAccountTitleIcon);
    final Label userAccountTitleLabel = new Label("<h2>User Account</h2>", Label.CONTENT_XHTML);
    userAccountTitle.addComponent(userAccountTitleLabel);
    gridLayout.addComponent(userAccountTitle, 0, 0);

    final HorizontalLayout titleLayout = new HorizontalLayout();
    titleLayout.setMargin(new MarginInfo(true, false, false, false));
    titleLayout.setSpacing(true);
    final Embedded titleIcon = new Embedded(null, getSite().getIcon("view-icon-customer"));
    titleIcon.setWidth(32, UNITS_PIXELS);
    titleIcon.setHeight(32, UNITS_PIXELS);
    titleLayout.addComponent(titleIcon);
    final Label titleLabel = new Label("<h2>Customer Accounts</h2>", Label.CONTENT_XHTML);
    titleLayout.addComponent(titleLabel);
    gridLayout.addComponent(titleLayout, 0, 3);

    final Table table = new Table();
    table.setPageLength(10);
    entityGrid = new Grid(table, entityContainer);
    entityGrid.setFields(fieldDefinitions);
    entityGrid.setFilters(filterDefinitions);
    //entityGrid.setFixedWhereCriteria("e.owner.companyId=:companyId");

    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    table.setColumnCollapsed("company", true);
    gridLayout.addComponent(entityGrid, 0, 5);

    final Button editUserButton = new Button("Edit User Account");
    editUserButton.setIcon(getSite().getIcon("button-icon-edit"));
    gridLayout.addComponent(editUserButton, 0, 2);
    editUserButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final User entity = ((SecurityProviderSessionImpl) getSite().getSecurityProvider())
                    .getUserFromSession();
            final UserAccountFlowlet customerView = getFlow().getFlowlet(UserAccountFlowlet.class);
            customerView.edit(entity, false);
            getFlow().forward(UserAccountFlowlet.class);
        }
    });

    final Company company = getSite().getSiteContext().getObject(Company.class);
    if (company.isOpenIdLogin()) {
        final Panel openIdPanel = new Panel();
        openIdPanel.setStyleName(Reindeer.PANEL_LIGHT);
        openIdPanel.setCaption("Choose OpenID Provider:");
        gridLayout.addComponent(openIdPanel, 0, 1);
        final HorizontalLayout openIdLayout = new HorizontalLayout();
        openIdPanel.setContent(openIdLayout);
        openIdLayout.setMargin(new MarginInfo(false, false, true, false));
        openIdLayout.setSpacing(true);
        final String returnViewName = "openidlink";
        final Map<String, String> urlIconMap = OpenIdUtil.getOpenIdProviderUrlIconMap();
        for (final String url : urlIconMap.keySet()) {
            openIdLayout.addComponent(OpenIdUtil.getLoginButton(url, urlIconMap.get(url), returnViewName));
        }
    }

    final HorizontalLayout customerButtonsLayout = new HorizontalLayout();
    gridLayout.addComponent(customerButtonsLayout, 0, 4);
    customerButtonsLayout.setMargin(false);
    customerButtonsLayout.setSpacing(true);

    final Button editCustomerDetailsButton = new Button("Edit Customer Details");
    customerButtonsLayout.addComponent(editCustomerDetailsButton);
    editCustomerDetailsButton.setEnabled(false);
    editCustomerDetailsButton.setIcon(getSite().getIcon("button-icon-edit"));
    editCustomerDetailsButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Customer entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final CustomerFlowlet customerView = getFlow().forward(CustomerFlowlet.class);
            customerView.edit(entity, false);
        }
    });

    final Button editCustomerMembersButton = new Button("Edit Customer Members");
    customerButtonsLayout.addComponent(editCustomerMembersButton);
    editCustomerMembersButton.setEnabled(false);
    editCustomerMembersButton.setIcon(getSite().getIcon("button-icon-edit"));
    editCustomerMembersButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Customer entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final GroupFlowlet view = getFlow().forward(GroupFlowlet.class);
            view.edit(entity.getMemberGroup(), false);
        }
    });

    final Button editCustomerAdminsButton = new Button("Edit Customer Admins");
    customerButtonsLayout.addComponent(editCustomerAdminsButton);
    editCustomerAdminsButton.setEnabled(false);
    editCustomerAdminsButton.setIcon(getSite().getIcon("button-icon-edit"));
    editCustomerAdminsButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Customer entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final GroupFlowlet view = getFlow().forward(GroupFlowlet.class);
            view.edit(entity.getAdminGroup(), false);
        }
    });

    table.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(final Property.ValueChangeEvent event) {
            editCustomerDetailsButton.setEnabled(table.getValue() != null);
            editCustomerMembersButton.setEnabled(table.getValue() != null);
            editCustomerAdminsButton.setEnabled(table.getValue() != null);
        }
    });

}

From source file:org.vaadin.tori.view.edit.EditViewImpl.java

License:Apache License

private Component buildReplacements() {
    VerticalLayout result = new VerticalLayout();
    result.addComponent(getSubTitle("Define post body regex-patterns/replacements to be "
            + "applied whenever posts are being displayed/previewed."));

    replacementsTable = new Table();
    replacementsTable.setWidth("100%");
    replacementsTable.setHeight("10em");
    replacementsTable.setSelectable(true);
    replacementsTable.setImmediate(true);
    replacementsTable.setEditable(true);
    replacementsTable.setTableFieldFactory(new TableFieldFactory() {

        @Override/*from  w w w .  j av a2 s.  c  o  m*/
        public Field<?> createField(final Container container, final Object itemId, final Object propertyId,
                final Component uiContext) {
            final TextField textField = new TextField();
            textField.setWidth(100.0f, Unit.PERCENTAGE);
            textField.addFocusListener(new FocusListener() {
                @Override
                public void focus(final FocusEvent event) {
                    replacementsTable.setValue(itemId);
                }
            });
            return textField;
        }
    });

    final Button removeButton = ComponentUtil.getSecondaryButton("Remove", new Button.ClickListener() {

        @Override
        public void buttonClick(final ClickEvent event) {
            replacementsTable.removeItem(replacementsTable.getValue());
        }
    });

    replacementsTable.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            removeButton.setEnabled(event.getProperty().getValue() != null);
        }
    });

    replacementsTable.addContainerProperty("regex", String.class, "", "Regex", null, null);
    replacementsTable.setSortContainerPropertyId("regex");
    replacementsTable.addContainerProperty("replacement", String.class, "", "Replacement", null, null);
    result.addComponent(replacementsTable);

    removeButton.setEnabled(false);

    Button newButton = ComponentUtil.getSecondaryButton("New", new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            final Object itemId = replacementsTable.addItem();
            replacementsTable.setValue(itemId);
        }
    });

    final HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    buttonsLayout.addComponent(removeButton);
    buttonsLayout.addComponent(newButton);
    result.addComponent(buttonsLayout);

    return result;
}

From source file:pl.exsio.frameset.vaadin.module.management.frames.FramesTree.java

License:Open Source License

private HorizontalLayout getControls(final JPAContainer<Frame> frames) {

    HorizontalLayout controls = new HorizontalLayout();
    final Button addButton = createAddFrameButton(frames);
    final Button removeButton = createRemoveFrameButton(frames);
    addButton.setEnabled(false);
    removeButton.setEnabled(false);// w  w  w.  java2  s.  c  o m
    controls.setMargin(true);
    controls.addComponent(addButton);
    controls.addComponent(removeButton);
    controls.setSpacing(true);
    if (this.security.canCreate()) {
        this.tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                addButton.setEnabled(true);
            }
        });
    }
    if (this.security.canCreate()) {
        this.tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                removeButton.setEnabled(true);
            }
        });
    }
    return controls;
}