Example usage for com.vaadin.ui Label setStyleName

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

Introduction

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

Prototype

@Override
    public void setStyleName(String style) 

Source Link

Usage

From source file:org.ikasan.dashboard.ui.administration.panel.UserManagementPanel.java

License:BSD License

@SuppressWarnings("deprecation")
protected void init() {
    this.setWidth("100%");
    this.setHeight("100%");

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();//from   w w w  .ja  v  a 2 s  .co  m

    Panel securityAdministrationPanel = new Panel();
    securityAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    securityAdministrationPanel.setHeight("100%");
    securityAdministrationPanel.setWidth("100%");

    GridLayout gridLayout = new GridLayout(2, 6);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(true);
    gridLayout.setSizeFull();

    Label mappingConfigurationLabel = new Label("User Management");
    mappingConfigurationLabel.setStyleName(ValoTheme.LABEL_HUGE);
    gridLayout.addComponent(mappingConfigurationLabel, 0, 0, 1, 0);

    Label userSearchHintLabel = new Label();
    userSearchHintLabel.setCaptionAsHtml(true);
    userSearchHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Type into the Username, Firstname or Surname fields to find a user.");
    userSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    userSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(userSearchHintLabel, 0, 1, 1, 1);

    Label usernameLabel = new Label("Username:");

    usernameField.setWidth("40%");

    final DragAndDropWrapper usernameFieldWrap = new DragAndDropWrapper(usernameField);
    usernameFieldWrap.setDragStartMode(DragStartMode.COMPONENT);

    firstName = new AutocompleteField<User>();
    firstName.setWidth("40%");
    surname = new AutocompleteField<User>();
    surname.setWidth("40%");
    final TextField department = new TextField();
    department.setWidth("40%");
    final TextField email = new TextField();
    email.setWidth("40%");

    final Table roleTable = new Table();
    roleTable.addContainerProperty("Role", String.class, null);
    roleTable.addContainerProperty("", Button.class, null);
    roleTable.setHeight("520px");
    roleTable.setWidth("250px");

    usernameField.setQueryListener(new AutocompleteQueryListener<User>() {
        @Override
        public void handleUserQuery(AutocompleteField<User> field, String query) {
            for (User user : userService.getUserByUsernameLike(query)) {
                field.addSuggestion(user, user.getUsername());
            }
        }
    });

    usernameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() {
        @Override
        public void onSuggestionPicked(User user) {
            UserManagementPanel.this.user = user;
            firstName.setText(user.getFirstName());
            surname.setText(user.getSurname());
            department.setValue(user.getDepartment());
            email.setValue(user.getEmail());

            final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername());

            roleTable.removeAllItems();

            for (final Role role : principal.getRoles()) {
                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        roleTable.removeItem(role);

                        principal.getRoles().remove(role);

                        securityService.savePrincipal(principal);

                        userDropTable.removeItem(principal.getName());
                    }
                });

                roleTable.addItem(new Object[] { role.getName(), deleteButton }, role);
            }

            associatedPrincipalsTable.removeAllItems();

            for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) {
                if (!ikasanPrincipal.getType().equals("user")) {
                    associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() },
                            ikasanPrincipal);
                }
            }
        }
    });

    firstName.setQueryListener(new AutocompleteQueryListener<User>() {
        @Override
        public void handleUserQuery(AutocompleteField<User> field, String query) {
            for (User user : userService.getUserByFirstnameLike(query)) {
                field.addSuggestion(user, user.getFirstName() + " " + user.getSurname());
            }
        }
    });

    firstName.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() {
        @Override
        public void onSuggestionPicked(User user) {
            UserManagementPanel.this.user = user;
            usernameField.setText(user.getUsername());
            firstName.setText(user.getFirstName());
            surname.setText(user.getSurname());
            department.setValue(user.getDepartment());
            email.setValue(user.getEmail());

            final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername());

            roleTable.removeAllItems();

            for (final Role role : principal.getRoles()) {
                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        roleTable.removeItem(role);

                        principal.getRoles().remove(role);

                        securityService.savePrincipal(principal);

                        userDropTable.removeItem(principal.getName());
                    }
                });

                roleTable.addItem(new Object[] { role.getName(), deleteButton }, role);
            }

            associatedPrincipalsTable.removeAllItems();

            for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) {
                if (!ikasanPrincipal.getType().equals("user")) {
                    associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() },
                            ikasanPrincipal);
                }
            }
        }
    });

    surname.setQueryListener(new AutocompleteQueryListener<User>() {
        @Override
        public void handleUserQuery(AutocompleteField<User> field, String query) {
            for (User user : userService.getUserBySurnameLike(query)) {
                field.addSuggestion(user, user.getFirstName() + " " + user.getSurname());
            }
        }
    });

    surname.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() {
        @Override
        public void onSuggestionPicked(User user) {
            UserManagementPanel.this.user = user;
            usernameField.setText(user.getUsername());
            firstName.setText(user.getFirstName());
            surname.setText(user.getSurname());
            department.setValue(user.getDepartment());
            email.setValue(user.getEmail());

            final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername());

            roleTable.removeAllItems();

            for (final Role role : principal.getRoles()) {
                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        roleTable.removeItem(role);

                        principal.getRoles().remove(role);

                        securityService.savePrincipal(principal);

                        userDropTable.removeItem(principal.getName());
                    }
                });

                roleTable.addItem(new Object[] { role.getName(), deleteButton }, role);

                associatedPrincipalsTable.removeAllItems();

                for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) {
                    if (!ikasanPrincipal.getType().equals("user")) {
                        associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() },
                                ikasanPrincipal);
                    }
                }
            }
        }
    });

    GridLayout formLayout = new GridLayout(2, 5);
    formLayout.setSpacing(true);
    formLayout.setWidth("100%");

    formLayout.setColumnExpandRatio(0, .1f);
    formLayout.setColumnExpandRatio(1, .8f);

    usernameLabel.setSizeUndefined();
    formLayout.addComponent(usernameLabel, 0, 0);
    formLayout.setComponentAlignment(usernameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(usernameFieldWrap, 1, 0);

    Label firstNameLabel = new Label("First name:");
    firstNameLabel.setSizeUndefined();
    formLayout.addComponent(firstNameLabel, 0, 1);
    formLayout.setComponentAlignment(firstNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(firstName, 1, 1);

    Label surnameLabel = new Label("Surname:");
    surnameLabel.setSizeUndefined();
    formLayout.addComponent(surnameLabel, 0, 2);
    formLayout.setComponentAlignment(surnameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(surname, 1, 2);

    Label departmentLabel = new Label("Department:");
    departmentLabel.setSizeUndefined();
    formLayout.addComponent(departmentLabel, 0, 3);
    formLayout.setComponentAlignment(departmentLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(department, 1, 3);

    Label emailLabel = new Label("Email address:");
    emailLabel.setSizeUndefined();
    formLayout.addComponent(emailLabel, 0, 4);
    formLayout.setComponentAlignment(emailLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(email, 1, 4);

    gridLayout.addComponent(formLayout, 0, 2, 1, 2);

    Label rolesAndGroupsHintLabel1 = new Label();
    rolesAndGroupsHintLabel1.setCaptionAsHtml(true);
    rolesAndGroupsHintLabel1.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Roles table below displays the roles that the user has. Roles can be deleted from this table.");
    rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_TINY);
    rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_LIGHT);
    rolesAndGroupsHintLabel1.setWidth(300, Unit.PIXELS);
    gridLayout.addComponent(rolesAndGroupsHintLabel1, 0, 3, 1, 3);

    Label rolesAndGroupsHintLabel2 = new Label();
    rolesAndGroupsHintLabel2.setCaptionAsHtml(true);
    rolesAndGroupsHintLabel2.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Groups table below displays all the LDAP groups that the user is a member of. You cannot manage these "
            + "from this application.");
    rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_TINY);
    rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_LIGHT);
    rolesAndGroupsHintLabel2.setWidth(300, Unit.PIXELS);
    gridLayout.addComponent(rolesAndGroupsHintLabel2, 0, 4, 1, 4);

    final ClientSideCriterion acceptCriterion = new SourceIs(usernameField);

    userDropTable.addContainerProperty("Members", String.class, null);
    userDropTable.addContainerProperty("", Button.class, null);
    userDropTable.setHeight("715px");
    userDropTable.setWidth("300px");

    userDropTable.setDragMode(TableDragMode.ROW);
    userDropTable.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            if (rolesCombo.getValue() == null) {
                // Do nothing if there is no role selected
                logger.info("Ignoring drop: " + dropEvent);
                return;
            }

            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final WrapperTransferable t = (WrapperTransferable) dropEvent.getTransferable();

            final AutocompleteField sourceContainer = (AutocompleteField) t.getDraggedComponent();
            logger.info("sourceContainer.getText(): " + sourceContainer.getText());

            Button deleteButton = new Button();

            deleteButton.setIcon(VaadinIcons.TRASH);
            deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
            deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

            final IkasanPrincipal principal = securityService.findPrincipalByName(sourceContainer.getText());
            final Role roleToRemove = (Role) rolesCombo.getValue();

            deleteButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    userDropTable.removeItem(principal.getName());

                    principal.getRoles().remove(roleToRemove);

                    securityService.savePrincipal(principal);

                    if (UserManagementPanel.this.usernameField.getText().equals(principal.getName())) {
                        roleTable.removeItem(roleToRemove);
                    }
                }
            });

            userDropTable.addItem(new Object[] { sourceContainer.getText(), deleteButton },
                    sourceContainer.getText());

            principal.getRoles().add((Role) rolesCombo.getValue());

            securityService.savePrincipal(principal);

            roleTable.removeAllItems();

            for (final Role role : principal.getRoles()) {
                Button roleDeleteButton = new Button();
                roleDeleteButton.setIcon(VaadinIcons.TRASH);
                roleDeleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                roleDeleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

                roleDeleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        roleTable.removeItem(role);

                        principal.getRoles().remove(role);

                        securityService.savePrincipal(principal);

                        userDropTable.removeItem(principal.getName());
                    }
                });

                roleTable.addItem(new Object[] { role.getName(), roleDeleteButton }, role);
            }
        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    gridLayout.addComponent(roleTable, 0, 5);

    this.associatedPrincipalsTable.addContainerProperty("Groups", String.class, null);
    this.associatedPrincipalsTable.addItemClickListener(this.associatedPrincipalItemClickListener);
    associatedPrincipalsTable.setHeight("520px");
    associatedPrincipalsTable.setWidth("400px");

    gridLayout.addComponent(this.associatedPrincipalsTable, 1, 5);

    this.rolesCombo = new ComboBox("Roles");
    this.rolesCombo.setWidth("90%");
    this.rolesCombo.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            final Role role = (Role) event.getProperty().getValue();

            if (role != null) {
                logger.info("Value changed got Role: " + role);

                List<IkasanPrincipal> principals = securityService.getAllPrincipalsWithRole(role.getName());

                userDropTable.removeAllItems();

                for (final IkasanPrincipal principal : principals) {
                    Button deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            userDropTable.removeItem(principal.getName());

                            principal.getRoles().remove(role);

                            securityService.savePrincipal(principal);

                            if (UserManagementPanel.this.usernameField.getText().equals(principal.getName())) {
                                roleTable.removeItem(role);
                            }
                        }
                    });

                    userDropTable.addItem(new Object[] { principal.getName(), deleteButton },
                            principal.getName());
                }
            }
        }
    });

    Panel roleMemberPanel = new Panel();

    roleMemberPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    roleMemberPanel.setHeight("100%");
    roleMemberPanel.setWidth("100%");

    GridLayout roleMemberLayout = new GridLayout();
    roleMemberLayout.setSpacing(true);
    roleMemberLayout.setWidth("100%");

    Label roleMemberAssociationsLabel = new Label("Role/Member Associations");
    roleMemberAssociationsLabel.setStyleName(ValoTheme.LABEL_HUGE);

    Label userDragHintLabel = new Label();
    userDragHintLabel.setCaptionAsHtml(true);
    userDragHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drop users into the table below to assign them the role.");

    roleMemberLayout.addComponent(roleMemberAssociationsLabel);
    roleMemberLayout.addComponent(userDragHintLabel);
    roleMemberLayout.addComponent(this.rolesCombo);
    roleMemberLayout.addComponent(this.userDropTable);

    roleMemberPanel.setContent(roleMemberLayout);

    securityAdministrationPanel.setContent(gridLayout);
    layout.addComponent(securityAdministrationPanel);

    VerticalLayout roleMemberPanelLayout = new VerticalLayout();
    roleMemberPanelLayout.setWidth("100%");
    roleMemberPanelLayout.setHeight("100%");
    roleMemberPanelLayout.setMargin(true);
    roleMemberPanelLayout.addComponent(roleMemberPanel);
    roleMemberPanelLayout.setSizeFull();

    HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
    hsplit.setFirstComponent(layout);
    hsplit.setSecondComponent(roleMemberPanelLayout);

    // Set the position of the splitter as percentage
    hsplit.setSplitPosition(65, Unit.PERCENTAGE);
    hsplit.setLocked(true);

    this.setContent(hsplit);
}

