Example usage for com.vaadin.ui Panel setContent

List of usage examples for com.vaadin.ui Panel setContent

Introduction

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

Prototype

@Override
public void setContent(Component content) 

Source Link

Document

Sets the content of this container.

Usage

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

License:BSD License

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

    this.createAssociatedRolesPanel();
    this.createPolicyDropPanel();

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);/*from   w ww .ja va  2  s . c o  m*/
    layout.setSpacing(true);
    layout.setWidth("100%");

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

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

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

    Label roleSearchHintLabel = new Label();
    roleSearchHintLabel.setCaptionAsHtml(true);
    roleSearchHintLabel.setCaption(
            VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Policy Name field to find a policy.");
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleSearchHintLabel, 0, 1, 1, 1);

    Layout controlLayout = this.initControlLayout();

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

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

    Label policyNameLabel = new Label("Policy Name:");
    policyNameLabel.setSizeUndefined();
    final DragAndDropWrapper policyNameFieldWrap = initPolicyNameField();

    formLayout.addComponent(policyNameLabel, 0, 0);
    formLayout.setComponentAlignment(policyNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(policyNameFieldWrap, 1, 0);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    this.descriptionField = new TextArea();
    this.descriptionField.setWidth("70%");
    this.descriptionField.setHeight("60px");
    formLayout.addComponent(descriptionLabel, 0, 1);
    formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    formLayout.addComponent(this.descriptionField, 1, 1);

    this.linkTypeLabel.setSizeUndefined();
    formLayout.addComponent(this.linkTypeLabel, 0, 2);
    formLayout.setComponentAlignment(this.linkTypeLabel, Alignment.MIDDLE_RIGHT);
    this.linkType.setWidth("70%");
    formLayout.addComponent(this.linkType, 1, 2);
    this.linkTypeLabel.setVisible(false);
    this.linkType.setVisible(false);

    this.linkedEntityLabel.setSizeUndefined();
    this.linkedEntity = new TextArea();
    this.linkedEntity.setWidth("70%");
    this.linkedEntity.setHeight("60px");

    formLayout.addComponent(this.linkedEntityLabel, 0, 3);
    formLayout.setComponentAlignment(this.linkedEntityLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(linkedEntity, 1, 3);
    this.linkedEntityLabel.setVisible(false);
    this.linkedEntity.setVisible(false);

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

    Label roleTableHintLabel = new Label();
    roleTableHintLabel.setCaptionAsHtml(true);
    roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Roles table below displays the roles that are assigned the current policy.");
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleTableHintLabel, 0, 4, 1, 4);

    gridLayout.addComponent(this.roleTable, 0, 5, 1, 5);

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

    HorizontalLayout roleMemberPanelLayout = new HorizontalLayout();
    roleMemberPanelLayout.setMargin(true);
    roleMemberPanelLayout.addComponent(this.policyDropPanel);
    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.panel.PrincipalManagementPanel.java

License:BSD License

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

    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);/*from  w w w  .j a  va 2  s  .c  o m*/
    layout.setSizeFull();

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

    GridLayout gridLayout = new GridLayout(2, 5);
    gridLayout.setWidth("100%");
    gridLayout.setHeight("100%");
    gridLayout.setMargin(true);
    gridLayout.setSizeFull();

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

    Label groupSearchHintLabel = new Label();
    groupSearchHintLabel.setCaptionAsHtml(true);
    groupSearchHintLabel.setCaption(
            VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Group Name field to find a group.");
    groupSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    groupSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(groupSearchHintLabel, 0, 1, 1, 1);

    Label principalNameLabel = new Label("Group Name:");
    principalNameLabel.setSizeUndefined();

    principalNameField = new AutocompleteField<IkasanPrincipal>();
    principalNameField.setWidth("70%");

    final DragAndDropWrapper principalNameFieldWrap = new DragAndDropWrapper(principalNameField);
    principalNameFieldWrap.setDragStartMode(DragStartMode.COMPONENT);

    principalTypeField.setWidth("70%");
    descriptionField.setWidth("70%");
    descriptionField.setHeight("60px");

    roleTable.addContainerProperty("Role", String.class, null);
    roleTable.addContainerProperty("", Button.class, null);
    roleTable.setHeight("610px");
    roleTable.setWidth("300px");

    userTable.addContainerProperty("Associated Users", String.class, null);
    userTable.setHeight("610px");
    userTable.setWidth("300px");

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

    principalNameField.setQueryListener(new AutocompleteQueryListener<IkasanPrincipal>() {
        @Override
        public void handleUserQuery(AutocompleteField<IkasanPrincipal> field, String query) {
            for (IkasanPrincipal principal : securityService.getPrincipalByNameLike(query)) {
                field.addSuggestion(principal, principal.getName());
            }
        }
    });

    principalNameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<IkasanPrincipal>() {
        @Override
        public void onSuggestionPicked(final IkasanPrincipal principal) {
            PrincipalManagementPanel.this.principal = principal;
            PrincipalManagementPanel.this.setValues();
        }
    });

    GridLayout formLayout = new GridLayout(2, 3);
    formLayout.setWidth("100%");
    formLayout.setHeight("135px");
    formLayout.setSpacing(true);

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

    formLayout.addComponent(principalNameLabel, 0, 0);
    formLayout.setComponentAlignment(principalNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(principalNameFieldWrap, 1, 0);

    Label principalTypeLabel = new Label("Group Type:");
    principalTypeLabel.setSizeUndefined();
    formLayout.addComponent(principalTypeLabel, 0, 1);
    formLayout.setComponentAlignment(principalTypeLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(principalTypeField, 1, 1);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    formLayout.addComponent(descriptionLabel, 0, 2);
    formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    formLayout.addComponent(descriptionField, 1, 2);

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

    principalDropTable.setDragMode(TableDragMode.ROW);
    principalDropTable.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            if (rolesCombo.getValue() == null) {
                // Do nothing if there is no role selected
                logger.info("Ignoring drop: " + dropEvent);
                return;
            }

            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) {
                    principalDropTable.removeItem(principal.getName());

                    principal.getRoles().remove(roleToRemove);

                    securityService.savePrincipal(principal);

                    if (principalNameField.getText().equals(principal.getName())) {
                        roleTable.removeItem(roleToRemove);
                    }
                }
            });

            principalDropTable.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);

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

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

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

    Label roleTableHintLabel = new Label();
    roleTableHintLabel.setCaptionAsHtml(true);
    roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Roles table below displays the roles that are assigned to the group. Roles can be deleted from this table.");
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleTableHintLabel, 0, 3, 1, 3);

    gridLayout.addComponent(roleTable, 0, 4);
    gridLayout.addComponent(userTable, 1, 4);

    this.rolesCombo = new ComboBox("Roles");
    this.rolesCombo.setWidth("90%");
    this.rolesCombo.addListener(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());

                principalDropTable.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) {
                            principalDropTable.removeItem(principal.getName());

                            principal.getRoles().remove(role);

                            securityService.savePrincipal(principal);

                            if (principalNameField.getText().equals(principal.getName())) {
                                roleTable.removeItem(role);
                            }
                        }
                    });

                    principalDropTable.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%");
    roleMemberLayout.setHeight("100%");

    Label roleGroupLabels = new Label("Role/Group Associations");
    roleGroupLabels.setStyleName(ValoTheme.LABEL_HUGE);
    gridLayout.addComponent(roleGroupLabels);

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

    roleMemberLayout.addComponent(roleGroupLabels);
    roleMemberLayout.addComponent(groupDragHintLabel);
    roleMemberLayout.addComponent(this.rolesCombo);
    roleMemberLayout.addComponent(this.principalDropTable);

    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.panel.RoleManagementPanel.java

