]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java
Introduce Commons Modeshape
[lgpl/argeo-commons.git] / security / eclipse / plugins / org.argeo.security.ui / src / main / java / org / argeo / security / ui / editors / ArgeoUserEditor.java
1 package org.argeo.security.ui.editors;
2
3 import org.argeo.ArgeoException;
4 import org.argeo.security.ArgeoSecurityService;
5 import org.argeo.security.ArgeoUser;
6 import org.argeo.security.SimpleArgeoUser;
7 import org.argeo.security.nature.SimpleUserNature;
8 import org.eclipse.core.runtime.IProgressMonitor;
9 import org.eclipse.ui.IEditorInput;
10 import org.eclipse.ui.IEditorSite;
11 import org.eclipse.ui.PartInitException;
12 import org.eclipse.ui.forms.editor.FormEditor;
13
14 /** Editor for an Argeo user. */
15 public class ArgeoUserEditor extends FormEditor {
16 public final static String ID = "org.argeo.security.ui.argeoUserEditor";
17
18 private ArgeoUser user;
19 private ArgeoSecurityService securityService;
20
21 public void init(IEditorSite site, IEditorInput input)
22 throws PartInitException {
23 super.init(site, input);
24 String username = ((ArgeoUserEditorInput) getEditorInput())
25 .getUsername();
26 if (username == null) {// new
27 user = new SimpleArgeoUser();
28 user.getUserNatures().put(SimpleUserNature.TYPE,
29 new SimpleUserNature());
30 } else
31 user = securityService.getSecurityDao().getUser(username);
32 this.setPartProperty("name", username != null ? username : "<new user>");
33 setPartName(username != null ? username : "<new user>");
34 }
35
36 protected void addPages() {
37 try {
38 addPage(new DefaultUserMainPage(this, securityService, user));
39
40 } catch (PartInitException e) {
41 throw new ArgeoException("Not able to add page ", e);
42 }
43 }
44
45 @Override
46 public void doSave(IProgressMonitor monitor) {
47 // list pages
48 // TODO: make it more generic
49 findPage(DefaultUserMainPage.ID).doSave(monitor);
50
51 if (securityService.getSecurityDao().userExists(user.getUsername()))
52 securityService.updateUser(user);
53 else {
54 securityService.newUser(user);
55 setPartName(user.getUsername());
56 }
57 firePropertyChange(PROP_DIRTY);
58 }
59
60 @Override
61 public void doSaveAs() {
62 }
63
64 @Override
65 public boolean isSaveAsAllowed() {
66 return false;
67 }
68
69 public void setSecurityService(ArgeoSecurityService securityService) {
70 this.securityService = securityService;
71 }
72 }