Lines 36-48
Link Here
|
36 |
import java.util.Collections; |
36 |
import java.util.Collections; |
37 |
import java.util.logging.Logger; |
37 |
import java.util.logging.Logger; |
38 |
import org.netbeans.modules.openide.util.NamedServicesProvider; |
38 |
import org.netbeans.modules.openide.util.NamedServicesProvider; |
|
|
39 |
import org.openide.cookies.InstanceCookie; |
39 |
import org.openide.filesystems.FileObject; |
40 |
import org.openide.filesystems.FileObject; |
40 |
import org.openide.filesystems.FileUtil; |
41 |
import org.openide.filesystems.FileUtil; |
41 |
import org.openide.loaders.DataFolder; |
42 |
import org.openide.loaders.DataFolder; |
|
|
43 |
import org.openide.loaders.DataObject; |
44 |
import org.openide.loaders.DataObject.Container; |
45 |
import org.openide.util.Exceptions; |
42 |
import org.openide.util.Lookup; |
46 |
import org.openide.util.Lookup; |
43 |
import org.openide.util.LookupEvent; |
47 |
import org.openide.util.LookupEvent; |
44 |
import org.openide.util.LookupListener; |
48 |
import org.openide.util.LookupListener; |
45 |
import org.openide.util.WeakListeners; |
49 |
import org.openide.util.WeakListeners; |
|
|
50 |
import org.openide.util.lookup.AbstractLookup; |
51 |
import org.openide.util.lookup.InstanceContent; |
46 |
import org.openide.util.lookup.Lookups; |
52 |
import org.openide.util.lookup.Lookups; |
47 |
import org.openide.util.lookup.ProxyLookup; |
53 |
import org.openide.util.lookup.ProxyLookup; |
48 |
|
54 |
|
Lines 55-62
Link Here
|
55 |
private static final Logger LOG = Logger.getLogger(RecognizeInstanceObjects.class.getName()); |
61 |
private static final Logger LOG = Logger.getLogger(RecognizeInstanceObjects.class.getName()); |
56 |
|
62 |
|
57 |
|
63 |
|
58 |
public Lookup create(String path) { |
64 |
public Lookup create(String path, Lookups.RecursionMode mode) { |
59 |
return new OverObjects(path); |
65 |
return new OverObjects(path, mode); |
60 |
} |
66 |
} |
61 |
|
67 |
|
62 |
|
68 |
|
Lines 65-79
Link Here
|
65 |
private static Lookup.Result<ClassLoader> CL = Lookup.getDefault().lookupResult(ClassLoader.class); |
71 |
private static Lookup.Result<ClassLoader> CL = Lookup.getDefault().lookupResult(ClassLoader.class); |
66 |
|
72 |
|
67 |
private final String path; |
73 |
private final String path; |
|
|
74 |
private final Lookups.RecursionMode mode; |
68 |
|
75 |
|
69 |
public OverObjects(String path) { |
76 |
public OverObjects(String path, Lookups.RecursionMode mode) { |
70 |
super(delegates(path)); |
77 |
super(delegates(path, mode)); |
71 |
this.path = path; |
78 |
this.path = path; |
|
|
79 |
this.mode = mode; |
72 |
CL.addLookupListener(WeakListeners.create(LookupListener.class, this, CL)); |
80 |
CL.addLookupListener(WeakListeners.create(LookupListener.class, this, CL)); |
73 |
} |
81 |
} |
74 |
|
82 |
|
75 |
@SuppressWarnings("deprecation") |
83 |
@SuppressWarnings("deprecation") |
76 |
private static Lookup[] delegates(String path) { |
84 |
private static Lookup[] delegates(final String path, final Lookups.RecursionMode mode) { |
77 |
Collection<? extends ClassLoader> allCL = CL.allInstances(); |
85 |
Collection<? extends ClassLoader> allCL = CL.allInstances(); |
78 |
ClassLoader ccl = Thread.currentThread().getContextClassLoader(); |
86 |
ClassLoader ccl = Thread.currentThread().getContextClassLoader(); |
79 |
if (ccl != null) { |
87 |
if (ccl != null) { |
Lines 84-89
Link Here
|
84 |
} |
92 |
} |
85 |
} |
93 |
} |
86 |
try { |
94 |
try { |
|
|
95 |
if (mode == Lookups.RecursionMode.FILE) { |
96 |
FileObject fo = FileUtil.getConfigFile(path); |
97 |
if (fo != null) { |
98 |
InstanceCookie cookie = DataObject.find(fo).getLookup().lookup(InstanceCookie.class); |
99 |
if (cookie != null) { |
100 |
InstanceContent ic = new InstanceContent(); |
101 |
ic.add(cookie, new InstanceContent.Convertor<InstanceCookie,Object>() { |
102 |
public Object convert(InstanceCookie cookie) { |
103 |
try { |
104 |
return cookie.instanceCreate(); |
105 |
} catch (Exception x) { |
106 |
Exceptions.printStackTrace(x); |
107 |
return null; |
108 |
} |
109 |
} |
110 |
public Class<? extends Object> type(InstanceCookie cookie) { |
111 |
try { |
112 |
return cookie.instanceClass(); |
113 |
} catch (Exception x) { |
114 |
Exceptions.printStackTrace(x); |
115 |
return Object.class; |
116 |
} |
117 |
} |
118 |
public String id(InstanceCookie cookie) { |
119 |
return path; |
120 |
} |
121 |
public String displayName(InstanceCookie cookie) { |
122 |
return path; |
123 |
} |
124 |
}); |
125 |
return new Lookup[] {new AbstractLookup(ic)}; |
126 |
} |
127 |
} |
128 |
return new Lookup[0]; |
129 |
} |
87 |
FileObject fo = FileUtil.createFolder(FileUtil.getConfigRoot(), path); |
130 |
FileObject fo = FileUtil.createFolder(FileUtil.getConfigRoot(), path); |
88 |
|
131 |
|
89 |
String s; |
132 |
String s; |
Lines 94-100
Link Here
|
94 |
} |
137 |
} |
95 |
|
138 |
|
96 |
org.openide.loaders.FolderLookup l; |
139 |
org.openide.loaders.FolderLookup l; |
97 |
l = new org.openide.loaders.FolderLookup(DataFolder.findFolder(fo), s); |
140 |
l = new org.openide.loaders.FolderLookup(DataFolder.findFolder(fo), s) { |
|
|
141 |
protected @Override InstanceCookie acceptFolder(DataFolder df) { |
142 |
return mode == Lookups.RecursionMode.NONRECURSIVE_FOLDER ? null : super.acceptFolder(df); |
143 |
} |
144 |
protected @Override InstanceCookie acceptContainer(Container df) { |
145 |
return mode == Lookups.RecursionMode.NONRECURSIVE_FOLDER ? null : super.acceptContainer(df); |
146 |
} |
147 |
}; |
98 |
return new Lookup[] { l.getLookup(), Lookups.metaInfServices(allCL.iterator().next(), "META-INF/namedservices/" + path) }; // NOI18N |
148 |
return new Lookup[] { l.getLookup(), Lookups.metaInfServices(allCL.iterator().next(), "META-INF/namedservices/" + path) }; // NOI18N |
99 |
} catch (IOException ex) { |
149 |
} catch (IOException ex) { |
100 |
return new Lookup[] { Lookups.metaInfServices(allCL.iterator().next(), "META-INF/namedservices/" + path) }; // NOI18N |
150 |
return new Lookup[] { Lookups.metaInfServices(allCL.iterator().next(), "META-INF/namedservices/" + path) }; // NOI18N |
Lines 103-109
Link Here
|
103 |
} |
153 |
} |
104 |
|
154 |
|
105 |
public void resultChanged(LookupEvent ev) { |
155 |
public void resultChanged(LookupEvent ev) { |
106 |
setLookups(delegates(path)); |
156 |
setLookups(delegates(path, mode)); |
107 |
} |
157 |
} |
108 |
} // end of OverObjects |
158 |
} // end of OverObjects |
109 |
} |
159 |
} |