License:BSD License

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

    this.initPolicyNameField();
    this.createPolicyDropPanel();

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

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

    GridLayout gridLayout = new GridLayout(2, 6);
    gridLayout.setWidth("100%");
    gridLayout.setHeight("100%");
    gridLayout.setMargin(true);
    gridLayout.setSizeFull();

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

    Label roleSearchHintLabel = new Label();
    roleSearchHintLabel.setCaptionAsHtml(true);
    roleSearchHintLabel.setCaption(
            VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Role Name field to find a role.");
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleSearchHintLabel, 0, 1, 1, 1);

    Layout controlLayout = this.initControlLayout();

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

    Label roleNameLabel = new Label("Role Name:");
    roleNameLabel.setSizeUndefined();
    initRoleNameField();

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

    formLayout.setColumnExpandRatio(0, 1);
    formLayout.setColumnExpandRatio(1, 5);

    this.roleNameField.setWidth("70%");
    formLayout.addComponent(roleNameLabel, 0, 0);
    formLayout.setComponentAlignment(roleNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(this.roleNameField, 1, 0);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    this.descriptionField = new TextArea();
    this.descriptionField.setWidth("70%");
    this.descriptionField.setHeight("60px");
    formLayout.addComponent(descriptionLabel, 0, 1);
    formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    formLayout.addComponent(descriptionField, 1, 1);

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

    Label roleTableHintLabel = new Label();
    roleTableHintLabel.setCaptionAsHtml(true);
    roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Associated Users/Groups table below displays the users/groups that are assigned the current role.");
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleTableHintLabel, 0, 4, 1, 4);

    this.associatedPrincipalsTable = new Table();
    this.associatedPrincipalsTable.addItemClickListener(this.associatedPrincipalItemClickListener);
    this.associatedPrincipalsTable.addContainerProperty("Associated Users/Groups", String.class, null);
    this.associatedPrincipalsTable.addContainerProperty("", Button.class, null);
    this.associatedPrincipalsTable.setHeight("600px");
    this.associatedPrincipalsTable.setWidth("650px");

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

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

    HorizontalLayout policyDropPanelLayout = new HorizontalLayout();
    policyDropPanelLayout.setMargin(true);
    policyDropPanelLayout.addComponent(this.policyDropPanel);
    policyDropPanelLayout.setSizeFull();

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

    // 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.panel.UserDirectoriesPanel.java

License:BSD License