From source file:org.ikasan.dashboard.ui.administration.window.NewPolicyWindow.java

License:BSD License

public void init() {
    this.setModal(true);
    this.setResizable(false);

    this.setWidth("600px");
    this.setHeight("400px");

    GridLayout gridLayout = new GridLayout(2, 8);
    gridLayout.setWidth("100%");
    gridLayout.setMargin(true);//from w w  w .j a  va 2s .  c  o  m
    gridLayout.setSpacing(true);

    gridLayout.setColumnExpandRatio(0, .1f);
    gridLayout.setColumnExpandRatio(1, .9f);

    Label createNewPolicyLabel = new Label("Create a New Policy");
    createNewPolicyLabel.setStyleName(ValoTheme.LABEL_HUGE);

    gridLayout.addComponent(createNewPolicyLabel, 0, 0, 1, 0);

    Label nameLabel = new Label("Name:");
    nameLabel.setSizeUndefined();
    this.policyName = new TextField();
    this.policyName.addValidator(new StringLengthValidator("A name must be entered.", 1, null, false));
    this.policyName.setWidth("80%");

    gridLayout.addComponent(nameLabel, 0, 1);
    gridLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(policyName, 1, 1);

    Label descriptionLabel = new Label("Description");
    descriptionLabel.setSizeUndefined();
    this.policyDescription = new TextArea();
    this.policyDescription
            .addValidator(new StringLengthValidator("A description must be entered.", 1, null, false));
    this.policyDescription.setRows(4);
    this.policyDescription.setWidth("80%");

    this.policyName.setValidationVisible(false);
    this.policyDescription.setValidationVisible(false);

    gridLayout.addComponent(descriptionLabel, 0, 2);
    gridLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    gridLayout.addComponent(policyDescription, 1, 2);

    Button createButton = new Button("Create");
    Button cancelButton = new Button("Cancel");

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(createButton);
    buttonLayout.setComponentAlignment(createButton, Alignment.MIDDLE_CENTER);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER);

    BeanItem<Policy> policyItem = new BeanItem<Policy>(this.policy);

    this.policyName.setPropertyDataSource(policyItem.getItemProperty("name"));
    this.policyDescription.setPropertyDataSource(policyItem.getItemProperty("description"));

    Label linkTypeLabel = new Label("Policy Link Type");
    linkTypeLabel.setSizeUndefined();
    gridLayout.addComponent(linkTypeLabel, 0, 3);
    gridLayout.setComponentAlignment(linkTypeLabel, Alignment.TOP_RIGHT);
    this.linkTypeCombo.setWidth("80%");
    gridLayout.addComponent(this.linkTypeCombo, 1, 3);

    List<PolicyLinkType> policyLinkTypes = this.securityService.getAllPolicyLinkTypes();

    this.linkTypeCombo.removeAllItems();

    for (PolicyLinkType policyLinkType : policyLinkTypes) {
        this.linkTypeCombo.addItem(policyLinkType);
        this.linkTypeCombo.setItemCaption(policyLinkType, policyLinkType.getName());
    }

    policyLinkHintLabel.setCaptionAsHtml(true);
    policyLinkHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " You are linking this policy to an entity. Click link below to search for the entity to link to.");
    policyLinkHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    policyLinkHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    policyLinkHintLabel.setVisible(false);
    gridLayout.addComponent(policyLinkHintLabel, 0, 4, 1, 4);

    linkButton.setStyleName(ValoTheme.BUTTON_LINK);
    linkButton.setVisible(false);
    linkButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            PolicyLinkType policyLinkType = (PolicyLinkType) NewPolicyWindow.this.linkTypeCombo.getValue();

            if (policyLinkType.getName().equals(PolicyLinkTypeConstants.MAPPING_CONFIGURATION_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationMappingSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationMappingSearchWindow);
            } else if (policyLinkType.getName().equals(PolicyLinkTypeConstants.MODULE_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationModuleSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationModuleSearchWindow);
            } else if (policyLinkType.getName().equals(PolicyLinkTypeConstants.FLOW_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationFlowSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationFlowSearchWindow);
            } else if (policyLinkType.getName().equals(PolicyLinkTypeConstants.BUSINESS_STREAM_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationBusinessStreamSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationBusinessStreamSearchWindow);
            }
        }
    });
    gridLayout.addComponent(this.linkButton, 1, 5);

    final Label linkedEntityLabel = new Label("Linked to");
    linkedEntityLabel.setSizeUndefined();

    this.linkedEntity = new TextArea();
    this.linkedEntity.addValidator(new StringLengthValidator(
            "If a Policy Link Type is selected, you must link to an approptiate entity.", 1, null, false));
    this.linkedEntity.setWidth("80%");
    this.linkedEntity.setValidationVisible(false);
    this.linkedEntity.setHeight("60px");

    gridLayout.addComponent(linkedEntityLabel, 0, 6);
    gridLayout.setComponentAlignment(linkedEntityLabel, Alignment.TOP_RIGHT);
    gridLayout.addComponent(linkedEntity, 1, 6);
    linkedEntityLabel.setVisible(false);
    linkedEntity.setVisible(false);

    this.policyAssociationMappingSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationMappingSearchWindow.getMappingConfiguration() != null) {
                NewPolicyWindow.this.linkedEntity.setValue(
                        policyAssociationMappingSearchWindow.getMappingConfiguration().toStringLite());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationMappingSearchWindow
                        .getMappingConfiguration().getId();
            }
        }
    });

    this.policyAssociationFlowSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationFlowSearchWindow.getFlow() != null) {
                NewPolicyWindow.this.linkedEntity
                        .setValue(policyAssociationFlowSearchWindow.getFlow().toString());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationFlowSearchWindow
                        .getFlow().getId();
            }
        }
    });

    this.policyAssociationModuleSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationModuleSearchWindow.getModule() != null) {
                NewPolicyWindow.this.linkedEntity
                        .setValue(policyAssociationModuleSearchWindow.getModule().toString());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationModuleSearchWindow
                        .getModule().getId();
            }
        }
    });

    this.policyAssociationBusinessStreamSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationBusinessStreamSearchWindow.getBusinessStream() != null) {
                NewPolicyWindow.this.linkedEntity
                        .setValue(policyAssociationBusinessStreamSearchWindow.getBusinessStream().toString());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationBusinessStreamSearchWindow
                        .getBusinessStream().getId();
            }
        }

    });

    this.linkTypeCombo.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            final PolicyLinkType policyLinkType = (PolicyLinkType) event.getProperty().getValue();

            if (policyLinkType != null) {
                linkButton.setVisible(true);
                linkedEntityLabel.setVisible(true);
                linkedEntity.setVisible(true);
                policyLinkHintLabel.setVisible(true);
            } else {
                linkButton.setVisible(false);
                linkedEntityLabel.setVisible(false);
                linkedEntity.setVisible(false);
                policyLinkHintLabel.setVisible(false);
            }
        }
    });

    gridLayout.addComponent(buttonLayout, 0, 7, 1, 7);
    gridLayout.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER);

    createButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                NewPolicyWindow.this.policyName.validate();
                NewPolicyWindow.this.policyDescription.validate();

                if (linkTypeCombo.getValue() != null) {
                    NewPolicyWindow.this.linkedEntity.validate();
                }
            } catch (InvalidValueException e) {
                NewPolicyWindow.this.policyName.setValidationVisible(true);
                NewPolicyWindow.this.policyDescription.setValidationVisible(true);
                NewPolicyWindow.this.linkedEntity.setValidationVisible(true);

                return;
            }

            NewPolicyWindow.this.policyName.setValidationVisible(false);
            NewPolicyWindow.this.policyDescription.setValidationVisible(false);
            NewPolicyWindow.this.linkedEntity.setValidationVisible(false);

            if (linkTypeCombo.getValue() != null) {
                PolicyLinkType policyLinkType = (PolicyLinkType) linkTypeCombo.getValue();
                String linkedEntityName = linkedEntity.getValue();
                PolicyLink policyLink = new PolicyLink(policyLinkType, associatedEntityId, linkedEntityName);

                securityService.savePolicyLink(policyLink);

                policy.setPolicyLink(policyLink);

                try {
                    securityService.savePolicy(policy);
                } catch (DataIntegrityViolationException e) {
                    Notification.show(
                            "Policy name must be unique. Please confirm that this policy does not already exist!",
                            Notification.Type.ERROR_MESSAGE);

                    return;
                } catch (RuntimeException e) {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    e.printStackTrace(pw);

                    Notification.show("Caught exception trying to save a Policy!", sw.toString(),
                            Notification.Type.ERROR_MESSAGE);

                    return;
                }
            } else {
                PolicyLink policyLink = policy.getPolicyLink();
                policy.setPolicyLink(null);

                try {
                    securityService.savePolicy(policy);
                } catch (DataIntegrityViolationException e) {
                    Notification.show(
                            "Policy name must be unique. Please confirm that this policy does not already exist!",
                            Notification.Type.ERROR_MESSAGE);

                    return;
                } catch (RuntimeException e) {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    e.printStackTrace(pw);

                    Notification.show("Caught exception trying to save a Policy!", sw.toString(),
                            Notification.Type.ERROR_MESSAGE);

                    return;
                }

                if (policyLink != null) {
                    securityService.deletePolicyLink(policyLink);
                }
            }

            Notification.show("New policy successfully created!");

            UI.getCurrent().removeWindow(NewPolicyWindow.this);
        }
    });

    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().removeWindow(NewPolicyWindow.this);
        }
    });

    this.setContent(gridLayout);
}

