Lines 16-21
Link Here
|
16 |
|
16 |
|
17 |
|
17 |
|
18 |
import java.io.IOException; |
18 |
import java.io.IOException; |
|
|
19 |
import java.io.ObjectInputStream; |
20 |
import java.io.ObjectOutputStream; |
21 |
import java.io.Serializable; |
19 |
import java.lang.ref.WeakReference; |
22 |
import java.lang.ref.WeakReference; |
20 |
import java.util.ArrayList; |
23 |
import java.util.ArrayList; |
21 |
import java.util.Collection; |
24 |
import java.util.Collection; |
Lines 23-28
Link Here
|
23 |
|
26 |
|
24 |
import org.openide.cookies.InstanceCookie; |
27 |
import org.openide.cookies.InstanceCookie; |
25 |
import org.openide.ErrorManager; |
28 |
import org.openide.ErrorManager; |
|
|
29 |
import org.openide.filesystems.FileObject; |
26 |
import org.openide.loaders.DataObject; |
30 |
import org.openide.loaders.DataObject; |
27 |
import org.openide.util.Lookup; |
31 |
import org.openide.util.Lookup; |
28 |
import org.openide.util.lookup.AbstractLookup; |
32 |
import org.openide.util.lookup.AbstractLookup; |
Lines 247-260
Link Here
|
247 |
|
251 |
|
248 |
|
252 |
|
249 |
/** <code>ProxyLookup</code> delegate so we can change the lookups on fly. */ |
253 |
/** <code>ProxyLookup</code> delegate so we can change the lookups on fly. */ |
250 |
private static final class ProxyLkp extends ProxyLookup { |
254 |
private static final class ProxyLkp extends ProxyLookup implements Serializable { |
|
|
255 |
|
256 |
private static final long serialVersionUID = 1L; |
251 |
|
257 |
|
252 |
/** <code>FolderLookup</code> we are associated with. */ |
258 |
/** <code>FolderLookup</code> we are associated with. */ |
253 |
private FolderLookup fl; |
259 |
private transient FolderLookup fl; |
254 |
|
260 |
|
255 |
/** Content to control the abstract lookup. */ |
261 |
/** Content to control the abstract lookup. */ |
256 |
private AbstractLookup.Content content; |
262 |
private transient AbstractLookup.Content content; |
257 |
|
263 |
|
|
|
264 |
private transient boolean readFromStream; |
258 |
|
265 |
|
259 |
/** Constructs lookup which holds all items+lookups from underlying world. |
266 |
/** Constructs lookup which holds all items+lookups from underlying world. |
260 |
* @param folder <code>FolderLookup</code> to associate to */ |
267 |
* @param folder <code>FolderLookup</code> to associate to */ |
Lines 270-281
Link Here
|
270 |
this.content = content; |
277 |
this.content = content; |
271 |
} |
278 |
} |
272 |
|
279 |
|
|
|
280 |
private void writeObject (ObjectOutputStream oos) throws IOException { |
281 |
Lookup[] ls = getLookups(); |
282 |
for (int i = 0; i < ls.length; i++) { |
283 |
oos.writeObject(ls[i]); |
284 |
} |
285 |
oos.writeObject(null); |
286 |
oos.writeObject (fl.folder); |
287 |
oos.writeObject (fl.rootName); |
288 |
oos.writeObject (content); |
289 |
} |
290 |
|
291 |
private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException { |
292 |
List ls = new ArrayList(); // List<Lookup> |
293 |
Lookup l; |
294 |
while ((l = (Lookup)ois.readObject()) != null) { |
295 |
ls.add(l); |
296 |
} |
297 |
Lookup[] arr = (Lookup[])ls.toArray(new Lookup[ls.size()]); |
298 |
DataFolder df = (DataFolder)ois.readObject (); |
299 |
String root = (String)ois.readObject (); |
300 |
|
301 |
fl = new FolderLookup (df, root, true); |
302 |
fl.lookup = this; |
303 |
|
304 |
content = (AbstractLookup.Content)ois.readObject (); |
305 |
|
306 |
setLookups (arr); |
307 |
|
308 |
readFromStream = true; |
309 |
} |
310 |
|
273 |
|
311 |
|
274 |
/** Updates internal data. |
312 |
/** Updates internal data. |
275 |
* @param items Items to assign to all pairs |
313 |
* @param items Items to assign to all pairs |
276 |
* @param lookups delegates to delegate to (first item is null) |
314 |
* @param lookups delegates to delegate to (first item is null) |
277 |
*/ |
315 |
*/ |
278 |
public void update(Collection items, List lookups) { |
316 |
public void update(Collection items, List lookups) { |
|
|
317 |
readFromStream = false; |
318 |
|
279 |
// remember the instance lookup |
319 |
// remember the instance lookup |
280 |
Lookup pairs = getLookups ()[0]; |
320 |
Lookup pairs = getLookups ()[0]; |
281 |
|
321 |
|
Lines 292-297
Link Here
|
292 |
|
332 |
|
293 |
/** Waits before the processing of changes is finished. */ |
333 |
/** Waits before the processing of changes is finished. */ |
294 |
protected void beforeLookup (Template template) { |
334 |
protected void beforeLookup (Template template) { |
|
|
335 |
if (readFromStream) { |
336 |
// ok |
337 |
return; |
338 |
} |
339 |
|
295 |
// do not wait in folder recognizer, but in all other cases |
340 |
// do not wait in folder recognizer, but in all other cases |
296 |
if (!FolderList.isFolderRecognizerThread ()) { |
341 |
if (!FolderList.isFolderRecognizerThread ()) { |
297 |
fl.instanceFinished (); |
342 |
fl.instanceFinished (); |
Lines 303-314
Link Here
|
303 |
|
348 |
|
304 |
/** Item that delegates to <code>InstanceCookie</code>. Item which |
349 |
/** Item that delegates to <code>InstanceCookie</code>. Item which |
305 |
* the internal lookup data structure is made from. */ |
350 |
* the internal lookup data structure is made from. */ |
306 |
private static final class ICItem extends AbstractLookup.Pair { |
351 |
private static final class ICItem extends AbstractLookup.Pair implements Serializable { |
307 |
private InstanceCookie ic; |
352 |
static final long serialVersionUID = 10L; |
|
|
353 |
|
354 |
/** when deserialized only primary file is stored */ |
355 |
private FileObject fo; |
356 |
|
357 |
private transient InstanceCookie ic; |
308 |
/** source data object */ |
358 |
/** source data object */ |
309 |
private DataObject obj; |
359 |
private transient DataObject obj; |
310 |
/** reference to created object */ |
360 |
/** reference to created object */ |
311 |
private WeakReference ref; |
361 |
private transient WeakReference ref; |
312 |
/** root folder */ |
362 |
/** root folder */ |
313 |
private String rootName; |
363 |
private String rootName; |
314 |
|
364 |
|
Lines 317-322
Link Here
|
317 |
this.ic = ic; |
367 |
this.ic = ic; |
318 |
this.obj = obj; |
368 |
this.obj = obj; |
319 |
this.rootName = rootName; |
369 |
this.rootName = rootName; |
|
|
370 |
this.fo = obj.getPrimaryFile(); |
371 |
} |
372 |
|
373 |
/** Initializes the item |
374 |
*/ |
375 |
public void init () { |
376 |
if (ic != null) return; |
377 |
|
378 |
ic = (InstanceCookie)obj.getCookie (InstanceCookie.class); |
379 |
if (ic == null) { |
380 |
// XXX handle more gracefully |
381 |
throw new IllegalStateException ("No cookie: " + obj); |
382 |
} |
383 |
} |
384 |
|
385 |
|
386 |
/** Initializes the cookie from data object. |
387 |
*/ |
388 |
private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException { |
389 |
ois.defaultReadObject(); |
390 |
obj = DataObject.find (fo); |
320 |
} |
391 |
} |
321 |
|
392 |
|
322 |
|
393 |
|
Lines 324-329
Link Here
|
324 |
* @return the class of the item |
395 |
* @return the class of the item |
325 |
*/ |
396 |
*/ |
326 |
protected boolean instanceOf (Class clazz) { |
397 |
protected boolean instanceOf (Class clazz) { |
|
|
398 |
init (); |
399 |
|
327 |
if (ic instanceof InstanceCookie.Of) { |
400 |
if (ic instanceof InstanceCookie.Of) { |
328 |
// special handling for special cookies |
401 |
// special handling for special cookies |
329 |
InstanceCookie.Of of = (InstanceCookie.Of)ic; |
402 |
InstanceCookie.Of of = (InstanceCookie.Of)ic; |
Lines 345-350
Link Here
|
345 |
* @return the instance of the object or null if it cannot be created |
418 |
* @return the instance of the object or null if it cannot be created |
346 |
*/ |
419 |
*/ |
347 |
public Object getInstance() { |
420 |
public Object getInstance() { |
|
|
421 |
init (); |
422 |
|
348 |
try { |
423 |
try { |
349 |
Object obj = ic.instanceCreate(); |
424 |
Object obj = ic.instanceCreate(); |
350 |
ref = new WeakReference (obj); |
425 |
ref = new WeakReference (obj); |
Lines 359-364
Link Here
|
359 |
|
434 |
|
360 |
/** Hash code is the <code>InstanceCookie</code>'s code. */ |
435 |
/** Hash code is the <code>InstanceCookie</code>'s code. */ |
361 |
public int hashCode () { |
436 |
public int hashCode () { |
|
|
437 |
init (); |
438 |
|
362 |
return System.identityHashCode (ic); |
439 |
return System.identityHashCode (ic); |
363 |
} |
440 |
} |
364 |
|
441 |
|
Lines 366-371
Link Here
|
366 |
public boolean equals (Object obj) { |
443 |
public boolean equals (Object obj) { |
367 |
if (obj instanceof ICItem) { |
444 |
if (obj instanceof ICItem) { |
368 |
ICItem i = (ICItem)obj; |
445 |
ICItem i = (ICItem)obj; |
|
|
446 |
i.init (); |
447 |
init (); |
369 |
return ic == i.ic; |
448 |
return ic == i.ic; |
370 |
} |
449 |
} |
371 |
return false; |
450 |
return false; |
Lines 375-385
Link Here
|
375 |
* @return string representing the item, that can be used for |
454 |
* @return string representing the item, that can be used for |
376 |
* persistance purposes to locate the same item next time */ |
455 |
* persistance purposes to locate the same item next time */ |
377 |
public String getId() { |
456 |
public String getId() { |
|
|
457 |
init (); |
458 |
|
378 |
return objectName(rootName, obj); |
459 |
return objectName(rootName, obj); |
379 |
} |
460 |
} |
380 |
|
461 |
|
381 |
/** Display name is extracted from name of the objects node. */ |
462 |
/** Display name is extracted from name of the objects node. */ |
382 |
public String getDisplayName () { |
463 |
public String getDisplayName () { |
|
|
464 |
init (); |
465 |
|
383 |
return obj.getNodeDelegate ().getDisplayName (); |
466 |
return obj.getNodeDelegate ().getDisplayName (); |
384 |
} |
467 |
} |
385 |
|
468 |
|
Lines 399-404
Link Here
|
399 |
* @return the correct class |
482 |
* @return the correct class |
400 |
*/ |
483 |
*/ |
401 |
public Class getType() { |
484 |
public Class getType() { |
|
|
485 |
init (); |
486 |
|
402 |
try { |
487 |
try { |
403 |
return ic.instanceClass (); |
488 |
return ic.instanceClass (); |
404 |
} catch (IOException ex) { |
489 |
} catch (IOException ex) { |