Example usage for com.vaadin.ui GridLayout addComponent

List of usage examples for com.vaadin.ui GridLayout addComponent

Introduction

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

Prototype

public void addComponent(Component component, int column, int row)
        throws OverlapsException, OutOfBoundsException 

Source Link

Document

Adds the component to the grid in cells column1,row1 (NortWest corner of the area.) End coordinates (SouthEast corner of the area) are the same as column1,row1.

Usage

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

License:BSD License

protected void populateDirectoryTable(final AuthenticationMethod authenticationMethod) {
    Button test = new Button("Test");
    test.setStyleName(BaseTheme.BUTTON_LINK);
    test.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                authenticationProviderFactory.testAuthenticationConnection(authenticationMethod);
            } catch (RuntimeException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);//from  w ww.ja  va 2 s .  com

                Notification.show("Error occurred while testing connection!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

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

                Notification.show("Error occurred while testing connection!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            }

            Notification.show("Connection Successful!");
        }
    });

    final Button enableDisableButton = new Button();

    if (authenticationMethod.isEnabled()) {
        enableDisableButton.setCaption("Disable");
    } else {
        enableDisableButton.setCaption("Enable");
    }
    enableDisableButton.setStyleName(BaseTheme.BUTTON_LINK);
    enableDisableButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                if (authenticationMethod.isEnabled()) {
                    authenticationMethod.setEnabled(false);
                } else {
                    authenticationMethod.setEnabled(true);
                }

                securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

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

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

                return;
            }

            if (authenticationMethod.isEnabled()) {
                enableDisableButton.setCaption("Disable");
                Notification.show("Enabled!");
            } else {
                enableDisableButton.setCaption("Enable");
                Notification.show("Disabled!");
            }
        }
    });

    Button delete = new Button("Delete");
    delete.setStyleName(BaseTheme.BUTTON_LINK);
    delete.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                securityService.deleteAuthenticationMethod(authenticationMethod);

                List<AuthenticationMethod> authenticationMethods = securityService.getAuthenticationMethods();

                directoryTable.removeAllItems();

                long order = 1;

                for (final AuthenticationMethod authenticationMethod : authenticationMethods) {
                    authenticationMethod.setOrder(order++);
                    securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);
                }

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

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

                return;
            }

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

    Button edit = new Button("Edit");
    edit.setStyleName(BaseTheme.BUTTON_LINK);
    edit.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            UserDirectoryManagementPanel authMethodPanel = new UserDirectoryManagementPanel(
                    authenticationMethod, securityService, authenticationProviderFactory, ldapService);

            Window window = new Window("Configure User Directory");
            window.setModal(true);
            window.setHeight("90%");
            window.setWidth("90%");

            window.setContent(authMethodPanel);

            UI.getCurrent().addWindow(window);
        }
    });

    Button synchronise = new Button("Synchronise");
    synchronise.setStyleName(BaseTheme.BUTTON_LINK);

    synchronise.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                ldapService.synchronize(authenticationMethod);

                authenticationMethod.setLastSynchronised(new Date());
                securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

                populateAll();
            } catch (UnexpectedRollbackException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                logger.error("Most specific cause: " + e.getMostSpecificCause());
                e.getMostSpecificCause().printStackTrace();
                logger.error("Most specific cause: " + e.getRootCause());
                e.getRootCause().printStackTrace();

                Notification.show("Error occurred while synchronizing!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

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

                Notification.show("Error occurred while synchronizing!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

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

                Notification.show("Error occurred while synchronizing!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            }

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

    GridLayout operationsLayout = new GridLayout(9, 2);
    operationsLayout.setWidth("250px");
    operationsLayout.addComponent(enableDisableButton, 0, 0);
    operationsLayout.addComponent(new Label(" "), 1, 0);
    operationsLayout.addComponent(edit, 2, 0);
    operationsLayout.addComponent(new Label(" "), 3, 0);
    operationsLayout.addComponent(delete, 4, 0);
    operationsLayout.addComponent(new Label(" "), 5, 0);
    operationsLayout.addComponent(test, 6, 0);
    operationsLayout.addComponent(new Label(" "), 7, 0);
    operationsLayout.addComponent(synchronise, 8, 0);

    TextArea synchronisedTextArea = new TextArea();
    synchronisedTextArea.setRows(3);
    synchronisedTextArea.setWordwrap(true);

    if (authenticationMethod.getLastSynchronised() != null) {
        synchronisedTextArea.setValue(
                "This directory was last synchronised at " + authenticationMethod.getLastSynchronised());
    } else {
        synchronisedTextArea.setValue("This directory has not been synchronised");
    }

    synchronisedTextArea.setSizeFull();
    synchronisedTextArea.setReadOnly(true);

    operationsLayout.addComponent(synchronisedTextArea, 0, 1, 8, 1);

    HorizontalLayout orderLayout = new HorizontalLayout();
    orderLayout.setWidth("50%");

    if (authenticationMethod.getOrder() != 1) {
        Button upArrow = new Button(VaadinIcons.ARROW_UP);
        upArrow.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        upArrow.addStyleName(ValoTheme.BUTTON_BORDERLESS);
        upArrow.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                if (authenticationMethod.getOrder() != 1) {
                    AuthenticationMethod upAuthMethod = securityService
                            .getAuthenticationMethodByOrder(authenticationMethod.getOrder() - 1);

                    upAuthMethod.setOrder(authenticationMethod.getOrder());
                    authenticationMethod.setOrder(authenticationMethod.getOrder() - 1);

                    securityService.saveOrUpdateAuthenticationMethod(upAuthMethod);
                    securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

                    populateAll();
                }
            }
        });

        orderLayout.addComponent(upArrow);
    }

    long numberOfAuthMethods = securityService.getNumberOfAuthenticationMethods();

    if (authenticationMethod.getOrder() != numberOfAuthMethods) {
        Button downArrow = new Button(VaadinIcons.ARROW_DOWN);
        downArrow.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        downArrow.addStyleName(ValoTheme.BUTTON_BORDERLESS);
        downArrow.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                long numberOfAuthMethods = securityService.getNumberOfAuthenticationMethods();

                if (authenticationMethod.getOrder() != numberOfAuthMethods) {
                    AuthenticationMethod downAuthMethod = securityService
                            .getAuthenticationMethodByOrder(authenticationMethod.getOrder() + 1);

                    downAuthMethod.setOrder(authenticationMethod.getOrder());
                    authenticationMethod.setOrder(authenticationMethod.getOrder() + 1);

                    securityService.saveOrUpdateAuthenticationMethod(downAuthMethod);
                    securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

                    populateAll();
                }
            }
        });

        orderLayout.addComponent(downArrow);
    }

    this.directoryTable.addItem(new Object[] { authenticationMethod.getName(), "Microsoft Active Directory",
            orderLayout, operationsLayout }, authenticationMethod);
}

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);// ww  w  .  jav  a2 s .  co  m

    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.window.PolicyAssociationFlowSearchWindow.java

