X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.security.ui.admin%2Fsrc%2Forg%2Fargeo%2Fsecurity%2Fui%2Fadmin%2Feditors%2FUserEditor.java;fp=org.argeo.security.ui.admin%2Fsrc%2Forg%2Fargeo%2Fsecurity%2Fui%2Fadmin%2Feditors%2FUserEditor.java;h=7518b8084aaf90892e0117f0ece1412b29f3d0e5;hb=dd3d0d60b62c99810eca8619a376b66dbca5e44d;hp=0000000000000000000000000000000000000000;hpb=40c3800ea57d5de136137e3fb0ff07cf54f2df48;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java new file mode 100644 index 000000000..7518b8084 --- /dev/null +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.admin.editors; + +import org.argeo.ArgeoException; +import org.argeo.security.ui.admin.SecurityAdminImages; +import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.admin.UserAdminConstants; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.forms.editor.FormEditor; +import org.osgi.service.useradmin.Role; +import org.osgi.service.useradmin.User; +import org.osgi.service.useradmin.UserAdmin; + +/** Editor for an Argeo user. */ +public class UserEditor extends FormEditor implements UserAdminConstants { + private static final long serialVersionUID = 8357851520380820241L; + + public final static String ID = SecurityAdminPlugin.PLUGIN_ID + + ".userEditor"; + + /* DEPENDENCY INJECTION */ + private UserAdmin userAdmin; + + // Context + private User user; + private String username; + + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + super.init(site, input); + username = ((UserEditorInput) getEditorInput()).getUsername(); + user = (User) userAdmin.getRole(username); + + String commonName = getProperty(KEY_CN); + // this.setPartProperty("name", commonName != null ? commonName + // : "username"); + + // if (user.getType() == Role.GROUP) { + // this.setPartProperty("icon", "icons/users.gif"); + // firePartPropertyChanged("icon", "icons/user.gif", "icons/users.gif"); + // } + setPartName(commonName != null ? commonName : "username"); + } + + protected void addPages() { + try { + + if (user.getType() == Role.GROUP) + addPage(new GroupMainPage(this, userAdmin)); + else + addPage(new UserMainPage(this)); + + + + } catch (Exception e) { + throw new ArgeoException("Cannot add pages", e); + } + } + + protected String getProperty(String key) { + Object obj = user.getProperties().get(key); + if (obj != null) + return (String) obj; + else + return ""; + } + + /** The property is directly updated!!! */ + @SuppressWarnings("unchecked") + protected void setProperty(String key, String value) { + user.getProperties().put(key, value); + } + + @Override + public void doSave(IProgressMonitor monitor) { + commitPages(true); + firePropertyChange(PROP_DIRTY); + } + + @Override + public void doSaveAs() { + } + + @Override + public boolean isSaveAsAllowed() { + return false; + } + + public void refresh() { + + } + + @Override + public void dispose() { + super.dispose(); + } + + /* DEPENDENCY INJECTION */ + public void setUserAdmin(UserAdmin userAdmin) { + this.userAdmin = userAdmin; + } +} \ No newline at end of file