From source file:org.ikasan.dashboard.ui.administration.window.NewRoleWindow.java

License:BSD License

public void init() {
    this.setWidth("550px");
    this.setHeight("240px");
    this.setModal(true);
    this.setResizable(false);

    GridLayout gridLayout = new GridLayout(2, 4);
    gridLayout.setWidth("100%");
    gridLayout.setMargin(true);//from   www  .ja  v a 2s  . c  om
    gridLayout.setSpacing(true);

    gridLayout.setColumnExpandRatio(0, .1f);
    gridLayout.setColumnExpandRatio(1, .9f);

    Label createNewRoleLabel = new Label("Create a New Role");
    createNewRoleLabel.setStyleName(ValoTheme.LABEL_HUGE);

    gridLayout.addComponent(createNewRoleLabel, 0, 0, 1, 0);

    Label nameLabel = new Label("Name:");
    nameLabel.setSizeUndefined();
    this.roleName = new TextField();
    this.roleName.addValidator(new StringLengthValidator("A name must be entered.", 1, null, false));
    this.roleName.setWidth("80%");

    gridLayout.addComponent(nameLabel, 0, 1);
    gridLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(roleName, 1, 1);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    this.roleDescription = new TextArea();
    this.roleDescription
            .addValidator(new StringLengthValidator("A description must be entered.", 1, null, false));
    this.roleDescription.setRows(4);
    roleDescription.setWidth("80%");

    this.roleName.setValidationVisible(false);
    this.roleDescription.setValidationVisible(false);

    gridLayout.addComponent(descriptionLabel, 0, 2);
    gridLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    gridLayout.addComponent(roleDescription, 1, 2);

    Button createButton = new Button("Save");
    Button cancelButton = new Button("Cancel");

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(createButton);
    buttonLayout.setComponentAlignment(createButton, Alignment.MIDDLE_CENTER);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER);

    gridLayout.addComponent(buttonLayout, 0, 3, 1, 3);
    gridLayout.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER);

    BeanItem<Role> policyItem = new BeanItem<Role>(this.role);

    roleName.setPropertyDataSource(policyItem.getItemProperty("name"));
    roleDescription.setPropertyDataSource(policyItem.getItemProperty("description"));

    createButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                NewRoleWindow.this.roleName.validate();
                NewRoleWindow.this.roleDescription.validate();
            } catch (InvalidValueException e) {
                NewRoleWindow.this.roleName.setValidationVisible(true);
                NewRoleWindow.this.roleDescription.setValidationVisible(true);

                return;
            }

            NewRoleWindow.this.roleName.setValidationVisible(false);
            NewRoleWindow.this.roleDescription.setValidationVisible(false);

            UI.getCurrent().removeWindow(NewRoleWindow.this);

            securityService.saveRole(role);

            Notification.show("Role successfully created!");
        }
    });

    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().removeWindow(NewRoleWindow.this);
        }
    });

    this.setContent(gridLayout);
}

