Node getCookie and super(..,lookup) are mutually exclusive. Some actions were incorrectly disabled (Find, RefreshRevisions). BLD200409011800
authorpkuzel@netbeans.org
Wed, 01 Sep 2004 17:03:29 +0000
changeset 51357822ca453f7c
parent 5134 c07e13a9744d
child 5136 e27ecced34a6
Node getCookie and super(..,lookup) are mutually exclusive. Some actions were incorrectly disabled (Find, RefreshRevisions).
vcscore/src/org/netbeans/modules/vcscore/versioning/impl/FileNode.java
vcscore/src/org/netbeans/modules/vcscore/versioning/impl/FolderNode.java
     1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/versioning/impl/FileNode.java	Wed Sep 01 15:32:15 2004 +0000
     1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/versioning/impl/FileNode.java	Wed Sep 01 17:03:29 2004 +0000
     1.3 @@ -50,11 +50,6 @@
     1.4          this.addPropertyChangeListener(propListener);
     1.5      }
     1.6  
     1.7 -    public Cookie getCookie(Class type) {
     1.8 -        if (type.isAssignableFrom(RefreshRevisionsCookie.class)) return this;
     1.9 -        return super.getCookie(type);
    1.10 -    }
    1.11 -
    1.12      public Action[] getActions(boolean context) {
    1.13          return new SystemAction[]{
    1.14              //SystemAction.get(DebugAction.class),
     2.1 --- a/vcscore/src/org/netbeans/modules/vcscore/versioning/impl/FolderNode.java	Wed Sep 01 15:32:15 2004 +0000
     2.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/versioning/impl/FolderNode.java	Wed Sep 01 17:03:29 2004 +0000
     2.3 @@ -27,6 +27,8 @@
     2.4  import org.openide.util.WeakListeners;
     2.5  import org.openide.util.HelpCtx;
     2.6  import org.openide.util.lookup.Lookups;
     2.7 +import org.openide.util.lookup.InstanceContent;
     2.8 +import org.openide.util.lookup.AbstractLookup;
     2.9  import org.openide.util.actions.SystemAction;
    2.10  import org.openide.util.actions.NodeAction;
    2.11  
    2.12 @@ -77,6 +79,8 @@
    2.13      /** The file or folder */
    2.14      private final FileObject file;
    2.15  
    2.16 +    private final InstanceContent content;
    2.17 +
    2.18      // XXX probably undeclatred dependency, copied from loaders.FolderNode
    2.19      static final String FOLDER_ICON_BASE =
    2.20          "org/openide/loaders/defaultFolder"; // NOI18N
    2.21 @@ -88,11 +92,50 @@
    2.22      }
    2.23      
    2.24      FolderNode(Children ch, FileObject file) {
    2.25 -        super(ch, Lookups.singleton(file));
    2.26 +        this(ch, file, new InstanceContent());
    2.27 +    }
    2.28 +
    2.29 +    private FolderNode(Children ch, FileObject file, InstanceContent content) {
    2.30 +        super(ch, new AbstractLookup(content));
    2.31 +
    2.32 +        // setup lookup content
    2.33 +
    2.34 +        content.add(file);
    2.35 +        content.add(this);
    2.36 +        InstanceContent.Convertor lazyDataObject = new InstanceContent.Convertor() {
    2.37 +            public Object convert(Object obj) {
    2.38 +                try {
    2.39 +                    return DataObject.find(FolderNode.this.file);
    2.40 +                } catch (DataObjectNotFoundException e) {
    2.41 +                    // ignore, call super later on
    2.42 +                }
    2.43 +                return null;
    2.44 +            }
    2.45 +            public Class type(Object obj) {
    2.46 +                return (Class) obj;
    2.47 +            }
    2.48 +            public String id(Object obj) {
    2.49 +                return "";
    2.50 +            }
    2.51 +            public String displayName(Object obj) {
    2.52 +                return "";
    2.53 +            }
    2.54 +        };
    2.55 +
    2.56 +        content.add(DataObject.class, lazyDataObject);
    2.57 +        if (file.isFolder()) {
    2.58 +            content.add(DataFolder.class, lazyDataObject);
    2.59 +        }
    2.60          this.file = file;
    2.61 +        this.content = content;
    2.62          init(file);
    2.63      }
    2.64 -    
    2.65 +
    2.66 +    /** Allows sobclasses to customize lookup content. */
    2.67 +    protected final InstanceContent getLookupContent() {
    2.68 +        return content;
    2.69 +    }
    2.70 +
    2.71      private void init(FileObject file) {
    2.72          try {
    2.73              FileSystem fs = file.getFileSystem();
    2.74 @@ -105,23 +148,6 @@
    2.75          }
    2.76      }
    2.77  
    2.78 -    public Cookie getCookie(Class type) {
    2.79 -        // mimics DataNode because some actions heavily depends on DataObject cookie existence
    2.80 -        if (type.isAssignableFrom(DataObject.class) || file.isFolder() && type.isAssignableFrom(DataFolder.class)) {
    2.81 -            try {
    2.82 -                return DataObject.find(file);
    2.83 -            } catch (DataObjectNotFoundException e) {
    2.84 -                // ignore, call super later on
    2.85 -            }
    2.86 -        }
    2.87 -
    2.88 -        if (type == FolderNode.class) { // DebugAction requires it
    2.89 -            return this;
    2.90 -        }
    2.91 -
    2.92 -        return super.getCookie(type);
    2.93 -    }
    2.94 -
    2.95      public String getName() {
    2.96          return file.getNameExt();
    2.97      }