This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 215297
Collapse All | Expand All

(-)a/java.api.common/nbproject/project.xml (+1 lines)
Lines 135-140 Link Here
135
                    <compile-dependency/>
135
                    <compile-dependency/>
136
                    <run-dependency>
136
                    <run-dependency>
137
                        <release-version>1</release-version>
137
                        <release-version>1</release-version>
138
                        <specification-version>1.59</specification-version>
138
                    </run-dependency>
139
                    </run-dependency>
139
                </dependency>
140
                </dependency>
140
                <dependency>
141
                <dependency>
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ActionFilterNode.java (-3 / +106 lines)
Lines 45-58 Link Here
45
45
46
46
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.net.URI;
48
import java.net.URL;
49
import java.net.URL;
49
import java.util.List;
50
import java.util.List;
50
import java.util.ArrayList;
51
import java.util.ArrayList;
52
import java.util.HashSet;
51
import java.util.Iterator;
53
import java.util.Iterator;
52
54
53
import java.util.Map;
55
import java.util.Set;
54
import java.util.concurrent.atomic.AtomicBoolean;
56
import java.util.concurrent.atomic.AtomicBoolean;
57
import java.util.regex.Pattern;
55
import javax.swing.Action;
58
import javax.swing.Action;
59
import org.apache.tools.ant.module.api.support.ActionUtils;
60
import org.netbeans.api.annotations.common.CheckForNull;
56
import org.netbeans.api.annotations.common.NonNull;
61
import org.netbeans.api.annotations.common.NonNull;
57
import org.netbeans.api.annotations.common.NullAllowed;
62
import org.netbeans.api.annotations.common.NullAllowed;
58
import org.netbeans.api.project.libraries.Library;
63
import org.netbeans.api.project.libraries.Library;
Lines 70-75 Link Here
70
import org.netbeans.api.project.FileOwnerQuery;
75
import org.netbeans.api.project.FileOwnerQuery;
71
import org.netbeans.api.project.Project;
76
import org.netbeans.api.project.Project;
72
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
77
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
78
import org.netbeans.api.java.queries.SourceForBinaryQuery;
73
import org.netbeans.api.project.ProjectManager;
79
import org.netbeans.api.project.ProjectManager;
74
import org.netbeans.api.project.libraries.LibrariesCustomizer;
80
import org.netbeans.api.project.libraries.LibrariesCustomizer;
75
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
81
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
Lines 85-90 Link Here
85
import org.openide.actions.EditAction;
91
import org.openide.actions.EditAction;
86
import org.openide.actions.FindAction;
92
import org.openide.actions.FindAction;
87
import org.openide.actions.OpenAction;
93
import org.openide.actions.OpenAction;
94
import org.openide.filesystems.URLMapper;
95
import org.openide.loaders.DataFolder;
88
import org.openide.util.Exceptions;
96
import org.openide.util.Exceptions;
89
import org.openide.util.Parameters;
97
import org.openide.util.Parameters;
90
import org.openide.util.RequestProcessor;
98
import org.openide.util.RequestProcessor;
Lines 250-258 Link Here
250
    }
258
    }
251
259
252
    private static Lookup createLookup(final Node original, Object... toAdd) {
260
    private static Lookup createLookup(final Node original, Object... toAdd) {
261
        final Lookup lookup = original.getLookup();
262
        final org.netbeans.spi.project.ui.PathFinder pathFinder =
263
                lookup.lookup(org.netbeans.spi.project.ui.PathFinder.class);
253
        final Lookup lkp = new ProxyLookup(
264
        final Lookup lkp = new ProxyLookup(
254
                original.getLookup(),
265
                Lookups.exclude(lookup, org.netbeans.spi.project.ui.PathFinder.class),
255
                Lookups.fixed (toAdd));
266
                Lookups.fixed (toAdd),
267
                Lookups.singleton(new PathFinder(pathFinder)));
256
        return lkp;
268
        return lkp;
257
    }
269
    }
258
270
Lines 633-636 Link Here
633
            }
645
            }
634
        }
646
        }
635
    }
647
    }