From source file:org.ikasan.dashboard.ui.framework.panel.PersistanceSetupPanel.java

License:BSD License

protected void createNotCreatedView() {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setWidth("100%");
    verticalLayout.setHeight("100%");
    verticalLayout.setMargin(true);/*from ww w  .  j  a  v a  2s. co  m*/

    Label ikasanWelcomeLabel1 = new Label("Welcome to Ikasan!");
    ikasanWelcomeLabel1.setStyleName("xlarge");
    ikasanWelcomeLabel1.setWidth("100%");
    ikasanWelcomeLabel1.setHeight("30px");

    Label ikasanWelcomeLabel2 = new Label("It appears that you are setting up Ikasan for the"
            + " first time and we need to create some database tables. If this is not the first time accessing the "
            + "Ikasan Console, it appears that there is an issue with the Ikasan database. If this is the case please "
            + "contact your local database administrator.");

    ikasanWelcomeLabel2.setStyleName("large");
    ikasanWelcomeLabel2.setWidth("60%");
    ikasanWelcomeLabel2.setHeight("70px");

    verticalLayout.addComponent(ikasanWelcomeLabel1);
    verticalLayout.addComponent(ikasanWelcomeLabel2);

    verticalLayout.addComponent(persistanceStoreTypeCombo);
    persistanceStoreTypeCombo.setHeight("30px");

    Button button = new Button("Create");
    button.setStyleName(ValoTheme.BUTTON_SMALL);
    button.setHeight("30px");

    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            String persistenceProvider = (String) PersistanceSetupPanel.this.persistanceStoreTypeCombo
                    .getValue();

            if (persistenceProvider == null) {
                Notification.show("Please select a database type!");
                return;
            }

            PersistenceService persistanceService = persistenceServiceFactory
                    .getPersistenceService(persistenceProvider);

            try {
                persistanceService.createPersistence();
                persistanceService.createAdminAccount();
            } catch (RuntimeException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Error trying to create Ikasan database!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);
            }

            Notification.show("Database successfully created!");
        }
    });

    verticalLayout.addComponent(button);
    this.setContent(verticalLayout);
}

From source file:org.ikasan.dashboard.ui.framework.panel.PersistanceSetupPanel.java

License:BSD License

protected void createAlreadyCreatedView() {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setWidth("100%");
    verticalLayout.setHeight("100%");
    verticalLayout.setMargin(true);/*w  w  w  . ja va  2s . c om*/

    Label ikasanWelcomeLabel1 = new Label("Welcome to Ikasan!");
    ikasanWelcomeLabel1.setStyleName("xlarge");
    ikasanWelcomeLabel1.setWidth("100%");
    ikasanWelcomeLabel1.setHeight("30px");

    Label ikasanWelcomeLabel2 = new Label(
            "It appears as thoug the Ikasan database has already been created. If you believe that this is not the case there may be an issue. "
                    + "Please contact your local database administrator or Ikasan/Middleware support.");

    ikasanWelcomeLabel2.setStyleName("large");
    ikasanWelcomeLabel2.setWidth("60%");
    ikasanWelcomeLabel2.setHeight("60px");

    verticalLayout.addComponent(ikasanWelcomeLabel1);
    verticalLayout.addComponent(ikasanWelcomeLabel2);

    //        verticalLayout.addComponent(persistanceStoreTypeCombo);

    this.setContent(verticalLayout);
}