protected void init() {
    Label userDirectories = new Label("User Directories");
    userDirectories.setStyleName(ValoTheme.LABEL_HUGE);

    Label parapraphOne = new Label();
    parapraphOne.setCaptionAsHtml(true);
    parapraphOne.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The table below shows the user directories currently configured for Ikasan.");
    parapraphOne.addStyleName(ValoTheme.LABEL_TINY);
    parapraphOne.addStyleName(ValoTheme.LABEL_LIGHT);

    Label parapraphTwo = new Label();
    parapraphTwo.setCaptionAsHtml(true);
    parapraphTwo.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The order of the directory is the order in which it will be searched for users and groups."
            + " It is recommended that each user exists in a single directory.");
    parapraphTwo.addStyleName(ValoTheme.LABEL_TINY);
    parapraphTwo.addStyleName(ValoTheme.LABEL_LIGHT);

    this.mainLayout.setWidth("100%");
    this.mainLayout.setSpacing(true);

    this.mainLayout.addComponent(userDirectories);
    this.mainLayout.addComponent(parapraphOne);
    this.mainLayout.addComponent(parapraphTwo);

    Button newDirectoryButton = new Button("Add Directory");
    newDirectoryButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            final UserDirectoryManagementPanel authMethodPanel = new UserDirectoryManagementPanel(
                    new AuthenticationMethod(), securityService, authenticationProviderFactory, ldapService);

            Window window = new Window("Configure User Directory");
            window.setModal(true);//from w w  w. ja  va  2  s  .  com
            window.setHeight("90%");
            window.setWidth("90%");

            window.setContent(authMethodPanel);

            UI.getCurrent().addWindow(window);

            window.addCloseListener(new Window.CloseListener() {
                @Override
                public void windowClose(Window.CloseEvent e) {
                    populateAll();
                }
            });
        }
    });

    this.mainLayout.addComponent(newDirectoryButton);

    this.setWidth("100%");
    this.setHeight("100%");

    this.directoryTable = new Table();
    this.directoryTable.setWidth("100%");
    this.directoryTable.setHeight("600px");
    this.directoryTable.setCellStyleGenerator(new IkasanCellStyleGenerator());
    this.directoryTable.addContainerProperty("Directory Name", String.class, null);
    this.directoryTable.addContainerProperty("Type", String.class, null);
    this.directoryTable.addContainerProperty("Order", Layout.class, null);
    this.directoryTable.addContainerProperty("Operations", Layout.class, null);

    this.directoryTable.setColumnExpandRatio("Directory Name", 25);
    this.directoryTable.setColumnExpandRatio("Type", 25);

    this.directoryTable.setColumnAlignment("Order", Align.CENTER);
    this.directoryTable.setColumnExpandRatio("Order", 10);
    this.directoryTable.setColumnAlignment("Operations", Align.CENTER);
    this.directoryTable.setColumnWidth("Operations", 300);

    this.mainLayout.addComponent(this.directoryTable);

    this.mainLayout.setMargin(true);

    Panel wrapperPanel = new Panel();
    wrapperPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    wrapperPanel.setSizeFull();
    wrapperPanel.setContent(this.mainLayout);

    HorizontalLayout wrapperLayout = new HorizontalLayout();
    wrapperLayout.setSizeFull();
    wrapperLayout.setMargin(true);
    wrapperLayout.addComponent(wrapperPanel);

    this.setContent(wrapperLayout);
}

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

