2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.security
.ui
.admin
.editors
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import javax
.jcr
.RepositoryException
;
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
.GridData
;
37 import org
.eclipse
.swt
.layout
.GridLayout
;
38 import org
.eclipse
.swt
.widgets
.Composite
;
39 import org
.eclipse
.swt
.widgets
.Label
;
40 import org
.eclipse
.swt
.widgets
.Text
;
41 import org
.eclipse
.ui
.forms
.AbstractFormPart
;
42 import org
.eclipse
.ui
.forms
.IManagedForm
;
43 import org
.eclipse
.ui
.forms
.SectionPart
;
44 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
45 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
46 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
47 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
48 import org
.eclipse
.ui
.forms
.widgets
.Section
;
49 import org
.osgi
.service
.useradmin
.Group
;
50 import org
.osgi
.service
.useradmin
.Role
;
51 import org
.osgi
.service
.useradmin
.User
;
52 import org
.osgi
.service
.useradmin
.UserAdmin
;
54 /** Display/edit main properties of a given group */
55 public class GroupMainPage
extends FormPage
implements ArgeoNames
{
56 final static String ID
= "GroupEditor.mainPage";
58 private final UserEditor editor
;
59 private UserAdmin userAdmin
;
61 // Local configuration
62 private final int PRE_TITLE_INDENT
= 10;
64 public GroupMainPage(FormEditor editor
, UserAdmin userAdmin
) {
65 super(editor
, ID
, "Main");
66 this.editor
= (UserEditor
) editor
;
67 this.userAdmin
= userAdmin
;
70 protected void createFormContent(final IManagedForm mf
) {
72 ScrolledForm form
= mf
.getForm();
76 Composite body
= form
.getBody();
77 GridLayout mainLayout
= new GridLayout();
78 body
.setLayout(mainLayout
);
79 appendOverviewPart(body
);
80 appendMembersPart(body
);
81 } catch (RepositoryException e
) {
82 throw new ArgeoException("Cannot create form content", e
);
86 /** Creates the general section */
87 protected void appendOverviewPart(Composite parent
) {
88 FormToolkit tk
= getManagedForm().getToolkit();
89 Composite body
= addSection(tk
, parent
, "Main information");
90 GridLayout layout
= new GridLayout(2, false);
91 body
.setLayout(layout
);
93 Text distinguishedName
= createLT(body
, "Group Name",
94 editor
.getProperty(UserAdminConstants
.KEY_UID
));
95 distinguishedName
.setEnabled(false);
97 final Text commonName
= createLT(body
, "Common Name",
98 editor
.getProperty(UserAdminConstants
.KEY_CN
));
99 commonName
.setEnabled(false);
101 // create form part (controller)
102 AbstractFormPart part
= new SectionPart((Section
) body
.getParent()) {
103 public void commit(boolean onSave
) {
104 super.commit(onSave
);
107 getManagedForm().addPart(part
);
110 /** Filtered table with members. Has drag & drop ability */
111 protected void appendMembersPart(Composite parent
)
112 throws RepositoryException
{
114 FormToolkit tk
= getManagedForm().getToolkit();
115 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
);
116 section
.setLayoutData(EclipseUiUtils
.fillAll());
117 section
.setText("Members of group "
118 + editor
.getProperty(UserAdminConstants
.KEY_CN
));
120 // Composite body = tk.createComposite(section, SWT.NONE);
121 Composite body
= new Composite(section
, SWT
.NO_FOCUS
);
122 section
.setClient(body
);
123 body
.setLayoutData(EclipseUiUtils
.fillAll());
125 createMemberPart(body
);
127 // create form part (controller)
128 AbstractFormPart part
= new SectionPart(section
) {
129 public void commit(boolean onSave
) {
130 super.commit(onSave
);
134 getManagedForm().addPart(part
);
138 private UserTableViewer userTableViewerCmp
;
139 private TableViewer userViewer
;
140 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
142 public void createMemberPart(Composite parent
) {
143 // parent.setLayout(EclipseUiUtils.noSpaceGridLayout());
144 // parent2.setLayoutData(EclipseUiUtils.fillAll());
145 // Composite parent = new Composite(parent2, SWT.NO_FOCUS);
146 // parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
147 // parent.setLayoutData(EclipseUiUtils.fillAll());
149 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
150 // Define the displayed columns
151 columnDefs
.add(new ColumnDefinition(new RoleIconLP(), "", 0, 24));
152 columnDefs
.add(new ColumnDefinition(new UserNameLP(),
153 "Distinguished Name", 240));
154 columnDefs
.add(new ColumnDefinition(new CommonNameLP(), "Common Name",
156 columnDefs
.add(new ColumnDefinition(new MailLP(), "Primary Mail", 150));
158 // Create and configure the table
159 userTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
160 | SWT
.H_SCROLL
| SWT
.V_SCROLL
, userAdmin
);
162 userTableViewerCmp
.setColumnDefinitions(columnDefs
);
163 userTableViewerCmp
.populate(true, false);
164 // userTableViewerCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
166 userTableViewerCmp
.setLayoutData(EclipseUiUtils
.fillAll());
169 userViewer
= userTableViewerCmp
.getTableViewer();
170 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
172 userTableViewerCmp
.refresh();
175 private class MyUserTableViewer
extends UserTableViewer
{
176 private static final long serialVersionUID
= 8467999509931900367L;
178 public MyUserTableViewer(Composite parent
, int style
,
179 UserAdmin userAdmin
) {
180 super(parent
, style
, userAdmin
, true);
184 protected List
<User
> listFilteredElements(String filter
) {
185 Group group
= (Group
) editor
.getDisplayedUser();
186 Role
[] roles
= group
.getMembers();
187 List
<User
> users
= new ArrayList
<User
>();
188 for (Role role
: roles
)
189 // if (role.getType() == Role.GROUP)
190 users
.add((User
) role
);
195 private void refreshFormTitle() throws RepositoryException
{
196 getManagedForm().getForm().setText(
197 editor
.getProperty(UserAdminConstants
.KEY_CN
));
200 private Composite
addSection(FormToolkit tk
, Composite parent
, String title
) {
201 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
);
202 GridData gd
= EclipseUiUtils
.fillWidth();
203 gd
.verticalAlignment
= PRE_TITLE_INDENT
;
204 section
.setLayoutData(gd
);
205 section
.setText(title
);
206 Composite body
= tk
.createComposite(section
, SWT
.WRAP
);
207 body
.setLayoutData(EclipseUiUtils
.fillAll());
208 section
.setClient(body
);
212 /** Creates label and text. */
213 protected Text
createLT(Composite body
, String label
, String value
) {
214 FormToolkit toolkit
= getManagedForm().getToolkit();
215 Label lbl
= toolkit
.createLabel(body
, label
);
216 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
217 Text text
= toolkit
.createText(body
, value
, SWT
.BORDER
);
218 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
222 // private class FormPartML implements ModifyListener {
223 // private static final long serialVersionUID = 6299808129505381333L;
224 // private AbstractFormPart formPart;
226 // public FormPartML(AbstractFormPart generalPart) {
227 // this.formPart = generalPart;
230 // public void modifyText(ModifyEvent e) {
231 // formPart.markDirty();