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
.Arrays
;
20 import javax
.jcr
.RepositoryException
;
22 import org
.argeo
.ArgeoException
;
23 import org
.argeo
.jcr
.ArgeoNames
;
24 import org
.argeo
.security
.ui
.admin
.internal
.UserAdminConstants
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.events
.ModifyEvent
;
27 import org
.eclipse
.swt
.events
.ModifyListener
;
28 import org
.eclipse
.swt
.layout
.GridData
;
29 import org
.eclipse
.swt
.layout
.GridLayout
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Label
;
32 import org
.eclipse
.swt
.widgets
.Text
;
33 import org
.eclipse
.ui
.forms
.AbstractFormPart
;
34 import org
.eclipse
.ui
.forms
.IManagedForm
;
35 import org
.eclipse
.ui
.forms
.SectionPart
;
36 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
37 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
38 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
39 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
40 import org
.eclipse
.ui
.forms
.widgets
.Section
;
42 /** Display/edit the properties common to all users */
43 public class UserMainPage
extends FormPage
implements ArgeoNames
{
44 final static String ID
= "argeoUserEditor.mainPage";
46 // private final static Log log = LogFactory.getLog(UserMainPage.class);
48 private final UserEditor editor
;
49 private char[] newPassword
;
51 public UserMainPage(FormEditor editor
) {
52 super(editor
, ID
, "Main");
53 this.editor
= (UserEditor
) editor
;
56 protected void createFormContent(final IManagedForm mf
) {
58 ScrolledForm form
= mf
.getForm();
59 refreshFormTitle(form
);
60 GridLayout mainLayout
= new GridLayout(1, true);
61 form
.getBody().setLayout(mainLayout
);
63 createGeneralPart(form
.getBody());
64 // createPassworPart(form.getBody());
65 } catch (RepositoryException e
) {
66 throw new ArgeoException("Cannot create form content", e
);
70 /** Creates the general section */
71 protected void createGeneralPart(Composite parent
)
72 throws RepositoryException
{
73 FormToolkit tk
= getManagedForm().getToolkit();
74 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
);
75 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
76 section
.setText("General");
77 Composite body
= tk
.createComposite(section
, SWT
.WRAP
);
78 section
.setClient(body
);
79 GridLayout layout
= new GridLayout(2, false);
80 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
81 body
.setLayout(layout
);
83 final Text commonName
= createLT(body
, "Common Name",
84 editor
.getProperty(UserAdminConstants
.KEY_CN
));
85 commonName
.setEnabled(false);
87 // final Text firstName = createLT(body, "First name",
88 // getProperty(ARGEO_FIRST_NAME));
89 // final Text lastName = createLT(body, "Last name",
90 // getProperty(ARGEO_LAST_NAME));
91 final Text email
= createLT(body
, "Email",
92 editor
.getProperty(UserAdminConstants
.KEY_MAIL
));
93 // final Text description = createLMT(body, "Description",
94 // getProperty(Property.JCR_DESCRIPTION));
96 // create form part (controller)
97 AbstractFormPart part
= new SectionPart(section
) {
98 public void commit(boolean onSave
) {
99 // TODO check mail validity
100 editor
.setProperty(UserAdminConstants
.KEY_MAIL
, email
.getText());
102 // userProfile.getSession().getWorkspace().getVersionManager()
103 // .checkout(userProfile.getPath());
104 // userProfile.setProperty(Property.JCR_TITLE,
105 // commonName.getText());
106 // userProfile.setProperty(ARGEO_FIRST_NAME,
107 // firstName.getText());
109 // .setProperty(ARGEO_LAST_NAME, lastName.getText());
110 // userProfile.setProperty(ARGEO_PRIMARY_EMAIL,
112 // userProfile.setProperty(Property.JCR_DESCRIPTION,
113 // description.getText());
114 // userProfile.getSession().save();
115 // userProfile.getSession().getWorkspace().getVersionManager()
116 // .checkin(userProfile.getPath());
117 super.commit(onSave
);
120 // if (username != null)
121 // username.addModifyListener(new FormPartML(part));
122 // commonName.addModifyListener(new FormPartML(part));
123 // firstName.addModifyListener(new FormPartML(part));
124 // lastName.addModifyListener(new FormPartML(part));
126 email
.addModifyListener(new FormPartML(part
));
127 getManagedForm().addPart(part
);
130 private void refreshFormTitle(ScrolledForm form
) throws RepositoryException
{
131 // form.setText(getProperty(Property.JCR_TITLE)
132 // + (userProfile.getProperty(ARGEO_ENABLED).getBoolean() ? ""
133 // : " [DISABLED]"));
136 // /** @return the property, or the empty string if not set */
137 // protected String getProperty(String name) throws RepositoryException {
138 // return userProfile.hasProperty(name) ? userProfile.getProperty(name)
139 // .getString() : "";
142 /** Creates the password section */
143 // protected void createPassworPart(Composite parent) {
144 // FormToolkit tk = getManagedForm().getToolkit();
145 // Section section = tk.createSection(parent, Section.TITLE_BAR);
146 // section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
147 // section.setText("Password");
149 // Composite body = tk.createComposite(section, SWT.WRAP);
150 // section.setClient(body);
151 // GridLayout layout = new GridLayout(2, false);
152 // body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
153 // body.setLayout(layout);
155 // // add widgets (view)
156 // final Text password1 = createLP(body, "New password", "");
157 // final Text password2 = createLP(body, "Repeat password", "");
158 // // create form part (controller)
159 // AbstractFormPart part = new SectionPart(section) {
161 // public void commit(boolean onSave) {
162 // if (!password1.getText().equals("")
163 // || !password2.getText().equals("")) {
164 // if (password1.getText().equals(password2.getText())) {
165 // newPassword = password1.getText().toCharArray();
166 // password1.setText("");
167 // password2.setText("");
168 // super.commit(onSave);
170 // password1.setText("");
171 // password2.setText("");
172 // throw new ArgeoException("Passwords are not equals");
178 // password1.addModifyListener(new FormPartML(part));
179 // password2.addModifyListener(new FormPartML(part));
180 // getManagedForm().addPart(part);
183 /** Creates label and text. */
184 protected Text
createLT(Composite body
, String label
, String value
) {
185 FormToolkit toolkit
= getManagedForm().getToolkit();
186 Label lbl
= toolkit
.createLabel(body
, label
);
187 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
188 Text text
= toolkit
.createText(body
, value
, SWT
.BORDER
);
189 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
193 /** Creates label and multiline text. */
194 protected Text
createLMT(Composite body
, String label
, String value
) {
195 FormToolkit toolkit
= getManagedForm().getToolkit();
196 Label lbl
= toolkit
.createLabel(body
, label
);
197 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
198 Text text
= toolkit
.createText(body
, value
, SWT
.BORDER
| SWT
.MULTI
);
199 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, true));
203 /** Creates label and password. */
204 protected Text
createLP(Composite body
, String label
, String value
) {
205 FormToolkit toolkit
= getManagedForm().getToolkit();
206 Label lbl
= toolkit
.createLabel(body
, label
);
207 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
208 Text text
= toolkit
.createText(body
, value
, SWT
.BORDER
| SWT
.PASSWORD
);
209 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
213 private class FormPartML
implements ModifyListener
{
214 private static final long serialVersionUID
= 6299808129505381333L;
215 private AbstractFormPart formPart
;
217 public FormPartML(AbstractFormPart generalPart
) {
218 this.formPart
= generalPart
;
221 public void modifyText(ModifyEvent e
) {
222 formPart
.markDirty();
227 public String
getNewPassword() {
228 if (newPassword
!= null)
229 return new String(newPassword
);
234 public void resetNewPassword() {
235 if (newPassword
!= null)
236 Arrays
.fill(newPassword
, 'x');