License:BSD License

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

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);/*from   www.  jav  a 2 s .com*/

    Panel securityAdministrationPanel = new Panel();
    securityAdministrationPanel.setStyleName("dashboard");
    securityAdministrationPanel.setWidth("100%");
    securityAdministrationPanel.setHeight("100%");

    GridLayout gridLayout = new GridLayout(2, 25);
    gridLayout.setSpacing(true);
    gridLayout.setWidth("100%");
    gridLayout.setHeight("100%");
    gridLayout.setMargin(true);
    gridLayout.setColumnExpandRatio(0, 0.3f);
    gridLayout.setColumnExpandRatio(1, 0.7f);

    authenticationMethodCombo.addItem(LOCAL_AUTHENTICATION);
    authenticationMethodCombo.setItemCaption(LOCAL_AUTHENTICATION, LOCAL_AUTHENTICATION.getCaption());
    authenticationMethodCombo.addItem(LDAP_LOCAL_AUTHENTICATION);
    authenticationMethodCombo.setItemCaption(LDAP_LOCAL_AUTHENTICATION, LDAP_LOCAL_AUTHENTICATION.getCaption());
    authenticationMethodCombo.addItem(LDAP_AUTHENTICATION);
    authenticationMethodCombo.setItemCaption(LDAP_AUTHENTICATION, LDAP_AUTHENTICATION.getCaption());

    authenticationMethodDropdownValuesMap.put(LOCAL_AUTHENTICATION.getValue(), LOCAL_AUTHENTICATION);
    authenticationMethodDropdownValuesMap.put(LDAP_LOCAL_AUTHENTICATION.getValue(), LDAP_LOCAL_AUTHENTICATION);
    authenticationMethodDropdownValuesMap.put(LDAP_AUTHENTICATION.getValue(), LDAP_AUTHENTICATION);

    final Label serverSettings = new Label("Server Settings");
    serverSettings.setStyleName("large-bold");

    gridLayout.addComponent(serverSettings, 0, 0);

    final Label directoryNameLabel = new Label("Directory Name:");
    directoryNameLabel.setSizeUndefined();
    this.directoryName = new TextField();
    this.directoryName.setWidth("400px");
    this.directoryName.setRequired(true);

    gridLayout.addComponent(directoryNameLabel, 0, 1);
    gridLayout.addComponent(this.directoryName, 1, 1);
    gridLayout.setComponentAlignment(directoryNameLabel, Alignment.MIDDLE_RIGHT);

    final Label ldapServerUrlLabel = new Label("LDAP Server URL:");
    ldapServerUrlLabel.setSizeUndefined();
    this.ldapServerUrl = new TextField();
    this.ldapServerUrl.setWidth("400px");

    gridLayout.addComponent(ldapServerUrlLabel, 0, 2);
    gridLayout.addComponent(this.ldapServerUrl, 1, 2);
    this.ldapServerUrl.setRequired(true);
    gridLayout.setComponentAlignment(ldapServerUrlLabel, Alignment.MIDDLE_RIGHT);

    Label hostnameExample = new Label("Hostname of server running LDAP. Example: ldap://ldap.example.com:389");
    gridLayout.addComponent(hostnameExample, 1, 3);

    final Label ldapBindUserDnLabel = new Label("Username:");
    ldapBindUserDnLabel.setSizeUndefined();
    this.ldapBindUserDn = new TextField();
    this.ldapBindUserDn.setWidth("400px");
    this.ldapBindUserDn.setRequired(true);

    gridLayout.addComponent(ldapBindUserDnLabel, 0, 4);
    gridLayout.addComponent(this.ldapBindUserDn, 1, 4);
    gridLayout.setComponentAlignment(ldapBindUserDnLabel, Alignment.MIDDLE_RIGHT);

    Label usernameExample = new Label("User to log into LDAP. Example: cn=user,DC=domain,DC=name");
    gridLayout.addComponent(usernameExample, 1, 5);

    final Label ldapBindUserPasswordLabel = new Label("Password:");
    ldapBindUserPasswordLabel.setSizeUndefined();
    this.ldapBindUserPassword = new PasswordField();
    this.ldapBindUserPassword.setWidth("100px");
    this.ldapBindUserPassword.setRequired(true);

    gridLayout.addComponent(ldapBindUserPasswordLabel, 0, 6);
    gridLayout.addComponent(this.ldapBindUserPassword, 1, 6);
    gridLayout.setComponentAlignment(ldapBindUserPasswordLabel, Alignment.MIDDLE_RIGHT);

    final Label ldapSchema = new Label("LDAP Schema");
    ldapSchema.setStyleName("large-bold");

    gridLayout.addComponent(ldapSchema, 0, 7);

    final Label ldapUserSearchDnLabel = new Label("User DN:");
    ldapUserSearchDnLabel.setSizeUndefined();
    this.ldapUserSearchDn = new TextField();
    this.ldapUserSearchDn.setRequired(true);
    this.ldapUserSearchDn.setWidth("400px");

    gridLayout.addComponent(ldapUserSearchDnLabel, 0, 8);
    gridLayout.setComponentAlignment(ldapUserSearchDnLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.ldapUserSearchDn, 1, 8);

    Label userDnExample = new Label("The base DN to use when searching for users.");
    gridLayout.addComponent(userDnExample, 1, 9);

    final Label applicationSecurityBaseDnLabel = new Label("Group DN:");
    applicationSecurityBaseDnLabel.setSizeUndefined();
    this.applicationSecurityBaseDn = new TextField();
    this.applicationSecurityBaseDn.setRequired(true);
    this.applicationSecurityBaseDn.setWidth("400px");
    gridLayout.addComponent(applicationSecurityBaseDnLabel, 0, 10);
    gridLayout.setComponentAlignment(applicationSecurityBaseDnLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.applicationSecurityBaseDn, 1, 10);

    Label groupDnExample = new Label("The base DN to use when searching for groups.");
    gridLayout.addComponent(groupDnExample, 1, 11);

    final Label ldapAttributes = new Label("LDAP Attributes");
    ldapAttributes.setStyleName("large-bold");

    CheckBox checkbox = new CheckBox("Populate default attributes");
    checkbox.setValue(false);

    checkbox.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();

            if (value == true) {
                ldapUserSearchFilter.setValue(LDAP_USER_SEARCH_FILTER);
                emailAttributeName.setValue(EMAIL_ATTRIBUTE_NAME);
                userAccountNameAttributeName.setValue(USER_ACCOUNT_NAME_ATTRIBUTE_NAME);
                accountTypeAttributeName.setValue(ACCOUNT_TYPE_ATTRIBUTE_NAME);
                firstNameAttributeName.setValue(FIRST_NAME_ATTRIBUTE_NAME);
                surnameAttributeName.setValue(SURNAME_ATTRIBUTE_NAME);
                departmentAttributeName.setValue(DEPARTMENT_ATTRIBUTE_NAME);
                ldapUserDescriptionAttributeName.setValue(LDAP_USER_DESCRIPTION_ATTRIBUTE_NAME);
                memberofAttributeName.setValue(MEMBER_OF_ATTRIBUTE_NAME);
                applicationSecurityGroupAttributeName.setValue(APPLICATION_SECURITY_GROUP_ATTRIBUTE_NAME);
                applicationSecurityDescriptionAttributeName
                        .setValue(APPLICATION_SECURITY_DESCRIPTION_ATTRIBUTE_NAME);
            } else {
                ldapUserSearchFilter.setValue("");
                emailAttributeName.setValue("");
                userAccountNameAttributeName.setValue("");
                accountTypeAttributeName.setValue("");
                firstNameAttributeName.setValue("");
                surnameAttributeName.setValue("");
                departmentAttributeName.setValue("");
                ldapUserDescriptionAttributeName.setValue("");
                memberofAttributeName.setValue("");
                applicationSecurityGroupAttributeName.setValue("");
                applicationSecurityDescriptionAttributeName.setValue("");
            }
        }
    });
    checkbox.setImmediate(true);

    gridLayout.addComponent(ldapAttributes, 0, 12);
    gridLayout.addComponent(checkbox, 1, 12);

    final Label userSearchFieldLabel = new Label("User Search Filter:");
    userSearchFieldLabel.setSizeUndefined();
    this.ldapUserSearchFilter = new TextField();
    this.ldapUserSearchFilter.setWidth("300px");
    this.ldapUserSearchFilter.setRequired(true);

    gridLayout.addComponent(userSearchFieldLabel, 0, 13);
    gridLayout.setComponentAlignment(userSearchFieldLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.ldapUserSearchFilter, 1, 13);

    final Label emailAttributeNameLabel = new Label("Email:");
    emailAttributeNameLabel.setSizeUndefined();
    this.emailAttributeName = new TextField();
    this.emailAttributeName.setWidth("300px");
    this.emailAttributeName.setRequired(true);

    gridLayout.addComponent(emailAttributeNameLabel, 0, 14);
    gridLayout.setComponentAlignment(emailAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.emailAttributeName, 1, 14);

    final Label userAccountNameAttributeNameLabel = new Label("Account Name:");
    userAccountNameAttributeNameLabel.setSizeUndefined();
    this.userAccountNameAttributeName = new TextField();
    this.userAccountNameAttributeName.setWidth("300px");
    this.userAccountNameAttributeName.setRequired(true);

    gridLayout.addComponent(userAccountNameAttributeNameLabel, 0, 15);
    gridLayout.setComponentAlignment(userAccountNameAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.userAccountNameAttributeName, 1, 15);

    final Label accountTypeAttributeNameLabel = new Label("Account Type:");
    accountTypeAttributeNameLabel.setSizeUndefined();
    this.accountTypeAttributeName = new TextField();
    this.accountTypeAttributeName.setWidth("300px");
    this.accountTypeAttributeName.setRequired(true);

    gridLayout.addComponent(accountTypeAttributeNameLabel, 0, 16);
    gridLayout.setComponentAlignment(accountTypeAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.accountTypeAttributeName, 1, 16);

    final Label firstNameAttributeNameLabel = new Label("First Name:");
    firstNameAttributeNameLabel.setSizeUndefined();
    this.firstNameAttributeName = new TextField();
    this.firstNameAttributeName.setWidth("300px");
    this.firstNameAttributeName.setRequired(true);

    gridLayout.addComponent(firstNameAttributeNameLabel, 0, 17);
    gridLayout.setComponentAlignment(firstNameAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.firstNameAttributeName, 1, 17);

    final Label surnameAttributeNameLabel = new Label("Surname:");
    surnameAttributeNameLabel.setSizeUndefined();
    this.surnameAttributeName = new TextField();
    this.surnameAttributeName.setWidth("300px");
    this.surnameAttributeName.setRequired(true);

    gridLayout.addComponent(surnameAttributeNameLabel, 0, 18);
    gridLayout.setComponentAlignment(surnameAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.surnameAttributeName, 1, 18);

    final Label departmentAttributeNameLabel = new Label("User Department:");
    departmentAttributeNameLabel.setSizeUndefined();
    this.departmentAttributeName = new TextField();
    this.departmentAttributeName.setWidth("300px");
    this.departmentAttributeName.setRequired(true);

    gridLayout.addComponent(departmentAttributeNameLabel, 0, 19);
    gridLayout.setComponentAlignment(departmentAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.departmentAttributeName, 1, 19);

    final Label ldapUserDescriptionAttributeNameLabel = new Label("User Description:");
    ldapUserDescriptionAttributeNameLabel.setSizeUndefined();
    this.ldapUserDescriptionAttributeName = new TextField();
    this.ldapUserDescriptionAttributeName.setWidth("300px");
    this.ldapUserDescriptionAttributeName.setRequired(true);

    gridLayout.addComponent(ldapUserDescriptionAttributeNameLabel, 0, 20);
    gridLayout.setComponentAlignment(ldapUserDescriptionAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.ldapUserDescriptionAttributeName, 1, 20);

    final Label memberOfAttributeNameLabel = new Label("Member Of:");
    memberOfAttributeNameLabel.setSizeUndefined();
    this.memberofAttributeName = new TextField();
    this.memberofAttributeName.setWidth("300px");
    this.memberofAttributeName.setRequired(true);

    gridLayout.addComponent(memberOfAttributeNameLabel, 0, 21);
    gridLayout.setComponentAlignment(memberOfAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.memberofAttributeName, 1, 21);

    final Label applicationSecurityGroupAttributeNameLabel = new Label("Group Name:");
    applicationSecurityGroupAttributeNameLabel.setSizeUndefined();
    this.applicationSecurityGroupAttributeName = new TextField();
    this.applicationSecurityGroupAttributeName.setWidth("300px");
    this.applicationSecurityGroupAttributeName.setRequired(true);

    gridLayout.addComponent(applicationSecurityGroupAttributeNameLabel, 0, 22);
    gridLayout.setComponentAlignment(applicationSecurityGroupAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.applicationSecurityGroupAttributeName, 1, 22);

    final Label applicationSecurityAttributeNameLabel = new Label("Group Description:");
    applicationSecurityAttributeNameLabel.setSizeUndefined();
    this.applicationSecurityDescriptionAttributeName = new TextField();
    this.applicationSecurityDescriptionAttributeName.setWidth("300px");
    this.applicationSecurityDescriptionAttributeName.setRequired(true);

    gridLayout.addComponent(applicationSecurityAttributeNameLabel, 0, 23);
    gridLayout.setComponentAlignment(applicationSecurityAttributeNameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(this.applicationSecurityDescriptionAttributeName, 1, 23);

    final BeanItem<AuthenticationMethod> authenticationMethodItem = new BeanItem<AuthenticationMethod>(
            authenticationMethod);

    this.directoryName.setPropertyDataSource(authenticationMethodItem.getItemProperty("name"));
    this.ldapServerUrl.setPropertyDataSource(authenticationMethodItem.getItemProperty("ldapServerUrl"));
    this.ldapBindUserDn.setPropertyDataSource(authenticationMethodItem.getItemProperty("ldapBindUserDn"));
    this.ldapBindUserPassword
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("ldapBindUserPassword"));
    this.ldapUserSearchDn
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("ldapUserSearchBaseDn"));
    this.ldapUserSearchFilter
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("ldapUserSearchFilter"));
    this.emailAttributeName
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("emailAttributeName"));
    this.userAccountNameAttributeName
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("userAccountNameAttributeName"));
    this.accountTypeAttributeName
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("accountTypeAttributeName"));
    this.applicationSecurityBaseDn
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("applicationSecurityBaseDn"));
    this.applicationSecurityGroupAttributeName.setPropertyDataSource(
            authenticationMethodItem.getItemProperty("applicationSecurityGroupAttributeName"));
    this.departmentAttributeName
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("departmentAttributeName"));
    this.firstNameAttributeName
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("firstNameAttributeName"));
    this.surnameAttributeName
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("surnameAttributeName"));
    this.ldapUserDescriptionAttributeName.setPropertyDataSource(
            authenticationMethodItem.getItemProperty("ldapUserDescriptionAttributeName"));
    this.applicationSecurityDescriptionAttributeName.setPropertyDataSource(
            authenticationMethodItem.getItemProperty("applicationSecurityDescriptionAttributeName"));
    this.memberofAttributeName
            .setPropertyDataSource(authenticationMethodItem.getItemProperty("memberofAttributeName"));

    Button saveButton = new Button("Save");
    saveButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                logger.info("saving auth method: " + authenticationMethod);
                authenticationMethod.setMethod(SecurityConstants.AUTH_METHOD_LDAP);

                if (authenticationMethod.getOrder() == null) {
                    authenticationMethod.setOrder(securityService.getNumberOfAuthenticationMethods() + 1);
                }

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

                Notification.show("Error trying to save the authentication method!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            }

            Notification.show("Saved!");
        }
    });

    GridLayout buttonLayout = new GridLayout(1, 1);
    buttonLayout.setWidth("200px");
    buttonLayout.setHeight("20px");
    buttonLayout.addComponent(saveButton);

    gridLayout.addComponent(buttonLayout, 0, 24, 1, 24);

    VerticalLayout wrapperLayout = new VerticalLayout();
    wrapperLayout.addComponent(gridLayout);
    wrapperLayout.setComponentAlignment(gridLayout, Alignment.TOP_CENTER);

    securityAdministrationPanel.setContent(wrapperLayout);
    layout.addComponent(securityAdministrationPanel);
    this.setContent(layout);
}

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 ww  .  j  a v  a2s . 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 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.dashboard.panel.DashboardPanel.java