License:BSD License

private void createSearchPanel() {
    this.searchPanel = new Panel();
    this.searchPanel.setSizeFull();
    this.searchPanel.setStyleName("dashboard");

    GridLayout layout = new GridLayout(2, 3);
    layout.setWidth("100%");
    layout.setHeight("180px");
    layout.setMargin(true);/*w  w w.  j  a  v a 2  s  .  c  o m*/

    Label serverLabel = new Label("Server");
    layout.addComponent(serverLabel, 0, 0);
    layout.addComponent(this.serverCombo, 1, 0);

    Label moduleLabel = new Label("Module");

    layout.addComponent(moduleLabel, 0, 1);
    layout.addComponent(this.moduleCombo, 1, 1);

    Button searchButton = new Button("Search");
    searchButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Module module = (Module) moduleCombo.getValue();
            Server server = (Server) serverCombo.getValue();

            Long moduleId = null;
            Long serverId = null;

            if (module != null) {
                moduleId = module.getId();
            }

            if (server != null) {
                serverId = server.getId();
            }

            List<Flow> flows = topologyService.getFlowsByServerIdAndModuleId(serverId, moduleId);
            resultsTable.removeAllItems();

            for (Flow flow : flows) {
                resultsTable.addItem(new Object[] { flow.getModule().getServer().getName(),
                        flow.getModule().getName(), flow.getName() }, flow);
            }
        }
    });

    layout.addComponent(searchButton, 0, 2, 1, 2);
    layout.setComponentAlignment(searchButton, Alignment.MIDDLE_CENTER);

    this.searchPanel.setContent(layout);
}

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

License:BSD License

private void createSearchPanel() {
    this.searchPanel = new Panel();
    this.searchPanel.setSizeFull();
    this.searchPanel.setStyleName("dashboard");

    GridLayout layout = new GridLayout(2, 2);
    layout.setWidth("100%");
    layout.setHeight("120px");
    layout.setMargin(true);/*from   w ww  .j  av  a 2  s .c o  m*/

    Label serverLabel = new Label("Server");
    layout.addComponent(serverLabel, 0, 0);
    layout.addComponent(this.serverCombo, 1, 0);

    Button searchButton = new Button("Search");
    searchButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Server server = (Server) serverCombo.getValue();

            Long moduleId = null;
            Long serverId = null;

            if (module != null) {
                moduleId = module.getId();
            }

            if (server != null) {
                serverId = server.getId();
            }

            List<Module> modules = topologyService.getAllModules();
            resultsTable.removeAllItems();

            for (Module module : modules) {
                resultsTable.addItem(new Object[] { module.getServer().getName(), module.getName(),
                        module.getDescription() }, module);
            }
        }
    });

    layout.addComponent(searchButton, 0, 1, 1, 1);
    layout.setComponentAlignment(searchButton, Alignment.MIDDLE_CENTER);

    this.searchPanel.setContent(layout);
}

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);//  ww  w . jav a 2s  .  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.mappingconfiguration.panel.MappingConfigurationView.java

License:BSD License

/**
 * Helper method to initialise this object.
 *//*from ww w .jav  a2  s. c  om*/
