Upload/Download of multiple files now possible
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / internal / Configuration.java
index a8cf2e2..c961a81 100644 (file)
@@ -4,13 +4,17 @@
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/cpl-v10.html
-  *
+ �*
  * Contributors:
  *    IBM - Initial API and implementation
  **********************************************************************/
 package net.sourceforge.phpeclipse.wiki.internal;
 
 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.preferences.UserValidationDialog;
+import net.sourceforge.phpeclipse.wiki.preferences.Util;
+
+import org.eclipse.swt.widgets.Shell;
 
 /**
  *  
@@ -206,4 +210,53 @@ public class Configuration implements IConfiguration, Comparable {
     return new String(out);
   }
 
+  public boolean isUserComplete() {
+    if (fUser==null || fUser.equals("")) {
+      return false;
+    }
+    if (fPassword==null || fPassword.equals("")) {
+      return false;
+    }
+    return true;
+  }
+  /**
+   * Asks the user to enter a password. Places the results in the supplied string[]. 
+   * result[0] must contain the username, 
+   * result[1] must contain the fPassword. 
+   * If the user canceled, both values must be zero.
+   * 
+   * @param location
+   *          the location to obtain the fPassword for
+   * @param username
+   *          the username
+   * @param message
+   *          a message to display to the fUser
+   * @param userMutable
+   *          whether the fUser can be changed in the dialog
+   * @param result
+   *          a String array of length two in which to put the result
+   */
+  public boolean promptForPassword(final String username, final String message, final boolean userMutable, final String[] result) {
+    if (isUserComplete()) {
+      result[0] = fUser; 
+      result[1] = fPassword;
+      return true;
+    }
+    result[0] = null;
+    result[1] = null;
+    Shell shell = Util.findShell();
+    if (shell == null) {
+      return false;
+    }
+    UserValidationDialog dialog = new UserValidationDialog(shell, fUrl, (username == null) ? "" : username, message);//$NON-NLS-1$
+    dialog.setUsernameMutable(userMutable);
+    dialog.open(); 
+    result[0] = dialog.getUsername();
+    result[1] = dialog.getPassword();
+    if (dialog.getAllowCaching()) {
+      fUser = result[0];
+      fPassword = result[1];
+    }
+    return dialog.getAllowCaching();
+  }
 }
\ No newline at end of file