License:BSD License

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

    GridLayout gridLayout = new GridLayout(3, 2);
    gridLayout.setWidth("100%");
    gridLayout.setHeight("100%");
    gridLayout.setMargin(true);//from w ww.j a  v  a2  s .  co m

    VerticalLayout layout = new VerticalLayout();

    // Initialize the container as required by the container type
    container.addContainerProperty("Alert", String.class, null);
    container.addContainerProperty("Module", String.class, null);
    container.addContainerProperty("Details", PopupView.class, null);

    table.setContainerDataSource(container);
    table.setImmediate(true);
    table.addItemClickListener(new SearchResultTableItemClickListener());

    table.setHeight("100%");
    table.setWidth("100%");
    layout.setSizeFull();
    layout.addComponent(table);

    Panel p1 = new Panel("Alerts");
    p1.setStyleName("dashboard");
    p1.setWidth("90%");
    p1.setHeight("90%");
    p1.setContent(layout);

    gridLayout.addComponent(p1, 0, 0);

    Panel p2 = new Panel("Errors");
    p2.setStyleName("dashboard");
    p2.setWidth("90%");
    p2.setHeight("90%");

    gridLayout.addComponent(p2, 1, 0);

    VerticalLayout healthLayout = new VerticalLayout();

    // Initialize the container as required by the container type
    healthContainer.addContainerProperty("Health Alert", String.class, null);
    healthContainer.addContainerProperty("Module", String.class, null);

    healthTable.setContainerDataSource(healthContainer);
    healthTable.setImmediate(true);

    healthTable.setHeight("100%");
    healthTable.setWidth("100%");
    healthLayout.addComponent(healthTable);

    Panel p3 = new Panel("Health");
    p3.setStyleName("dashboard");
    p3.setWidth("90%");
    p3.setHeight("90%");
    p3.setContent(healthLayout);

    gridLayout.addComponent(p3, 2, 0);

    Panel p4 = new Panel("Topology");
    p4.setStyleName("dashboard");
    p4.setWidth("90%");
    p4.setHeight("90%");

    gridLayout.addComponent(p4, 0, 1);

    Panel p5 = new Panel("Dashboard Item 5");
    p5.setStyleName("dashboard");
    p5.setWidth("90%");
    p5.setHeight("90%");

    gridLayout.addComponent(p5, 1, 1);

    Panel p6 = new Panel("Dashboard Item 6");
    p6.setStyleName("dashboard");
    p6.setWidth("90%");
    p6.setHeight("90%");

    gridLayout.addComponent(p6, 2, 1);

    this.setContent(gridLayout);

    //        Broadcaster.register(this);
}

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();/* ww w . j  av a 2s  .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.mappingconfiguration.panel.MappingConfigurationPanel.java

License:BSD License

/**
 * Helper method to initialise this object.
 *///from w w  w. jav  a2 s  .  c om