protected void init() {
    this.setSizeFull();

    HorizontalLayout topContainer = new HorizontalLayout();
    topContainer.setSizeFull();
    topContainer.setMargin(true);
    topContainer.addComponent(this.searchPanel);
    HorizontalLayout bottomContainer = new HorizontalLayout();
    bottomContainer.setMargin(true);
    bottomContainer.setSizeFull();
    bottomContainer.addComponent(this.viewComponentContainer);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = verticalSplitPanel.getSplitPosition();
            splitUnit = verticalSplitPanel.getSplitPositionUnit();
            verticalSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            verticalSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    this.verticalSplitPanel = new VerticalSplitPanel(topContainer, bottomContainer);
    this.verticalSplitPanel.addStyleName(ValoTheme.SPLITPANEL_LARGE);
    this.verticalSplitPanel.setSizeFull();
    this.verticalSplitPanel.setSplitPosition(260, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(verticalSplitPanel);

    this.setContent(wrapper);
}

From source file:org.ikasan.dashboard.ui.monitor.component.MonitorPanel.java

License:BSD License

public Component buildServerComponent() {
    Panel component = new Panel();
    component.setSizeFull();//from  www.ja  v  a 2  s .  co  m
    component.addStyleName(ValoTheme.PANEL_BORDERLESS);

    GridLayout layout = new GridLayout(2, 4);
    layout.setSizeFull();
    layout.setMargin(true);

    Label serverNameLabel = new Label(server.getName());
    serverNameLabel.setStyleName(ValoTheme.LABEL_LARGE);
    serverNameLabel.setWidth("100%");
    Label serverDescriptionLabel = new Label(server.getDescription());
    serverDescriptionLabel.setWidth("100%");
    serverDescriptionLabel.setStyleName(ValoTheme.LABEL_LARGE);
    Label serverUrlLabel = new Label(server.getUrl() + ":" + server.getPort());
    serverUrlLabel.setStyleName(ValoTheme.LABEL_LARGE);
    serverUrlLabel.setWidth("100%");

    layout.addComponent(serverNameLabel, 0, 0);
    layout.addComponent(serverDescriptionLabel, 0, 1);
    layout.addComponent(serverUrlLabel, 0, 2);

    statusLabel.setCaptionAsHtml(true);

    MonitorIcons icon = MonitorIcons.SERVER;
    icon.setSizePixels(64);

    Label serverLabel = new Label();
    serverLabel.setCaption(icon.getHtml());
    serverLabel.setCaptionAsHtml(true);

    layout.addComponent(serverLabel, 1, 0, 1, 2);
    layout.setComponentAlignment(serverLabel, Alignment.MIDDLE_CENTER);

    layout.addComponent(statusLabel, 0, 3, 1, 3);
    layout.setComponentAlignment(statusLabel, Alignment.MIDDLE_CENTER);

    buildFilterTable();

    component.setContent(layout);

    Component contentWrapper = createContentWrapper(component, buildFilterTable());

    contentWrapper.addStyleName("top10-revenue");
    return contentWrapper;
}

From source file:org.ikasan.dashboard.ui.topology.component.ActionedExclusionTab.java

License:BSD License

public Layout createLayout() {
    this.actionedExclusionsTable = new Table();
    this.actionedExclusionsTable.setSizeFull();
    this.actionedExclusionsTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    this.actionedExclusionsTable.addContainerProperty("Module Name", String.class, null);
    this.actionedExclusionsTable.addContainerProperty("Flow Name", String.class, null);
    this.actionedExclusionsTable.addContainerProperty("Action", String.class, null);
    this.actionedExclusionsTable.addContainerProperty("Actioned By", String.class, null);
    this.actionedExclusionsTable.addContainerProperty("Timestamp", String.class, null);

    this.actionedExclusionsTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override// w  w w  .j  a  v  a  2 s  .c o m
        public void itemClick(ItemClickEvent itemClickEvent) {
            ExclusionEventAction exclusionEventAction = (ExclusionEventAction) itemClickEvent.getItemId();

            ErrorOccurrence errorOccurrence = (ErrorOccurrence) errorReportingService
                    .find(exclusionEventAction.getErrorUri());
            ExclusionEventAction action = hospitalManagementService
                    .getExclusionEventActionByErrorUri(exclusionEventAction.getErrorUri());
            ActionedExclusionEventViewWindow actionExclusionEventViewWindow = new ActionedExclusionEventViewWindow(
                    errorOccurrence, serialiserFactory, action, hospitalManagementService, topologyService);

            UI.getCurrent().addWindow(actionExclusionEventViewWindow);
        }
    });

    Button searchButton = new Button("Search");
    searchButton.setStyleName(ValoTheme.BUTTON_SMALL);
    searchButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            actionedExclusionsTable.removeAllItems();

            ArrayList<String> modulesNames = null;

            if (errorOccurenceModules.getItemIds().size() > 0) {
                modulesNames = new ArrayList<String>();
                for (Object module : errorOccurenceModules.getItemIds()) {
                    modulesNames.add(((Module) module).getName());
                }
            }

            ArrayList<String> flowNames = null;

            if (errorOccurenceFlows.getItemIds().size() > 0) {
                flowNames = new ArrayList<String>();
                for (Object flow : errorOccurenceFlows.getItemIds()) {
                    flowNames.add(((Flow) flow).getName());
                }
            }

            ArrayList<String> componentNames = null;

            if (errorOccurenceComponents.getItemIds().size() > 0) {
                componentNames = new ArrayList<String>();
                for (Object component : errorOccurenceComponents.getItemIds()) {
                    componentNames.add(((Component) component).getName());
                }
            }

            if (modulesNames == null && flowNames == null && componentNames == null
                    && !((BusinessStream) businessStreamCombo.getValue()).getName().equals("All")) {
                BusinessStream businessStream = ((BusinessStream) businessStreamCombo.getValue());

                modulesNames = new ArrayList<String>();

                for (BusinessStreamFlow flow : businessStream.getFlows()) {
                    modulesNames.add(flow.getFlow().getModule().getName());
                }
            }

            List<ExclusionEventAction> exclusionEventActions = hospitalManagementService
                    .getActionedExclusions(modulesNames, flowNames, fromDate.getValue(), toDate.getValue());

            for (ExclusionEventAction exclusionEventAction : exclusionEventActions) {
                Date date = new Date(exclusionEventAction.getTimestamp());
                SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
                String timestamp = format.format(date);

                actionedExclusionsTable
                        .addItem(
                                new Object[] { exclusionEventAction.getModuleName(),
                                        exclusionEventAction.getFlowName(), exclusionEventAction.getAction(),
                                        exclusionEventAction.getActionedBy(), timestamp },
                                exclusionEventAction);
            }
        }
    });

    Button clearButton = new Button("Clear");
    clearButton.setStyleName(ValoTheme.BUTTON_SMALL);
    clearButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            errorOccurenceModules.removeAllItems();
            errorOccurenceFlows.removeAllItems();
            errorOccurenceComponents.removeAllItems();
        }
    });

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(false);
    layout.setHeight(270, Unit.PIXELS);

    GridLayout listSelectLayout = new GridLayout(3, 1);
    listSelectLayout.setSpacing(true);
    listSelectLayout.setSizeFull();

    errorOccurenceModules.setIcon(VaadinIcons.ARCHIVE);
    errorOccurenceModules.addContainerProperty("Module Name", String.class, null);
    errorOccurenceModules.addContainerProperty("", Button.class, null);
    errorOccurenceModules.setSizeFull();
    errorOccurenceModules.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceModules.setDragMode(TableDragMode.ROW);
    errorOccurenceModules.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Module) {
                final Module module = (Module) t.getItemId();
                logger.info("sourceContainer.getText(): " + module.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceModules.removeItem(module);
                    }
                });

                errorOccurenceModules.addItem(new Object[] { module.getName(), deleteButton }, module);

                for (final Flow flow : module.getFlows()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceFlows.removeItem(flow);
                        }
                    });

                    errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                    for (final Component component : flow.getComponents()) {
                        deleteButton = new Button();
                        deleteButton.setIcon(VaadinIcons.TRASH);
                        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                        // Add the delete functionality to each role that is added
                        deleteButton.addClickListener(new Button.ClickListener() {
                            public void buttonClick(ClickEvent event) {
                                errorOccurenceComponents.removeItem(component);
                            }
                        });

                        errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                                component);
                    }
                }
            }

        }

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

    listSelectLayout.addComponent(errorOccurenceModules, 0, 0);

    errorOccurenceFlows.setIcon(VaadinIcons.AUTOMATION);
    errorOccurenceFlows.addContainerProperty("Flow Name", String.class, null);
    errorOccurenceFlows.addContainerProperty("", Button.class, null);
    errorOccurenceFlows.setSizeFull();
    errorOccurenceFlows.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceFlows.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();
                logger.info("sourceContainer.getText(): " + flow.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceFlows.removeItem(flow);
                    }
                });

                errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                for (final Component component : flow.getComponents()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceComponents.removeItem(component);
                        }
                    });

                    errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                            component);
                }
            }

        }

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

    listSelectLayout.addComponent(errorOccurenceFlows, 1, 0);

    errorOccurenceComponents.setIcon(VaadinIcons.COG);
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.addContainerProperty("Component Name", String.class, null);
    errorOccurenceComponents.addContainerProperty("", Button.class, null);
    errorOccurenceComponents.setCellStyleGenerator(new IkasanCellStyleGenerator());
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceComponents.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Component) {
                final Component component = (Component) t.getItemId();
                logger.info("sourceContainer.getText(): " + component.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceComponents.removeItem(component);
                    }
                });

                errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton }, component);

            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
    listSelectLayout.addComponent(this.errorOccurenceComponents, 2, 0);

    GridLayout dateSelectLayout = new GridLayout(2, 1);

    dateSelectLayout.setSizeFull();
    fromDate = new PopupDateField("From date");
    fromDate.setResolution(Resolution.MINUTE);
    fromDate.setValue(this.getMidnightToday());
    dateSelectLayout.addComponent(fromDate, 0, 0);
    toDate = new PopupDateField("To date");
    toDate.setResolution(Resolution.MINUTE);
    toDate.setValue(this.getTwentyThreeFixtyNineToday());
    dateSelectLayout.addComponent(toDate, 1, 0);

    final VerticalSplitPanel vSplitPanel = new VerticalSplitPanel();
    vSplitPanel.setHeight("95%");

    GridLayout searchLayout = new GridLayout(2, 1);
    searchLayout.setSpacing(true);
    searchLayout.addComponent(searchButton, 0, 0);
    searchLayout.addComponent(clearButton, 1, 0);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    final HorizontalLayout hListSelectLayout = new HorizontalLayout();
    hListSelectLayout.setHeight(150, Unit.PIXELS);
    hListSelectLayout.setWidth("100%");
    hListSelectLayout.addComponent(listSelectLayout);

    final HorizontalLayout hDateSelectLayout = new HorizontalLayout();
    hDateSelectLayout.setHeight(40, Unit.PIXELS);
    hDateSelectLayout.setWidth("100%");
    hDateSelectLayout.addComponent(dateSelectLayout);

    final HorizontalLayout hSearchLayout = new HorizontalLayout();
    hSearchLayout.setHeight(30, Unit.PIXELS);
    hSearchLayout.setWidth("100%");
    hSearchLayout.addComponent(searchLayout);
    hSearchLayout.setComponentAlignment(searchLayout, Alignment.MIDDLE_CENTER);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = vSplitPanel.getSplitPosition();
            splitUnit = vSplitPanel.getSplitPositionUnit();
            vSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            vSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    Label filterHintLabel = new Label();
    filterHintLabel.setCaptionAsHtml(true);
    filterHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag items from the topology tree to the tables below in order to narrow your search.");
    filterHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    filterHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(filterHintLabel);
    layout.addComponent(hListSelectLayout);
    layout.addComponent(hDateSelectLayout);
    layout.addComponent(hSearchLayout);
    layout.setSizeFull();

    Panel filterPanel = new Panel();
    filterPanel.setHeight(300, Unit.PIXELS);
    filterPanel.setWidth("100%");
    filterPanel.setContent(layout);
    filterPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);

    vSplitPanel.setFirstComponent(filterPanel);

    CssLayout hErrorTable = new CssLayout();
    hErrorTable.setSizeFull();
    hErrorTable.addComponent(this.actionedExclusionsTable);

    vSplitPanel.setSecondComponent(hErrorTable);
    vSplitPanel.setSplitPosition(310, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(vSplitPanel);

    return wrapper;
}

