Added a method, that will even setup command, that does not require GUI customization. QBE200308200100-BLD200308251153
authormentlicher@netbeans.org
Tue, 19 Aug 2003 14:23:43 +0000
changeset 3504ee5bb58f73f7
parent 3503 1d0cda124b86
child 3505 9450c7cd90d2
Added a method, that will even setup command, that does not require GUI customization.
The intention is to at least set the password if one is needed.
The prompt for password is made even when the GUI customization is not required,
because the password is likely to be very important for the command to execute successfully.
This is a fix of issue #35315.
vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandSupport.java
vcscore/src/org/netbeans/modules/vcscore/commands/CommandCustomizationSupport.java
     1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandSupport.java	Mon Aug 18 12:39:26 2003 +0000
     1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandSupport.java	Tue Aug 19 14:23:43 2003 +0000
     1.3 @@ -487,14 +487,22 @@
     1.4          String newExec = CommandCustomizationSupport.preCustomize(fileSystem, vcsCmd, vars);
     1.5          if (commandExec != null && newExec == null) return new UserCancelException();
     1.6          Object finalCustomizer = null;
     1.7 -        if ((commandExec == null || newExec != null) && doCreateCustomizer) {
     1.8 -            finalCustomizer = createCustomizer(customizer, newExec, vars, forEachFile,
     1.9 -                                               cmd, files, cacheProvider, valueAdjustment,
    1.10 -                                               cmdCanRunOnMultipleFiles,
    1.11 -                                               cmdCanRunOnMultipleFilesInFolder);
    1.12 -            if (finalCustomizer instanceof UserCommandCustomizer) {
    1.13 -                customizer = (UserCommandCustomizer) finalCustomizer;
    1.14 -            } else customizer = null;
    1.15 +        if (commandExec == null || newExec != null) {
    1.16 +            if (doCreateCustomizer) {
    1.17 +                finalCustomizer = createCustomizer(customizer, newExec, vars, forEachFile,
    1.18 +                                                   cmd, files, cacheProvider, valueAdjustment,
    1.19 +                                                   cmdCanRunOnMultipleFiles,
    1.20 +                                                   cmdCanRunOnMultipleFilesInFolder);
    1.21 +                if (finalCustomizer instanceof UserCommandCustomizer) {
    1.22 +                    customizer = (UserCommandCustomizer) finalCustomizer;
    1.23 +                } else customizer = null;
    1.24 +            } else {
    1.25 +                try {
    1.26 +                    CommandCustomizationSupport.setupUncustomizedCommand(fileSystem, newExec, vars, vcsCmd);
    1.27 +                } catch (UserCancelException ucex) {
    1.28 +                    return ucex;
    1.29 +                }
    1.30 +            }
    1.31          }
    1.32          if (newExec != null) cmd.setPreferredExec(newExec);
    1.33          cmd.setAdditionalVariables(vars);
     2.1 --- a/vcscore/src/org/netbeans/modules/vcscore/commands/CommandCustomizationSupport.java	Mon Aug 18 12:39:26 2003 +0000
     2.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/commands/CommandCustomizationSupport.java	Tue Aug 19 14:23:43 2003 +0000
     2.3 @@ -837,6 +837,42 @@
     2.4          }
     2.5      }
     2.6      
     2.7 +    private static void doPromptForPasswordIfNecessary(final VcsFileSystem fileSystem,
     2.8 +                                                       final String exec,
     2.9 +                                                       final Hashtable vars) throws UserCancelException {
    2.10 +        synchronized (vars) {
    2.11 +            if (exec != null && needPromptForPR("PASSWORD", exec, vars)) { // NOI18N
    2.12 +                String password;
    2.13 +                synchronized (promptLock) { // disable the possibility, that the user
    2.14 +                    // will be prompted multiple times at once by concurrenly running commands
    2.15 +                    password = fileSystem.getPassword();
    2.16 +                    if (password == null) {
    2.17 +                        NotifyDescriptorInputPassword nd = new NotifyDescriptorInputPassword (g("MSG_Password"), g("MSG_Password")); // NOI18N
    2.18 +                        if (NotifyDescriptor.OK_OPTION.equals (DialogDisplayer.getDefault ().notify (nd))) {
    2.19 +                            password = nd.getInputText ();
    2.20 +                        } else {
    2.21 +                            fileSystem.setPassword(null);
    2.22 +                            throw new UserCancelException();
    2.23 +                        }
    2.24 +                        fileSystem.setPassword(password);
    2.25 +                    }
    2.26 +                }
    2.27 +                vars.put("PASSWORD", password); // NOI18N
    2.28 +            }
    2.29 +        }
    2.30 +    }
    2.31 +    
    2.32 +    /**
    2.33 +     * Setup some necessary variables, but do not present any GUI - the command
    2.34 +     * does not wish to be customized. The only exception is a prompt for password.
    2.35 +     * This method just sets the password (and prompt for it if it's not set).
    2.36 +     */
    2.37 +    public static void setupUncustomizedCommand(final VcsFileSystem fileSystem,
    2.38 +                                                final String exec, final Hashtable vars,
    2.39 +                                                final VcsCommand cmd) throws UserCancelException {
    2.40 +        doPromptForPasswordIfNecessary(fileSystem, exec, vars);
    2.41 +    }
    2.42 +    
    2.43      /** The table of FS and its global descriptor string. */
    2.44      private static Map globalInputStrs = Collections.synchronizedMap(new WeakHashMap());
    2.45      /** The table of FS and its parsed global descriptor */
    2.46 @@ -880,25 +916,7 @@
    2.47                   */
    2.48          }
    2.49          synchronized (vars) {
    2.50 -            if (exec != null && needPromptForPR("PASSWORD", exec, vars)) { // NOI18N
    2.51 -                String password;
    2.52 -                synchronized (promptLock) { // disable the possibility, that the user
    2.53 -                    // will be prompted multiple times at once by concurrenly running commands
    2.54 -                    password = fileSystem.getPassword();
    2.55 -                    if (password == null) {
    2.56 -                        NotifyDescriptorInputPassword nd = new NotifyDescriptorInputPassword (g("MSG_Password"), g("MSG_Password")); // NOI18N
    2.57 -                        if (NotifyDescriptor.OK_OPTION.equals (DialogDisplayer.getDefault ().notify (nd))) {
    2.58 -                            password = nd.getInputText ();
    2.59 -                        } else {
    2.60 -                            fileSystem.setPassword(null);
    2.61 -                            throw new UserCancelException();
    2.62 -                        }
    2.63 -                        fileSystem.setPassword(password);
    2.64 -                    }
    2.65 -                }
    2.66 -                vars.put("PASSWORD", password); // NOI18N
    2.67 -            /* Do not change forEachFile, if the command is successful it will not ask any more */
    2.68 -            }
    2.69 +            doPromptForPasswordIfNecessary(fileSystem, exec, vars);
    2.70              if (forEachFile == null || forEachFile[0] == true) {
    2.71                  final String[] userParams = fileSystem.getUserParams();
    2.72                  final Hashtable userParamsVarNames = new Hashtable(); // Variable names of prompt for additional parameters