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
.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
;
51 /** Display/edit main properties of a given group */
52 public class GroupMainPage
extends FormPage
implements ArgeoNames
{
53 final static String ID
= "GroupEditor.mainPage";
55 private final UserEditor editor
;
57 private UserAdmin userAdmin
;
59 public GroupMainPage(FormEditor editor
, UserAdmin userAdmin
) {
60 super(editor
, ID
, "Main");
61 this.editor
= (UserEditor
) editor
;
62 this.userAdmin
= userAdmin
;
65 protected void createFormContent(final IManagedForm mf
) {
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
);
78 /** Creates the general section */
79 protected void createGeneralPart(Composite parent
)
80 throws RepositoryException
{
81 parent
.setLayout(new GridLayout());
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
));
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());
94 createMemberPart(body
);
96 // create form part (controller)
97 AbstractFormPart part
= new SectionPart(section
) {
98 public void commit(boolean onSave
) {
103 getManagedForm().addPart(part
);
107 private UserTableViewer userTableViewerCmp
;
108 private TableViewer userViewer
;
109 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
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());
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",
125 columnDefs
.add(new ColumnDefinition(new MailLP(), "Primary Mail", 150));
127 // Create and configure the table
128 userTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
129 | SWT
.H_SCROLL
| SWT
.V_SCROLL
, userAdmin
);
131 userTableViewerCmp
.setColumnDefinitions(columnDefs
);
132 userTableViewerCmp
.populate(true, false);
133 // userTableViewerCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
135 userTableViewerCmp
.setLayoutData(EclipseUiUtils
.fillAll());
138 userViewer
= userTableViewerCmp
.getTableViewer();
139 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
141 userTableViewerCmp
.refresh();
144 private class MyUserTableViewer
extends UserTableViewer
{
145 private static final long serialVersionUID
= 8467999509931900367L;
147 public MyUserTableViewer(Composite parent
, int style
,
148 UserAdmin userAdmin
) {
149 super(parent
, style
, userAdmin
, true);
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
);
164 private void refreshFormTitle(ScrolledForm form
) throws RepositoryException
{
165 // form.setText(getProperty(Property.JCR_TITLE)
166 // + (userProfile.getProperty(ARGEO_ENABLED).getBoolean() ? ""
167 // : " [DISABLED]"));
170 // private class FormPartML implements ModifyListener {
171 // private static final long serialVersionUID = 6299808129505381333L;
172 // private AbstractFormPart formPart;
174 // public FormPartML(AbstractFormPart generalPart) {
175 // this.formPart = generalPart;
178 // public void modifyText(ModifyEvent e) {
179 // formPart.markDirty();