648
649
    private static final class PathFinder implements org.netbeans.spi.project.ui.PathFinder {
650
651
        private static final Pattern SRCDIRJAVA = Pattern.compile("\\.java$"); // NOI18N
652
        private static final String SUBST = ".class"; // NOI18N
653
654
        //@GuardBy("PathFinder.class")
655
        private static URI currentKey;
656
        //@GuardBy("PathFinder.class")
657
        private static Set<URI> currentValues;
658
        
659
        private final org.netbeans.spi.project.ui.PathFinder delegate;
660
661
        public PathFinder(@NullAllowed final org.netbeans.spi.project.ui.PathFinder delegate) {
662
            this.delegate = delegate;
663
        }
664
665
        @Override
666
        public Node findPath(Node root, Object target) {
667
            Node result = null;
668
            if (delegate != null && target instanceof FileObject) {
669
                FileObject binRoot = root.getLookup().lookup(FileObject.class);
670
                if (binRoot == null) {
671
                    final DataFolder dobj = root.getLookup().lookup(DataFolder.class);
672
                    binRoot = dobj == null ? null : dobj.getPrimaryFile();
673
                }
674
                if (binRoot != null) {
675
                    FileObject newTarget = rebase(binRoot, (FileObject) target);
676
                    if (newTarget != null) {
677
                        result = delegate.findPath(root, newTarget);
678
                    }
679
                }
680
            }
681
            return result;
682
        }
683
684
        @CheckForNull
685
        static FileObject rebase(
686
                @NonNull final FileObject binRoot,
687
                @NonNull final FileObject sourceTarget) {
688
689
            if (shouldIgnore(sourceTarget.toURI(), binRoot.toURI())) {
690
                return null;
691
            }
692
            final URL providedBinRootURL = (URL) sourceTarget.getAttribute("classfile-root");    //NOI18N
693
            final String providedBinaryName = (String) sourceTarget.getAttribute("classfile-binaryName");   //NOI18N
694
            if (providedBinRootURL != null && providedBinaryName != null) {
695
                final FileObject providedBinRoot = URLMapper.findFileObject(providedBinRootURL);
696
                if (binRoot.equals(providedBinRoot)) {
697
                    return binRoot.getFileObject(providedBinaryName + SUBST);
698
                }
699
            } else {
700
                for (FileObject srcRoot : SourceForBinaryQuery.findSourceRoots(binRoot.toURL()).getRoots()) {
701
                    if (FileUtil.isParentOf(srcRoot, sourceTarget)) {
702
                        final FileObject[] newTarget = ActionUtils.regexpMapFiles(
703
                            new FileObject[]{sourceTarget},
704
                            srcRoot,
705
                            SRCDIRJAVA,
706
                            binRoot,
707
                            SUBST,
708
                            true);
709
                        if (newTarget != null) {
710
                            return newTarget[0];
711
                        }
712
                    }
713
                }
714
            }
715
            ignore(sourceTarget.toURI(), binRoot.toURI());
716
            return null;
717
        }
718
719
        private static synchronized boolean shouldIgnore (
720
                @NonNull final URI key,
721
                @NonNull final URI value) {
722
            if (!key.equals(currentKey)) {
723
                return false;
724
            }
725
            return currentValues.contains(value);
726
        }
727
728
        private static synchronized void ignore(
729
                @NonNull final URI key,
730
                @NonNull final URI value) {
731
            if (!key.equals(currentKey)) {
732
                currentKey = key;
733
                currentValues = new HashSet<URI>();
734
            }
735
            currentValues.add(value);
736
        }
737
        
738
    }
636
}
739
}
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/LibrariesNode.java (-2 / +29 lines)
Lines 117-123 Link Here
117
*/
117
*/
118
public final class LibrariesNode extends AbstractNode {
118
public final class LibrariesNode extends AbstractNode {
119
119
120
    private static final Image ICON_BADGE = ImageUtilities.loadImage("org/netbeans/modules/java/api/common/project/ui/resources/libraries-badge.png");    //NOI18N
120
    private static final Image ICON_BADGE = ImageUtilities.loadImage("org/netbeans/modules/java/api/common/project/ui/resources/libraries-badge.png");    //NOI18N    
121
    public static final RequestProcessor rp = new RequestProcessor ();
121
    public static final RequestProcessor rp = new RequestProcessor ();
122
    private static Icon folderIconCache;
122
    private static Icon folderIconCache;
123
    private static Icon openedFolderIconCache;
123
    private static Icon openedFolderIconCache;
Lines 147-153 Link Here
147
        super (new LibrariesChildren (project, eval, helper, refHelper, classPathProperty,
147
        super (new LibrariesChildren (project, eval, helper, refHelper, classPathProperty,
148
                    classPathIgnoreRef, platformProperty,
148
                    classPathIgnoreRef, platformProperty,
149
                    webModuleElementName, cs, extraKeys),
149
                    webModuleElementName, cs, extraKeys),
150
                Lookups.singleton(project));
150
                Lookups.fixed(project, new PathFinder()));
151
        this.displayName = displayName;
151
        this.displayName = displayName;
152
        this.librariesNodeActions = librariesNodeActions;
152
        this.librariesNodeActions = librariesNodeActions;
153
    }
153
    }