@SuppressWarnings("serial")
protected void init() {
    layout = new GridLayout(5, 6);
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.setWidth("100%");

    this.addStyleName(ValoTheme.PANEL_BORDERLESS);

    paramQueriesLayout = new VerticalLayout();

    toolBarLayout = new HorizontalLayout();
    toolBarLayout.setWidth("100%");

    Button linkButton = new Button();

    linkButton.setIcon(VaadinIcons.REPLY_ALL);
    linkButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    linkButton.setDescription("Return to search results");
    linkButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    linkButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Navigator navigator = new Navigator(UI.getCurrent(), menuLayout.getContentContainer());

            for (IkasanUIView view : topLevelNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }

            saveRequiredMonitor.manageSaveRequired("mappingView");

            navigator = new Navigator(UI.getCurrent(), mappingNavigator.getContainer());

            for (IkasanUIView view : mappingNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }
        }
    });

    toolBarLayout.addComponent(linkButton);
    toolBarLayout.setExpandRatio(linkButton, 0.865f);

    this.editButton.setIcon(VaadinIcons.EDIT);
    this.editButton.setDescription("Edit the mapping configuration");
    this.editButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.editButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    this.editButton.setVisible(false);
    this.editButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            setEditable(true);
            mappingConfigurationFunctionalGroup.editButtonPressed();
        }
    });

    toolBarLayout.addComponent(this.editButton);
    toolBarLayout.setExpandRatio(this.editButton, 0.045f);

    this.saveButton.setIcon(VaadinIcons.HARDDRIVE);
    this.saveButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.saveButton.setDescription("Save the mapping configuration");
    this.saveButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    this.saveButton.setVisible(false);
    this.saveButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                logger.info("Save button clicked!!");
                save();
                setEditable(false);
                Notification.show("Changes Saved!", "", Notification.Type.HUMANIZED_MESSAGE);
                mappingConfigurationFunctionalGroup.saveOrCancelButtonPressed();
            } catch (InvalidValueException e) {
                // We can ignore this one as we have already dealt with the
                // validation messages using the validation framework.
            } catch (Exception e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Cauget exception trying to save a Mapping Configuration!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });

    toolBarLayout.addComponent(this.saveButton);
    toolBarLayout.setExpandRatio(this.saveButton, 0.045f);

    this.cancelButton.setIcon(VaadinIcons.CLOSE_CIRCLE);
    this.cancelButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.cancelButton.setDescription("Cancel the current edit");
    this.cancelButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    this.cancelButton.setVisible(false);
    this.cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            setEditable(false);
            mappingConfigurationFunctionalGroup.saveOrCancelButtonPressed();

            Navigator navigator = new Navigator(UI.getCurrent(), menuLayout.getContentContainer());

            for (IkasanUIView view : topLevelNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }

            saveRequiredMonitor.manageSaveRequired("mappingView");

            navigator = new Navigator(UI.getCurrent(), mappingNavigator.getContainer());

            for (IkasanUIView view : mappingNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }
        }
    });

    toolBarLayout.addComponent(this.cancelButton);
    toolBarLayout.setExpandRatio(this.cancelButton, 0.045f);

    FileDownloader fd = new FileDownloader(this.getMappingConfigurationExportStream());
    fd.extend(exportMappingConfigurationButton);

    this.exportMappingConfigurationButton.setIcon(VaadinIcons.DOWNLOAD_ALT);
    this.exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.exportMappingConfigurationButton.setDescription("Export the current mapping configuration");
    this.exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    toolBarLayout.addComponent(this.exportMappingConfigurationButton);
    toolBarLayout.setExpandRatio(this.exportMappingConfigurationButton, 0.045f);

    final GridLayout contentLayout = new GridLayout(1, 2);
    contentLayout.setWidth("100%");

    contentLayout.addComponent(toolBarLayout);
    contentLayout.addComponent(createMappingConfigurationForm());

    VerticalSplitPanel vpanel = new VerticalSplitPanel(contentLayout, createTableLayout(false));
    vpanel.setStyleName(ValoTheme.SPLITPANEL_LARGE);

    paramQueriesLayout.setSpacing(true);

    Label configValueLabels = new Label("Source Configuration Value Queries:");
    layout.addComponent(configValueLabels, 2, 2, 3, 2);
    Panel queryParamsPanel = new Panel();
    queryParamsPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    queryParamsPanel.setHeight(100, Unit.PIXELS);
    queryParamsPanel.setWidth(100, Unit.PERCENTAGE);
    queryParamsPanel.setContent(paramQueriesLayout);
    this.layout.addComponent(queryParamsPanel, 2, 3, 3, 5);

    vpanel.setSplitPosition(325, Unit.PIXELS);
    this.setContent(vpanel);
    this.setSizeFull();
}

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

