It's now possible to attach property change listeners to the runtime commands. BLD200206210100
authormentlicher@netbeans.org
Thu, 20 Jun 2002 17:42:56 +0000
changeset 2344d62d4fa72289
parent 2343 41fddc1ea153
child 2345 65bf3203ec48
It's now possible to attach property change listeners to the runtime commands.
The default implementation of runtime node attach itself as a weak listener, so that
it does not miss any property change.
The former implementation was obsolete, the command updated the node,
but when the node was being created in the mean time it did not get updated.
This is a fix to issue #24423.
vcscore/src/org/netbeans/modules/vcscore/runtime/RuntimeCommand.java
vcscore/src/org/netbeans/modules/vcscore/runtime/RuntimeCommandNode.java
vcscore/src/org/netbeans/modules/vcscore/runtime/VcsRuntimeCommand.java
     1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/runtime/RuntimeCommand.java	Thu Jun 20 11:46:35 2002 +0000
     1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/runtime/RuntimeCommand.java	Thu Jun 20 17:42:56 2002 +0000
     1.3 @@ -13,6 +13,8 @@
     1.4  
     1.5  package org.netbeans.modules.vcscore.runtime;
     1.6  
     1.7 +import java.beans.PropertyChangeListener;
     1.8 +import java.beans.PropertyChangeSupport;
     1.9  import java.lang.ref.Reference;
    1.10  import java.lang.ref.WeakReference;
    1.11  
    1.12 @@ -63,14 +65,20 @@
    1.13      
    1.14      public static final int STATE_KILLED_BUT_RUNNING = RuntimeCommandNode.STATE_KILLED_BUT_RUNNING;
    1.15      
    1.16 +    public static final String PROP_STATE = "state";
    1.17 +    public static final String PROP_DISPLAY_NAME = "displayName";
    1.18 +    
    1.19      private Reference nodeDelegate = new WeakReference(null);
    1.20      
    1.21 +    private PropertyChangeSupport changeSupport;
    1.22 +    
    1.23      /** Creates new RuntimeCommand */
    1.24      public RuntimeCommand() {
    1.25 +        changeSupport = new PropertyChangeSupport(this);
    1.26      }
    1.27      
    1.28      /**
    1.29 -     * Subclasses should return a nema of the command. 
    1.30 +     * Subclasses should return a name of the command. 
    1.31       */
    1.32      public abstract String getName();
    1.33      
    1.34 @@ -146,4 +154,23 @@
    1.35          return (Node) nodeDelegate.get();
    1.36      }
    1.37      
    1.38 +    public final void addPropertyChangeListener(PropertyChangeListener propertyListener) {
    1.39 +        changeSupport.addPropertyChangeListener(propertyListener);
    1.40 +    }
    1.41 +    
    1.42 +    public final void addPropertyChangeListener(String propertyName, PropertyChangeListener propertyListener) {
    1.43 +        changeSupport.addPropertyChangeListener(propertyName, propertyListener);
    1.44 +    }
    1.45 +    
    1.46 +    public final void removePropertyChangeListener(PropertyChangeListener propertyListener) {
    1.47 +        changeSupport.removePropertyChangeListener(propertyListener);
    1.48 +    }
    1.49 +    
    1.50 +    public final void removePropertyChangeListener(String propertyName, PropertyChangeListener propertyListener) {
    1.51 +        changeSupport.removePropertyChangeListener(propertyName, propertyListener);
    1.52 +    }
    1.53 +    
    1.54 +    protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
    1.55 +        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
    1.56 +    }
    1.57  }
     2.1 --- a/vcscore/src/org/netbeans/modules/vcscore/runtime/RuntimeCommandNode.java	Thu Jun 20 11:46:35 2002 +0000
     2.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/runtime/RuntimeCommandNode.java	Thu Jun 20 17:42:56 2002 +0000
     2.3 @@ -13,6 +13,8 @@
     2.4  
     2.5  package org.netbeans.modules.vcscore.runtime;
     2.6  
     2.7 +import java.beans.PropertyChangeEvent;
     2.8 +import java.beans.PropertyChangeListener;
     2.9  import java.awt.Image;
    2.10  
    2.11  import org.openide.actions.PropertiesAction;
    2.12 @@ -20,6 +22,7 @@
    2.13  import org.openide.util.actions.SystemAction;
    2.14  import org.openide.util.Utilities;
    2.15  import org.openide.util.NbBundle;
    2.16 +import org.openide.util.WeakListener;
    2.17  
    2.18  import org.netbeans.modules.vcscore.commands.VcsCommandExecutor;
    2.19  import org.netbeans.modules.vcscore.commands.CommandsPool;
    2.20 @@ -32,7 +35,7 @@
    2.21   *
    2.22   * @author  Martin Entlicher
    2.23   */
    2.24 -public class RuntimeCommandNode extends AbstractNode {
    2.25 +public class RuntimeCommandNode extends AbstractNode implements PropertyChangeListener {
    2.26  
    2.27      static final int STATE_WAITING = 10;
    2.28      static final int STATE_RUNNING = 11;
    2.29 @@ -56,6 +59,7 @@
    2.30          if (displayName == null || displayName.length() == 0) displayName = command.getName();
    2.31          setDisplayName(displayName);
    2.32          setShortDescription(NbBundle.getMessage(RuntimeCommandNode.class, "RuntimeCommandNode.Description", displayName));
    2.33 +        comm.addPropertyChangeListener(WeakListener.propertyChange(this, comm));
    2.34          setState(comm.getState());
    2.35          setDefaultAction(CommandOutputViewAction.getInstance());
    2.36          getCookieSet().add(comm);
    2.37 @@ -96,13 +100,22 @@
    2.38      
    2.39      public SystemAction[] getActions() {
    2.40          return command.getActions();
    2.41 -
    2.42      }
    2.43  
    2.44      public Sheet createSheet() {
    2.45          return command.createSheet();
    2.46      }
    2.47      
    2.48 +    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
    2.49 +        String propertyName = propertyChangeEvent.getPropertyName();
    2.50 +        if (RuntimeCommand.PROP_STATE.equals(propertyName)) {
    2.51 +            setState(command.getState());
    2.52 +        } else if (RuntimeCommand.PROP_DISPLAY_NAME.equals(propertyName)) {
    2.53 +            String displayName = command.getDisplayName();
    2.54 +            if (displayName == null || displayName.length() == 0) displayName = command.getName();
    2.55 +            setDisplayName(displayName);
    2.56 +        }
    2.57 +    }
    2.58  
    2.59  
    2.60      private String g(String name) {
     3.1 --- a/vcscore/src/org/netbeans/modules/vcscore/runtime/VcsRuntimeCommand.java	Thu Jun 20 11:46:35 2002 +0000
     3.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/runtime/VcsRuntimeCommand.java	Thu Jun 20 17:42:56 2002 +0000
     3.3 @@ -164,10 +164,7 @@
     3.4  
     3.5      public void setState(int state) {
     3.6          this.state = state;
     3.7 -        RuntimeCommandNode node = (RuntimeCommandNode) getExistingNodeDelegate();
     3.8 -        if (node != null) {
     3.9 -            node.setState(state);
    3.10 -        }
    3.11 +        firePropertyChange(PROP_STATE, null, null);
    3.12      }
    3.13      
    3.14      public void notifyRemoved() {