From source file:org.ikasan.dashboard.ui.framework.panel.ProfilePanel.java

License:BSD License

@SuppressWarnings("deprecation")
protected void init() {
    this.setWidth("100%");
    this.setHeight("100%");

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();/*from w w  w  .  j a v a2  s. c o  m*/

    Panel securityAdministrationPanel = new Panel();
    securityAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    securityAdministrationPanel.setHeight("100%");
    securityAdministrationPanel.setWidth("100%");

    GridLayout gridLayout = new GridLayout(2, 6);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(true);
    gridLayout.setSizeFull();

    Label mappingConfigurationLabel = new Label("User Profile");
    mappingConfigurationLabel.setStyleName(ValoTheme.LABEL_HUGE);
    gridLayout.addComponent(mappingConfigurationLabel, 0, 0, 1, 0);

    Label usernameLabel = new Label("Username:");

    usernameField.setWidth("65%");

    firstName = new TextField();
    firstName.setWidth("65%");
    firstName.setNullRepresentation("");
    surname = new TextField();
    surname.setWidth("65%");
    surname.setNullRepresentation("");
    department.setWidth("65%");
    department.setNullRepresentation("");
    email.setWidth("65%");
    email.setNullRepresentation("");

    roleTable.addContainerProperty("Role", String.class, null);
    roleTable.addStyleName("ikasan");
    roleTable.addStyleName(ValoTheme.TABLE_SMALL);
    roleTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    roleTable.setHeight("520px");
    roleTable.setWidth("250px");

    GridLayout formLayout = new GridLayout(2, 5);
    formLayout.setSpacing(true);
    formLayout.setWidth("100%");

    formLayout.setColumnExpandRatio(0, .1f);
    formLayout.setColumnExpandRatio(1, .8f);

    usernameLabel.setSizeUndefined();
    formLayout.addComponent(usernameLabel, 0, 0);
    formLayout.setComponentAlignment(usernameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(usernameField, 1, 0);

    Label firstNameLabel = new Label("First name:");
    firstNameLabel.setSizeUndefined();
    formLayout.addComponent(firstNameLabel, 0, 1);
    formLayout.setComponentAlignment(firstNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(firstName, 1, 1);

    Label surnameLabel = new Label("Surname:");
    surnameLabel.setSizeUndefined();
    formLayout.addComponent(surnameLabel, 0, 2);
    formLayout.setComponentAlignment(surnameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(surname, 1, 2);

    Label departmentLabel = new Label("Department:");
    departmentLabel.setSizeUndefined();
    formLayout.addComponent(departmentLabel, 0, 3);
    formLayout.setComponentAlignment(departmentLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(department, 1, 3);

    Label emailLabel = new Label("Email address:");
    emailLabel.setSizeUndefined();
    formLayout.addComponent(emailLabel, 0, 4);
    formLayout.setComponentAlignment(emailLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(email, 1, 4);

    gridLayout.addComponent(formLayout, 0, 2, 1, 2);

    Label rolesAndGroupsHintLabel1 = new Label();
    rolesAndGroupsHintLabel1.setCaptionAsHtml(true);
    rolesAndGroupsHintLabel1.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Roles table below displays the Ikasan roles that the user has.");
    rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_TINY);
    rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_LIGHT);
    rolesAndGroupsHintLabel1.setWidth(300, Unit.PIXELS);
    gridLayout.addComponent(rolesAndGroupsHintLabel1, 0, 3, 1, 3);

    Label rolesAndGroupsHintLabel2 = new Label();
    rolesAndGroupsHintLabel2.setCaptionAsHtml(true);
    rolesAndGroupsHintLabel2.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Groups table below displays all the LDAP groups that the user is a member of.");

    rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_TINY);
    rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_LIGHT);
    rolesAndGroupsHintLabel2.setWidth(300, Unit.PIXELS);
    gridLayout.addComponent(rolesAndGroupsHintLabel2, 0, 4, 1, 4);

    dashboadActivityTable.addContainerProperty("Action", String.class, null);
    dashboadActivityTable.addContainerProperty("Date/Time", String.class, null);
    dashboadActivityTable.addStyleName("ikasan");
    dashboadActivityTable.addStyleName(ValoTheme.TABLE_SMALL);
    dashboadActivityTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    dashboadActivityTable.setHeight("350px");
    dashboadActivityTable.setWidth("300px");

    this.permissionChangeTable.addContainerProperty("Action", String.class, null);
    this.permissionChangeTable.addContainerProperty("Date/Time", String.class, null);
    this.permissionChangeTable.addStyleName("ikasan");
    this.permissionChangeTable.addStyleName(ValoTheme.TABLE_SMALL);
    this.permissionChangeTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    this.permissionChangeTable.setHeight("350px");
    this.permissionChangeTable.setWidth("300px");

    gridLayout.addComponent(roleTable, 0, 5);

    this.associatedPrincipalsTable.addContainerProperty("Groups", String.class, null);
    this.associatedPrincipalsTable.addItemClickListener(this.associatedPrincipalItemClickListener);
    this.associatedPrincipalsTable.addStyleName("ikasan");
    this.associatedPrincipalsTable.addStyleName(ValoTheme.TABLE_SMALL);
    this.associatedPrincipalsTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    associatedPrincipalsTable.setHeight("520px");
    associatedPrincipalsTable.setWidth("400px");

    gridLayout.addComponent(this.associatedPrincipalsTable, 1, 5);

    Panel roleMemberPanel = new Panel();

    roleMemberPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    roleMemberPanel.setHeight("100%");
    roleMemberPanel.setWidth("100%");

    GridLayout roleMemberLayout = new GridLayout();
    roleMemberLayout.setSpacing(true);
    roleMemberLayout.setWidth("100%");

    Label dashboardActivityLabel = new Label("Dashboard Activity");
    dashboardActivityLabel.setStyleName(ValoTheme.LABEL_HUGE);

    roleMemberLayout.addComponent(dashboardActivityLabel);
    roleMemberLayout.addComponent(this.dashboadActivityTable);

    Label permissionChangeLabel = new Label("User Security Changes");
    permissionChangeLabel.setStyleName(ValoTheme.LABEL_HUGE);

    roleMemberLayout.addComponent(permissionChangeLabel);
    roleMemberLayout.addComponent(this.permissionChangeTable);

    roleMemberPanel.setContent(roleMemberLayout);

    securityAdministrationPanel.setContent(gridLayout);
    layout.addComponent(securityAdministrationPanel);

    VerticalLayout roleMemberPanelLayout = new VerticalLayout();
    roleMemberPanelLayout.setWidth("100%");
    roleMemberPanelLayout.setHeight("100%");
    roleMemberPanelLayout.setMargin(true);
    roleMemberPanelLayout.addComponent(roleMemberPanel);
    roleMemberPanelLayout.setSizeFull();

    HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
    hsplit.setFirstComponent(layout);
    hsplit.setSecondComponent(roleMemberPanelLayout);

    // Set the position of the splitter as percentage
    hsplit.setSplitPosition(65, Unit.PERCENTAGE);
    hsplit.setLocked(true);

    this.setContent(hsplit);
}

From source file:org.ikasan.dashboard.ui.framework.window.AdminPasswordDialog.java

License:BSD License

/**
 * Helper method to initialise this object.
 * /*from   w  ww .j  a  v a2s. c om*/
 * @param userService
 * @param authProvider
 * @param visibilityGroup
 * @param userDetailsHelper
 * @param commitHandler
 */
protected void init() {
    super.setModal(true);
    super.setResizable(false);
    super.center();
    this.setWidth(300, Unit.PIXELS);
    this.setHeight(220, Unit.PIXELS);

    super.setClosable(false);

    GridLayout form = new GridLayout(2, 4);
    form.setColumnExpandRatio(0, .15f);
    form.setColumnExpandRatio(1, .85f);
    form.setWidth(100, Unit.PERCENTAGE);
    form.setMargin(true);
    form.setSpacing(true);

    Label newTypeLabel = new Label("Initial Administration Password");
    newTypeLabel.setStyleName(ValoTheme.LABEL_HUGE);
    form.addComponent(newTypeLabel, 0, 0, 1, 0);

    Label passwordLabel = new Label("Password:");
    passwordLabel.setSizeUndefined();
    form.addComponent(passwordLabel, 0, 1);
    form.setComponentAlignment(passwordLabel, Alignment.MIDDLE_RIGHT);

    final PasswordField passwordField = new PasswordField();
    passwordField.addValidator(new StringLengthValidator("The username must not be empty", 1, null, true));
    passwordField.setValidationVisible(false);
    passwordField.setStyleName("ikasan");
    form.addComponent(passwordField, 1, 1);

    Label passwordConfirmLabel = new Label("Confirm Password:");
    passwordConfirmLabel.setSizeUndefined();
    form.addComponent(passwordConfirmLabel, 0, 2);
    form.setComponentAlignment(passwordConfirmLabel, Alignment.MIDDLE_RIGHT);

    final PasswordField passwordConfirmField = new PasswordField();
    passwordConfirmField.setStyleName("ikasan");
    passwordConfirmField
            .addValidator(new StringLengthValidator("The password must not be empty", 1, null, true));
    passwordConfirmField.setValidationVisible(false);
    form.addComponent(passwordConfirmField, 1, 2);

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

    Button saveButton = new Button("Save");
    saveButton.addStyleName(ValoTheme.BUTTON_SMALL);
    saveButton.setClickShortcut(KeyCode.ENTER);

    saveButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                passwordField.validate();
                passwordConfirmField.validate();

                if (!passwordField.getValue().equals(passwordConfirmField.getValue())) {
                    Notification.show("Password and confirmation must be the same!", Type.ERROR_MESSAGE);

                    return;
                }
            } catch (InvalidValueException e) {
                passwordField.setValidationVisible(true);
                passwordConfirmField.setValidationVisible(true);
                return;
            }

            password = passwordField.getValue();

            passwordField.setValue("");
            passwordConfirmField.setValue("");
            close();

        }
    });
    buttons.addComponent(saveButton);

    form.addComponent(buttons, 0, 3, 1, 3);
    form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);

    this.setContent(form);
}

