The Basic variables node is made gray (looks like disabled) and all BLD200207020100
authormentlicher@netbeans.org
Fri, 28 Jun 2002 10:46:24 +0000
changeset 2361bfd4c9f2ca0b
parent 2360 afc2ac026933
child 2362 b29d9841e9b9
The Basic variables node is made gray (looks like disabled) and all
it's variables are copied into Accessory node when CONFIG_INPUT_DESCRIPTOR
variable is defined.
This is a fix of issue #25175.
vcs.advanced/src/org/netbeans/modules/vcs/advanced/UserVariablesPanel.java
vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/AccessoryVariableNode.java
vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/BasicVariableNode.java
vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/Bundle.properties
     1.1 --- a/vcs.advanced/src/org/netbeans/modules/vcs/advanced/UserVariablesPanel.java	Thu Jun 27 14:27:05 2002 +0000
     1.2 +++ b/vcs.advanced/src/org/netbeans/modules/vcs/advanced/UserVariablesPanel.java	Fri Jun 28 10:46:24 2002 +0000
     1.3 @@ -15,6 +15,8 @@
     1.4  import java.util.*;
     1.5  import java.awt.*;
     1.6  import java.awt.event.*;
     1.7 +import java.beans.PropertyChangeEvent;
     1.8 +import java.beans.PropertyChangeListener;
     1.9  import javax.swing.*;
    1.10  import javax.swing.event.*;
    1.11  import javax.swing.border.*;
    1.12 @@ -28,6 +30,7 @@
    1.13  
    1.14  import org.netbeans.modules.vcscore.util.*;
    1.15  import org.netbeans.modules.vcscore.*;
    1.16 +import org.netbeans.modules.vcs.advanced.VcsCustomizer;
    1.17  import org.netbeans.modules.vcs.advanced.variables.*;
    1.18  
    1.19  /** User variables panel.
    1.20 @@ -35,13 +38,23 @@
    1.21   * @author Martin Entlicher
    1.22   */
    1.23  //-------------------------------------------
    1.24 -public class UserVariablesPanel extends JPanel implements EnhancedCustomPropertyEditor, ExplorerManager.Provider {
    1.25 +public class UserVariablesPanel extends JPanel implements EnhancedCustomPropertyEditor,
    1.26 +                                                          ExplorerManager.Provider,
    1.27 +                                                          PropertyChangeListener {
    1.28 +    
    1.29 +    /** This property is fired when the variable CONFIG_INPUT_DESCRIPTOR is
    1.30 +     * defined/undefined with a meaningfull value */
    1.31 +    public static final String PROP_CONFIG_INPUT_DESCRIPTOR = "configInputDescriptor"; // NOI18N
    1.32 +    
    1.33      private Debug E=new Debug("UserVariablesPanel", true); // NOI18N
    1.34      //private Debug D=E;
    1.35  
    1.36      private UserVariablesEditor editor;
    1.37      private ExplorerManager manager = null;
    1.38 -    private Children.SortedArray basicChildren = null;
    1.39 +    private Children.Array varCh = null;
    1.40 +    private BasicVariableNode basicRoot = null;
    1.41 +    private AccessoryVariableNode accessoryRoot = null;
    1.42 +    private Children basicChildren = null;
    1.43      private Children.SortedArray accessoryChildren = null;
    1.44  
    1.45      //-------------------------------------------
    1.46 @@ -87,22 +100,58 @@
    1.47          getAccessibleContext().setAccessibleDescription(g("ACS_UserVariablesPanelA11yDesc"));  // NOI18N
    1.48      }
    1.49      
    1.50 +    public static final boolean isConfigInputDescriptorVar(VcsConfigVariable var) {
    1.51 +        if (VcsCustomizer.VAR_CONFIG_INPUT_DESCRIPTOR.equals(var.getName())) {
    1.52 +            String value = var.getValue();
    1.53 +            if (value != null && value.length() > 0) {
    1.54 +                try {
    1.55 +                    VariableInputDescriptor.parseItems(value);
    1.56 +                } catch (VariableInputFormatException vifex) {
    1.57 +                    return false;
    1.58 +                }
    1.59 +                return true;
    1.60 +            }
    1.61 +        }
    1.62 +        return false;
    1.63 +    }
    1.64 +    
    1.65 +    private static final Comparator getRootVarsComparator() {
    1.66 +        return new Comparator() {
    1.67 +            public int compare(Object o1, Object o2) {
    1.68 +                if (o1.equals(o2)) return 0;
    1.69 +                if ((o1 instanceof BasicVariableNode) && (o2 instanceof AccessoryVariableNode)) return -1;
    1.70 +                else return +1;
    1.71 +            }
    1.72 +            public boolean equals(Object obj) {
    1.73 +                return false;
    1.74 +            }
    1.75 +        };
    1.76 +    }
    1.77 +    
    1.78      private AbstractNode createNodes() {
    1.79 -        Children.Array varCh = new Children.Array();
    1.80 +        Children.SortedArray varChSorted = new Children.SortedArray();
    1.81 +        varChSorted.setComparator(getRootVarsComparator());
    1.82 +        varCh = varChSorted;
    1.83          AbstractNode varRoot = new AbstractNode(varCh);
    1.84          varRoot.setDisplayName(g("CTL_VariablesNodeName"));
    1.85          varRoot.setShortDescription(g("CTL_VariablesNodeDescription"));
    1.86          varRoot.setIconBase("org/netbeans/modules/vcs/advanced/variables/AccessoryVariables"); // NOI18N
    1.87          basicChildren = new Children.SortedArray();
    1.88 -        //basicCh.add(new Node[] { node });
    1.89 -        AbstractNode basicRoot = new BasicVariableNode(basicChildren);
    1.90 +        basicRoot = new BasicVariableNode(basicChildren);
    1.91          accessoryChildren = new Children.SortedArray();
    1.92 -        AbstractNode accessoryRoot = new AccessoryVariableNode(accessoryChildren);
    1.93 +        accessoryRoot = new AccessoryVariableNode(accessoryChildren);
    1.94 +        //basicRoot.addPropertyChangeListener(WeakListener.propertyChange(this, basicRoot));
    1.95 +        //accessoryRoot.addPropertyChangeListener(WeakListener.propertyChange(this, accessoryRoot));
    1.96 +        accessoryRoot.addVariablePropertyChangeListener(this);
    1.97          varCh.add(new Node[] { basicRoot, accessoryRoot });
    1.98          Vector variables = (Vector) editor.getValue();
    1.99 +        boolean disableBasic = false;
   1.100          for(Enumeration enum = variables.elements(); enum.hasMoreElements(); ) {
   1.101              VcsConfigVariable var = (VcsConfigVariable) enum.nextElement();
   1.102              String name = var.getName();
   1.103 +            if (isConfigInputDescriptorVar(var)) {
   1.104 +                disableBasic = true;
   1.105 +            }
   1.106              if (var.isBasic()) {
   1.107                  basicChildren.add(new BasicVariableNode[] { new BasicVariableNode(var) });
   1.108              } else {
   1.109 @@ -113,9 +162,54 @@
   1.110                  accessoryChildren.add(new AccessoryVariableNode[] { new AccessoryVariableNode(var) });
   1.111              }
   1.112          }
   1.113 +        if (disableBasic) disableBasicVariables();
   1.114          return varRoot;
   1.115      }
   1.116 +    
   1.117 +    public void disableBasicVariables() {
   1.118 +        if (!basicRoot.isEnabled()) return ;
   1.119 +        Node[] nodes = basicChildren.getNodes();
   1.120 +        for (int i = 0; i < nodes.length; i++) {
   1.121 +            BasicVariableNode varNode = (BasicVariableNode) nodes[i];
   1.122 +            VcsConfigVariable var = varNode.getVariable();
   1.123 +            var.setOrder(i);
   1.124 +            accessoryChildren.add(new AccessoryVariableNode[] { new AccessoryVariableNode(var) });
   1.125 +        }
   1.126 +        varCh.remove(new Node[] { basicRoot });
   1.127 +        basicChildren = Children.LEAF;
   1.128 +        basicRoot = new BasicVariableNode(basicChildren);
   1.129 +        basicRoot.setEnabled(false);
   1.130 +        varCh.add(new Node[] { basicRoot });
   1.131 +    }
   1.132 +    
   1.133 +    public void enableBasicVariables() {
   1.134 +        if (basicRoot.isEnabled()) return ;
   1.135 +        varCh.remove(new Node[] { basicRoot });
   1.136 +        basicChildren = new Children.SortedArray();
   1.137 +        basicRoot = new BasicVariableNode(basicChildren);
   1.138 +        varCh.add(new Node[] { basicRoot });
   1.139 +        Node[] nodes = accessoryChildren.getNodes();
   1.140 +        for (int i = 0; i < nodes.length; i++) {
   1.141 +            AccessoryVariableNode varNode = (AccessoryVariableNode) nodes[i];
   1.142 +            VcsConfigVariable var = varNode.getVariable();
   1.143 +            if (var.isBasic()) {
   1.144 +                basicChildren.add(new BasicVariableNode[] { new BasicVariableNode(var) });
   1.145 +                accessoryChildren.remove(new Node[] { varNode });
   1.146 +            }
   1.147 +        }
   1.148 +    }
   1.149  
   1.150 +    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
   1.151 +        if (PROP_CONFIG_INPUT_DESCRIPTOR.equals(propertyChangeEvent.getPropertyName())) {
   1.152 +            Object newValue = propertyChangeEvent.getNewValue();
   1.153 +            if (Boolean.TRUE.equals(newValue)) {
   1.154 +                disableBasicVariables();
   1.155 +            } else if (Boolean.FALSE.equals(newValue)) {
   1.156 +                enableBasicVariables();
   1.157 +            }
   1.158 +        }
   1.159 +    }
   1.160 +    
   1.161      public org.openide.explorer.ExplorerManager getExplorerManager() {
   1.162          if (manager == null) {
   1.163              synchronized(this) {
   1.164 @@ -156,4 +250,5 @@
   1.165      private String g(String s) {
   1.166          return NbBundle.getMessage(UserVariablesPanel.class, s);
   1.167      }
   1.168 +    
   1.169  }
     2.1 --- a/vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/AccessoryVariableNode.java	Thu Jun 27 14:27:05 2002 +0000
     2.2 +++ b/vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/AccessoryVariableNode.java	Fri Jun 28 10:46:24 2002 +0000
     2.3 @@ -14,10 +14,13 @@
     2.4  package org.netbeans.modules.vcs.advanced.variables;
     2.5  
     2.6  import java.awt.datatransfer.*;
     2.7 +import java.beans.PropertyChangeEvent;
     2.8 +import java.beans.PropertyChangeListener;
     2.9  import java.util.Collection;
    2.10  import java.util.Enumeration;
    2.11  import java.util.Comparator;
    2.12  import java.util.ArrayList;
    2.13 +import java.util.Iterator;
    2.14  
    2.15  import org.openide.*;
    2.16  import org.openide.nodes.*;
    2.17 @@ -29,6 +32,9 @@
    2.18  
    2.19  import org.netbeans.modules.vcscore.VcsConfigVariable;
    2.20  
    2.21 +import org.netbeans.modules.vcs.advanced.VcsCustomizer;
    2.22 +import org.netbeans.modules.vcs.advanced.UserVariablesPanel;
    2.23 +
    2.24  /**
    2.25   *
    2.26   * @author  Martin Entlicher
    2.27 @@ -37,6 +43,9 @@
    2.28  
    2.29      private VcsConfigVariable var = null;
    2.30      private Children.Array list = null;
    2.31 +    //private PropertyChangeSupport propSupport = new PropertyChangeSupport(new Object());
    2.32 +    // For some reason it does not work with PropertyChangeSupport
    2.33 +    private ArrayList changeListeners = new ArrayList();
    2.34  
    2.35      /** Creates new AccessoryVariableNode */
    2.36      public AccessoryVariableNode(Children.SortedArray list) {
    2.37 @@ -105,6 +114,32 @@
    2.38          return var;
    2.39      }
    2.40      
    2.41 +    public final void addVariablePropertyChangeListener(PropertyChangeListener propertyChangeListener) {
    2.42 +        //propSupport.addPropertyChangeListener(propertyChangeListener);
    2.43 +        synchronized (changeListeners) {
    2.44 +            changeListeners.add(propertyChangeListener);
    2.45 +        }
    2.46 +    }
    2.47 +    
    2.48 +    public final void removeVariablePropertyChangeListener(PropertyChangeListener propertyChangeListener) {
    2.49 +        //propSupport.removePropertyChangeListener(propertyChangeListener);
    2.50 +        synchronized (changeListeners) {
    2.51 +            changeListeners.remove(propertyChangeListener);
    2.52 +        }
    2.53 +    }
    2.54 +    
    2.55 +    protected final void fireVariablePropertyChange(String propertyName, Object oldValue, Object newValue) {
    2.56 +        //propSupport.firePropertyChange(propertyName, oldValue, newValue);
    2.57 +        ArrayList listeners;
    2.58 +        synchronized (changeListeners) {
    2.59 +            listeners = new ArrayList(changeListeners);
    2.60 +        }
    2.61 +        for (Iterator it = listeners.iterator(); it.hasNext(); ) {
    2.62 +            PropertyChangeListener l = (PropertyChangeListener) it.next();
    2.63 +            l.propertyChange(new PropertyChangeEvent(this, propertyName, oldValue, newValue));
    2.64 +        }
    2.65 +    }
    2.66 +    
    2.67      public Collection getAllAccessoryVariablesNames() {
    2.68          AccessoryVariableNode root = this;
    2.69          if (Children.LEAF.equals(this.getChildren())) {
    2.70 @@ -134,6 +169,15 @@
    2.71          return (Children.LEAF.equals(getChildren()));
    2.72      }
    2.73      
    2.74 +    public void destroy() throws java.io.IOException {
    2.75 +        if (VcsCustomizer.VAR_CONFIG_INPUT_DESCRIPTOR.equals(var.getName())) {
    2.76 +            ((AccessoryVariableNode) getParentNode()).fireVariablePropertyChange(
    2.77 +                UserVariablesPanel.PROP_CONFIG_INPUT_DESCRIPTOR,
    2.78 +                Boolean.TRUE, Boolean.FALSE);
    2.79 +        }
    2.80 +        super.destroy();
    2.81 +    }
    2.82 +    
    2.83      /** Copy this node to the clipboard.
    2.84       *
    2.85       * @return The transferable for VcsCommand
    2.86 @@ -232,6 +276,11 @@
    2.87              
    2.88              public void setValue(Object value) {
    2.89                  var.setValue((String) value);
    2.90 +                if (VcsCustomizer.VAR_CONFIG_INPUT_DESCRIPTOR.equals(var.getName())) {
    2.91 +                    ((AccessoryVariableNode) AccessoryVariableNode.this.getParentNode()).fireVariablePropertyChange(
    2.92 +                        UserVariablesPanel.PROP_CONFIG_INPUT_DESCRIPTOR,
    2.93 +                        Boolean.FALSE, new Boolean(UserVariablesPanel.isConfigInputDescriptorVar(var)));
    2.94 +                }
    2.95                  //cmd.fireChanged();
    2.96              }
    2.97          });
     3.1 --- a/vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/BasicVariableNode.java	Thu Jun 27 14:27:05 2002 +0000
     3.2 +++ b/vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/BasicVariableNode.java	Fri Jun 28 10:46:24 2002 +0000
     3.3 @@ -34,17 +34,27 @@
     3.4   * @author  Martin Entlicher
     3.5   */
     3.6  public class BasicVariableNode extends AbstractNode {
     3.7 -
     3.8 +    
     3.9 +    private static final String DISABLED_PRE = "<html><font color=\"#999999\">"; // NOI18N
    3.10 +    private static final String DISABLED_POST = "</font></html>"; // NOI18N
    3.11 +    
    3.12      private VcsConfigVariable var = null;
    3.13 -    private Children.SortedArray list = null;
    3.14 +    //private Children.SortedArray list = null;
    3.15 +    private boolean enabled = true;
    3.16  
    3.17      /** Creates new BasicVariableNode */
    3.18 -    public BasicVariableNode(Children.SortedArray list) {
    3.19 +    public BasicVariableNode(Children list) {
    3.20          super(list);
    3.21 -        init(list, null);
    3.22 -        list.setComparator(getComparator());
    3.23 +        if (list instanceof Children.SortedArray) {
    3.24 +            Children.SortedArray sortedList = (Children.SortedArray) list;
    3.25 +            init(sortedList, null);
    3.26 +            sortedList.setComparator(getComparator());
    3.27 +            setShortDescription(g("CTL_BasicVarsDescription"));
    3.28 +        } else {
    3.29 +            setShortDescription(g("CTL_BasicVarsDisabledDescription"));
    3.30 +            setEnabled(false);
    3.31 +        }
    3.32          setDisplayName(g("CTL_BasicVarsName"));
    3.33 -        setShortDescription(g("CTL_BasicVarsDescription"));
    3.34      }
    3.35      
    3.36      private Comparator getComparator() {
    3.37 @@ -80,7 +90,7 @@
    3.38      
    3.39      private void init(Children.SortedArray list, VcsConfigVariable var) {
    3.40          this.var = var;
    3.41 -        this.list = list;
    3.42 +        //this.list = list;
    3.43          getCookieSet().add(new VariablesIndex());
    3.44          setIconBase("org/netbeans/modules/vcs/advanced/variables/BasicVariables"); // NOI18N
    3.45      }
    3.46 @@ -106,6 +116,24 @@
    3.47          }
    3.48      }
    3.49      
    3.50 +    public String getDisplayName() {
    3.51 +        if (enabled) return super.getDisplayName();
    3.52 +        else return DISABLED_PRE + super.getDisplayName() + DISABLED_POST;
    3.53 +    }
    3.54 +    
    3.55 +    public void setEnabled(boolean enabled) {
    3.56 +        if (this.enabled == enabled) return ;
    3.57 +        this.enabled = enabled;
    3.58 +        if (enabled) setIconBase("org/netbeans/modules/vcs/advanced/variables/BasicVariables"); // NOI18N
    3.59 +        else setIconBase("org/netbeans/modules/vcs/advanced/variables/BasicVariablesGray"); // NOI18N
    3.60 +        firePropertyChange(Node.PROP_DISPLAY_NAME, null, null);
    3.61 +        firePropertyChange(Node.PROP_ICON, null, null);
    3.62 +    }
    3.63 +    
    3.64 +    public boolean isEnabled() {
    3.65 +        return enabled;
    3.66 +    }
    3.67 +    
    3.68      public VcsConfigVariable getVariable() {
    3.69          return var;
    3.70      }
    3.71 @@ -238,6 +266,11 @@
    3.72          actions.toArray(array);
    3.73          return array;
    3.74      }
    3.75 +    
    3.76 +    public SystemAction[] getActions() {
    3.77 +        if (enabled) return super.getActions();
    3.78 +        else return new SystemAction[0];
    3.79 +    }
    3.80  
    3.81      public Sheet createSheet() {
    3.82          Sheet sheet = Sheet.createDefault();
     4.1 --- a/vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/Bundle.properties	Thu Jun 27 14:27:05 2002 +0000
     4.2 +++ b/vcs.advanced/src/org/netbeans/modules/vcs/advanced/variables/Bundle.properties	Fri Jun 28 10:46:24 2002 +0000
     4.3 @@ -12,6 +12,7 @@
     4.4  # Sample ResourceBundle properties file
     4.5  CTL_BasicVarsName=Basic
     4.6  CTL_BasicVarsDescription=Configuration variables customizable in FS customizer
     4.7 +CTL_BasicVarsDisabledDescription=Use CONFIG_INPUT_DESCRIPTOR variable to define profile customizer and Accessory node to edit variables.
     4.8  # {0}.. Variable display name
     4.9  CTL_BasicVarDescription=Customizable variable ''{0}''
    4.10  CTL_AccessoryVarsName=Accessory