import org.apache.commons.logging.LogFactory;
import org.argeo.security.ArgeoSecurityService;
import org.argeo.security.ArgeoUser;
+import org.argeo.security.SimpleArgeoUser;
import org.argeo.security.nature.SimpleUserNature;
import org.argeo.security.ui.SecurityUiPlugin;
import org.eclipse.jface.viewers.CellEditor;
public class DefaultUserMainPage extends FormPage {
final static String ID = "argeoUserEditor.mainPage";
+ private final static Log log = LogFactory.getLog(DefaultUserMainPage.class);
private final static Image ROLE_CHECKED = SecurityUiPlugin
.getImageDescriptor("icons/security.gif").createImage();
- private final static Log log = LogFactory.getLog(ArgeoUserEditor.class);
private ArgeoUser user;
private SimpleUserNature simpleNature;
createGeneralPart(form.getBody());
createRolesPart(form.getBody());
+ createPassworPart(form.getBody());
}
/** Creates the general section */
body.setLayout(layout);
// add widgets (view)
- tk.createLabel(body, "Username");
- tk.createLabel(body, user.getUsername());
+ final Text username;
+ if (user.getUsername() != null) {
+ tk.createLabel(body, "Username");
+ tk.createLabel(body, user.getUsername());
+ username = null;
+ } else {
+ username = createLT(body, "Username", "");
+ }
final Text firstName = createLT(body, "First name",
simpleNature.getFirstName());
final Text lastName = createLT(body, "Last name",
// create form part (controller)
AbstractFormPart part = new SectionPart(section) {
public void commit(boolean onSave) {
+ if (username != null) {
+ ((SimpleArgeoUser) user).setUsername(username.getText());
+ username.setEditable(false);
+ username.setEnabled(false);
+ }
simpleNature.setFirstName(firstName.getText());
simpleNature.setLastName(lastName.getText());
simpleNature.setEmail(email.getText());
simpleNature.setDescription(description.getText());
super.commit(onSave);
- if (log.isDebugEnabled())
- log.debug("General part committed");
+ if (log.isTraceEnabled())
+ log.trace("General part committed");
}
};
+ if (username != null)
+ username.addModifyListener(new FormPartML(part));
firstName.addModifyListener(new FormPartML(part));
lastName.addModifyListener(new FormPartML(part));
email.addModifyListener(new FormPartML(part));
getManagedForm().addPart(part);
}
+ /** Creates the password section */
+ protected void createPassworPart(Composite parent) {
+ FormToolkit tk = getManagedForm().getToolkit();
+ Section section = tk.createSection(parent, Section.TITLE_BAR);
+ section.setText("Password");
+
+ Composite body = tk.createComposite(section, SWT.WRAP);
+ section.setClient(body);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = layout.marginHeight = 0;
+ layout.numColumns = 2;
+ body.setLayout(layout);
+
+ // add widgets (view)
+ final Text password1 = createLP(body, "New password", "");
+ final Text password2 = createLP(body, "Repeat password", "");
+ // create form part (controller)
+ AbstractFormPart part = new SectionPart(section) {
+ public void commit(boolean onSave) {
+ if (!password1.getText().equals("")
+ && password1.getText().equals(password2.getText())) {
+ ((SimpleArgeoUser) user).setPassword(password1.getText());
+ }
+ super.commit(onSave);
+ if (log.isTraceEnabled())
+ log.trace("Password part committed");
+ }
+ };
+ password1.addModifyListener(new FormPartML(part));
+ password2.addModifyListener(new FormPartML(part));
+ getManagedForm().addPart(part);
+ }
+
/** Creates the role section */
protected void createRolesPart(Composite parent) {
FormToolkit tk = getManagedForm().getToolkit();
public void commit(boolean onSave) {
// roles have already been modified in editing
super.commit(onSave);
- if (log.isDebugEnabled())
- log.debug("Role part committed");
+ if (log.isTraceEnabled())
+ log.trace("Role part committed");
}
};
getManagedForm().addPart(part);
return text;
}
+ /** Creates label and password. */
+ protected Text createLP(Composite body, String label, String value) {
+ FormToolkit toolkit = getManagedForm().getToolkit();
+ toolkit.createLabel(body, label);
+ Text text = toolkit.createText(body, value, SWT.BORDER | SWT.PASSWORD);
+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ return text;
+ }
+
public void setSimpleNatureType(String simpleNatureType) {
this.simpleNatureType = simpleNatureType;
}
private class RolesContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
- return securityService.getSecurityDao().listEditableRoles()
- .toArray();
+ return securityService.listEditableRoles().toArray();
}
public void dispose() {