License:BSD License

/**
 * Helper method to initialise this object.
 *///www  .j  a  v a  2s.c  om
@SuppressWarnings("serial")
protected void init() {
    layout = new GridLayout(5, 6);
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.setWidth("100%");

    this.addStyleName(ValoTheme.PANEL_BORDERLESS);

    this.parameterQueryTextFields = new ArrayList<TextField>();

    this.typeComboBox.setReadOnly(false);
    this.clientComboBox.setReadOnly(false);
    this.sourceContextComboBox.setReadOnly(false);
    this.targetContextComboBox.setReadOnly(false);
    super.clientComboBox.unselect(super.clientComboBox.getValue());
    super.sourceContextComboBox.unselect(super.sourceContextComboBox.getValue());
    super.targetContextComboBox.unselect(super.targetContextComboBox.getValue());
    super.typeComboBox.unselect(super.typeComboBox.getValue());

    super.mappingConfigurationFunctionalGroup.editButtonPressed();

    super.mappingConfiguration = new MappingConfiguration();
    this.mappingConfigurationConfigurationValuesTable.populateTable(mappingConfiguration);

    HorizontalLayout toolBarLayout = new HorizontalLayout();
    toolBarLayout.setWidth("100%");

    Label spacerLabel = new Label("");
    toolBarLayout.addComponent(spacerLabel);
    toolBarLayout.setExpandRatio(spacerLabel, 0.865f);

    this.editButton.setIcon(VaadinIcons.EDIT);
    this.editButton.setDescription("Edit the mapping configuration");
    this.editButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.editButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    toolBarLayout.addComponent(editButton);
    toolBarLayout.setExpandRatio(editButton, 0.045f);

    this.saveButton.setIcon(VaadinIcons.HARDDRIVE);
    this.saveButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.saveButton.setDescription("Save the mapping configuration");
    this.saveButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    toolBarLayout.addComponent(saveButton);
    toolBarLayout.setExpandRatio(saveButton, 0.045f);

    this.cancelButton.setIcon(VaadinIcons.CLOSE_CIRCLE);
    this.cancelButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.cancelButton.setDescription("Cancel the current edit");
    this.cancelButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    toolBarLayout.addComponent(this.cancelButton);
    toolBarLayout.setExpandRatio(this.cancelButton, 0.045f);

    final VerticalLayout contentLayout = new VerticalLayout();

    contentLayout.addComponent(toolBarLayout);
    contentLayout.addComponent(createMappingConfigurationForm());

    VerticalSplitPanel vpanel = new VerticalSplitPanel(contentLayout, createTableLayout(false));
    vpanel.setStyleName(ValoTheme.SPLITPANEL_LARGE);

    Button addParametersButton = new Button();
    addParametersButton.setIcon(VaadinIcons.FORM);
    addParametersButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    addParametersButton.setDescription(
            "Add new key location queries. The number of fields created corresponds to the number of query parameters.");
    addParametersButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    addParametersButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            addParamQueryFields();
        }
    });

    paramQueriesLayout.removeAllComponents();
    //        paramQueriesLayout.addComponent(addParametersButton);
    paramQueriesLayout.setSpacing(true);

    Label configValueLabels = new Label("Source Configuration Value Queries:");
    layout.addComponent(configValueLabels, 2, 2);
    layout.addComponent(addParametersButton, 3, 2);

    Panel queryParamsPanel = new Panel();
    queryParamsPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    queryParamsPanel.setHeight(140, Unit.PIXELS);
    queryParamsPanel.setWidth(100, Unit.PERCENTAGE);
    queryParamsPanel.setContent(paramQueriesLayout);
    this.layout.addComponent(queryParamsPanel, 2, 3, 3, 5);

    vpanel.setSplitPosition(325, Unit.PIXELS);
    this.setContent(vpanel);
    this.setSizeFull();

}