]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/GroupMainPage.java
Work on userAdmin UI:
[lgpl/argeo-commons.git] / org.argeo.security.ui.admin / src / org / argeo / security / ui / admin / editors / GroupMainPage.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.ui.admin.editors;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.jcr.RepositoryException;
22
23 import org.argeo.ArgeoException;
24 import org.argeo.eclipse.ui.EclipseUiUtils;
25 import org.argeo.jcr.ArgeoNames;
26 import org.argeo.security.ui.admin.internal.ColumnDefinition;
27 import org.argeo.security.ui.admin.internal.CommonNameLP;
28 import org.argeo.security.ui.admin.internal.MailLP;
29 import org.argeo.security.ui.admin.internal.RoleIconLP;
30 import org.argeo.security.ui.admin.internal.UserAdminConstants;
31 import org.argeo.security.ui.admin.internal.UserNameLP;
32 import org.argeo.security.ui.admin.internal.UserTableDefaultDClickListener;
33 import org.argeo.security.ui.admin.internal.UserTableViewer;
34 import org.eclipse.jface.viewers.TableViewer;
35 import org.eclipse.swt.SWT;
36 import org.eclipse.swt.layout.GridLayout;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.ui.forms.AbstractFormPart;
39 import org.eclipse.ui.forms.IManagedForm;
40 import org.eclipse.ui.forms.SectionPart;
41 import org.eclipse.ui.forms.editor.FormEditor;
42 import org.eclipse.ui.forms.editor.FormPage;
43 import org.eclipse.ui.forms.widgets.FormToolkit;
44 import org.eclipse.ui.forms.widgets.ScrolledForm;
45 import org.eclipse.ui.forms.widgets.Section;
46 import org.osgi.service.useradmin.Group;
47 import org.osgi.service.useradmin.Role;
48 import org.osgi.service.useradmin.User;
49 import org.osgi.service.useradmin.UserAdmin;
50
51 /** Display/edit main properties of a given group */
52 public class GroupMainPage extends FormPage implements ArgeoNames {
53 final static String ID = "GroupEditor.mainPage";
54
55 private final UserEditor editor;
56
57 private UserAdmin userAdmin;
58
59 public GroupMainPage(FormEditor editor, UserAdmin userAdmin) {
60 super(editor, ID, "Main");
61 this.editor = (UserEditor) editor;
62 this.userAdmin = userAdmin;
63 }
64
65 protected void createFormContent(final IManagedForm mf) {
66 try {
67 ScrolledForm form = mf.getForm();
68 form.getBody().getParent().setLayoutData(EclipseUiUtils.fillAll());
69 form.setExpandHorizontal(true);
70 refreshFormTitle(form);
71 // GridLayout mainLayout = new GridLayout(1, true);
72 createGeneralPart(form.getBody());
73 } catch (RepositoryException e) {
74 throw new ArgeoException("Cannot create form content", e);
75 }
76 }
77
78 /** Creates the general section */
79 protected void createGeneralPart(Composite parent)
80 throws RepositoryException {
81 parent.setLayout(new GridLayout());
82
83 FormToolkit tk = getManagedForm().getToolkit();
84 Section section = tk.createSection(parent, Section.TITLE_BAR);
85 section.setLayoutData(EclipseUiUtils.fillAll());
86 section.setText("Members of "
87 + editor.getProperty(UserAdminConstants.KEY_CN));
88
89 // Composite body = tk.createComposite(section, SWT.NONE);
90 Composite body = new Composite(section, SWT.NO_FOCUS);
91 section.setClient(body);
92 body.setLayoutData(EclipseUiUtils.fillAll());
93
94 createMemberPart(body);
95
96 // create form part (controller)
97 AbstractFormPart part = new SectionPart(section) {
98 public void commit(boolean onSave) {
99 super.commit(onSave);
100 }
101 };
102
103 getManagedForm().addPart(part);
104 }
105
106 // UI Objects
107 private UserTableViewer userTableViewerCmp;
108 private TableViewer userViewer;
109 private List<ColumnDefinition> columnDefs = new ArrayList<ColumnDefinition>();
110
111 public void createMemberPart(Composite parent) {
112 // parent.setLayout(EclipseUiUtils.noSpaceGridLayout());
113 // parent2.setLayoutData(EclipseUiUtils.fillAll());
114 // Composite parent = new Composite(parent2, SWT.NO_FOCUS);
115 // parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
116 // parent.setLayoutData(EclipseUiUtils.fillAll());
117
118 parent.setLayout(EclipseUiUtils.noSpaceGridLayout());
119 // Define the displayed columns
120 columnDefs.add(new ColumnDefinition(new RoleIconLP(), "", 0, 24));
121 columnDefs.add(new ColumnDefinition(new UserNameLP(),
122 "Distinguished Name", 240));
123 columnDefs.add(new ColumnDefinition(new CommonNameLP(), "Common Name",
124 150));
125 columnDefs.add(new ColumnDefinition(new MailLP(), "Primary Mail", 150));
126
127 // Create and configure the table
128 userTableViewerCmp = new MyUserTableViewer(parent, SWT.MULTI
129 | SWT.H_SCROLL | SWT.V_SCROLL, userAdmin);
130
131 userTableViewerCmp.setColumnDefinitions(columnDefs);
132 userTableViewerCmp.populate(true, false);
133 // userTableViewerCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
134 // false, false));
135 userTableViewerCmp.setLayoutData(EclipseUiUtils.fillAll());
136
137 // Links
138 userViewer = userTableViewerCmp.getTableViewer();
139 userViewer.addDoubleClickListener(new UserTableDefaultDClickListener());
140 // Really?
141 userTableViewerCmp.refresh();
142 }
143
144 private class MyUserTableViewer extends UserTableViewer {
145 private static final long serialVersionUID = 8467999509931900367L;
146
147 public MyUserTableViewer(Composite parent, int style,
148 UserAdmin userAdmin) {
149 super(parent, style, userAdmin, true);
150 }
151
152 @Override
153 protected List<User> listFilteredElements(String filter) {
154 Group group = (Group) editor.getDisplayedUser();
155 Role[] roles = group.getMembers();
156 List<User> users = new ArrayList<User>();
157 for (Role role : roles)
158 // if (role.getType() == Role.GROUP)
159 users.add((User) role);
160 return users;
161 }
162 }
163
164 private void refreshFormTitle(ScrolledForm form) throws RepositoryException {
165 // form.setText(getProperty(Property.JCR_TITLE)
166 // + (userProfile.getProperty(ARGEO_ENABLED).getBoolean() ? ""
167 // : " [DISABLED]"));
168 }
169
170 // private class FormPartML implements ModifyListener {
171 // private static final long serialVersionUID = 6299808129505381333L;
172 // private AbstractFormPart formPart;
173 //
174 // public FormPartML(AbstractFormPart generalPart) {
175 // this.formPart = generalPart;
176 // }
177 //
178 // public void modifyText(ModifyEvent e) {
179 // formPart.markDirty();
180 // }
181 // }
182 }