From source file:org.ikasan.dashboard.ui.topology.component.CategorisedErrorTab.java

License:BSD License

public Layout createCategorisedErrorLayout() {
    this.categorizedErrorOccurenceTable = new FilterTable();
    this.categorizedErrorOccurenceTable.setSizeFull();
    this.categorizedErrorOccurenceTable.addContainerProperty("", Label.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("", .03f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Module Name", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Module Name", .15f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Flow Name", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Flow Name", .18f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Component Name", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Component Name", .2f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Error Message", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Error Message", .33f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Timestamp", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Timestamp", .1f);

    this.categorizedErrorOccurenceTable.addStyleName("wordwrap-table");
    this.categorizedErrorOccurenceTable.addStyleName(ValoTheme.TABLE_NO_STRIPES);

    //      this.categorizedErrorOccurenceTable.setFilterBarVisible(true);

    this.categorizedErrorOccurenceTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override/*from w ww.  java  2s  .c o m*/
        public void itemClick(ItemClickEvent itemClickEvent) {
            CategorisedErrorOccurrence errorOccurrence = (CategorisedErrorOccurrence) itemClickEvent
                    .getItemId();
            CategorisedErrorOccurrenceViewWindow errorOccurrenceViewWindow = new CategorisedErrorOccurrenceViewWindow(
                    errorOccurrence, serialiserFactory);

            UI.getCurrent().addWindow(errorOccurrenceViewWindow);
        }
    });

    this.categorizedErrorOccurenceTable.setCellStyleGenerator(new CustomTable.CellStyleGenerator() {
        @Override
        public String getStyle(CustomTable source, Object itemId, Object propertyId) {

            CategorisedErrorOccurrence categorisedErrorOccurrence = (CategorisedErrorOccurrence) itemId;

            if (propertyId == null) {
                // Styling for row         

                if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.TRIVIAL)) {
                    return "ikasan-green-small";
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.MAJOR)) {
                    return "ikasan-green-small";
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.CRITICAL)) {
                    return "ikasan-orange-small";
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.BLOCKER)) {
                    return "ikasan-red-small";
                }
            }

            if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.TRIVIAL)) {
                return "ikasan-green-small";
            } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.MAJOR)) {
                return "ikasan-green-small";
            } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.CRITICAL)) {
                return "ikasan-orange-small";
            } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.BLOCKER)) {
                return "ikasan-red-small";
            }

            return "ikasan-small";
        }
    });

    Button searchButton = new Button("Search");
    searchButton.setStyleName(ValoTheme.BUTTON_SMALL);
    searchButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            categorizedErrorOccurenceTable.removeAllItems();

            ArrayList<String> modulesNames = null;

            if (errorOccurenceModules.getItemIds().size() > 0) {
                modulesNames = new ArrayList<String>();
                for (Object module : errorOccurenceModules.getItemIds()) {
                    modulesNames.add(((Module) module).getName());
                }
            }

            ArrayList<String> flowNames = null;

            if (errorOccurenceFlows.getItemIds().size() > 0) {
                flowNames = new ArrayList<String>();
                for (Object flow : errorOccurenceFlows.getItemIds()) {
                    flowNames.add(((Flow) flow).getName());
                }
            }

            ArrayList<String> componentNames = null;

            if (errorOccurenceComponents.getItemIds().size() > 0) {
                componentNames = new ArrayList<String>();
                for (Object component : errorOccurenceComponents.getItemIds()) {
                    componentNames.add(((Component) component).getName());
                }
            }

            if (modulesNames == null && flowNames == null && componentNames == null
                    && !((BusinessStream) businessStreamCombo.getValue()).getName().equals("All")) {
                BusinessStream businessStream = ((BusinessStream) businessStreamCombo.getValue());

                modulesNames = new ArrayList<String>();

                for (BusinessStreamFlow flow : businessStream.getFlows()) {
                    modulesNames.add(flow.getFlow().getModule().getName());
                }
            }

            String errorCategory = null;

            if (errorCategoryCombo != null && errorCategoryCombo.getValue() != null) {
                errorCategory = (String) errorCategoryCombo.getValue();
            }

            List<CategorisedErrorOccurrence> categorisedErrorOccurences = errorCategorisationService
                    .findCategorisedErrorOccurences(modulesNames, flowNames, componentNames, "", "",
                            errorCategory, errorFromDate.getValue(), errorToDate.getValue());

            for (CategorisedErrorOccurrence categorisedErrorOccurrence : categorisedErrorOccurences) {
                ErrorOccurrence errorOccurrence = categorisedErrorOccurrence.getErrorOccurrence();

                Date date = new Date(errorOccurrence.getTimestamp());
                SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
                String timestamp = format.format(date);

                Label categoryLabel = new Label();

                if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.BLOCKER)) {
                    categoryLabel = new Label(VaadinIcons.BAN.getHtml(), ContentMode.HTML);
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.CRITICAL)) {
                    categoryLabel = new Label(VaadinIcons.EXCLAMATION.getHtml(), ContentMode.HTML);
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.MAJOR)) {
                    categoryLabel = new Label(VaadinIcons.ARROW_UP.getHtml(), ContentMode.HTML);
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.TRIVIAL)) {
                    categoryLabel = new Label(VaadinIcons.ARROW_DOWN.getHtml(), ContentMode.HTML);
                }

                categorizedErrorOccurenceTable
                        .addItem(
                                new Object[] { categoryLabel, errorOccurrence.getModuleName(),
                                        errorOccurrence.getFlowName(), errorOccurrence.getFlowElementName(),
                                        categorisedErrorOccurrence.getErrorCategorisation()
                                                .getErrorDescription(),
                                        timestamp },
                                categorisedErrorOccurrence);
            }
        }
    });

    Button clearButton = new Button("Clear");
    clearButton.setStyleName(ValoTheme.BUTTON_SMALL);
    clearButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            errorOccurenceModules.removeAllItems();
            errorOccurenceFlows.removeAllItems();
            errorOccurenceComponents.removeAllItems();
        }
    });

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(false);
    layout.setHeight(270, Unit.PIXELS);

    GridLayout listSelectLayout = new GridLayout(3, 1);
    listSelectLayout.setSpacing(true);
    listSelectLayout.setSizeFull();

    errorOccurenceModules.setIcon(VaadinIcons.ARCHIVE);
    errorOccurenceModules.addContainerProperty("Module Name", String.class, null);
    errorOccurenceModules.addContainerProperty("", Button.class, null);
    errorOccurenceModules.setSizeFull();
    errorOccurenceModules.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceModules.setDragMode(TableDragMode.ROW);
    errorOccurenceModules.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Module) {
                final Module module = (Module) t.getItemId();
                logger.info("sourceContainer.getText(): " + module.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceModules.removeItem(module);
                    }
                });

                errorOccurenceModules.addItem(new Object[] { module.getName(), deleteButton }, module);

                for (final Flow flow : module.getFlows()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceFlows.removeItem(flow);
                        }
                    });

                    errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                    for (final Component component : flow.getComponents()) {
                        deleteButton = new Button();
                        deleteButton.setIcon(VaadinIcons.TRASH);
                        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                        // Add the delete functionality to each role that is added
                        deleteButton.addClickListener(new Button.ClickListener() {
                            public void buttonClick(ClickEvent event) {
                                errorOccurenceComponents.removeItem(component);
                            }
                        });

                        errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                                component);
                    }
                }
            }

        }

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

    listSelectLayout.addComponent(errorOccurenceModules, 0, 0);

    errorOccurenceFlows.setIcon(VaadinIcons.AUTOMATION);
    errorOccurenceFlows.addContainerProperty("Flow Name", String.class, null);
    errorOccurenceFlows.addContainerProperty("", Button.class, null);
    errorOccurenceFlows.setSizeFull();
    errorOccurenceFlows.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceFlows.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();
                logger.info("sourceContainer.getText(): " + flow.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceFlows.removeItem(flow);
                    }
                });

                errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                for (final Component component : flow.getComponents()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceComponents.removeItem(component);
                        }
                    });

                    errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                            component);
                }
            }

        }

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

    listSelectLayout.addComponent(errorOccurenceFlows, 1, 0);

    errorOccurenceComponents.setIcon(VaadinIcons.COG);
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.addContainerProperty("Component Name", String.class, null);
    errorOccurenceComponents.addContainerProperty("", Button.class, null);
    errorOccurenceComponents.setCellStyleGenerator(new IkasanCellStyleGenerator());
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceComponents.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Component) {
                final Component component = (Component) t.getItemId();
                logger.info("sourceContainer.getText(): " + component.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceComponents.removeItem(component);
                    }
                });

                errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton }, component);

            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
    listSelectLayout.addComponent(this.errorOccurenceComponents, 2, 0);

    errorCategoryCombo = new ComboBox("Error Category");
    errorCategoryCombo.setNullSelectionAllowed(true);
    errorCategoryCombo.addItem(ErrorCategorisation.TRIVIAL);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.TRIVIAL, VaadinIcons.ARROW_DOWN);
    errorCategoryCombo.addItem(ErrorCategorisation.MAJOR);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.MAJOR, VaadinIcons.ARROW_UP);
    errorCategoryCombo.addItem(ErrorCategorisation.CRITICAL);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.CRITICAL, VaadinIcons.EXCLAMATION_CIRCLE_O);
    errorCategoryCombo.addItem(ErrorCategorisation.BLOCKER);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.BLOCKER, VaadinIcons.BAN);

    GridLayout dateSelectLayout = new GridLayout(3, 1);
    dateSelectLayout.addComponent(errorCategoryCombo, 2, 0);
    dateSelectLayout.setSizeFull();
    errorFromDate = new PopupDateField("From date");
    errorFromDate.setResolution(Resolution.MINUTE);
    errorFromDate.setValue(this.getMidnightToday());
    dateSelectLayout.addComponent(errorFromDate, 0, 0);
    errorToDate = new PopupDateField("To date");
    errorToDate.setResolution(Resolution.MINUTE);
    errorToDate.setValue(this.getTwentyThreeFixtyNineToday());
    dateSelectLayout.addComponent(errorToDate, 1, 0);

    final VerticalSplitPanel vSplitPanel = new VerticalSplitPanel();
    vSplitPanel.setHeight("95%");

    GridLayout searchLayout = new GridLayout(2, 1);
    searchLayout.setSpacing(true);
    searchLayout.addComponent(searchButton, 0, 0);
    searchLayout.addComponent(clearButton, 1, 0);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    final HorizontalLayout hListSelectLayout = new HorizontalLayout();
    hListSelectLayout.setHeight(150, Unit.PIXELS);
    hListSelectLayout.setWidth("100%");
    hListSelectLayout.addComponent(listSelectLayout);

    final HorizontalLayout hDateSelectLayout = new HorizontalLayout();
    hDateSelectLayout.setHeight(40, Unit.PIXELS);
    hDateSelectLayout.setWidth("100%");
    hDateSelectLayout.addComponent(dateSelectLayout);

    final HorizontalLayout hSearchLayout = new HorizontalLayout();
    hSearchLayout.setHeight(30, Unit.PIXELS);
    hSearchLayout.setWidth("100%");
    hSearchLayout.addComponent(searchLayout);
    hSearchLayout.setComponentAlignment(searchLayout, Alignment.MIDDLE_CENTER);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = vSplitPanel.getSplitPosition();
            splitUnit = vSplitPanel.getSplitPositionUnit();
            vSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            vSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    Label filterHintLabel = new Label();
    filterHintLabel.setCaptionAsHtml(true);
    filterHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag items from the topology tree to the tables below in order to narrow your search.");
    filterHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    filterHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(filterHintLabel);
    layout.addComponent(hListSelectLayout);
    layout.addComponent(hDateSelectLayout);
    layout.addComponent(hSearchLayout);
    layout.setSizeFull();

    Panel filterPanel = new Panel();
    filterPanel.setHeight(300, Unit.PIXELS);
    filterPanel.setWidth("100%");
    filterPanel.setContent(layout);
    filterPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);

    vSplitPanel.setFirstComponent(filterPanel);

    CssLayout hErrorTable = new CssLayout();
    hErrorTable.setSizeFull();
    hErrorTable.addComponent(this.categorizedErrorOccurenceTable);

    vSplitPanel.setSecondComponent(hErrorTable);
    vSplitPanel.setSplitPosition(310, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(vSplitPanel);

    return wrapper;
}

