1 package org
.argeo
.security
.ui
.admin
.editors
;
3 import java
.util
.Arrays
;
6 import javax
.jcr
.Property
;
7 import javax
.jcr
.RepositoryException
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.jcr
.ArgeoNames
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.ModifyEvent
;
15 import org
.eclipse
.swt
.events
.ModifyListener
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Label
;
20 import org
.eclipse
.swt
.widgets
.Text
;
21 import org
.eclipse
.ui
.forms
.AbstractFormPart
;
22 import org
.eclipse
.ui
.forms
.IManagedForm
;
23 import org
.eclipse
.ui
.forms
.SectionPart
;
24 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
25 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
26 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
27 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
28 import org
.eclipse
.ui
.forms
.widgets
.Section
;
31 * Display/edit the properties common to all Argeo users
33 public class DefaultUserMainPage
extends FormPage
implements ArgeoNames
{
34 final static String ID
= "argeoUserEditor.mainPage";
36 private final static Log log
= LogFactory
.getLog(DefaultUserMainPage
.class);
37 private Node userProfile
;
39 private char[] newPassword
;
41 public DefaultUserMainPage(FormEditor editor
, Node userProfile
) {
42 super(editor
, ID
, "Main");
43 this.userProfile
= userProfile
;
46 protected void createFormContent(final IManagedForm mf
) {
48 ScrolledForm form
= mf
.getForm();
49 form
.setText(userProfile
.getProperty(ARGEO_FIRST_NAME
).getString()
51 + userProfile
.getProperty(ARGEO_LAST_NAME
).getString());
52 GridLayout mainLayout
= new GridLayout(1, true);
53 // ColumnLayout mainLayout = new ColumnLayout();
54 // mainLayout.minNumColumns = 1;
55 // mainLayout.maxNumColumns = 4;
56 // mainLayout.topMargin = 0;
57 // mainLayout.bottomMargin = 5;
58 // mainLayout.leftMargin = mainLayout.rightMargin =
59 // mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 10;
60 form
.getBody().setLayout(mainLayout
);
62 createGeneralPart(form
.getBody());
63 createPassworPart(form
.getBody());
64 } catch (RepositoryException e
) {
65 throw new ArgeoException("Cannot create form content", e
);
69 /** Creates the general section */
70 protected void createGeneralPart(Composite parent
)
71 throws RepositoryException
{
72 FormToolkit tk
= getManagedForm().getToolkit();
73 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
);
74 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
75 section
.setText("General");
76 Composite body
= tk
.createComposite(section
, SWT
.WRAP
);
77 section
.setClient(body
);
78 GridLayout layout
= new GridLayout(2, false);
79 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
80 body
.setLayout(layout
);
83 // final Text username;
84 // if (user.getUsername() != null) {
85 // tk.createLabel(body, "Username");
86 // tk.createLabel(body, user.getUsername());
89 // username = createLT(body, "Username", "");
91 final Text firstName
= createLT(body
, "First name",
92 userProfile
.getProperty(ARGEO_FIRST_NAME
));
93 final Text lastName
= createLT(body
, "Last name",
94 userProfile
.getProperty(ARGEO_LAST_NAME
));
95 final Text email
= createLT(body
, "Email",
96 userProfile
.getProperty(ARGEO_PRIMARY_EMAIL
));
97 final Text description
= createLT(body
, "Description",
98 userProfile
.getProperty(Property
.JCR_DESCRIPTION
));
100 // create form part (controller)
101 AbstractFormPart part
= new SectionPart(section
) {
102 public void commit(boolean onSave
) {
103 // if (username != null) {
104 // ((SimpleArgeoUser) user).setUsername(username.getText());
105 // username.setEditable(false);
106 // username.setEnabled(false);
108 // simpleNature.setFirstName(firstName.getText());
109 // simpleNature.setLastName(lastName.getText());
110 // simpleNature.setEmail(email.getText());
111 // simpleNature.setDescription(description.getText());
113 userProfile
.setProperty(ARGEO_FIRST_NAME
,
114 firstName
.getText());
116 .setProperty(ARGEO_LAST_NAME
, lastName
.getText());
117 userProfile
.setProperty(ARGEO_PRIMARY_EMAIL
,
119 userProfile
.setProperty(Property
.JCR_DESCRIPTION
,
120 description
.getText());
121 userProfile
.getSession().save();
122 super.commit(onSave
);
123 if (log
.isTraceEnabled())
124 log
.trace("General part committed");
125 } catch (RepositoryException e
) {
126 throw new ArgeoException("Cannot commit", e
);
130 // if (username != null)
131 // username.addModifyListener(new FormPartML(part));
132 firstName
.addModifyListener(new FormPartML(part
));
133 lastName
.addModifyListener(new FormPartML(part
));
134 email
.addModifyListener(new FormPartML(part
));
135 description
.addModifyListener(new FormPartML(part
));
136 getManagedForm().addPart(part
);
139 /** Creates the password section */
140 protected void createPassworPart(Composite parent
) {
141 FormToolkit tk
= getManagedForm().getToolkit();
142 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
);
143 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
144 section
.setText("Password");
146 Composite body
= tk
.createComposite(section
, SWT
.WRAP
);
147 section
.setClient(body
);
148 GridLayout layout
= new GridLayout(2, false);
149 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
150 body
.setLayout(layout
);
152 // add widgets (view)
153 final Text password1
= createLP(body
, "New password", "");
154 final Text password2
= createLP(body
, "Repeat password", "");
155 // create form part (controller)
156 AbstractFormPart part
= new SectionPart(section
) {
158 public void commit(boolean onSave
) {
159 if (!password1
.getText().equals("")
160 || !password2
.getText().equals("")) {
161 if (password1
.getText().equals(password2
.getText())) {
162 newPassword
= password1
.getText().toCharArray();
163 password1
.setText("");
164 password2
.setText("");
165 super.commit(onSave
);
167 password1
.setText("");
168 password2
.setText("");
169 throw new ArgeoException("Passwords are not equals");
175 password1
.addModifyListener(new FormPartML(part
));
176 password2
.addModifyListener(new FormPartML(part
));
177 getManagedForm().addPart(part
);
180 /** Creates label and text. */
181 protected Text
createLT(Composite body
, String label
, String value
) {
182 FormToolkit toolkit
= getManagedForm().getToolkit();
183 Label lbl
= toolkit
.createLabel(body
, label
);
184 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
185 Text text
= toolkit
.createText(body
, value
, SWT
.BORDER
);
186 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
190 protected Text
createLT(Composite body
, String label
, Property value
)
191 throws RepositoryException
{
192 return createLT(body
, label
, value
.getString());
195 /** Creates label and password. */
196 protected Text
createLP(Composite body
, String label
, String value
) {
197 FormToolkit toolkit
= getManagedForm().getToolkit();
198 Label lbl
= toolkit
.createLabel(body
, label
);
199 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
200 Text text
= toolkit
.createText(body
, value
, SWT
.BORDER
| SWT
.PASSWORD
);
201 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
205 private class FormPartML
implements ModifyListener
{
206 private AbstractFormPart formPart
;
208 public FormPartML(AbstractFormPart generalPart
) {
209 this.formPart
= generalPart
;
212 public void modifyText(ModifyEvent e
) {
213 formPart
.markDirty();
218 public String
getNewPassword() {
219 if (newPassword
!= null)
220 return new String(newPassword
);
225 public void resetNewPassword() {
226 if (newPassword
!= null)
227 Arrays
.fill(newPassword
, 'x');