Lines 931-934 Link Here
931
        Node[] createNodes(Key key);
931
        Node[] createNodes(Key key);
932
    }
932
    }
933
933
934
    private static final class PathFinder implements org.netbeans.spi.project.ui.PathFinder {
935
        
936
937
        PathFinder() {
938
        }
939
940
        @Override
941
        public Node findPath(Node root, Object target) {
942
            Node result = null;
943
            for (Node  node : root.getChildren().getNodes(true)) {
944
                final org.netbeans.spi.project.ui.PathFinder pf =
945
                    node.getLookup().lookup(org.netbeans.spi.project.ui.PathFinder.class);
946
                if (pf == null) {
947
                    continue;
948
                }
949
                result = pf.findPath(node, target);
950
                if (result != null) {
951
                    break;
952
                }
953
            }
954
            return result;
955
        }
956
957
    }
958
959
    
960
934
}
961
}
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/PlatformNode.java (-3 / +27 lines)
Lines 111-119 Link Here
111
111
112
    private PlatformNode(PlatformProvider pp, ClassPathSupport cs) {
112
    private PlatformNode(PlatformProvider pp, ClassPathSupport cs) {
113
        super (new PlatformContentChildren (cs), new ProxyLookup(new Lookup[]{
113
        super (new PlatformContentChildren (cs), new ProxyLookup(new Lookup[]{
114
            Lookups.fixed(new PlatformEditable(pp), new JavadocProvider(pp)),
114
            Lookups.fixed(new PlatformEditable(pp), new JavadocProvider(pp),  new PathFinder()),
115
            new PlatformFolderLookup(new InstanceContent(), pp)
115
                    new PlatformFolderLookup(new InstanceContent(), pp)
116
        }));
116
            }));
117
        this.pp = pp;
117
        this.pp = pp;
118
        this.pp.addChangeListener(this);
118
        this.pp.addChangeListener(this);
119
        setIconBaseWithExtension(PLATFORM_ICON);
119
        setIconBaseWithExtension(PLATFORM_ICON);
Lines 403-408 Link Here
403
403
404
    }
404
    }
405
405
406
    private static final class PathFinder implements org.netbeans.spi.project.ui.PathFinder {
407
408
        PathFinder() {
409
        }
410
411
        @Override
412
        public Node findPath(Node root, Object target) {
413
            Node result = null;
414
            for (Node node : root.getChildren().getNodes(true)) {
415
                final org.netbeans.spi.project.ui.PathFinder pf =
416
                    node.getLookup().lookup(org.netbeans.spi.project.ui.PathFinder.class);
417
                if (pf == null) {
418
                    continue;
419
                }
420
                result = pf.findPath(node, target);
421
                if (result != null) {
422
                    break;
423
                }
424
            }
425
            return result;
426
        }
427
428
    }
429
406
}
430
}
407
431
408
432
(-)a/java.j2seproject/nbproject/project.xml (-1 / +1 lines)
Lines 212-218 Link Here
212
                    <compile-dependency/>
212
                    <compile-dependency/>
213
                    <run-dependency>
213
                    <run-dependency>
214
                        <release-version>1</release-version>
214
                        <release-version>1</release-version>
215
                        <specification-version>1.47</specification-version>
215
                        <specification-version>1.59</specification-version>
216
                    </run-dependency>
216
                    </run-dependency>
217
                </dependency>
217
                </dependency>
218
                <dependency>