From source file:org.ikasan.dashboard.ui.framework.window.LoginDialog.java

License:BSD License

/**
 * Helper method to initialise this object.
 * /* w  ww  .  java2 s.  c o  m*/
 * @param userService
 * @param authProvider
 * @param visibilityGroup
 * @param userDetailsHelper
 * @param commitHandler
 */
protected void init(AuthenticationService authenticationService, VisibilityGroup visibilityGroup,
        final NavigationPanel commitHandler) {
    super.setModal(true);
    super.setResizable(false);
    super.center();
    this.setWidth(300, Unit.PIXELS);
    this.setHeight(200, Unit.PIXELS);

    PropertysetItem item = new PropertysetItem();
    item.addItemProperty(LoginFieldGroup.USERNAME, new ObjectProperty<String>(""));
    item.addItemProperty(LoginFieldGroup.PASSWORD, new ObjectProperty<String>(""));

    GridLayout form = new GridLayout(2, 4);
    form.setColumnExpandRatio(0, .15f);
    form.setColumnExpandRatio(1, .85f);
    form.setWidth(100, Unit.PERCENTAGE);
    form.setMargin(true);
    form.setSpacing(true);

    Label newTypeLabel = new Label("Login");
    newTypeLabel.setStyleName(ValoTheme.LABEL_HUGE);
    form.addComponent(newTypeLabel, 0, 0, 1, 0);

    Label usernameLabel = new Label("Username:");
    usernameLabel.setSizeUndefined();
    form.addComponent(usernameLabel, 0, 1);
    form.setComponentAlignment(usernameLabel, Alignment.MIDDLE_RIGHT);

    final TextField userNameField = new TextField();
    userNameField.addValidator(new StringLengthValidator("The username must not be empty", 1, null, true));
    userNameField.setValidationVisible(false);
    userNameField.setStyleName("ikasan");
    form.addComponent(userNameField, 1, 1);

    Label passwordLabel = new Label("Password:");
    passwordLabel.setSizeUndefined();
    form.addComponent(passwordLabel, 0, 2);
    form.setComponentAlignment(passwordLabel, Alignment.MIDDLE_RIGHT);

    final PasswordField passwordField = new PasswordField();
    passwordField.setStyleName("ikasan");
    passwordField.addValidator(new StringLengthValidator("The password must not be empty", 1, null, true));
    passwordField.setValidationVisible(false);
    form.addComponent(passwordField, 1, 2);

    final LoginFieldGroup binder = new LoginFieldGroup(item, visibilityGroup, authenticationService);
    binder.bind(userNameField, LoginFieldGroup.USERNAME);
    binder.bind(passwordField, LoginFieldGroup.PASSWORD);

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

    Button loginButton = new Button("Login");
    loginButton.addStyleName(ValoTheme.BUTTON_SMALL);
    loginButton.setClickShortcut(KeyCode.ENTER);

    loginButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                userNameField.validate();
                passwordField.validate();
            } catch (InvalidValueException e) {
                userNameField.setValidationVisible(true);
                passwordField.setValidationVisible(true);
                return;
            }

            try {
                binder.commit();
                userNameField.setValue("");
                passwordField.setValue("");
                close();
                commitHandler.postCommit();
            } catch (CommitException e) {
                Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    buttons.addComponent(loginButton);

    Button cancelButton = new Button("Cancel");
    cancelButton.setStyleName(ValoTheme.BUTTON_SMALL);
    cancelButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            close();
            binder.discard();
        }
    });
    buttons.addComponent(cancelButton);

    form.addComponent(buttons, 0, 3, 1, 3);
    form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);

    this.setContent(form);
}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationPanel.java

License:BSD License

/**
 * Helper method to create the form associated with the mapping
 * configuration.//from  w w w  .j  a  v  a  2 s  .c  o m
 * 
 * @return the Layout of the form
 */
