Lines 54-76
Link Here
|
54 |
* @param colleciton to put Pair into if found |
54 |
* @param colleciton to put Pair into if found |
55 |
*/ |
55 |
*/ |
56 |
private static void addCookie (Node node, Class c, Collection collection) { |
56 |
private static void addCookie (Node node, Class c, Collection collection) { |
57 |
Object res; |
57 |
java.util.HashSet toAdd = new java.util.HashSet (); |
58 |
AbstractLookup.Pair pair; |
58 |
AbstractLookup.Pair pair; |
59 |
Object prev = CookieSet.entryQueryMode (c); |
59 |
Object prev = CookieSet.entryQueryMode (c); |
60 |
try { |
60 |
try { |
61 |
res = node.getCookie (c); |
61 |
node.lookupCookieItems (c, toAdd); |
62 |
} finally { |
62 |
} finally { |
63 |
pair = CookieSet.exitQueryMode (prev); |
63 |
pair = CookieSet.exitQueryMode (prev); |
64 |
} |
64 |
} |
65 |
|
65 |
|
66 |
if (pair == null) { |
66 |
if (pair != null) { |
67 |
if (res == null) { |
67 |
toAdd.clear (); |
68 |
return; |
68 |
toAdd.add (pair); |
69 |
} |
|
|
70 |
pair = new LookupItem (res); |
71 |
} |
69 |
} |
72 |
|
70 |
|
73 |
collection.add (pair); |
71 |
java.util.Iterator it = toAdd.iterator (); |
|
|
72 |
while (it.hasNext ()) { |
73 |
collection.add (it.next ()); |
74 |
} |
74 |
} |
75 |
} |
75 |
|
76 |
|
76 |
|
77 |
|
Lines 78-95
Link Here
|
78 |
* @param template the template |
79 |
* @param template the template |
79 |
*/ |
80 |
*/ |
80 |
protected final void beforeLookup (Template template) { |
81 |
protected final void beforeLookup (Template template) { |
81 |
Class type = template.getType (); |
82 |
if (NO_COOKIE_CHANGE.get () == this) { |
|
|
83 |
// no beforeLookup mangling we just want all the pairs see X1 |
84 |
return; |
85 |
} |
82 |
|
86 |
|
83 |
if (type == Object.class) { |
87 |
Class origType = template.getType (); |
|
|
88 |
|
89 |
Class type; |
90 |
if (origType == Object.class) { |
84 |
type = Node.Cookie.class; |
91 |
type = Node.Cookie.class; |
|
|
92 |
} else { |
93 |
type = origType; |
85 |
} |
94 |
} |
86 |
|
95 |
|
87 |
if (Node.Cookie.class.isAssignableFrom (type)) { |
96 |
if (Node.Cookie.class.isAssignableFrom (type)) { |
88 |
if (!queriedCookieClasses.contains (type)) { |
97 |
boolean queriedCookieClassesChanged; |
89 |
synchronized (this) { |
98 |
synchronized (this) { |
90 |
queriedCookieClasses.add (type); |
99 |
queriedCookieClassesChanged = this.queriedCookieClasses.add (type); |
91 |
} |
100 |
} |
92 |
|
101 |
|
|
|
102 |
if (queriedCookieClassesChanged) { |
93 |
Object prev = NO_COOKIE_CHANGE.get (); |
103 |
Object prev = NO_COOKIE_CHANGE.get (); |
94 |
try { |
104 |
try { |
95 |
NO_COOKIE_CHANGE.set (node); |
105 |
NO_COOKIE_CHANGE.set (node); |
Lines 98-103
Link Here
|
98 |
NO_COOKIE_CHANGE.set (prev); |
108 |
NO_COOKIE_CHANGE.set (prev); |
99 |
} |
109 |
} |
100 |
} |
110 |
} |
|
|
111 |
|
112 |
if (type == origType) { |
113 |
// e.g. we really searched for cookie, |
114 |
return; // and do not do the special treatment of FilterNode |
115 |
// as the cookie was either found or not and in such |
116 |
// case it is not supposed to be found |
117 |
} |
118 |
} |
119 |
|
120 |
if (node instanceof FilterNode && !Node.Cookie.class.isAssignableFrom (origType)) { |
121 |
// still ask |
122 |
boolean queriedCookieClassesChanged; |
123 |
synchronized (this) { |
124 |
queriedCookieClassesChanged = this.queriedCookieClasses.add (type); |
125 |
} |
126 |
|
127 |
if (queriedCookieClassesChanged) { |
128 |
Object prev = NO_COOKIE_CHANGE.get (); |
129 |
try { |
130 |
NO_COOKIE_CHANGE.set (node); |
131 |
addCookie (node, origType, this); |
132 |
} finally { |
133 |
NO_COOKIE_CHANGE.set (prev); |
134 |
} |
135 |
} |
101 |
} |
136 |
} |
102 |
} |
137 |
} |
103 |
/** See #40734 and NodeLookupTest and CookieActionIsTooSlowTest. |
138 |
/** See #40734 and NodeLookupTest and CookieActionIsTooSlowTest. |
Lines 113-122
Link Here
|
113 |
// if it is cookie change, do the rescan, try to keep order |
148 |
// if it is cookie change, do the rescan, try to keep order |
114 |
synchronized (this) { |
149 |
synchronized (this) { |
115 |
java.util.HashSet toQuery = new java.util.HashSet (queriedCookieClasses); |
150 |
java.util.HashSet toQuery = new java.util.HashSet (queriedCookieClasses); |
116 |
Iterator it = lookup (new Template (Node.Cookie.class)).allItems ().iterator (); |
151 |
Iterator it; |
|
|
152 |
Object prev = NO_COOKIE_CHANGE.get (); |
153 |
try { |
154 |
NO_COOKIE_CHANGE.set (this); |
155 |
it = lookup (Node.TEMPL_COOKIE).allItems ().iterator (); |
156 |
} finally { |
157 |
NO_COOKIE_CHANGE.set (prev); |
158 |
} |
117 |
instances.add (new LookupItem (node)); |
159 |
instances.add (new LookupItem (node)); |
118 |
while (it.hasNext()) { |
160 |
while (it.hasNext()) { |
119 |
Item item = (Item)it.next (); |
161 |
Item item = (Item)it.next (); |
|
|
162 |
|
163 |
if (item instanceof DelegatePair) { |
164 |
// we are filter node then |
165 |
org.openide.util.Lookup del = ((FilterNode)node).getOriginal ().getLookup (); |
166 |
org.openide.util.Lookup.Item found = del.lookupItem (new org.openide.util.Lookup.Template ( |
167 |
item.getType (), item.getId (), item.getInstance () |
168 |
)); |
169 |
if (found != null) { |
170 |
instances.add (new DelegatePair (found)); |
171 |
} |
172 |
continue; |
173 |
} |
174 |
|
120 |
Class c = item.getType (); |
175 |
Class c = item.getType (); |
121 |
toQuery.remove (c); |
176 |
toQuery.remove (c); |
122 |
addCookie (node, c, instances); |
177 |
addCookie (node, c, instances); |
Lines 190-196
Link Here
|
190 |
} |
245 |
} |
191 |
|
246 |
|
192 |
/** Simple Pair to hold cookies and nodes */ |
247 |
/** Simple Pair to hold cookies and nodes */ |
193 |
private static class LookupItem extends AbstractLookup.Pair { |
248 |
static class LookupItem extends AbstractLookup.Pair { |
194 |
private Object instance; |
249 |
private Object instance; |
195 |
|
250 |
|
196 |
public LookupItem( Object instance ) { |
251 |
public LookupItem( Object instance ) { |
Lines 232-236
Link Here
|
232 |
return c.isInstance (instance); |
287 |
return c.isInstance (instance); |
233 |
} |
288 |
} |
234 |
} // End of LookupItem class |
289 |
} // End of LookupItem class |
|
|
290 |
|
291 |
/** Simple Pair that delegates to another pair */ |
292 |
static class DelegatePair extends AbstractLookup.Pair { |
293 |
private org.openide.util.Lookup.Item item; |
294 |
|
295 |
public DelegatePair ( org.openide.util.Lookup.Item item) { |
296 |
this.item = item; |
297 |
} |
298 |
|
299 |
public String getDisplayName() { |
300 |
return item.getDisplayName (); |
301 |
} |
302 |
|
303 |
public String getId () { |
304 |
return item.getId (); |
305 |
} |
306 |
|
307 |
public Object getInstance() { |
308 |
return item.getInstance (); |
309 |
} |
310 |
|
311 |
public Class getType() { |
312 |
return item.getType (); |
313 |
} |
314 |
|
315 |
public boolean equals( Object object ) { |
316 |
if ( object instanceof DelegatePair ) { |
317 |
return item.equals (((DelegatePair)object).item); |
318 |
} |
319 |
return false; |
320 |
} |
321 |
|
322 |
public int hashCode() { |
323 |
return item.hashCode() + 777; |
324 |
} |
325 |
|
326 |
protected boolean creatorOf(Object obj) { |
327 |
return obj == getInstance (); |
328 |
} |
329 |
|
330 |
protected boolean instanceOf(Class c) { |
331 |
return c.isAssignableFrom (getType ()); |
332 |
} |
333 |
} // End of DelegatePair class |
235 |
|
334 |
|
236 |
} |
335 |
} |