You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by de...@apache.org on 2009/09/16 05:11:24 UTC
svn commit: r815595 - in
/geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins:
org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/operations/
org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/
org.apache....
Author: delos
Date: Wed Sep 16 03:11:23 2009
New Revision: 815595
URL: http://svn.apache.org/viewvc?rev=815595&view=rev
Log:
GERONIMODEVTOOLS-320 Provide facility to change id/pw associated with server instance (withing creating a new instance of the server)
Added:
geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/operations/GeronimoAccountManager.java
geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/ManageAccountWizard.java
Modified:
geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.java
geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.properties
geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/sections/ServerEditorSecuritySection.java
geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/AbstractWizard.java
Added: geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/operations/GeronimoAccountManager.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/operations/GeronimoAccountManager.java?rev=815595&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/operations/GeronimoAccountManager.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/operations/GeronimoAccountManager.java Wed Sep 16 03:11:23 2009
@@ -0,0 +1,135 @@
+package org.apache.geronimo.st.core.operations;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.geronimo.st.core.internal.Trace;
+import org.eclipse.wst.server.core.IRuntime;
+
+//currently, only geronimo-admin with properties file realm is supported
+public class GeronimoAccountManager {
+ private Properties userProperties;
+ private Properties groupProperties;
+
+ private String securityPath;
+ private static final String userPropertiesFile = "users.properties";
+ private static final String groupPropertiesFile = "groups.properties";
+
+ public GeronimoAccountManager(IRuntime runtime){
+ if (runtime!=null){
+ securityPath = runtime.getLocation().toOSString()+"/var/security";
+ }
+ }
+
+ public void init() throws Exception{
+ userProperties = new Properties();
+ groupProperties= new Properties();
+ try {
+ userProperties.load(new FileInputStream(new File(securityPath,userPropertiesFile)));
+ groupProperties.load(new FileInputStream(new File(securityPath,groupPropertiesFile)));
+ } catch (FileNotFoundException e) {
+ Trace.trace(Trace.SEVERE, e.getMessage());
+ throw e;
+ } catch (IOException e) {
+ Trace.trace(Trace.SEVERE, e.getMessage());
+ throw e;
+ }
+ }
+
+ public String[] getUserList(){
+ return userProperties.keySet().toArray(new String[0]);
+ }
+
+ public String[] getGroupList(){
+ return groupProperties.keySet().toArray(new String[0]);
+ }
+
+ public boolean modifyUser(String oldName, String newName,String newGroup, String passwd){
+ boolean operationResult = false;
+
+ operationResult = true;
+ return operationResult;
+ }
+
+ private void addUserIntoGroup(String groupName,String userName){
+ String userList = groupProperties.getProperty(groupName);
+ int index = getIndexOfUser(userName,userList);
+ if (index!=-1){
+ //user already exists
+ return;
+ }else {
+ userList = userList.concat(",").concat(userName);
+ }
+ groupProperties.setProperty(groupName, userList);
+ }
+
+ private void delUserFromGroup(String groupName,String userName){
+ String userList = groupProperties.getProperty(groupName);
+ int index = getIndexOfUser(userName,userList);
+ if (index == -1) return;
+ else{
+ userList = removeUser(userList,index);
+ }
+ groupProperties.setProperty(groupName, userList);
+ }
+
+ private String removeUser(String userList, int index) {
+ String[] users = userList.split(",");
+ StringBuilder usersStr = new StringBuilder();
+ for (int i=0;i<users.length;i++){
+ if (i!=index) {
+ usersStr.append(users[i].concat(","));
+ }
+ }
+ //delete last comma
+ usersStr.deleteCharAt(usersStr.length()-1);
+
+ return usersStr.toString();
+ }
+
+ public void delUser(String userName){
+ String password = userProperties.getProperty(userName);
+ if (password!=null) {
+ userProperties.remove(userName);
+ }
+
+ Set<Object> groupSet = groupProperties.keySet();
+ for (Object group:groupSet){
+ delUserFromGroup((String)group,userName);
+ }
+ }
+
+
+ public void addUser(String userName,String groupName,String password){
+ userProperties.setProperty(userName, password);
+ addUserIntoGroup(groupName,userName);
+ }
+
+ public void persist() throws Exception, IOException{
+ try{
+ groupProperties.store(new FileOutputStream(new File(securityPath,groupPropertiesFile)), "");
+ userProperties.store(new FileOutputStream(new File(securityPath,userPropertiesFile)), "");
+ } catch (FileNotFoundException e) {
+ Trace.trace(Trace.SEVERE, e.getMessage());
+ throw e;
+ } catch (IOException e) {
+ Trace.trace(Trace.SEVERE, e.getMessage());
+ throw e;
+ }
+ }
+
+ private int getIndexOfUser(String username,String userList){
+ String[] users = userList.split(",");
+ for (int i=0;i<users.length;i++){
+ if (users[i].equalsIgnoreCase(username))
+ return i;
+ }
+ return -1;
+ }
+
+}
Modified: geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.java?rev=815595&r1=815594&r2=815595&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.java (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.java Wed Sep 16 03:11:23 2009
@@ -228,6 +228,7 @@
public static String remove;
public static String edit;
// Wizard/Wizard Pages
+ public static String wizardTitle_ManageAccount;
public static String wizardNewTitle_ResRef;
public static String wizardEditTitle_ResRef;
public static String wizardPageTitle_ResRef;
@@ -300,6 +301,16 @@
public static String wizardTabManual_Dependency;
public static String wizardTabServer_Dependency;
public static String dependencyGroupLabel;
+
+ public static String addUser;
+ public static String delUser;
+ public static String editUser;
+ public static String oldPassword;
+ public static String newPassword;
+ public static String groupName;
+ public static String passwordNotEqual;
+ public static String cannotSave;
+ public static String cannotRead;
public static String groupId;
public static String artifactId;
@@ -468,16 +479,9 @@
public static String createCustomAssembly;
public static String convertAppsToPlugins;
-
-
-
-
-
-
-
-
-
-
+ public static String manageAccount;
+ public static String manageAccountDescription;
+ public static String isNotLocalHost;
public static String poolName;
public static String dbType;
Modified: geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.properties
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.properties?rev=815595&r1=815594&r2=815595&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.properties (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/internal/Messages.properties Wed Sep 16 03:11:23 2009
@@ -326,6 +326,20 @@
securityRunAsSubjectId=Id
securityRefreshRoles=Refresh Roles from Deployment Descriptor/Annotations
+addUser = Add user
+delUser = Delete user
+editUser = Edit user
+oldPassword = Old password
+newPassword = New password
+confirmPassword = Confirm password
+groupName = Group name
+passwordNotEqual = Password doesn't match!
+manageAccount = Manage Account
+manageAccountDescription = Manage account for default "Properties File Realm"
+cannotSave = Account information can't be stored!
+cannotRead = Account information can't be read!
+isNotLocalHost = It is not a local host.
+
dependencyGroupLabel=Dependency type and location
groupId=Group Id
artifactId=Artifact Id
@@ -473,6 +487,8 @@
savePageTitle=Save Resource
savePageMessage=Data must be saved before entering or leaving the Source page.
+wizardTitle_ManageAccount=Manage Account
+
wizardTitle_PluginManager=Create and Install Geronimo Plugins
wizardPage0Title_PluginManager=Plugin Manager
wizardPage0Description_PluginManager=Select your local plugin repository and the action to take.
Modified: geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/sections/ServerEditorSecuritySection.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/sections/ServerEditorSecuritySection.java?rev=815595&r1=815594&r2=815595&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/sections/ServerEditorSecuritySection.java (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/sections/ServerEditorSecuritySection.java Wed Sep 16 03:11:23 2009
@@ -17,19 +17,34 @@
package org.apache.geronimo.st.ui.sections;
import org.apache.geronimo.st.core.IGeronimoServer;
+import org.apache.geronimo.st.core.operations.GeronimoAccountManager;
+import org.apache.geronimo.st.ui.CommonMessages;
import org.apache.geronimo.st.ui.commands.SetPasswordCommand;
import org.apache.geronimo.st.ui.commands.SetUsernameCommand;
import org.apache.geronimo.st.ui.internal.Messages;
+import org.apache.geronimo.st.ui.internal.Trace;
+import org.apache.geronimo.st.ui.wizards.ManageAccountWizard;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.util.SocketUtil;
/**
* @version $Rev$ $Date$
@@ -39,6 +54,8 @@
Text username;
Text password;
+
+ Button manageAccountButton;
public ServerEditorSecuritySection() {
super();
@@ -56,13 +73,51 @@
Section section = toolkit.createSection(parent,
ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED
- | ExpandableComposite.TITLE_BAR | Section.DESCRIPTION
+ | ExpandableComposite.TITLE_BAR
| ExpandableComposite.FOCUS_TITLE);
section.setText(Messages.editorSectionSecurityTitle);
- section.setDescription(Messages.editorSectionSecurityDescription);
+ // section.setDescription(Messages.editorSectionSecurityDescription);
section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+ Composite textComposite = toolkit.createComposite(section);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ textComposite.setLayout(gridLayout);
+ textComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ section.setDescriptionControl(textComposite);
+ //text
+ Label label = toolkit.createLabel(textComposite, Messages.editorSectionSecurityDescription);
+
+ // Button for managing account
+ Button manageAccountButton = toolkit.createButton(textComposite, CommonMessages.manageAccount, SWT.PUSH);
+ GridData buttonData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
+ manageAccountButton.setLayoutData(buttonData);
+ manageAccountButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ // if the server is started and local host, then we can bring up the dialog
+ if (!isLocalHost())
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), CommonMessages.errorOpenWizard, CommonMessages.isNotLocalHost);
+ else
+ {
+ GeronimoAccountManager manager = new GeronimoAccountManager(server.getRuntime());
+ try {
+ manager.init();
+ } catch (Exception e1) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), CommonMessages.errorOpenWizard, CommonMessages.cannotRead);
+ Trace.trace(Trace.SEVERE, "Properties file containing user information can't be read!", e1);
+ return;
+ }
+ ManageAccountWizard wizard = new ManageAccountWizard(manager);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
+ dialog.open();
+ if (dialog.getReturnCode() == Dialog.OK) {
+ }
+ }
+ }
+
+ });
+
Composite composite = toolkit.createComposite(section);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
@@ -76,7 +131,6 @@
// ------- Label and text field for the username -------
createLabel(composite, Messages.username, toolkit);
-
username = toolkit.createText(composite, getUserName(), SWT.BORDER);
username.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
username.addModifyListener(new ModifyListener() {
@@ -110,4 +164,16 @@
}
return "";
}
+
+ private boolean isLocalHost(){
+ return !(server.getServerType().supportsRemoteHosts()
+ && !SocketUtil.isLocalhost(server.getHost()));
+ }
+
+ private boolean isServerRunning () {
+ if (gs == null || gs.getServer() == null)
+ return false;
+
+ return gs.getServer().getServerState() == IServer.STATE_STARTED;
+ }
}
Modified: geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/AbstractWizard.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/AbstractWizard.java?rev=815595&r1=815594&r2=815595&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/AbstractWizard.java (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/AbstractWizard.java Wed Sep 16 03:11:23 2009
@@ -99,8 +99,10 @@
return label;
}
- protected Text createTextField(Composite composite, String initialValue) {
- Text text = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ protected Text createTextField(Composite composite, String initialValue,boolean isPassword) {
+ int style = SWT.SINGLE | SWT.BORDER;
+ if (isPassword) style |= SWT.PASSWORD;
+ Text text = new Text(composite, style);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
data.grabExcessHorizontalSpace = true;
data.widthHint = 100;
@@ -110,6 +112,10 @@
}
return text;
}
+
+ protected Text createTextField(Composite composite, String initialValue) {
+ return createTextField(composite,initialValue,false);
+ }
protected Text createMultiTextField(Composite composite, String[] initialValue) {
Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
Added: geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/ManageAccountWizard.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/ManageAccountWizard.java?rev=815595&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/ManageAccountWizard.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.1.5/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/wizards/ManageAccountWizard.java Wed Sep 16 03:11:23 2009
@@ -0,0 +1,222 @@
+package org.apache.geronimo.st.ui.wizards;
+
+import org.apache.geronimo.st.core.operations.GeronimoAccountManager;
+import org.apache.geronimo.st.ui.CommonMessages;
+import org.apache.geronimo.st.ui.internal.Messages;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class ManageAccountWizard extends AbstractWizard {
+
+ protected Button addUser;
+ protected Button delUser;
+ protected Button editUser;
+
+ protected Label userName;
+ protected Label groupName;
+ protected Label newPassword;
+ protected Label confirmPassword;
+
+ protected Composite actioncomposite;
+ protected Text userNameText;
+ protected Combo userNameComobox;
+ protected Combo groupComobox;
+ protected Text newPasswordText;
+ protected Text confirmPasswordText;
+
+ private String[] nameList;
+ private String[] groupList;
+
+ private GeronimoAccountManager manager;
+
+
+ public ManageAccountWizard(GeronimoAccountManager mgr) {
+ super();
+ manager = mgr;
+ nameList = manager.getUserList();
+ groupList = manager.getGroupList();
+ }
+
+
+ public class ManageAccountWizardPage extends AbstractWizardPage {
+
+ public ManageAccountWizardPage(String pageName) {
+ super(pageName);
+ }
+
+
+ protected Composite createComposite(Composite parent) {
+ Composite composite =super.createComposite(parent);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ // layout.makeColumnsEqualWidth=true;
+ composite.setLayout(layout);
+ return composite;
+ }
+
+ @Override
+ protected String getWizardPageDescription() {
+ return CommonMessages.manageAccountDescription;
+ }
+
+ @Override
+ protected String getWizardPageTitle() {
+ return CommonMessages.manageAccount;
+ }
+
+ public void createControl(final Composite parent) {
+ final Composite composite = createComposite(parent);
+ addUser = this.createButton(composite, CommonMessages.addUser);
+ GridData data = new GridData();
+ data.horizontalSpan = 1;
+ data.grabExcessHorizontalSpace=true;
+ data.horizontalAlignment = GridData.CENTER;
+ addUser.setLayoutData(data);
+ addUser.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent arg0) {
+ updateUIByAction(composite);
+ }
+ });
+
+ delUser = this.createButton(composite, CommonMessages.delUser);
+ data = new GridData();
+ data.horizontalSpan = 1;
+ data.grabExcessHorizontalSpace=true;
+ data.horizontalAlignment = GridData.CENTER;
+ delUser.setLayoutData(data);
+ delUser.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent arg0) {
+ updateUIByAction(composite);
+ }
+ });
+
+ editUser = this.createButton(composite, CommonMessages.editUser);
+ data = new GridData();
+ data.horizontalSpan = 1;
+ data.grabExcessHorizontalSpace=true;
+ data.horizontalAlignment = GridData.CENTER;
+ editUser.setLayoutData(data);
+ editUser.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent arg0) {
+ updateUIByAction(composite);
+ }
+ });
+
+ // updateUIByAction(composite);
+
+ setControl(composite);
+ }
+
+ private void updateUIByAction(Composite composite){
+ if (actioncomposite!=null) actioncomposite.dispose();
+
+ actioncomposite = this.createComposite(composite);
+ GridLayout layout = new GridLayout();
+ layout.numColumns=2;
+ actioncomposite.setLayout(layout);
+ GridData data = new GridData(GridData.FILL, GridData.FILL,true,true);
+ data.horizontalSpan =3;
+ actioncomposite.setLayoutData(data);
+
+ if (addUser.getSelection()){
+ userName = this.createLabel(actioncomposite, CommonMessages.username);
+ userNameText = this.createTextField(actioncomposite, "",false);
+
+ groupName = this.createLabel(actioncomposite, CommonMessages.groupName);
+ groupComobox = this.createCombo(actioncomposite, groupList, false);
+ groupComobox.select(0);
+
+ newPassword = this.createLabel(actioncomposite, CommonMessages.newPassword);
+ newPasswordText = this.createTextField(actioncomposite, "",true);
+
+ confirmPassword = this.createLabel(actioncomposite, CommonMessages.confirmPassword);
+ confirmPasswordText = this.createTextField(actioncomposite,"",true);
+ }else if (delUser.getSelection()){
+ userName = this.createLabel(actioncomposite, CommonMessages.username);
+ userNameComobox = this.createCombo(actioncomposite, nameList, false);
+ userNameComobox.select(0);
+
+ }else{
+ userName = this.createLabel(actioncomposite, CommonMessages.username);
+ userNameComobox = this.createCombo(actioncomposite, nameList, true);
+ userNameComobox.select(0);
+
+ newPassword = this.createLabel(actioncomposite, CommonMessages.newPassword);
+ newPasswordText = this.createTextField(actioncomposite, "",true);
+
+ confirmPassword = this.createLabel(actioncomposite, CommonMessages.confirmPassword);
+ confirmPasswordText = this.createTextField(actioncomposite,"",true);
+ }
+
+
+ composite.layout();
+ }
+
+ }
+
+
+
+ @Override
+ protected String getAddWizardWindowTitle() {
+ return Messages.wizardTitle_ManageAccount;
+ }
+
+ @Override
+ protected String getEditWizardWindowTitle() {
+ return Messages.wizardTitle_ManageAccount;
+ }
+
+ @Override
+ public boolean performFinish() {
+ if (addUser.getSelection()){
+ String newPwd = newPasswordText.getText();
+ String confirmPwd = confirmPasswordText.getText();
+ if (!newPwd.equals(confirmPwd)){
+ MessageDialog.openError(Display.getDefault().getActiveShell(), CommonMessages.addUser , CommonMessages.passwordNotEqual);
+ return false;
+ }
+
+ String name = userNameText.getText();
+ String groupName = groupComobox.getItem(groupComobox.getSelectionIndex());
+ manager.addUser(name, groupName, newPwd);
+ }else if (delUser.getSelection()){
+ String name = userNameComobox.getItem(userNameComobox.getSelectionIndex());
+ manager.delUser(name);
+ }else{
+ String newPwd = newPasswordText.getText();
+ String confirmPwd = confirmPasswordText.getText();
+ if (!newPwd.equals(confirmPwd)){
+ MessageDialog.openError(Display.getDefault().getActiveShell(), CommonMessages.editUser , CommonMessages.passwordNotEqual);
+ return false;
+ }
+ String groupName = groupComobox.getItem(groupComobox.getSelectionIndex());
+ String newName = userNameText.getText();
+ String oldName = userNameComobox.getItem(userNameComobox.getSelectionIndex());
+
+ manager.modifyUser(oldName, newName, groupName, newPwd);
+ }
+
+ try {
+ manager.persist();
+ } catch (Exception e) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(), CommonMessages.manageAccount , CommonMessages.cannotSave);
+ return false;
+ }
+ return true;
+ }
+
+ public void addPages() {
+ addPage(new ManageAccountWizardPage(CommonMessages.manageAccount));
+ }
+
+}