protected GridLayout createMappingConfigurationForm() {
    Label mappingConfigurationLabel = new Label(this.name);
    mappingConfigurationLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(mappingConfigurationLabel, 0, 0, 1, 0);

    HorizontalLayout clientLabelLayout = new HorizontalLayout();
    clientLabelLayout.setHeight(25, Unit.PIXELS);
    clientLabelLayout.setWidth(100, Unit.PIXELS);

    Label clientLabel = new Label("Client:");
    clientLabel.setSizeUndefined();
    clientLabelLayout.addComponent(clientLabel);
    clientLabelLayout.setComponentAlignment(clientLabel, Alignment.MIDDLE_RIGHT);

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

    HorizontalLayout clientComboBoxLayout = new HorizontalLayout();
    clientComboBoxLayout.setHeight(25, Unit.PIXELS);
    clientComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.clientComboBox.setWidth(300, Unit.PIXELS);
    this.clientComboBox.removeAllValidators();
    this.clientComboBox.addValidator(new NullValidator("A client must be selected!", false));
    this.clientComboBox.setValidationVisible(false);
    clientComboBoxLayout.addComponent(this.clientComboBox);
    layout.addComponent(clientComboBoxLayout, 1, 1);

    HorizontalLayout typeLabelLayout = new HorizontalLayout();
    typeLabelLayout.setHeight(25, Unit.PIXELS);
    typeLabelLayout.setWidth(100, Unit.PIXELS);

    Label typeLabel = new Label("Type:");
    typeLabel.setSizeUndefined();
    typeLabelLayout.addComponent(typeLabel);
    typeLabelLayout.setComponentAlignment(typeLabel, Alignment.MIDDLE_RIGHT);

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

    HorizontalLayout typeComboBoxLayout = new HorizontalLayout();
    typeComboBoxLayout.setHeight(25, Unit.PIXELS);
    typeComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.typeComboBox.setWidth(300, Unit.PIXELS);
    this.typeComboBox.removeAllValidators();
    this.typeComboBox.addValidator(new NullValidator("A type must be selected!", false));
    this.typeComboBox.setValidationVisible(false);
    typeComboBoxLayout.addComponent(this.typeComboBox);
    layout.addComponent(typeComboBoxLayout, 1, 2);

    HorizontalLayout sourceContextLabelLayout = new HorizontalLayout();
    sourceContextLabelLayout.setHeight(25, Unit.PIXELS);
    sourceContextLabelLayout.setWidth(100, Unit.PIXELS);

    Label sourceContextLabel = new Label("Source Context:");
    sourceContextLabel.setSizeUndefined();
    sourceContextLabelLayout.addComponent(sourceContextLabel);
    sourceContextLabelLayout.setComponentAlignment(sourceContextLabel, Alignment.MIDDLE_RIGHT);

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

    HorizontalLayout sourceContextComboBoxLayout = new HorizontalLayout();
    sourceContextComboBoxLayout.setHeight(25, Unit.PIXELS);
    sourceContextComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.sourceContextComboBox.setWidth(300, Unit.PIXELS);
    this.sourceContextComboBox.removeAllValidators();
    this.sourceContextComboBox.addValidator(new NullValidator("A source context must be selected", false));
    this.sourceContextComboBox.setValidationVisible(false);
    sourceContextComboBoxLayout.addComponent(this.sourceContextComboBox);
    layout.addComponent(sourceContextComboBoxLayout, 1, 3);

    HorizontalLayout targetContextLabelLayout = new HorizontalLayout();
    targetContextLabelLayout.setHeight(25, Unit.PIXELS);
    targetContextLabelLayout.setWidth(100, Unit.PIXELS);

    Label targetContextLabel = new Label("Target Context:");
    targetContextLabel.setSizeUndefined();
    targetContextLabelLayout.addComponent(targetContextLabel);
    targetContextLabelLayout.setComponentAlignment(targetContextLabel, Alignment.MIDDLE_RIGHT);

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

    HorizontalLayout targetContextComboBoxLayout = new HorizontalLayout();
    targetContextComboBoxLayout.setHeight(25, Unit.PIXELS);
    targetContextComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.targetContextComboBox.setWidth(300, Unit.PIXELS);
    this.targetContextComboBox.removeAllValidators();
    this.targetContextComboBox.addValidator(new NullValidator("A target context must be selected", false));
    this.targetContextComboBox.setValidationVisible(false);
    targetContextComboBoxLayout.addComponent(this.targetContextComboBox);
    layout.addComponent(this.targetContextComboBox, 1, 4);

    HorizontalLayout descriptionLabelLayout = new HorizontalLayout();
    descriptionLabelLayout.setHeight(25, Unit.PIXELS);
    descriptionLabelLayout.setWidth(100, Unit.PIXELS);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    descriptionLabelLayout.addComponent(descriptionLabel);
    descriptionLabelLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);

    layout.addComponent(descriptionLabelLayout, 0, 5);
    layout.setComponentAlignment(descriptionLabelLayout, Alignment.TOP_RIGHT);

    HorizontalLayout descriptionTextAreaLayout = new HorizontalLayout();
    descriptionTextAreaLayout.setHeight(75, Unit.PIXELS);
    descriptionTextAreaLayout.setWidth(350, Unit.PIXELS);
    this.descriptionTextArea = new TextArea();
    this.descriptionTextArea.setWidth(300, Unit.PIXELS);
    this.descriptionTextArea.setRows(4);
    this.descriptionTextArea
            .addValidator(new StringLengthValidator("A description must be entered.", 1, null, true));
    this.descriptionTextArea.setValidationVisible(false);
    descriptionTextAreaLayout.addComponent(this.descriptionTextArea);
    layout.addComponent(descriptionTextAreaLayout, 1, 5);

    Label numParamsLabel = new Label("Number of source parameters:");
    numParamsLabel.setWidth(175, Unit.PIXELS);

    layout.addComponent(numParamsLabel, 2, 1);
    this.numberOfParametersTextField = new TextField();
    this.numberOfParametersTextField.setWidth(75, Unit.PIXELS);
    this.numberOfParametersTextField.removeAllValidators();
    this.numberOfParametersTextField.addValidator(
            new LongValidator("Number of source parameters " + "and key location queries must be defined."));
    this.numberOfParametersTextField.setValidationVisible(false);
    layout.addComponent(this.numberOfParametersTextField, 3, 1);

    HorizontalLayout queriesLabelLayout = new HorizontalLayout();
    queriesLabelLayout.setHeight(25, Unit.PIXELS);
    queriesLabelLayout.setWidth(250, Unit.PIXELS);

    return layout;
}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationSearchPanel.java

License:BSD License

/**
 * Helper method to initialise this object.
 *//*from  w  w  w .  ja v a 2  s  . c  om*/