From source file:org.ikasan.dashboard.ui.topology.component.ErrorOccurrenceTab.java

License:BSD License

public Layout createCategorisedErrorLayout() {
    this.errorOccurenceTable = new Table();
    this.errorOccurenceTable.setSizeFull();
    this.errorOccurenceTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    this.errorOccurenceTable.addStyleName(ValoTheme.TABLE_SMALL);
    this.errorOccurenceTable.addStyleName("ikasan");
    this.errorOccurenceTable.addContainerProperty("Module Name", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Module Name", .14f);
    this.errorOccurenceTable.addContainerProperty("Flow Name", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Flow Name", .18f);
    this.errorOccurenceTable.addContainerProperty("Component Name", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Component Name", .2f);
    this.errorOccurenceTable.addContainerProperty("Error Message", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Error Message", .33f);
    this.errorOccurenceTable.addContainerProperty("Timestamp", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Timestamp", .1f);

    this.errorOccurenceTable.addStyleName("wordwrap-table");

    this.errorOccurenceTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override// ww w . java2s . c  om
        public void itemClick(ItemClickEvent itemClickEvent) {
            ErrorOccurrence errorOccurrence = (ErrorOccurrence) itemClickEvent.getItemId();
            ErrorOccurrenceViewWindow errorOccurrenceViewWindow = new ErrorOccurrenceViewWindow(
                    errorOccurrence);

            UI.getCurrent().addWindow(errorOccurrenceViewWindow);
        }
    });

    Button searchButton = new Button("Search");
    searchButton.setStyleName(ValoTheme.BUTTON_SMALL);
    searchButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            errorOccurenceTable.removeAllItems();

            ArrayList<String> modulesNames = null;

            if (errorOccurenceModules.getItemIds().size() > 0) {
                modulesNames = new ArrayList<String>();
                for (Object module : errorOccurenceModules.getItemIds()) {
                    modulesNames.add(((Module) module).getName());
                }
            }

            ArrayList<String> flowNames = null;

            if (errorOccurenceFlows.getItemIds().size() > 0) {
                flowNames = new ArrayList<String>();
                for (Object flow : errorOccurenceFlows.getItemIds()) {
                    flowNames.add(((Flow) flow).getName());
                }
            }

            ArrayList<String> componentNames = null;

            if (errorOccurenceComponents.getItemIds().size() > 0) {
                componentNames = new ArrayList<String>();
                for (Object component : errorOccurenceComponents.getItemIds()) {
                    componentNames.add(((Component) component).getName());
                }
            }

            if (modulesNames == null && flowNames == null && componentNames == null
                    && !((BusinessStream) businessStreamCombo.getValue()).getName().equals("All")) {
                BusinessStream businessStream = ((BusinessStream) businessStreamCombo.getValue());

                modulesNames = new ArrayList<String>();

                for (BusinessStreamFlow flow : businessStream.getFlows()) {
                    modulesNames.add(flow.getFlow().getModule().getName());
                }
            }

            List<ErrorOccurrence> errorOccurences = errorReportingService.find(modulesNames, flowNames,
                    componentNames, errorFromDate.getValue(), errorToDate.getValue());

            for (ErrorOccurrence errorOccurrence : errorOccurences) {
                Date date = new Date(errorOccurrence.getTimestamp());
                SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
                String timestamp = format.format(date);

                errorOccurenceTable.addItem(new Object[] { errorOccurrence.getModuleName(),
                        errorOccurrence.getFlowName(), errorOccurrence.getFlowElementName(),
                        errorOccurrence.getErrorMessage(), timestamp }, errorOccurrence);
            }
        }
    });

    Button clearButton = new Button("Clear");
    clearButton.setStyleName(ValoTheme.BUTTON_SMALL);
    clearButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            errorOccurenceModules.removeAllItems();
            errorOccurenceFlows.removeAllItems();
            errorOccurenceComponents.removeAllItems();
        }
    });

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(false);
    layout.setHeight(270, Unit.PIXELS);

    GridLayout listSelectLayout = new GridLayout(3, 1);
    listSelectLayout.setSpacing(true);
    listSelectLayout.setSizeFull();

    errorOccurenceModules.setIcon(VaadinIcons.ARCHIVE);
    errorOccurenceModules.addContainerProperty("Module Name", String.class, null);
    errorOccurenceModules.addContainerProperty("", Button.class, null);
    errorOccurenceModules.setSizeFull();
    errorOccurenceModules.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceModules.setDragMode(TableDragMode.ROW);
    errorOccurenceModules.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Module) {
                final Module module = (Module) t.getItemId();
                logger.info("sourceContainer.getText(): " + module.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceModules.removeItem(module);
                    }
                });

                errorOccurenceModules.addItem(new Object[] { module.getName(), deleteButton }, module);

                for (final Flow flow : module.getFlows()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceFlows.removeItem(flow);
                        }
                    });

                    errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                    for (final Component component : flow.getComponents()) {
                        deleteButton = new Button();
                        deleteButton.setIcon(VaadinIcons.TRASH);
                        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                        // Add the delete functionality to each role that is added
                        deleteButton.addClickListener(new Button.ClickListener() {
                            public void buttonClick(ClickEvent event) {
                                errorOccurenceComponents.removeItem(component);
                            }
                        });

                        errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                                component);
                    }
                }
            }

        }

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

    listSelectLayout.addComponent(errorOccurenceModules, 0, 0);

    errorOccurenceFlows.setIcon(VaadinIcons.AUTOMATION);
    errorOccurenceFlows.addContainerProperty("Flow Name", String.class, null);
    errorOccurenceFlows.addContainerProperty("", Button.class, null);
    errorOccurenceFlows.setSizeFull();
    errorOccurenceFlows.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceFlows.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();
                logger.info("sourceContainer.getText(): " + flow.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceFlows.removeItem(flow);
                    }
                });

                errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                for (final Component component : flow.getComponents()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceComponents.removeItem(component);
                        }
                    });

                    errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                            component);
                }
            }

        }

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

    listSelectLayout.addComponent(errorOccurenceFlows, 1, 0);

    errorOccurenceComponents.setIcon(VaadinIcons.COG);
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.addContainerProperty("Component Name", String.class, null);
    errorOccurenceComponents.addContainerProperty("", Button.class, null);
    errorOccurenceComponents.setCellStyleGenerator(new IkasanCellStyleGenerator());
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceComponents.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

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

            if (t.getItemId() instanceof Component) {
                final Component component = (Component) t.getItemId();
                logger.info("sourceContainer.getText(): " + component.getName());

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

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceComponents.removeItem(component);
                    }
                });

                errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton }, component);

            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
    listSelectLayout.addComponent(this.errorOccurenceComponents, 2, 0);

    GridLayout dateSelectLayout = new GridLayout(2, 1);

    dateSelectLayout.setSizeFull();
    errorFromDate = new PopupDateField("From date");
    errorFromDate.setResolution(Resolution.MINUTE);
    errorFromDate.setValue(this.getMidnightToday());
    dateSelectLayout.addComponent(errorFromDate, 0, 0);
    errorToDate = new PopupDateField("To date");
    errorToDate.setResolution(Resolution.MINUTE);
    errorToDate.setValue(this.getTwentyThreeFixtyNineToday());
    dateSelectLayout.addComponent(errorToDate, 1, 0);

    final VerticalSplitPanel vSplitPanel = new VerticalSplitPanel();
    vSplitPanel.setHeight("95%");

    GridLayout searchLayout = new GridLayout(2, 1);
    searchLayout.setSpacing(true);
    searchLayout.addComponent(searchButton, 0, 0);
    searchLayout.addComponent(clearButton, 1, 0);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    final HorizontalLayout hListSelectLayout = new HorizontalLayout();
    hListSelectLayout.setHeight(150, Unit.PIXELS);
    hListSelectLayout.setWidth("100%");
    hListSelectLayout.addComponent(listSelectLayout);

    final HorizontalLayout hDateSelectLayout = new HorizontalLayout();
    hDateSelectLayout.setHeight(40, Unit.PIXELS);
    hDateSelectLayout.setWidth("100%");
    hDateSelectLayout.addComponent(dateSelectLayout);

    final HorizontalLayout hSearchLayout = new HorizontalLayout();
    hSearchLayout.setHeight(30, Unit.PIXELS);
    hSearchLayout.setWidth("100%");
    hSearchLayout.addComponent(searchLayout);
    hSearchLayout.setComponentAlignment(searchLayout, Alignment.MIDDLE_CENTER);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = vSplitPanel.getSplitPosition();
            splitUnit = vSplitPanel.getSplitPositionUnit();
            vSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            vSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    Label filterHintLabel = new Label();
    filterHintLabel.setCaptionAsHtml(true);
    filterHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag items from the topology tree to the tables below in order to narrow your search.");
    filterHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    filterHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(filterHintLabel);
    layout.addComponent(hListSelectLayout);
    layout.addComponent(hDateSelectLayout);
    layout.addComponent(hSearchLayout);
    layout.setSizeFull();

    Panel filterPanel = new Panel();
    filterPanel.setHeight(300, Unit.PIXELS);
    filterPanel.setWidth("100%");
    filterPanel.setContent(layout);
    filterPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);

    vSplitPanel.setFirstComponent(filterPanel);

    CssLayout hErrorTable = new CssLayout();
    hErrorTable.setSizeFull();
    hErrorTable.addComponent(this.errorOccurenceTable);

    vSplitPanel.setSecondComponent(hErrorTable);
    vSplitPanel.setSplitPosition(310, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(vSplitPanel);

    return wrapper;
}