218
                <dependency>
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java (-3 / +23 lines)
Lines 64-74 Link Here
64
import org.netbeans.api.annotations.common.NonNull;
64
import org.netbeans.api.annotations.common.NonNull;
65
import org.netbeans.api.java.platform.JavaPlatform;
65
import org.netbeans.api.java.platform.JavaPlatform;
66
import org.netbeans.api.java.platform.JavaPlatformManager;
66
import org.netbeans.api.java.platform.JavaPlatformManager;
67
import org.netbeans.api.java.project.JavaProjectConstants;
67
import org.netbeans.api.project.FileOwnerQuery;
68
import org.netbeans.api.project.FileOwnerQuery;
68
import org.netbeans.api.project.Project;
69
import org.netbeans.api.project.Project;
69
import org.netbeans.api.project.ProjectInformation;
70
import org.netbeans.api.project.ProjectInformation;
70
import org.netbeans.api.project.ProjectManager;
71
import org.netbeans.api.project.ProjectManager;
71
import org.netbeans.api.project.ProjectUtils;
72
import org.netbeans.api.project.ProjectUtils;
73
import org.netbeans.api.project.SourceGroup;
72
import org.netbeans.api.project.libraries.LibraryManager;
74
import org.netbeans.api.project.libraries.LibraryManager;
73
import org.netbeans.modules.java.api.common.SourceRoots;
75
import org.netbeans.modules.java.api.common.SourceRoots;
74
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
76
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
Lines 221-226 Link Here
221
        return helper;
223
        return helper;
222
    }
224
    }
223
    
225
    
226
    @Override