@SuppressWarnings("serial")
protected void init() {
    this.addStyleName(ValoTheme.PANEL_BORDERLESS);

    final Label typeLabel = new Label("Type:");
    final Label sourceContextLabel = new Label("Source Context:");
    final Label targetContextLabel = new Label("Target Context:");

    final GridLayout contentLayout = new GridLayout(4, 6);
    contentLayout.setColumnExpandRatio(0, .15f);
    contentLayout.setColumnExpandRatio(1, .35f);
    contentLayout.setColumnExpandRatio(2, .05f);
    contentLayout.setColumnExpandRatio(3, .45f);
    contentLayout.setWidth("100%");
    contentLayout.setSpacing(true);

    Label errorOccurrenceDetailsLabel = new Label("Mapping Configuration Search");
    errorOccurrenceDetailsLabel.setStyleName(ValoTheme.LABEL_HUGE);
    contentLayout.addComponent(errorOccurrenceDetailsLabel, 0, 0, 1, 0);

    Label clientLabel = new Label("Client:");
    clientLabel.setSizeUndefined();
    contentLayout.addComponent(clientLabel, 0, 1);
    contentLayout.setComponentAlignment(clientLabel, Alignment.MIDDLE_RIGHT);

    this.clientComboBox.setWidth(80, Unit.PERCENTAGE);
    this.clientComboBox.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty() != null && event.getProperty().getValue() != null) {
                typeComboBox.refresh(((ConfigurationServiceClient) event.getProperty().getValue()).getName());
                sourceContextComboBox
                        .refresh(((ConfigurationServiceClient) event.getProperty().getValue()).getName(), null);
                targetContextComboBox.refresh(
                        ((ConfigurationServiceClient) event.getProperty().getValue()).getName(), null, null);

                typeLabel.setVisible(true);
                typeComboBox.setVisible(true);
            }
        }
    });
    contentLayout.addComponent(clientComboBox, 1, 1);

    typeLabel.setSizeUndefined();
    contentLayout.addComponent(typeLabel, 0, 2);
    contentLayout.setComponentAlignment(typeLabel, Alignment.MIDDLE_RIGHT);
    typeLabel.setVisible(false);

    this.typeComboBox.setWidth(80, Unit.PERCENTAGE);
    this.typeComboBox.setVisible(false);
    this.typeComboBox.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            String client = null;

            if (clientComboBox.getValue() != null) {
                client = ((ConfigurationServiceClient) clientComboBox.getValue()).getName();
            }

            if (event.getProperty() != null && event.getProperty().getValue() != null) {
                sourceContextComboBox.refresh(client,
                        ((ConfigurationType) event.getProperty().getValue()).getName());
                targetContextComboBox.refresh(client,
                        ((ConfigurationType) event.getProperty().getValue()).getName(), null);

                sourceContextLabel.setVisible(true);
                sourceContextComboBox.setVisible(true);
            }
        }
    });
    contentLayout.addComponent(this.typeComboBox, 1, 2);

    sourceContextLabel.setSizeUndefined();
    contentLayout.addComponent(sourceContextLabel, 0, 3);
    contentLayout.setComponentAlignment(sourceContextLabel, Alignment.MIDDLE_RIGHT);
    sourceContextLabel.setVisible(false);

    this.sourceContextComboBox.setWidth(80, Unit.PERCENTAGE);
    this.sourceContextComboBox.setVisible(false);
    this.sourceContextComboBox.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            String type = null;
            String client = null;

            if (typeComboBox.getValue() != null) {
                type = ((ConfigurationType) typeComboBox.getValue()).getName();
            }

            if (clientComboBox.getValue() != null) {
                client = ((ConfigurationServiceClient) clientComboBox.getValue()).getName();
            }

            if (event.getProperty() != null && event.getProperty().getValue() != null) {
                targetContextComboBox.refresh(client, type,
                        ((ConfigurationContext) event.getProperty().getValue()).getName());

                targetContextLabel.setVisible(true);
                targetContextComboBox.setVisible(true);
            }
        }
    });
    contentLayout.addComponent(this.sourceContextComboBox, 1, 3);

    targetContextLabel.setSizeUndefined();
    contentLayout.addComponent(targetContextLabel, 0, 4);
    contentLayout.setComponentAlignment(targetContextLabel, Alignment.MIDDLE_RIGHT);
    targetContextLabel.setVisible(false);

    this.targetContextComboBox.setWidth(80, Unit.PERCENTAGE);
    this.targetContextComboBox.setVisible(false);
    contentLayout.addComponent(this.targetContextComboBox, 1, 4);

    Label actionsLabel = newActions.getActionsLabel();
    actionsLabel.setStyleName(ValoTheme.LABEL_HUGE);
    contentLayout.addComponent(actionsLabel, 2, 0, 3, 0);

    Label createNewClientLabel = newActions.getNewClientLabel();
    createNewClientLabel.setSizeUndefined();
    contentLayout.addComponent(createNewClientLabel, 2, 1);
    contentLayout.setComponentAlignment(createNewClientLabel, Alignment.MIDDLE_RIGHT);
    contentLayout.addComponent(newActions.getNewClientButton(), 3, 1);
    contentLayout.setComponentAlignment(newActions.getNewClientButton(), Alignment.MIDDLE_LEFT);

    Label createNewTypeLabel = newActions.getNewTypeLabel();
    createNewTypeLabel.setSizeUndefined();
    contentLayout.addComponent(createNewTypeLabel, 2, 2);
    contentLayout.setComponentAlignment(createNewTypeLabel, Alignment.MIDDLE_RIGHT);
    contentLayout.addComponent(newActions.getNewTypeButton(), 3, 2);
    contentLayout.setComponentAlignment(newActions.getNewTypeButton(), Alignment.MIDDLE_LEFT);

    Label createContextTypeLabel = newActions.getNewContextLabel();
    createContextTypeLabel.setSizeUndefined();
    contentLayout.addComponent(createContextTypeLabel, 2, 3);
    contentLayout.setComponentAlignment(createContextTypeLabel, Alignment.MIDDLE_RIGHT);
    contentLayout.addComponent(newActions.getNewContextButton(), 3, 3);
    contentLayout.setComponentAlignment(newActions.getNewContextButton(), Alignment.MIDDLE_LEFT);

    Label createMappingConfigurationLabel = newActions.getNewMappingConfigurationLabel();
    createMappingConfigurationLabel.setSizeUndefined();
    contentLayout.addComponent(createMappingConfigurationLabel, 2, 4);
    contentLayout.setComponentAlignment(createMappingConfigurationLabel, Alignment.MIDDLE_RIGHT);
    contentLayout.addComponent(newActions.getNewMappingConfigurationButton(), 3, 4);
    contentLayout.setComponentAlignment(newActions.getNewMappingConfigurationButton(), Alignment.MIDDLE_LEFT);

    Label importMappingConfigurationLabel = newActions.getImportMappingConfigurationLabel();
    importMappingConfigurationLabel.setSizeUndefined();
    contentLayout.addComponent(importMappingConfigurationLabel, 2, 5);
    contentLayout.setComponentAlignment(importMappingConfigurationLabel, Alignment.MIDDLE_RIGHT);
    contentLayout.addComponent(newActions.getImportMappingConfigurationButton(), 3, 5);
    contentLayout.setComponentAlignment(newActions.getImportMappingConfigurationButton(),
            Alignment.MIDDLE_LEFT);

    Button button = new Button("Search");
    button.setStyleName(ValoTheme.BUTTON_SMALL);
    button.addClickListener(searchButtonClickListener);

    contentLayout.addComponent(button, 1, 5);

    this.setContent(contentLayout);
}