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 org
.argeo
.ArgeoException
;
22 import org
.argeo
.security
.ui
.admin
.SecurityAdminImages
;
23 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
24 import org
.argeo
.security
.ui
.admin
.internal
.UserAdminConstants
;
25 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
26 import org
.eclipse
.ui
.IEditorInput
;
27 import org
.eclipse
.ui
.IEditorSite
;
28 import org
.eclipse
.ui
.PartInitException
;
29 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
30 import org
.osgi
.service
.useradmin
.Authorization
;
31 import org
.osgi
.service
.useradmin
.Role
;
32 import org
.osgi
.service
.useradmin
.User
;
33 import org
.osgi
.service
.useradmin
.UserAdmin
;
35 /** Editor for a user, might be a user or a group. */
36 public class UserEditor
extends FormEditor
implements UserAdminConstants
{
37 private static final long serialVersionUID
= 8357851520380820241L;
39 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
42 /* DEPENDENCY INJECTION */
43 private UserAdmin userAdmin
;
47 private String username
;
49 public void init(IEditorSite site
, IEditorInput input
)
50 throws PartInitException
{
51 super.init(site
, input
);
52 username
= ((UserEditorInput
) getEditorInput()).getUsername();
53 user
= (User
) userAdmin
.getRole(username
);
55 String commonName
= getProperty(KEY_CN
);
56 // this.setPartProperty("name", commonName != null ? commonName
59 // if (user.getType() == Role.GROUP) {
60 // this.setPartProperty("icon", "icons/users.gif");
61 // firePartPropertyChanged("icon", "icons/user.gif", "icons/users.gif");
63 setPartName(commonName
!= null ? commonName
: "username");
64 setTitleImage(user
.getType() == Role
.GROUP ? SecurityAdminImages
.ICON_GROUP
65 : SecurityAdminImages
.ICON_USER
);
68 protected List
<User
> getFlatGroups() {
69 Authorization currAuth
= userAdmin
.getAuthorization(user
);
70 String
[] roles
= currAuth
.getRoles();
72 List
<User
> groups
= new ArrayList
<User
>();
73 for (String roleStr
: roles
) {
74 User currRole
= (User
) userAdmin
.getRole(roleStr
);
75 if (!groups
.contains(currRole
))
81 /** Exposes the user (or group) that is displayed by the current editor */
82 protected User
getDisplayedUser() {
86 void updateEditorTitle(String title
) {
90 protected void addPages() {
93 if (user
.getType() == Role
.GROUP
)
94 addPage(new GroupMainPage(this, userAdmin
));
96 addPage(new UserMainPage(this, userAdmin
));
98 } catch (Exception e
) {
99 throw new ArgeoException("Cannot add pages", e
);
103 protected String
getProperty(String key
) {
104 Object obj
= user
.getProperties().get(key
);
111 /** The property is directly updated!!! */
112 @SuppressWarnings("unchecked")
113 protected void setProperty(String key
, String value
) {
114 user
.getProperties().put(key
, value
);
118 public void doSave(IProgressMonitor monitor
) {
120 firePropertyChange(PROP_DIRTY
);
124 public void doSaveAs() {
128 public boolean isSaveAsAllowed() {
132 public void refresh() {
137 public void dispose() {
141 /* DEPENDENCY INJECTION */
142 public void setUserAdmin(UserAdmin userAdmin
) {
143 this.userAdmin
= userAdmin
;