Removed some internal constants
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / preferences / UserValidationDialog.java
index 652d150..38e00e6 100644 (file)
@@ -10,9 +10,6 @@
  *******************************************************************************/
 package net.sourceforge.phpeclipse.wiki.preferences;
 
-
-
-
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.window.Window;
@@ -30,261 +27,280 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
 /**
- * A dialog for prompting for a username and fPassword
+ * A dialog for prompting for a category and fPassword
  */
 public class UserValidationDialog extends Dialog {
-       // widgets
-       protected Text usernameField;
-       protected Text passwordField;
-       protected Button allowCachingButton;
-
-       protected String domain;
-       protected String defaultUsername;
-       protected String password = null;
-       protected boolean allowCaching = false;
-       protected Image keyLockImage;
-       
-       // whether or not the username can be changed
-       protected boolean isUsernameMutable = true;
-       protected boolean showAllowCachingButton = true;
-       protected String username = null;
-       protected String message = null;
-
-       /**
-        * Creates a new UserValidationDialog.
-        * 
-        * @param parentShell  the parent shell
-        * @param location  the location
-        * @param defaultName  the default fUser name
-        * @param message  a mesage to display to the fUser
-        */
-       public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) {
-               super(parentShell);
-               this.defaultUsername = defaultName;
-               this.domain = location;
-               this.message = message;
-       }
-       /**
-        * @see Window#configureShell
-        */
-       protected void configureShell(Shell newShell) {
-               super.configureShell(newShell);
-               newShell.setText(Messages.getString("UserValidationDialog.required")); //$NON-NLS-1$
-               // set F1 help
-//             WorkbenchHelp.setHelp(newShell, IHelpContextIds.USER_VALIDATION_DIALOG);        
-       }
-       /**
-        * @see Window#create
-        */ 
-       public void create() {
-               super.create();
-               // add some default values
-               usernameField.setText(defaultUsername);
-       
-               if (isUsernameMutable) {
-                       // give focus to username field
-                       usernameField.selectAll();
-                       usernameField.setFocus();
-               } else {
-                       usernameField.setEditable(false);
-                       passwordField.setFocus();
-               }
-       }
-       
-       /**
-        * @see Dialog#createDialogArea
-        */
-       protected Control createDialogArea(Composite parent) {
-               Composite top = new Composite(parent, SWT.NONE);
-               GridLayout layout = new GridLayout();
-               layout.numColumns = 2;
-               
-               top.setLayout(layout);
-               top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-       
-               Composite imageComposite = new Composite(top, SWT.NONE);
-               layout = new GridLayout();
-               imageComposite.setLayout(layout);
-               imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
-
-               Composite main = new Composite(top, SWT.NONE);
-               layout = new GridLayout();
-               layout.numColumns = 3;
-               main.setLayout(layout);
-               main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-               
-               Label imageLabel = new Label(imageComposite, SWT.NONE);
-               keyLockImage = TeamImages.getImageDescriptor(ITeamUIImages.IMG_KEY_LOCK).createImage();
-               imageLabel.setImage(keyLockImage);
-               GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
-               imageLabel.setLayoutData(data);
-               
-               if (message != null) {
-                       Label messageLabel = new Label(main, SWT.WRAP);
-                       messageLabel.setText(message);
-                       data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
-                       data.horizontalSpan = 3;
-                       data.widthHint = 300;
-                       messageLabel.setLayoutData(data);
-               }
-               if (domain != null) {
-                       Label d = new Label(main, SWT.WRAP);
-                       d.setText(Messages.getString("UserValidationDialog.5")); //$NON-NLS-1$
-                       data = new GridData();
-                       d.setLayoutData(data);
-                       Label label = new Label(main, SWT.WRAP);
-                       if (isUsernameMutable) {
-                               label.setText(Messages.bind("UserValidationDialog.labelUser", domain)); //$NON-NLS-1$
-                       } else {
-                               label.setText(Messages.bind("UserValidationDialog.labelPassword", new Object[]{defaultUsername, domain})); //$NON-NLS-1$
-                       }
-                       data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
-                       data.horizontalSpan = 2;
-                       data.widthHint = 300;
-                       label.setLayoutData(data);
-               }
-               createUsernameFields(main);
-               createPasswordFields(main);
-               
-               if(domain != null && showAllowCachingButton) {
-                       allowCachingButton = new Button(main, SWT.CHECK);
-                       allowCachingButton.setText(Messages.getString("UserValidationDialog.6")); //$NON-NLS-1$
-                       data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
-                       data.horizontalSpan = 3;
-                       allowCachingButton.setLayoutData(data);
-                       allowCachingButton.addSelectionListener(new SelectionAdapter() {
-                               public void widgetSelected(SelectionEvent e) {
-                                       allowCaching = allowCachingButton.getSelection();
-                               }
-                       });
-                       Composite warningComposite = new Composite(main, SWT.NONE);
-                       layout = new GridLayout();
-                       layout.numColumns = 2;
-                       layout.marginHeight = 0;
-                       layout.marginHeight = 0;
-                       warningComposite.setLayout(layout);
-                       data = new GridData(GridData.FILL_HORIZONTAL);
-                       data.horizontalSpan = 3;
-                       warningComposite.setLayoutData(data);
-                       Label warningLabel = new Label(warningComposite, SWT.NONE);
-                       warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING));
-                       warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING));
-                       Label warningText = new Label(warningComposite, SWT.WRAP);
-                       warningText.setText(Messages.getString("UserValidationDialog.7")); //$NON-NLS-1$
-                       data = new GridData(GridData.FILL_HORIZONTAL);
-                       data.widthHint = 300;
-                       warningText.setLayoutData(data);
-               }
-               
-        Dialog.applyDialogFont(parent);
-        
-               return main;
-       }
-       /**
-        * Create a spacer.
-        */
-       protected void createSpacer(Composite top, int columnSpan, int vertSpan) {
-               Label l = new Label(top, SWT.NONE);
-               GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
-               data.horizontalSpan = columnSpan;
-               data.verticalSpan = vertSpan;
-               l.setLayoutData(data);
-       }
-       
-       /**
-        * Creates the three widgets that represent the fPassword entry area.
-        * 
-        * @param parent  the parent of the widgets
-        */
-       protected void createPasswordFields(Composite parent) {
-               new Label(parent, SWT.NONE).setText(Messages.getString("UserValidationDialog.fPassword")); //$NON-NLS-1$
-               
-               passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD);
-               GridData data = new GridData(GridData.FILL_HORIZONTAL);
-               data.horizontalSpan = 2;
-               data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
-               passwordField.setLayoutData(data);
-       }
-       /**
-        * Creates the three widgets that represent the fUser name entry area.
-        * 
-        * @param parent  the parent of the widgets
-        */
-       protected void createUsernameFields(Composite parent) {
-               new Label(parent, SWT.NONE).setText(Messages.getString("UserValidationDialog.fUser")); //$NON-NLS-1$
-               
-               usernameField = new Text(parent, SWT.BORDER);
-               GridData data = new GridData(GridData.FILL_HORIZONTAL);
-               data.horizontalSpan = 2;
-               data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
-               usernameField.setLayoutData(data);
-       }
-       
-       /**
-        * Returns the fPassword entered by the fUser, or null
-        * if the fUser canceled.
-        * 
-        * @return the entered fPassword
-        */
-       public String getPassword() {
-               return password;
-       }
-       
-       /**
-        * Returns the username entered by the fUser, or null
-        * if the fUser canceled.
-        * 
-        * @return the entered username
-        */
-       public String getUsername() {
-               return username;
-       }
-       
-       /**
-        * Returns <code>true</code> if the save fPassword checkbox was selected.
-        * @return <code>true</code> if the save fPassword checkbox was selected and <code>false</code>
-        * otherwise.
-        */
-       public boolean getAllowCaching() {
-               return allowCaching;
-       }
-       
-       /**
-        * Notifies that the ok button of this dialog has been pressed.
-        * <p>
-        * The default implementation of this framework method sets
-        * this dialog's return code to <code>Window.OK</code>
-        * and closes the dialog. Subclasses may override.
-        * </p>
-        */
-       protected void okPressed() {
-               password = passwordField.getText();
-               username = usernameField.getText();
-       
-               super.okPressed();
-       }
-       /**
-        * Sets whether or not the username field should be mutable.
-        * This method must be called before create(), otherwise it
-        * will be ignored.
-        * 
-        * @param value  whether the username is mutable
-        */
-       public void setUsernameMutable(boolean value) {
-               isUsernameMutable = value;
-       }
-       
-       public void setShowAllowCachingButton(boolean value) {
-               showAllowCachingButton = value;
-       }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.dialogs.Dialog#close()
-        */
-       public boolean close() {
-               if(keyLockImage != null) {
-                       keyLockImage.dispose();
-               }
-               return super.close();
-       }
-}
+  // widgets
+  protected Text usernameField;
+
+  protected Text passwordField;
+
+  protected Button allowCachingButton;
+
+  protected String domain;
+
+  protected String defaultUsername;
+
+  protected String password = null;
+
+  protected boolean allowCaching = false;
+
+  protected Image keyLockImage;
+
+  // whether or not the category can be changed
+  protected boolean isUsernameMutable = true;
+
+  protected boolean showAllowCachingButton = true;
+
+  protected String username = null;
+
+  protected String message = null;
+
+  /**
+   * Creates a new CategoryDialog.
+   * 
+   * @param parentShell
+   *          the parent shell
+   * @param location
+   *          the location
+   * @param defaultName
+   *          the default fUser name
+   * @param message
+   *          a mesage to display to the fUser
+   */
+  public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) {
+    super(parentShell);
+    this.defaultUsername = defaultName;
+    this.domain = location;
+    this.message = message;
+  }
+
+  /**
+   * @see Window#configureShell
+   */
+  protected void configureShell(Shell newShell) {
+    super.configureShell(newShell);
+    newShell.setText(Messages.getString("CategoryDialog.required")); //$NON-NLS-1$
+    // set F1 help
+    //         WorkbenchHelp.setHelp(newShell, IHelpContextIds.USER_VALIDATION_DIALOG);
+  }
+
+  /**
+   * @see Window#create
+   */
+  public void create() {
+    super.create();
+    // add some default values
+    usernameField.setText(defaultUsername);
+
+    if (isUsernameMutable) {
+      // give focus to category field
+      usernameField.selectAll();
+      usernameField.setFocus();
+    } else {
+      usernameField.setEditable(false);
+      passwordField.setFocus();
+    }
+  }
+
+  /**
+   * @see Dialog#createDialogArea
+   */
+  protected Control createDialogArea(Composite parent) {
+    Composite top = new Composite(parent, SWT.NONE);
+    GridLayout layout = new GridLayout();
+    layout.numColumns = 2;
+
+    top.setLayout(layout);
+    top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+    Composite imageComposite = new Composite(top, SWT.NONE);
+    layout = new GridLayout();
+    imageComposite.setLayout(layout);
+    imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+
+    Composite main = new Composite(top, SWT.NONE);
+    layout = new GridLayout();
+    layout.numColumns = 3;
+    main.setLayout(layout);
+    main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+    Label imageLabel = new Label(imageComposite, SWT.NONE);
+    keyLockImage = TeamImages.getImageDescriptor(ITeamUIImages.IMG_KEY_LOCK).createImage();
+    imageLabel.setImage(keyLockImage);
+    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
+    imageLabel.setLayoutData(data);
+
+    if (message != null) {
+      Label messageLabel = new Label(main, SWT.WRAP);
+      messageLabel.setText(message);
+      data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
+      data.horizontalSpan = 3;
+      data.widthHint = 300;
+      messageLabel.setLayoutData(data);
+    }
+    if (domain != null) {
+      Label d = new Label(main, SWT.WRAP);
+      d.setText(Messages.getString("CategoryDialog.5")); //$NON-NLS-1$
+      data = new GridData();
+      d.setLayoutData(data);
+      Label label = new Label(main, SWT.WRAP);
+      if (isUsernameMutable) {
+        label.setText(Messages.bind("CategoryDialog.labelUser", domain)); //$NON-NLS-1$
+      } else {
+        label.setText(Messages.bind("CategoryDialog.labelPassword", new Object[] { defaultUsername, domain })); //$NON-NLS-1$
+      }
+      data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
+      data.horizontalSpan = 2;
+      data.widthHint = 300;
+      label.setLayoutData(data);
+    }
+    createUsernameFields(main);
+    createPasswordFields(main);
+
+    if (domain != null && showAllowCachingButton) {
+      allowCachingButton = new Button(main, SWT.CHECK);
+      allowCachingButton.setText(Messages.getString("CategoryDialog.6")); //$NON-NLS-1$
+      data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
+      data.horizontalSpan = 3;
+      allowCachingButton.setLayoutData(data);
+      allowCachingButton.addSelectionListener(new SelectionAdapter() {
+        public void widgetSelected(SelectionEvent e) {
+          allowCaching = allowCachingButton.getSelection();
+        }
+      });
+      Composite warningComposite = new Composite(main, SWT.NONE);
+      layout = new GridLayout();
+      layout.numColumns = 2;
+      layout.marginHeight = 0;
+      layout.marginHeight = 0;
+      warningComposite.setLayout(layout);
+      data = new GridData(GridData.FILL_HORIZONTAL);
+      data.horizontalSpan = 3;
+      warningComposite.setLayoutData(data);
+      Label warningLabel = new Label(warningComposite, SWT.NONE);
+      warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING));
+      warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING));
+      Label warningText = new Label(warningComposite, SWT.WRAP);
+      warningText.setText(Messages.getString("CategoryDialog.7")); //$NON-NLS-1$
+      data = new GridData(GridData.FILL_HORIZONTAL);
+      data.widthHint = 300;
+      warningText.setLayoutData(data);
+    }
+
+    Dialog.applyDialogFont(parent);
+
+    return main;
+  }
+
+  /**
+   * Create a spacer.
+   */
+  protected void createSpacer(Composite top, int columnSpan, int vertSpan) {
+    Label l = new Label(top, SWT.NONE);
+    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
+    data.horizontalSpan = columnSpan;
+    data.verticalSpan = vertSpan;
+    l.setLayoutData(data);
+  }
+
+  /**
+   * Creates the three widgets that represent the fPassword entry area.
+   * 
+   * @param parent
+   *          the parent of the widgets
+   */
+  protected void createPasswordFields(Composite parent) {
+    new Label(parent, SWT.NONE).setText(Messages.getString("CategoryDialog.password")); //$NON-NLS-1$
+
+    passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD);
+    GridData data = new GridData(GridData.FILL_HORIZONTAL);
+    data.horizontalSpan = 2;
+    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
+    passwordField.setLayoutData(data);
+  }
+
+  /**
+   * Creates the three widgets that represent the fUser name entry area.
+   * 
+   * @param parent
+   *          the parent of the widgets
+   */
+  protected void createUsernameFields(Composite parent) {
+    new Label(parent, SWT.NONE).setText(Messages.getString("CategoryDialog.user")); //$NON-NLS-1$
+
+    usernameField = new Text(parent, SWT.BORDER);
+    GridData data = new GridData(GridData.FILL_HORIZONTAL);
+    data.horizontalSpan = 2;
+    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
+    usernameField.setLayoutData(data);
+  }
+
+  /**
+   * Returns the fPassword entered by the fUser, or null if the fUser canceled.
+   * 
+   * @return the entered fPassword
+   */
+  public String getPassword() {
+    return password;
+  }
+
+  /**
+   * Returns the category entered by the fUser, or null if the fUser canceled.
+   * 
+   * @return the entered category
+   */
+  public String getUsername() {
+    return username;
+  }
+
+  /**
+   * Returns <code>true</code> if the save fPassword checkbox was selected.
+   * 
+   * @return <code>true</code> if the save fPassword checkbox was selected and <code>false</code> otherwise.
+   */
+  public boolean getAllowCaching() {
+    return allowCaching;
+  }
+
+  /**
+   * Notifies that the ok button of this dialog has been pressed.
+   * <p>
+   * The default implementation of this framework method sets this dialog's return code to <code>Window.OK</code> and closes the
+   * dialog. Subclasses may override.
+   * </p>
+   */
+  protected void okPressed() {
+    password = passwordField.getText();
+    username = usernameField.getText();
+
+    super.okPressed();
+  }
+
+  /**
+   * Sets whether or not the category field should be mutable. This method must be called before create(), otherwise it will be
+   * ignored.
+   * 
+   * @param value
+   *          whether the category is mutable
+   */
+  public void setUsernameMutable(boolean value) {
+    isUsernameMutable = value;
+  }
+
+  public void setShowAllowCachingButton(boolean value) {
+    showAllowCachingButton = value;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.jface.dialogs.Dialog#close()
+   */
+  public boolean close() {
+    if (keyLockImage != null) {
+      keyLockImage.dispose();
+    }
+    return super.close();
+  }
+}
\ No newline at end of file