224
    public Node findPath(Node root, Object target) {
227
    public Node findPath(Node root, Object target) {
225
        Project prj = root.getLookup().lookup(Project.class);
228
        Project prj = root.getLookup().lookup(Project.class);
226
        if (prj == null) {
229
        if (prj == null) {
Lines 229-237 Link Here
229
        
232
        
230
        if (target instanceof FileObject) {
233
        if (target instanceof FileObject) {
231
            FileObject fo = (FileObject) target;
234
            FileObject fo = (FileObject) target;
232
            Project owner = FileOwnerQuery.getOwner(fo);
235
            if (isOtherProjectSource(fo, prj)) {
233
            if (!prj.equals(owner)) {
236
                return null; // Don't waste time if project does not own the fo among sources
234
                return null; // Don't waste time if project does not own the fo
235
            }
237
            }
236
            
238
            
237
            for (Node n : root.getChildren().getNodes(true)) {
239
            for (Node n : root.getChildren().getNodes(true)) {
Lines 244-249 Link Here
244
        
246
        
245
        return null;
247
        return null;
246
    }
248
    }
249
250
    private static boolean isOtherProjectSource(
251
            @NonNull final FileObject fo,
252
            @NonNull final Project me) {
253
        final Project owner = FileOwnerQuery.getOwner(fo);
254
        if (owner == null) {
255
            return false;
256
        }
257
        if (me.equals(owner)) {
258
            return false;
259
        }
260
        for (SourceGroup sg : ProjectUtils.getSources(owner).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
261
            if (FileUtil.isParentOf(sg.getRootFolder(), fo)) {
262
                return true;
263
            }
264
        }
265
        return false;
266
    }
247
    
267
    
248
    
268
    
249
    
269
    
(-)a/java.project/nbproject/project.xml (-1 / +1 lines)
Lines 151-157 Link Here
151
                    <compile-dependency/>
151
                    <compile-dependency/>
152
                    <run-dependency>
152
                    <run-dependency>
153
                        <release-version>1</release-version>
153
                        <release-version>1</release-version>
154
                        <specification-version>1.45</specification-version>
154
                        <specification-version>1.59</specification-version>
155
                    </run-dependency>
155
                    </run-dependency>
156
                </dependency>
156
                </dependency>
157
                <dependency>
157
                <dependency>
(-)a/java.project/src/org/netbeans/spi/java/project/support/ui/PackageRootNode.java (-1 / +2 lines)
Lines 383-389 Link Here
383
    
383
    
384
    /** If contained in the lookup can perform the search for a node
384
    /** If contained in the lookup can perform the search for a node
385
     */    
385
     */    
386
    public static class PathFinder {
386
    public static class PathFinder implements org.netbeans.spi.project.ui.PathFinder {
387
        
387
        
388
        private SourceGroup group;
388
        private SourceGroup group;
389
        
389
        
Lines 391-396 Link Here
391
            this.group = group;
391
            this.group = group;
392
        }
392
        }
393
        
393
        
394
        @Override
394
        public Node findPath( Node root, Object object ) {
395
        public Node findPath( Node root, Object object ) {
395
            FileObject fo;
396
            FileObject fo;
396
            if (object instanceof FileObject) {
397
            if (object instanceof FileObject) {
(-)a/java.project/src/org/netbeans/spi/java/project/support/ui/PackageView.java (-9 / +3 lines)
Lines 74-79 Link Here
74
import org.netbeans.modules.java.project.JavaProjectSettings;
74
import org.netbeans.modules.java.project.JavaProjectSettings;
75
import org.netbeans.modules.java.project.PackageDisplayUtils;
75
import org.netbeans.modules.java.project.PackageDisplayUtils;
76
import static org.netbeans.spi.java.project.support.ui.Bundle.*;
76
import static org.netbeans.spi.java.project.support.ui.Bundle.*;
77
import org.netbeans.spi.project.ui.PathFinder;
77
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileUtil;
79
import org.openide.filesystems.FileUtil;
79
import org.openide.nodes.AbstractNode;
80
import org.openide.nodes.AbstractNode;
Lines 120-137 Link Here
120
     */
121
     */
121
    public static Node findPath(Node rootNode, Object object) {
122
    public static Node findPath(Node rootNode, Object object) {
122
        
123
        
123
        PackageRootNode.PathFinder pf = rootNode.getLookup().lookup(PackageRootNode.PathFinder.class);
124
        final PathFinder pf = rootNode.getLookup().lookup(PathFinder.class);
124
        
125
        if ( pf != null ) {
125
        if ( pf != null ) {
126
            return pf.findPath( rootNode, object );
126
            return pf.findPath( rootNode, object );
127
        } else {
128
            TreeRootNode.PathFinder pf2 = rootNode.getLookup().lookup(TreeRootNode.PathFinder.class);
129
            if (pf2 != null) {
130
                return pf2.findPath(rootNode, object);
131
            } else {
132
                return null;
133
            }
134
        }
127
        }
128
        return null;
135
    }
129
    }
136
    
130
    
137
    /**
131
    /**
(-)a/java.project/src/org/netbeans/spi/java/project/support/ui/TreeRootNode.java (-1 / +2 lines)
Lines 171-177 Link Here
171
    }
171
    }
172
172
173
    /** Copied from PhysicalView and PackageRootNode. */
173
    /** Copied from PhysicalView and PackageRootNode. */
174
    public static final class PathFinder {
174
    public static final class PathFinder implements org.netbeans.spi.project.ui.PathFinder {
175
        
175
        
176
        private final SourceGroup g;
176
        private final SourceGroup g;
177
        private final boolean reduced;
177
        private final boolean reduced;
Lines 181-186 Link Here
181
            this.reduced = reduced;
181
            this.reduced = reduced;
182
        }
182
        }
183
        
183
        
184
        @Override
184
        public Node findPath(Node rootNode, Object o) {
185
        public Node findPath(Node rootNode, Object o) {
185
            FileObject fo;
186
            FileObject fo;
186
            if (o instanceof FileObject) {
187
            if (o instanceof FileObject) {
(-)a/projectuiapi/apichanges.xml (+16 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="PathFinder">
111
            <api name="general"/>
112
            <summary>Extracted <code>findPath</code> method into a new interface <code>PathFinder</code></summary>
113
            <version major="1" minor="59"/>
114
            <date day="12" month="7" year="2012"/>
115
            <author login="tzezula"/>
116
            <compatibility addition="yes"/>
117
            <description>
118
                <p>
119
                    Extracted <code>findPath</code> method from <code>LogicalViewProvider</code> into a new interface <code>PathFinder</code>.
120
                    A new <code>PathFinder</code> simplifies delegation of <code>findPath</code> method.
121
                </p>
122
            </description>
123
            <class package="org.netbeans.spi.project.ui" name="PathFinder"/>
124
            <issue number="208241"/>
125
        </change>
110
        <change id="setAsMain">
126
        <change id="setAsMain">
111
            <api name="general"/>
127
            <api name="general"/>
112
            <summary>Programmatically setting main project deprecated</summary>
128
            <summary>Programmatically setting main project deprecated</summary>
(-)a/projectuiapi/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint -Xlint:-serial
43
javac.compilerargs=-Xlint -Xlint:-serial
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=1.58.0
45
spec.version.base=1.59.0
46
is.autoload=true
46
is.autoload=true
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/projectuiapi/src/org/netbeans/spi/project/ui/LogicalViewProvider.java (-36 / +2 lines)
Lines 55-61 Link Here
55
 * @see ProjectIconAnnotator
55
 * @see ProjectIconAnnotator
56
 * @author Jesse Glick
56
 * @author Jesse Glick
57
 */
57
 */
58
public interface LogicalViewProvider {
58
public interface LogicalViewProvider extends PathFinder {
59
59
60
    /**
60
    /**
61
     * Create a logical view node.
61
     * Create a logical view node.
Lines 72-111 Link Here
72
     * @return a node displaying the contents of the project in an intuitive way
72
     * @return a node displaying the contents of the project in an intuitive way
73
     * @see CommonProjectActions#forType
73
     * @see CommonProjectActions#forType
74
     */
74
     */
75
    Node createLogicalView();
75
    Node createLogicalView();        
76
    
77
    /**  
78
    * Try to find a given node in the logical view.  
79
    * If some node within the logical view tree has the supplied object  
80
    * in its lookup, it ought to be returned if that is practical.  
81
    * If there are multiple such nodes, the one most suitable for display
82
    * to the user should be returned.<BR>
83
    * This may be used to select nodes corresponding to files, etc.  
84
    * The following constraint should hold:  
85
    * <pre>  
86
    * private static boolean isAncestor(Node root, Node n) {  
87
    *     if (n == null) return false;  
88
    *     if (n == root) return true;  
89
    *     return isAncestor(root, n.getParentNode());  
90
    * }  
91
    * // ...  
92
    * Node root = ...;  
93
    * Object target = ...;  
94
    * LogicalViewProvider lvp = ...;  
95
    * Node n = lvp.findPath(root, target);  
96
    * if (n != null) {  
97
    *     assert isAncestor(root, n);  
98
    *     Lookup.Template tmpl = new Lookup.Template(null, null, target); 
99
    *     Collection res = n.getLookup().lookup(tmpl).allInstances();  
100
    *     assert Collections.singleton(target).equals(new HashSet(res)); 
101
    * }  
102
    * </pre>  
103
    * @param root a root node. E.g. a node from {@link #createLogicalView} or some wapper
104
    *        (FilterNode) around the node. The provider of the functionality is
105
    *        responsible for finding the appropriate node in the wrapper's children.
106
    * @param target a target cookie, such as a {@link org.openide.loaders.DataObject}
107
    * @return a subnode with that cookie, or null  
108
    */
109
    Node findPath(Node root, Object target);
110
    
76
    
111
}
77
}
(-)a/projectuiapi/src/org/netbeans/spi/project/ui/PathFinder.java (+87 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.project.ui;
43
44
import org.openide.nodes.Node;
45
46
/**
47
 * Ability to find a subnode representing a target.
48
 * Extended by the {@link LogicalViewProvider}.
49
 * @author Tomas Zezula
50
 * @since 1.59
51
 */
52
public interface PathFinder {
53
54
    /**
55
    * Try to find a given node in the logical view.
56
    * If some node within the logical view tree has the supplied object
57
    * in its lookup, it ought to be returned if that is practical.
58
    * If there are multiple such nodes, the one most suitable for display
59
    * to the user should be returned.<BR>
60
    * This may be used to select nodes corresponding to files, etc.
61
    * The following constraint should hold:
62
    * <pre>
63
    * private static boolean isAncestor(Node root, Node n) {
64
    *     if (n == null) return false;
65
    *     if (n == root) return true;
66
    *     return isAncestor(root, n.getParentNode());
67
    * }
68
    * // ...
69
    * Node root = ...;
70
    * Object target = ...;
71
    * LogicalViewProvider lvp = ...;
72
    * Node n = lvp.findPath(root, target);
73
    * if (n != null) {
74
    *     assert isAncestor(root, n);
75
    *     Lookup.Template tmpl = new Lookup.Template(null, null, target);
76
    *     Collection res = n.getLookup().lookup(tmpl).allInstances();
77
    *     assert Collections.singleton(target).equals(new HashSet(res));
78
    * }
79
    * </pre>
80
    * @param root a root node. E.g. a node from {@link #createLogicalView} or some wapper
81
    *        (FilterNode) around the node. The provider of the functionality is
82
    *        responsible for finding the appropriate node in the wrapper's children.
83
    * @param target a target cookie, such as a {@link org.openide.loaders.DataObject}
84
    * @return a subnode with that cookie, or null
85
    */
86
    Node findPath(Node root, Object target);
87
}

Return to bug 215297