Process the pre-commands just after the command is fully customized. BLD200406271800
authormentlicher@netbeans.org
Fri, 25 Jun 2004 17:14:57 +0000
changeset 4830a9266b4ffb5c
parent 4829 96c3686749fa
child 4831 b12f5840e987
Process the pre-commands just after the command is fully customized.
This is a fix of issue #45464.
vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandCustomizer.java
vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandSupport.java
vcscore/src/org/netbeans/modules/vcscore/commands/CommandProcessor.java
     1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandCustomizer.java	Fri Jun 25 13:20:08 2004 +0000
     1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandCustomizer.java	Fri Jun 25 17:14:57 2004 +0000
     1.3 @@ -7,7 +7,7 @@
     1.4   * http://www.sun.com/
     1.5   * 
     1.6   * The Original Code is NetBeans. The Initial Developer of the Original
     1.7 - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
     1.8 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
     1.9   * Microsystems, Inc. All Rights Reserved.
    1.10   */
    1.11  
    1.12 @@ -25,6 +25,7 @@
    1.13  
    1.14  import org.openide.NotifyDescriptor;
    1.15  
    1.16 +import org.netbeans.modules.vcscore.commands.CommandExecutionContext;
    1.17  import org.netbeans.modules.vcscore.commands.VcsDescribedCommand;
    1.18  import org.netbeans.modules.vcscore.util.VariableInputDescriptor;
    1.19  import org.netbeans.modules.vcscore.util.VariableInputDialog;
    1.20 @@ -36,6 +37,8 @@
    1.21   */
    1.22  public class UserCommandCustomizer extends JPanel implements ActionListener, Runnable {
    1.23      
    1.24 +    private CommandExecutionContext executionContext;
    1.25 +    private VcsDescribedCommand cmdOriginal;
    1.26      private VcsDescribedCommand cmd;
    1.27      private List actionListeners = new ArrayList();
    1.28      private VariableInputDialog dlg;
    1.29 @@ -43,7 +46,8 @@
    1.30      private String title;
    1.31      
    1.32      /** Creates a new instance of UserCommandCustomizer */
    1.33 -    public UserCommandCustomizer() {
    1.34 +    public UserCommandCustomizer(CommandExecutionContext executionContext) {
    1.35 +        this.executionContext = executionContext;
    1.36          setLayout(new java.awt.GridBagLayout());
    1.37          gridBagConstraints = new java.awt.GridBagConstraints();
    1.38          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    1.39 @@ -55,6 +59,7 @@
    1.40                             String title) {
    1.41          //System.out.println("\nUserCommandCustomizer.setCommand("+cmd+", "+dlg+")");
    1.42          this.cmd = cmd;
    1.43 +        if (this.cmdOriginal == null) this.cmdOriginal = cmd;
    1.44          this.title = title;
    1.45          this.dlg = dlg;
    1.46          if (!isVisible()) {
    1.47 @@ -78,6 +83,9 @@
    1.48                      for (Iterator it = listenersToNotify.iterator(); it.hasNext(); ) {
    1.49                          ((ActionListener) it.next()).actionPerformed(ev);
    1.50                      }
    1.51 +                    if (NotifyDescriptor.OK_OPTION.equals(ev.getSource())) {
    1.52 +                        
    1.53 +                    }
    1.54                  }
    1.55              }
    1.56          });
    1.57 @@ -129,6 +137,14 @@
    1.58      }
    1.59  
    1.60      /**
    1.61 +     * After the customizer is successfully finished and closed, this method is
    1.62 +     * called to do some post-customization work.
    1.63 +     */
    1.64 +    public void doPostCustomizationWork() {
    1.65 +        UserCommandSupport.commandCustomizedAndWillRun(cmdOriginal, executionContext);
    1.66 +    }
    1.67 +    
    1.68 +    /**
    1.69       * To update the dialog's content.
    1.70       */
    1.71      public void run() {
    1.72 @@ -149,42 +165,4 @@
    1.73          }
    1.74      }
    1.75      
    1.76 -    /*
    1.77 -    private void setCommandVariables() {
    1.78 -        dlg.processActions();
    1.79 -        // put the dialog's variables back with all necessary modifications done.
    1.80 -        //vars.clear();
    1.81 -        //vars.putAll(dlgVars);
    1.82 -        Map vars = cmd.getAdditionalVariables();
    1.83 -        VariableInputDescriptor inputDescriptor = dlg.getInputDescriptor();
    1.84 -        VariableInputDescriptor globalInputDescriptor = dlg.getGlobalInputDescriptor();
    1.85 -        if (inputDescriptor != null) {
    1.86 -            inputDescriptor.addValuesToHistory();
    1.87 -        }
    1.88 -        if (globalInputDescriptor != null) {
    1.89 -            globalInputDescriptor.addValuesToHistory();
    1.90 -        }
    1.91 -        Hashtable valuesTable = dlg.getUserParamsValuesTable();
    1.92 -        for (Enumeration enum = userParamsVarNames.keys(); enum.hasMoreElements(); ) {
    1.93 -            String varName = (String) enum.nextElement();
    1.94 -            //System.out.println("varName = "+varName+", label = "+userParamsVarNames.get(varName));
    1.95 -            String value = (String) valuesTable.get(userParamsVarNames.get(varName));
    1.96 -            vars.put(varName, value);
    1.97 -            int index = ((Integer) userParamsIndexes.get(varName)).intValue();
    1.98 -            if (index >= 0) userParams[index] = value;
    1.99 -            else {
   1.100 -                String[] cmdUserParams = (String[]) cmd.getProperty(VcsCommand.PROPERTY_USER_PARAMS);
   1.101 -                cmdUserParams[-index - 1] = value;
   1.102 -                cmd.setProperty(VcsCommand.PROPERTY_USER_PARAMS, cmdUserParams);
   1.103 -            }
   1.104 -            //D.deb("put("+varName+", "+valuesTable.get(userParamsVarNames.get(varName))+")");
   1.105 -        }
   1.106 -        fileSystem.setUserParams(userParams);
   1.107 -        if (forEachFile != null) {
   1.108 -            forEachFile[0] = dlg.getPromptForEachFile();
   1.109 -            fileSystem.setPromptForVarsForEachFile(forEachFile[0]);
   1.110 -        }
   1.111 -    }
   1.112 -     */
   1.113 -    
   1.114  }
     2.1 --- a/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandSupport.java	Fri Jun 25 13:20:08 2004 +0000
     2.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandSupport.java	Fri Jun 25 17:14:57 2004 +0000
     2.3 @@ -474,6 +474,9 @@
     2.4          Object obj = doCustomization(doCreateCustomizer, null, cmd, files, cacheProvider,
     2.5                                       valueAdjustment, cmdCanRunOnMultipleFiles,
     2.6                                       cmdCanRunOnMultipleFilesInFolder);
     2.7 +        if (obj == null) {
     2.8 +            commandCustomizedAndWillRun(cmd, executionContext);
     2.9 +        }
    2.10          //System.out.println("AFTER doCustomization("+doCreateCustomizer+", "+cmd.getVcsCommand()+"), files = "+files+", MODULE = "+cmd.getAdditionalVariables().get("MODULE")+", DIR = "+cmd.getAdditionalVariables().get("DIR"));
    2.11          return obj;
    2.12      }
    2.13 @@ -527,19 +530,6 @@
    2.14          String commandExec = (String) vcsCmd.getProperty(VcsCommand.PROPERTY_EXEC);
    2.15          StructuredExec structuredExec = (StructuredExec) vcsCmd.getProperty(VcsCommand.PROPERTY_EXEC_STRUCTURED);
    2.16          boolean success = CommandCustomizationSupport.preCustomize(executionContext, vcsCmd, vars);
    2.17 -        if (success) {
    2.18 -            if (structuredExec != null) {
    2.19 -                structuredExec = CommandCustomizationSupport.preCustomizeStructuredExec(executionContext, vcsCmd, vars);
    2.20 -                success = structuredExec != null;
    2.21 -                if (success) cmd.setPreferredStructuredExec(structuredExec);
    2.22 -            } else if (commandExec != null) {
    2.23 -                commandExec = CommandCustomizationSupport.preCustomizeExec(executionContext, vcsCmd, vars);
    2.24 -                success = commandExec != null;
    2.25 -                if (success) cmd.setPreferredExec(commandExec);
    2.26 -            }
    2.27 -        }
    2.28 -        //String newExec = CommandCustomizationSupport.preCustomize(executionContext, vcsCmd, vars);
    2.29 -        //if (commandExec != null && newExec == null) return new UserCancelException();
    2.30          if (!success) return new UserCancelException();
    2.31          Object finalCustomizer = null;
    2.32          if (commandExec != null || structuredExec != null) {
    2.33 @@ -632,17 +622,7 @@
    2.34              String commandExec = (String) vcsCmd.getProperty(VcsCommand.PROPERTY_EXEC);
    2.35              StructuredExec structuredExec = (StructuredExec) vcsCmd.getProperty(VcsCommand.PROPERTY_EXEC_STRUCTURED);
    2.36              boolean success = CommandCustomizationSupport.preCustomize(executionContext, vcsCmd, vars);
    2.37 -            if (success) {
    2.38 -                if (structuredExec != null) {
    2.39 -                    structuredExec = CommandCustomizationSupport.preCustomizeStructuredExec(executionContext, vcsCmd, vars);
    2.40 -                    success = structuredExec != null;
    2.41 -                    if (success) nextCmd.setPreferredStructuredExec(structuredExec);
    2.42 -                } else if (commandExec != null) {
    2.43 -                    commandExec = CommandCustomizationSupport.preCustomizeExec(executionContext, vcsCmd, vars);
    2.44 -                    success = commandExec != null;
    2.45 -                    if (success) nextCmd.setPreferredExec(commandExec);
    2.46 -                }
    2.47 -            } else return null;
    2.48 +            if (!success) return null;
    2.49              nextCmd.setAdditionalVariables(newVars);
    2.50              return nextCustomizedCommand;
    2.51          }
    2.52 @@ -780,7 +760,7 @@
    2.53          }
    2.54          //System.out.println("\ncreateCustomizer("+customizer+", "+files+", "+forEachFile+"), dlg = "+dlg);
    2.55          if (dlg == null) return null;
    2.56 -        if (customizer == null) customizer = new UserCommandCustomizer();
    2.57 +        if (customizer == null) customizer = new UserCommandCustomizer(executionContext);
    2.58          final UserCommandCustomizer finalCustomizer = customizer;
    2.59          customizer.setCommand(command, dlg, title.toString());
    2.60          dlg.addCloseListener(new ActionListener() {
    2.61 @@ -828,6 +808,7 @@
    2.62                                          valueAdjustment, new Hashtable(vars), forEachFile,
    2.63                                          cmdCanRunOnMultipleFiles, cmdCanRunOnMultipleFilesInFolder);
    2.64                      }
    2.65 +                    //commandCustomizedAndWillRun(finalCustomizer.getOriginalCommand());
    2.66                  }
    2.67              }
    2.68          });
    2.69 @@ -836,6 +817,36 @@
    2.70      }
    2.71      
    2.72      /**
    2.73 +     * Called <b>after</b> the customizer is finished and the command is going
    2.74 +     * to be scheduled for execution.
    2.75 +     */
    2.76 +    static boolean commandCustomizedAndWillRun(VcsDescribedCommand cmd, CommandExecutionContext executionContext) {
    2.77 +        boolean successfull = true;
    2.78 +        do {
    2.79 +            //System.out.println("commandCustomizedAndWillRun("+cmd.getName()+")");
    2.80 +            VcsCommand vcsCmd = cmd.getVcsCommand();
    2.81 +            String commandExec = (String) vcsCmd.getProperty(VcsCommand.PROPERTY_EXEC);
    2.82 +            StructuredExec structuredExec = (StructuredExec) vcsCmd.getProperty(VcsCommand.PROPERTY_EXEC_STRUCTURED);
    2.83 +            boolean success = true;
    2.84 +            if (structuredExec != null) {
    2.85 +                Hashtable vars = new Hashtable(cmd.getAdditionalVariables());
    2.86 +                structuredExec = CommandCustomizationSupport.preCustomizeStructuredExec(executionContext, vcsCmd, vars);
    2.87 +                success = structuredExec != null;
    2.88 +                if (success) cmd.setPreferredStructuredExec(structuredExec);
    2.89 +            } else if (commandExec != null) {
    2.90 +                Hashtable vars = new Hashtable(cmd.getAdditionalVariables());
    2.91 +                commandExec = CommandCustomizationSupport.preCustomizeExec(executionContext, vcsCmd, vars);
    2.92 +                success = commandExec != null;
    2.93 +                if (success) cmd.setPreferredExec(commandExec);
    2.94 +            }
    2.95 +            //String newExec = CommandCustomizationSupport.preCustomize(executionContext, vcsCmd, vars);
    2.96 +            //if (commandExec != null && newExec == null) return new UserCancelException();
    2.97 +            if (!success) successfull = false;
    2.98 +        } while((cmd = (VcsDescribedCommand) cmd.getNextCommand()) != null);
    2.99 +        return successfull;
   2.100 +    }
   2.101 +    
   2.102 +    /**
   2.103       * Get the class of the action.
   2.104       */
   2.105      public Class getActionClass() {
     3.1 --- a/vcscore/src/org/netbeans/modules/vcscore/commands/CommandProcessor.java	Fri Jun 25 13:20:08 2004 +0000
     3.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/commands/CommandProcessor.java	Fri Jun 25 17:14:57 2004 +0000
     3.3 @@ -400,6 +400,7 @@
     3.4              java.lang.reflect.Method getDisplayNameMethod = null;
     3.5              java.lang.reflect.Method getHelpIDMethod = null;
     3.6              java.lang.reflect.Method getInitialFocusedComponentMethod = null;
     3.7 +            java.lang.reflect.Method doPostCustomizationWorkMethod = null;
     3.8              if (cust instanceof ActionListener) actionL = (ActionListener) cust;
     3.9              try {
    3.10                  addActionListenerMethod = cust.getClass().getMethod("addActionListener", new Class[] { ActionListener.class });
    3.11 @@ -413,6 +414,9 @@
    3.12              try {
    3.13                  getInitialFocusedComponentMethod = cust.getClass().getMethod("getInitialFocusedComponent", null);
    3.14              } catch (Exception ex) {}
    3.15 +            try {
    3.16 +                doPostCustomizationWorkMethod = cust.getClass().getMethod("doPostCustomizationWork", null);
    3.17 +            } catch (Exception ex) {}
    3.18              String displayName = null;
    3.19              if (getDisplayNameMethod != null) {
    3.20                  try {
    3.21 @@ -481,6 +485,13 @@
    3.22              }
    3.23              dialog.setVisible(true);
    3.24              status = statusContainer[0];
    3.25 +            if (status && doPostCustomizationWorkMethod != null) {
    3.26 +                try {
    3.27 +                    doPostCustomizationWorkMethod.invoke(cust, null);
    3.28 +                } catch (Exception ex) {
    3.29 +                    ErrorManager.getDefault().notify(ex);
    3.30 +                }
    3.31 +            }
    3.32          } else {
    3.33              //PropertyPanel panel = new PropertyPanel(
    3.34              //beanNode.getPropertySets();