List of usage examples for com.vaadin.ui.themes ValoTheme BUTTON_ICON_ONLY
String BUTTON_ICON_ONLY
To view the source code for com.vaadin.ui.themes ValoTheme BUTTON_ICON_ONLY.
Click Source Link
From source file:org.ikasan.dashboard.ui.administration.panel.PrincipalManagementPanel.java
License:BSD License
@SuppressWarnings("deprecation") protected void init() { this.setWidth("100%"); this.setHeight("100%"); VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true);//from w ww . ja v a2 s . com layout.setSizeFull(); Panel securityAdministrationPanel = new Panel(); securityAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); securityAdministrationPanel.setHeight("100%"); securityAdministrationPanel.setWidth("100%"); GridLayout gridLayout = new GridLayout(2, 5); gridLayout.setWidth("100%"); gridLayout.setHeight("100%"); gridLayout.setMargin(true); gridLayout.setSizeFull(); Label groupManagementLabel = new Label("Group Management"); groupManagementLabel.setStyleName(ValoTheme.LABEL_HUGE); gridLayout.addComponent(groupManagementLabel, 0, 0, 1, 0); Label groupSearchHintLabel = new Label(); groupSearchHintLabel.setCaptionAsHtml(true); groupSearchHintLabel.setCaption( VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Group Name field to find a group."); groupSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY); groupSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT); gridLayout.addComponent(groupSearchHintLabel, 0, 1, 1, 1); Label principalNameLabel = new Label("Group Name:"); principalNameLabel.setSizeUndefined(); principalNameField = new AutocompleteField<IkasanPrincipal>(); principalNameField.setWidth("70%"); final DragAndDropWrapper principalNameFieldWrap = new DragAndDropWrapper(principalNameField); principalNameFieldWrap.setDragStartMode(DragStartMode.COMPONENT); principalTypeField.setWidth("70%"); descriptionField.setWidth("70%"); descriptionField.setHeight("60px"); roleTable.addContainerProperty("Role", String.class, null); roleTable.addContainerProperty("", Button.class, null); roleTable.setHeight("610px"); roleTable.setWidth("300px"); userTable.addContainerProperty("Associated Users", String.class, null); userTable.setHeight("610px"); userTable.setWidth("300px"); principalDropTable.addContainerProperty("Members", String.class, null); principalDropTable.addContainerProperty("", Button.class, null); principalDropTable.setHeight("700px"); principalDropTable.setWidth("300px"); principalNameField.setQueryListener(new AutocompleteQueryListener<IkasanPrincipal>() { @Override public void handleUserQuery(AutocompleteField<IkasanPrincipal> field, String query) { for (IkasanPrincipal principal : securityService.getPrincipalByNameLike(query)) { field.addSuggestion(principal, principal.getName()); } } }); principalNameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<IkasanPrincipal>() { @Override public void onSuggestionPicked(final IkasanPrincipal principal) { PrincipalManagementPanel.this.principal = principal; PrincipalManagementPanel.this.setValues(); } }); GridLayout formLayout = new GridLayout(2, 3); formLayout.setWidth("100%"); formLayout.setHeight("135px"); formLayout.setSpacing(true); formLayout.setColumnExpandRatio(0, .1f); formLayout.setColumnExpandRatio(1, .8f); formLayout.addComponent(principalNameLabel, 0, 0); formLayout.setComponentAlignment(principalNameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(principalNameFieldWrap, 1, 0); Label principalTypeLabel = new Label("Group Type:"); principalTypeLabel.setSizeUndefined(); formLayout.addComponent(principalTypeLabel, 0, 1); formLayout.setComponentAlignment(principalTypeLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(principalTypeField, 1, 1); Label descriptionLabel = new Label("Description:"); descriptionLabel.setSizeUndefined(); formLayout.addComponent(descriptionLabel, 0, 2); formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT); formLayout.addComponent(descriptionField, 1, 2); gridLayout.addComponent(formLayout, 0, 2, 1, 2); principalDropTable.setDragMode(TableDragMode.ROW); principalDropTable.setDropHandler(new DropHandler() { @Override public void drop(final DragAndDropEvent dropEvent) { // criteria verify that this is safe logger.info("Trying to drop: " + dropEvent); if (rolesCombo.getValue() == null) { // Do nothing if there is no role selected logger.info("Ignoring drop: " + dropEvent); return; } final WrapperTransferable t = (WrapperTransferable) dropEvent.getTransferable(); final AutocompleteField sourceContainer = (AutocompleteField) t.getDraggedComponent(); logger.info("sourceContainer.getText(): " + sourceContainer.getText()); Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); final IkasanPrincipal principal = securityService.findPrincipalByName(sourceContainer.getText()); final Role roleToRemove = (Role) rolesCombo.getValue(); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { principalDropTable.removeItem(principal.getName()); principal.getRoles().remove(roleToRemove); securityService.savePrincipal(principal); if (principalNameField.getText().equals(principal.getName())) { roleTable.removeItem(roleToRemove); } } }); principalDropTable.addItem(new Object[] { sourceContainer.getText(), deleteButton }, sourceContainer.getText()); principal.getRoles().add((Role) rolesCombo.getValue()); securityService.savePrincipal(principal); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { Button roleDeleteButton = new Button(); roleDeleteButton.setIcon(VaadinIcons.TRASH); roleDeleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); roleDeleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); roleDeleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); principalDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), roleDeleteButton }, role); } } @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } }); Label roleTableHintLabel = new Label(); roleTableHintLabel.setCaptionAsHtml(true); roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " The Roles table below displays the roles that are assigned to the group. Roles can be deleted from this table."); roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY); roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT); gridLayout.addComponent(roleTableHintLabel, 0, 3, 1, 3); gridLayout.addComponent(roleTable, 0, 4); gridLayout.addComponent(userTable, 1, 4); this.rolesCombo = new ComboBox("Roles"); this.rolesCombo.setWidth("90%"); this.rolesCombo.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { final Role role = (Role) event.getProperty().getValue(); if (role != null) { logger.info("Value changed got Role: " + role); List<IkasanPrincipal> principals = securityService.getAllPrincipalsWithRole(role.getName()); principalDropTable.removeAllItems(); for (final IkasanPrincipal principal : principals) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { principalDropTable.removeItem(principal.getName()); principal.getRoles().remove(role); securityService.savePrincipal(principal); if (principalNameField.getText().equals(principal.getName())) { roleTable.removeItem(role); } } }); principalDropTable.addItem(new Object[] { principal.getName(), deleteButton }, principal.getName()); } } } }); Panel roleMemberPanel = new Panel(); roleMemberPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); roleMemberPanel.setHeight("100%"); roleMemberPanel.setWidth("100%"); GridLayout roleMemberLayout = new GridLayout(); roleMemberLayout.setSpacing(true); roleMemberLayout.setWidth("100%"); roleMemberLayout.setHeight("100%"); Label roleGroupLabels = new Label("Role/Group Associations"); roleGroupLabels.setStyleName(ValoTheme.LABEL_HUGE); gridLayout.addComponent(roleGroupLabels); Label groupDragHintLabel = new Label(); groupDragHintLabel.setCaptionAsHtml(true); groupDragHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Drop groups into the table below to assign them the role."); roleMemberLayout.addComponent(roleGroupLabels); roleMemberLayout.addComponent(groupDragHintLabel); roleMemberLayout.addComponent(this.rolesCombo); roleMemberLayout.addComponent(this.principalDropTable); roleMemberPanel.setContent(roleMemberLayout); securityAdministrationPanel.setContent(gridLayout); layout.addComponent(securityAdministrationPanel); VerticalLayout roleMemberPanelLayout = new VerticalLayout(); roleMemberPanelLayout.setWidth("100%"); roleMemberPanelLayout.setHeight("100%"); roleMemberPanelLayout.setMargin(true); roleMemberPanelLayout.addComponent(roleMemberPanel); roleMemberPanelLayout.setSizeFull(); HorizontalSplitPanel hsplit = new HorizontalSplitPanel(); hsplit.setFirstComponent(layout); hsplit.setSecondComponent(roleMemberPanelLayout); // Set the position of the splitter as percentage hsplit.setSplitPosition(65, Unit.PERCENTAGE); hsplit.setLocked(true); this.setContent(hsplit); }
From source file:org.ikasan.dashboard.ui.administration.panel.PrincipalManagementPanel.java
License:BSD License
/** * //from w ww. ja v a 2 s . c om */ protected void setValues() { this.principal = this.securityService.findPrincipalByName(this.principal.getName()); this.principalNameField.setText(this.principal.getName()); this.principalTypeField.setValue(this.principal.getType()); this.descriptionField.setValue(this.principal.getDescription()); this.roleTable.removeAllItems(); this.userTable.removeAllItems(); List<User> users = this.securityService.getUsersAssociatedWithPrincipal(this.principal.getId()); for (final User user : users) { String userString = "(" + user.getName() + ") " + user.getFirstName() + " " + user.getSurname(); userTable.addItem(new Object[] { userString }, user); } for (final Role role : principal.getRoles()) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { PrincipalManagementPanel.this.roleTable.removeItem(role); PrincipalManagementPanel.this.principal.getRoles().remove(role); PrincipalManagementPanel.this.securityService.savePrincipal(principal); PrincipalManagementPanel.this.principalDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); } }
From source file:org.ikasan.dashboard.ui.administration.panel.RoleManagementPanel.java
License:BSD License
/** * /* www. ja va 2 s. co m*/ */ protected void createPolicyDropPanel() { this.policyDropPanel = new Panel(); this.policyDropPanel.setStyleName(ValoTheme.PANEL_BORDERLESS); this.policyDropPanel.setHeight("100%"); this.policyDropPanel.setWidth("100%"); this.policyTable = new Table(); this.policyTable.addContainerProperty("Role Policies", String.class, null); this.policyTable.addContainerProperty("", Button.class, null); this.policyTable.setHeight("720px"); this.policyTable.setWidth("300px"); this.policyTable.setDragMode(TableDragMode.ROW); this.policyTable.setDropHandler(new DropHandler() { @Override public void drop(final DragAndDropEvent dropEvent) { if (role == null) { // Do nothing if there is no role selected logger.info("Ignoring drop: " + dropEvent); return; } // criteria verify that this is safe logger.info("Trying to drop: " + dropEvent); final WrapperTransferable t = (WrapperTransferable) dropEvent.getTransferable(); final AutocompleteField sourceContainer = (AutocompleteField) t.getDraggedComponent(); logger.info("sourceContainer.getText(): " + sourceContainer.getText()); Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.setDescription("Remove Policy from this Role"); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { Policy policy = RoleManagementPanel.this.securityService .findPolicyByName(sourceContainer.getText()); logger.info("Trying to remove policy: " + policy); Role selectedRole = RoleManagementPanel.this.securityService .findRoleByName(RoleManagementPanel.this.roleNameField.getText()); logger.info("From role: " + selectedRole); selectedRole.getPolicies().remove(policy); RoleManagementPanel.this.saveRole(selectedRole); RoleManagementPanel.this.policyTable.removeItem(policy.getName()); } }); Policy policy = RoleManagementPanel.this.securityService .findPolicyByName(sourceContainer.getText()); Role selectedRole = RoleManagementPanel.this.securityService .findRoleByName(RoleManagementPanel.this.roleNameField.getText()); selectedRole.getPolicies().add(policy); RoleManagementPanel.this.saveRole(selectedRole); RoleManagementPanel.this.policyTable.addItem( new Object[] { sourceContainer.getText(), deleteButton }, sourceContainer.getText()); } @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } }); GridLayout layout = new GridLayout(); layout.setSpacing(true); layout.setWidth("100%"); Label associatedPoliciesLabel = new Label("Associated Policies"); associatedPoliciesLabel.setStyleName(ValoTheme.LABEL_HUGE); Label policy1HintLabel = new Label(); policy1HintLabel.setCaptionAsHtml(true); policy1HintLabel.setCaption( VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the text box below to find a policy."); policy1HintLabel.addStyleName(ValoTheme.LABEL_TINY); policy1HintLabel.addStyleName(ValoTheme.LABEL_LIGHT); layout.addComponent(associatedPoliciesLabel); layout.addComponent(policy1HintLabel); layout.addComponent(policyNameFieldWrap); Label policy2HintLabel = new Label(); policy2HintLabel.setCaptionAsHtml(true); policy2HintLabel.setCaption( VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Drag below to associate policy with current role."); policy2HintLabel.addStyleName(ValoTheme.LABEL_TINY); policy2HintLabel.addStyleName(ValoTheme.LABEL_LIGHT); layout.addComponent(policy2HintLabel); layout.addComponent(this.policyTable); this.policyDropPanel.setContent(layout); }
From source file:org.ikasan.dashboard.ui.administration.panel.RoleManagementPanel.java
License:BSD License
/** * Helper method to initialise behaviour of the role name field. * //from w ww . jav a 2s . c o m * @return */ protected void initRoleNameField() { // The policy field name is an autocomplete field. this.roleNameField = new AutocompleteField<Role>(); this.roleNameField.setWidth("80%"); // In order to have the auto complete work we must add a query listener. // The query listener gets activated when a user begins to type into // the field and hits the database looking for suggestions. roleNameField.setQueryListener(new AutocompleteQueryListener<Role>() { @Override public void handleUserQuery(AutocompleteField<Role> field, String query) { // Iterate over the returned results and add them as suggestions for (Role role : securityService.getRoleByNameLike(query)) { field.addSuggestion(role, role.getName()); } } }); // Once a suggestion is selected the listener below gets fired and we populate // associated fields as required. roleNameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<Role>() { @Override public void onSuggestionPicked(final Role pickedRole) { RoleManagementPanel.this.role = pickedRole; // Populate all the policy related fields. RoleManagementPanel.this.roleItem = new BeanItem<Role>(RoleManagementPanel.this.role); RoleManagementPanel.this.roleNameField.setPropertyDataSource(roleItem.getItemProperty("name")); RoleManagementPanel.this.descriptionField .setPropertyDataSource(roleItem.getItemProperty("description")); RoleManagementPanel.this.policyTable.removeAllItems(); for (final Policy policy : role.getPolicies()) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.setDescription("Remove Policy from this Role"); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { Policy selectedPolicy = RoleManagementPanel.this.securityService .findPolicyByName(policy.getName()); Role selectedRole = RoleManagementPanel.this.securityService .findRoleByName(role.getName()); selectedRole.getPolicies().remove(selectedPolicy); RoleManagementPanel.this.saveRole(selectedRole); RoleManagementPanel.this.policyTable.removeItem(policy.getName()); } }); RoleManagementPanel.this.policyTable.addItem(new Object[] { policy.getName(), deleteButton }, policy.getName()); } RoleManagementPanel.this.associatedPrincipalsTable.removeAllItems(); logger.info("Trying to get pinciplas for role: " + role); List<IkasanPrincipal> principals = RoleManagementPanel.this.securityService .getAllPrincipalsWithRole(role.getName()); logger.info("Adding the following number of principals : " + principals.size()); for (final IkasanPrincipal ikasanPrincipal : principals) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.setDescription("Unassign this role from the given User/Group"); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { Role selectedRole = RoleManagementPanel.this.securityService .findRoleByName(RoleManagementPanel.this.roleNameField.getText()); logger.info("Removing principal role: " + selectedRole); ikasanPrincipal.getRoles().remove(selectedRole); RoleManagementPanel.this.securityService.savePrincipal(ikasanPrincipal); RoleManagementPanel.this.associatedPrincipalsTable.removeItem(ikasanPrincipal); } }); RoleManagementPanel.this.associatedPrincipalsTable .addItem(new Object[] { ikasanPrincipal.getName(), deleteButton }, ikasanPrincipal); } } }); }
From source file:org.ikasan.dashboard.ui.administration.panel.RoleManagementPanel.java
License:BSD License
/** * //from w w w . ja va2s .co m */ protected Layout initControlLayout() { this.newButton.setIcon(VaadinIcons.PLUS); this.newButton.setDescription("Create a New Role"); this.newButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.newButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.newButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { final NewRoleWindow newRoleWindow = new NewRoleWindow(securityService); UI.getCurrent().addWindow(newRoleWindow); newRoleWindow.addCloseListener(new Window.CloseListener() { // inline close-listener public void windowClose(CloseEvent e) { RoleManagementPanel.this.role = newRoleWindow.getRole(); RoleManagementPanel.this.roleItem = new BeanItem<Role>(RoleManagementPanel.this.role); RoleManagementPanel.this.roleNameField.setText(RoleManagementPanel.this.role.getName()); RoleManagementPanel.this.roleNameField .setPropertyDataSource(roleItem.getItemProperty("name")); RoleManagementPanel.this.descriptionField .setPropertyDataSource(roleItem.getItemProperty("description")); } }); } }); this.saveButton.setStyleName(ValoTheme.BUTTON_LINK); this.saveButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { try { RoleManagementPanel.this.save(); Notification.show("Saved"); } catch (RuntimeException e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); Notification.show("Cauget exception trying to save a Policy!", sw.toString(), Notification.Type.ERROR_MESSAGE); } } }); this.deleteButton.setIcon(VaadinIcons.TRASH); this.deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.deleteButton.setDescription("Delete the Current Role"); this.deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { try { RoleManagementPanel.this.securityService.deleteRole(role); RoleManagementPanel.this.roleNameField.setText(""); RoleManagementPanel.this.descriptionField.setValue(""); RoleManagementPanel.this.policyTable.removeAllItems(); Notification.show("Deleted"); } catch (RuntimeException e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); Notification.show("Cauget exception trying to delete a Policy!", sw.toString(), Notification.Type.ERROR_MESSAGE); } } }); HorizontalLayout controlLayout = new HorizontalLayout(); controlLayout.setWidth("100%"); controlLayout.setHeight("20px"); Label spacerLabel = new Label(""); controlLayout.addComponent(spacerLabel); controlLayout.setExpandRatio(spacerLabel, 0.91f); controlLayout.addComponent(newButton); controlLayout.setExpandRatio(newButton, 0.045f); controlLayout.addComponent(deleteButton); controlLayout.setExpandRatio(deleteButton, 0.045f); return controlLayout; }
From source file:org.ikasan.dashboard.ui.administration.panel.RoleManagementPanel.java
License:BSD License
@Override public void enter(ViewChangeEvent event) { this.policyNameField.clearChoices(); this.roleNameField.clearChoices(); if (this.role != null) { RoleManagementPanel.this.associatedPrincipalsTable.removeAllItems(); logger.info("Trying to get pincipals for role: " + role); List<IkasanPrincipal> principals = RoleManagementPanel.this.securityService .getAllPrincipalsWithRole(role.getName()); logger.info("Adding the following number of principals : " + principals.size()); for (final IkasanPrincipal ikasanPrincipal : principals) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.setDescription("Unassign this role from the given User/Group"); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { Role selectedRole = RoleManagementPanel.this.securityService .findRoleByName(RoleManagementPanel.this.roleNameField.getText()); logger.info("Removing principal role: " + selectedRole); ikasanPrincipal.getRoles().remove(selectedRole); RoleManagementPanel.this.securityService.savePrincipal(ikasanPrincipal); RoleManagementPanel.this.associatedPrincipalsTable.removeItem(ikasanPrincipal); }//from w w w.ja v a2 s . co m }); RoleManagementPanel.this.associatedPrincipalsTable .addItem(new Object[] { ikasanPrincipal.getName(), deleteButton }, ikasanPrincipal); } } }
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 ww w .j a va 2 s. c o m 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.UserManagementPanel.java
License:BSD License
@SuppressWarnings("deprecation") protected void init() { this.setWidth("100%"); this.setHeight("100%"); VerticalLayout layout = new VerticalLayout(); layout.setSizeFull();/*from ww w. j a va 2 s. co m*/ Panel securityAdministrationPanel = new Panel(); securityAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); securityAdministrationPanel.setHeight("100%"); securityAdministrationPanel.setWidth("100%"); GridLayout gridLayout = new GridLayout(2, 6); gridLayout.setMargin(true); gridLayout.setSpacing(true); gridLayout.setSizeFull(); Label mappingConfigurationLabel = new Label("User Management"); mappingConfigurationLabel.setStyleName(ValoTheme.LABEL_HUGE); gridLayout.addComponent(mappingConfigurationLabel, 0, 0, 1, 0); Label userSearchHintLabel = new Label(); userSearchHintLabel.setCaptionAsHtml(true); userSearchHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Username, Firstname or Surname fields to find a user."); userSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY); userSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT); gridLayout.addComponent(userSearchHintLabel, 0, 1, 1, 1); Label usernameLabel = new Label("Username:"); usernameField.setWidth("40%"); final DragAndDropWrapper usernameFieldWrap = new DragAndDropWrapper(usernameField); usernameFieldWrap.setDragStartMode(DragStartMode.COMPONENT); firstName = new AutocompleteField<User>(); firstName.setWidth("40%"); surname = new AutocompleteField<User>(); surname.setWidth("40%"); final TextField department = new TextField(); department.setWidth("40%"); final TextField email = new TextField(); email.setWidth("40%"); final Table roleTable = new Table(); roleTable.addContainerProperty("Role", String.class, null); roleTable.addContainerProperty("", Button.class, null); roleTable.setHeight("520px"); roleTable.setWidth("250px"); usernameField.setQueryListener(new AutocompleteQueryListener<User>() { @Override public void handleUserQuery(AutocompleteField<User> field, String query) { for (User user : userService.getUserByUsernameLike(query)) { field.addSuggestion(user, user.getUsername()); } } }); usernameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() { @Override public void onSuggestionPicked(User user) { UserManagementPanel.this.user = user; firstName.setText(user.getFirstName()); surname.setText(user.getSurname()); department.setValue(user.getDepartment()); email.setValue(user.getEmail()); final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername()); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); } associatedPrincipalsTable.removeAllItems(); for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) { if (!ikasanPrincipal.getType().equals("user")) { associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal); } } } }); firstName.setQueryListener(new AutocompleteQueryListener<User>() { @Override public void handleUserQuery(AutocompleteField<User> field, String query) { for (User user : userService.getUserByFirstnameLike(query)) { field.addSuggestion(user, user.getFirstName() + " " + user.getSurname()); } } }); firstName.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() { @Override public void onSuggestionPicked(User user) { UserManagementPanel.this.user = user; usernameField.setText(user.getUsername()); firstName.setText(user.getFirstName()); surname.setText(user.getSurname()); department.setValue(user.getDepartment()); email.setValue(user.getEmail()); final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername()); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); } associatedPrincipalsTable.removeAllItems(); for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) { if (!ikasanPrincipal.getType().equals("user")) { associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal); } } } }); surname.setQueryListener(new AutocompleteQueryListener<User>() { @Override public void handleUserQuery(AutocompleteField<User> field, String query) { for (User user : userService.getUserBySurnameLike(query)) { field.addSuggestion(user, user.getFirstName() + " " + user.getSurname()); } } }); surname.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() { @Override public void onSuggestionPicked(User user) { UserManagementPanel.this.user = user; usernameField.setText(user.getUsername()); firstName.setText(user.getFirstName()); surname.setText(user.getSurname()); department.setValue(user.getDepartment()); email.setValue(user.getEmail()); final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername()); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); associatedPrincipalsTable.removeAllItems(); for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) { if (!ikasanPrincipal.getType().equals("user")) { associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal); } } } } }); GridLayout formLayout = new GridLayout(2, 5); formLayout.setSpacing(true); formLayout.setWidth("100%"); formLayout.setColumnExpandRatio(0, .1f); formLayout.setColumnExpandRatio(1, .8f); usernameLabel.setSizeUndefined(); formLayout.addComponent(usernameLabel, 0, 0); formLayout.setComponentAlignment(usernameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(usernameFieldWrap, 1, 0); Label firstNameLabel = new Label("First name:"); firstNameLabel.setSizeUndefined(); formLayout.addComponent(firstNameLabel, 0, 1); formLayout.setComponentAlignment(firstNameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(firstName, 1, 1); Label surnameLabel = new Label("Surname:"); surnameLabel.setSizeUndefined(); formLayout.addComponent(surnameLabel, 0, 2); formLayout.setComponentAlignment(surnameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(surname, 1, 2); Label departmentLabel = new Label("Department:"); departmentLabel.setSizeUndefined(); formLayout.addComponent(departmentLabel, 0, 3); formLayout.setComponentAlignment(departmentLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(department, 1, 3); Label emailLabel = new Label("Email address:"); emailLabel.setSizeUndefined(); formLayout.addComponent(emailLabel, 0, 4); formLayout.setComponentAlignment(emailLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(email, 1, 4); gridLayout.addComponent(formLayout, 0, 2, 1, 2); Label rolesAndGroupsHintLabel1 = new Label(); rolesAndGroupsHintLabel1.setCaptionAsHtml(true); rolesAndGroupsHintLabel1.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " The Roles table below displays the roles that the user has. Roles can be deleted from this table."); rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_TINY); rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_LIGHT); rolesAndGroupsHintLabel1.setWidth(300, Unit.PIXELS); gridLayout.addComponent(rolesAndGroupsHintLabel1, 0, 3, 1, 3); Label rolesAndGroupsHintLabel2 = new Label(); rolesAndGroupsHintLabel2.setCaptionAsHtml(true); rolesAndGroupsHintLabel2.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " The Groups table below displays all the LDAP groups that the user is a member of. You cannot manage these " + "from this application."); rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_TINY); rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_LIGHT); rolesAndGroupsHintLabel2.setWidth(300, Unit.PIXELS); gridLayout.addComponent(rolesAndGroupsHintLabel2, 0, 4, 1, 4); final ClientSideCriterion acceptCriterion = new SourceIs(usernameField); userDropTable.addContainerProperty("Members", String.class, null); userDropTable.addContainerProperty("", Button.class, null); userDropTable.setHeight("715px"); userDropTable.setWidth("300px"); userDropTable.setDragMode(TableDragMode.ROW); userDropTable.setDropHandler(new DropHandler() { @Override public void drop(final DragAndDropEvent dropEvent) { if (rolesCombo.getValue() == null) { // Do nothing if there is no role selected logger.info("Ignoring drop: " + dropEvent); return; } // criteria verify that this is safe logger.info("Trying to drop: " + dropEvent); final WrapperTransferable t = (WrapperTransferable) dropEvent.getTransferable(); final AutocompleteField sourceContainer = (AutocompleteField) t.getDraggedComponent(); logger.info("sourceContainer.getText(): " + sourceContainer.getText()); Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); final IkasanPrincipal principal = securityService.findPrincipalByName(sourceContainer.getText()); final Role roleToRemove = (Role) rolesCombo.getValue(); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { userDropTable.removeItem(principal.getName()); principal.getRoles().remove(roleToRemove); securityService.savePrincipal(principal); if (UserManagementPanel.this.usernameField.getText().equals(principal.getName())) { roleTable.removeItem(roleToRemove); } } }); userDropTable.addItem(new Object[] { sourceContainer.getText(), deleteButton }, sourceContainer.getText()); principal.getRoles().add((Role) rolesCombo.getValue()); securityService.savePrincipal(principal); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { Button roleDeleteButton = new Button(); roleDeleteButton.setIcon(VaadinIcons.TRASH); roleDeleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); roleDeleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); roleDeleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), roleDeleteButton }, role); } } @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } }); gridLayout.addComponent(roleTable, 0, 5); this.associatedPrincipalsTable.addContainerProperty("Groups", String.class, null); this.associatedPrincipalsTable.addItemClickListener(this.associatedPrincipalItemClickListener); associatedPrincipalsTable.setHeight("520px"); associatedPrincipalsTable.setWidth("400px"); gridLayout.addComponent(this.associatedPrincipalsTable, 1, 5); this.rolesCombo = new ComboBox("Roles"); this.rolesCombo.setWidth("90%"); this.rolesCombo.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { final Role role = (Role) event.getProperty().getValue(); if (role != null) { logger.info("Value changed got Role: " + role); List<IkasanPrincipal> principals = securityService.getAllPrincipalsWithRole(role.getName()); userDropTable.removeAllItems(); for (final IkasanPrincipal principal : principals) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { userDropTable.removeItem(principal.getName()); principal.getRoles().remove(role); securityService.savePrincipal(principal); if (UserManagementPanel.this.usernameField.getText().equals(principal.getName())) { roleTable.removeItem(role); } } }); userDropTable.addItem(new Object[] { principal.getName(), deleteButton }, principal.getName()); } } } }); Panel roleMemberPanel = new Panel(); roleMemberPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); roleMemberPanel.setHeight("100%"); roleMemberPanel.setWidth("100%"); GridLayout roleMemberLayout = new GridLayout(); roleMemberLayout.setSpacing(true); roleMemberLayout.setWidth("100%"); Label roleMemberAssociationsLabel = new Label("Role/Member Associations"); roleMemberAssociationsLabel.setStyleName(ValoTheme.LABEL_HUGE); Label userDragHintLabel = new Label(); userDragHintLabel.setCaptionAsHtml(true); userDragHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Drop users into the table below to assign them the role."); roleMemberLayout.addComponent(roleMemberAssociationsLabel); roleMemberLayout.addComponent(userDragHintLabel); roleMemberLayout.addComponent(this.rolesCombo); roleMemberLayout.addComponent(this.userDropTable); roleMemberPanel.setContent(roleMemberLayout); securityAdministrationPanel.setContent(gridLayout); layout.addComponent(securityAdministrationPanel); VerticalLayout roleMemberPanelLayout = new VerticalLayout(); roleMemberPanelLayout.setWidth("100%"); roleMemberPanelLayout.setHeight("100%"); roleMemberPanelLayout.setMargin(true); roleMemberPanelLayout.addComponent(roleMemberPanel); roleMemberPanelLayout.setSizeFull(); HorizontalSplitPanel hsplit = new HorizontalSplitPanel(); hsplit.setFirstComponent(layout); hsplit.setSecondComponent(roleMemberPanelLayout); // Set the position of the splitter as percentage hsplit.setSplitPosition(65, Unit.PERCENTAGE); hsplit.setLocked(true); this.setContent(hsplit); }
From source file:org.ikasan.dashboard.ui.framework.panel.ProfilePanel.java
License:BSD License
@Override public void enter(ViewChangeEvent event) { List<Role> roles = this.securityService.getAllRoles(); this.dashboadActivityTable.removeAllItems(); IkasanAuthentication ikasanAuthentication = (IkasanAuthentication) VaadinService.getCurrentRequest() .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER); this.user = (User) ikasanAuthentication.getPrincipal(); usernameField.setValue(user.getUsername()); firstName.setValue(user.getFirstName()); surname.setValue(user.getSurname()); department.setValue(user.getDepartment()); email.setValue(user.getEmail());//from w w w . jav a 2s.co m final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername()); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); dashboadActivityTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName() }, role); associatedPrincipalsTable.removeAllItems(); for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) { if (!ikasanPrincipal.getType().equals("user")) { associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal); } } } ArrayList<String> subjects = new ArrayList<String>(); subjects.add(SystemEventConstants.DASHBOARD_LOGIN_CONSTANTS); subjects.add(SystemEventConstants.DASHBOARD_LOGOUT_CONSTANTS); subjects.add(SystemEventConstants.DASHBOARD_SESSION_EXPIRED_CONSTANTS); List<SystemEvent> events = this.systemEventService.listSystemEvents(subjects, user.getUsername(), null, null); for (SystemEvent systemEvent : events) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss"); String date = dateFormat.format(systemEvent.getTimestamp()); dashboadActivityTable.addItem(new Object[] { systemEvent.getAction(), date }, systemEvent); } subjects = new ArrayList<String>(); subjects.add(SystemEventConstants.DASHBOARD_USER_ROLE_CHANGED_CONSTANTS); events = this.systemEventService.listSystemEvents(subjects, user.getUsername(), null, null); for (SystemEvent systemEvent : events) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss"); String date = dateFormat.format(systemEvent.getTimestamp()); this.permissionChangeTable.addItem(new Object[] { systemEvent.getAction(), date }, systemEvent); } }
From source file:org.ikasan.dashboard.ui.mappingconfiguration.component.MappingConfigurationConfigurationValuesTable.java
License:BSD License
/** * Method to add a record to the component. * //from www . jav a 2s .com * @throws MappingConfigurationServiceException */ public void addNewRecord() throws MappingConfigurationServiceException { Long sourceSystemGroupId = null; if (this.mappingConfiguration.getNumberOfParams() > 1) { sourceSystemGroupId = this.mappingConfigurationService.getNextSequenceNumber(); } TargetConfigurationValue targetConfigurationValue = new TargetConfigurationValue(); targetConfigurationValue.setTargetSystemValue("Add targetSystemValue"); this.mappingConfigurationService.saveTargetConfigurationValue(targetConfigurationValue); VerticalLayout tableCellLayout = new VerticalLayout(); SourceConfigurationValue sourceConfigurationValue = null; final Button deleteButton = new Button("Delete"); ArrayList<SourceConfigurationValue> sourceConfigurationValues = new ArrayList<SourceConfigurationValue>(); for (int i = 0; i < this.mappingConfiguration.getNumberOfParams(); i++) { sourceConfigurationValue = new SourceConfigurationValue(); sourceConfigurationValue.setSourceSystemValue("Add source system value"); sourceConfigurationValue.setSourceConfigGroupId(sourceSystemGroupId); sourceConfigurationValue.setTargetConfigurationValue(targetConfigurationValue); sourceConfigurationValue.setMappingConfigurationId(this.mappingConfiguration.getId()); sourceConfigurationValues.add(sourceConfigurationValue); this.mappingConfiguration.getSourceConfigurationValues().add(sourceConfigurationValue); BeanItem<SourceConfigurationValue> item = new BeanItem<SourceConfigurationValue>( sourceConfigurationValue); final TextField tf = new TextField(item.getItemProperty("sourceSystemValue")); tableCellLayout.addComponent(tf); tf.setReadOnly(true); tf.setWidth(300, Unit.PIXELS); } BeanItem<TargetConfigurationValue> targetConfigurationItem = new BeanItem<TargetConfigurationValue>( targetConfigurationValue); final TextField targetConfigurationTextField = new TextField( targetConfigurationItem.getItemProperty("targetSystemValue")); targetConfigurationTextField.setReadOnly(true); targetConfigurationTextField.setWidth(300, Unit.PIXELS); final DeleteRowAction action = new DeleteRowAction(sourceConfigurationValues, this.mappingConfiguration, this, this.mappingConfigurationService, this.systemEventService); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.setDescription("Delete this record"); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { IkasanMessageDialog dialog = new IkasanMessageDialog("Delete record", "This mapping configuration record will be permanently removed. " + "Are you sure you wish to proceed?.", action); UI.getCurrent().addWindow(dialog); } }); final IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest() .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER); if (authentication != null && (authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY) || authentication.hasGrantedAuthority(SecurityConstants.EDIT_MAPPING_AUTHORITY)) || authentication.canAccessLinkedItem(PolicyLinkTypeConstants.MAPPING_CONFIGURATION_LINK_TYPE, mappingConfiguration.getId())) { deleteButton.setVisible(true); } else { deleteButton.setVisible(false); } Item item = this.container.addItemAt(0, sourceConfigurationValue); Property<Layout> sourceProperty = item.getItemProperty("Source Configuration Value"); sourceProperty.setValue(tableCellLayout); Property<TextField> targetProperty = item.getItemProperty("Target Configuration Value"); targetProperty.setValue(targetConfigurationTextField); Property<Button> deleteProperty = item.getItemProperty("Delete"); deleteProperty.setValue(deleteButton); this.mappingConfigurationService.saveMappingConfiguration(mappingConfiguration); this.setEditable(true); IkasanAuthentication principal = (IkasanAuthentication) VaadinService.getCurrentRequest() .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER); logger.info("User: " + principal.getName() + " added new mapping configuration value for Mapping Configuration " + this.mappingConfiguration); systemEventService.logSystemEvent(MappingConfigurationConstants.MAPPING_CONFIGURATION_SERVICE, "Added new mapping configuration value for Mapping Configuration: " + this.mappingConfiguration, principal.getName()); }