Lines 48-56
Link Here
|
48 |
import java.util.logging.Level; |
48 |
import java.util.logging.Level; |
49 |
import java.util.logging.Logger; |
49 |
import java.util.logging.Logger; |
50 |
|
50 |
|
51 |
import org.openide.*; |
|
|
52 |
import org.openide.filesystems.*; |
51 |
import org.openide.filesystems.*; |
53 |
import org.openide.cookies.InstanceCookie; |
52 |
import org.openide.cookies.InstanceCookie; |
|
|
53 |
import org.openide.util.Exceptions; |
54 |
import org.openide.util.Task; |
54 |
import org.openide.util.Task; |
55 |
import org.openide.util.TaskListener; |
55 |
import org.openide.util.TaskListener; |
56 |
import org.openide.util.RequestProcessor; |
56 |
import org.openide.util.RequestProcessor; |
Lines 158-163
Link Here
|
158 |
* Started immediately after the <code>recognizingTask</code> is finished. |
158 |
* Started immediately after the <code>recognizingTask</code> is finished. |
159 |
*/ |
159 |
*/ |
160 |
private Task creationTask; |
160 |
private Task creationTask; |
|
|
161 |
/** shall instances be precreated? */ |
162 |
private boolean precreateInstances; |
161 |
|
163 |
|
162 |
/* -------------------------------------------------------------------- */ |
164 |
/* -------------------------------------------------------------------- */ |
163 |
/* -- Constructor(s) -------------------------------------------------- */ |
165 |
/* -- Constructor(s) -------------------------------------------------- */ |
Lines 168-173
Link Here
|
168 |
*/ |
170 |
*/ |
169 |
public FolderInstance (DataFolder df) { |
171 |
public FolderInstance (DataFolder df) { |
170 |
this ((DataObject.Container)df); |
172 |
this ((DataObject.Container)df); |
|
|
173 |
} |
174 |
|
175 |
/** Create new folder instance. |
176 |
* @param df data folder to create instances from |
177 |
* @param precreateInstances if true, then instances for all cookies |
178 |
* are created before {@link #postCreationTask} is called |
179 |
* @since 7.3 |
180 |
*/ |
181 |
public FolderInstance (DataFolder df, boolean precreateInstances) { |
182 |
this ((DataObject.Container)df); |
183 |
this.precreateInstances = precreateInstances; |
171 |
} |
184 |
} |
172 |
|
185 |
|
173 |
/** A new object that listens on changes in a container. |
186 |
/** A new object that listens on changes in a container. |
Lines 237-251
Link Here
|
237 |
*/ |
250 |
*/ |
238 |
public Class<?> instanceClass () |
251 |
public Class<?> instanceClass () |
239 |
throws java.io.IOException, ClassNotFoundException { |
252 |
throws java.io.IOException, ClassNotFoundException { |
240 |
Object object = this.object; |
253 |
Object tmp = this.object; |
241 |
if (object != null) { |
254 |
if (tmp != null) { |
242 |
if (object instanceof java.io.IOException) { |
255 |
if (tmp instanceof java.io.IOException) { |
243 |
throw (java.io.IOException)object; |
256 |
throw (java.io.IOException)tmp; |
244 |
} |
257 |
} |
245 |
if (object instanceof ClassNotFoundException) { |
258 |
if (tmp instanceof ClassNotFoundException) { |
246 |
throw (ClassNotFoundException)object; |
259 |
throw (ClassNotFoundException)tmp; |
247 |
} |
260 |
} |
248 |
return object.getClass (); |
261 |
return tmp.getClass (); |
249 |
} |
262 |
} |
250 |
|
263 |
|
251 |
return Object.class; |
264 |
return Object.class; |
Lines 258-289
Link Here
|
258 |
*/ |
271 |
*/ |
259 |
public Object instanceCreate () |
272 |
public Object instanceCreate () |
260 |
throws java.io.IOException, ClassNotFoundException { |
273 |
throws java.io.IOException, ClassNotFoundException { |
261 |
Object object = CURRENT.get (); |
274 |
Object tmp = CURRENT.get (); |
262 |
|
275 |
|
263 |
if (object == null || LAST_CURRENT.get () != this) { |
276 |
if (tmp == null || LAST_CURRENT.get () != this) { |
264 |
err.fine("do into waitFinished"); // NOI18N |
277 |
err.fine("do into waitFinished"); // NOI18N |
265 |
waitFinished (); |
278 |
waitFinished (); |
266 |
|
279 |
|
267 |
object = FolderInstance.this.object; |
280 |
tmp = FolderInstance.this.object; |
268 |
} |
281 |
} |
269 |
|
282 |
|
270 |
if (err.isLoggable(Level.FINE)) { |
283 |
if (err.isLoggable(Level.FINE)) { |
271 |
err.fine("instanceCreate: " + object); // NOI18N |
284 |
err.fine("instanceCreate: " + tmp); // NOI18N |
272 |
} |
285 |
} |
273 |
|
286 |
|
274 |
if (object instanceof java.io.IOException) { |
287 |
if (tmp instanceof java.io.IOException) { |
275 |
throw (java.io.IOException)object; |
288 |
throw (java.io.IOException)tmp; |
276 |
} |
289 |
} |
277 |
if (object instanceof ClassNotFoundException) { |
290 |
if (tmp instanceof ClassNotFoundException) { |
278 |
throw (ClassNotFoundException)object; |
291 |
throw (ClassNotFoundException)tmp; |
279 |
} |
292 |
} |
280 |
|
293 |
|
281 |
if (object == CURRENT) { |
294 |
if (tmp == CURRENT) { |
282 |
// uninitialized |
295 |
// uninitialized |
283 |
throw new IOException ("Cyclic reference. Somebody is trying to get value from FolderInstance (" + getClass ().getName () + ") from the same thread that is processing the instance"); // NOI18N |
296 |
throw new IOException ("Cyclic reference. Somebody is trying to get value from FolderInstance (" + getClass ().getName () + ") from the same thread that is processing the instance"); // NOI18N |
284 |
} |
297 |
} |
285 |
|
298 |
|
286 |
return object; |
299 |
return tmp; |
287 |
} |
300 |
} |
288 |
|
301 |
|
289 |
/* -------------------------------------------------------------------- */ |
302 |
/* -------------------------------------------------------------------- */ |
Lines 406-420
Link Here
|
406 |
} |
419 |
} |
407 |
|
420 |
|
408 |
if (cookie == null) { |
421 |
if (cookie == null) { |
409 |
DataFolder folder = dob.getCookie(DataFolder.class); |
422 |
DataFolder fld = dob.getCookie(DataFolder.class); |
410 |
if (folder != null) { |
423 |
if (fld != null) { |
411 |
HoldInstance previous = map.get (folder.getPrimaryFile ()); |
424 |
HoldInstance previous = map.get (fld.getPrimaryFile ()); |
412 |
if (previous != null && previous.cookie != null) { |
425 |
if (previous != null && previous.cookie != null) { |
413 |
// the old cookie will be returned if the folder is already registered |
426 |
// the old cookie will be returned if the folder is already registered |
414 |
cookie = previous; |
427 |
cookie = previous; |
415 |
acceptType = 2; |
428 |
acceptType = 2; |
416 |
} else { |
429 |
} else { |
417 |
cookie = acceptFolder (folder); |
430 |
cookie = acceptFolder (fld); |
418 |
acceptType = 3; |
431 |
acceptType = 3; |
419 |
} |
432 |
} |
420 |
} |
433 |
} |
Lines 650-666
Link Here
|
650 |
* @param arr collection of DataObjects |
663 |
* @param arr collection of DataObjects |
651 |
*/ |
664 |
*/ |
652 |
final void processObjects (final Collection<DataObject> arr) { |
665 |
final void processObjects (final Collection<DataObject> arr) { |
653 |
creationTask = postCreationTask (new Runnable () { |
666 |
class R implements Runnable { |
654 |
public void run () { |
667 |
HoldInstance[] all; |
655 |
defaultProcessObjects (arr); |
668 |
Object[] instances; |
|
|
669 |
|
670 |
public void init() { |
671 |
all = defaultProcessObjects(arr); |
656 |
} |
672 |
} |
657 |
}); |
673 |
|
|
|
674 |
public void instances() { |
675 |
instances = new Object[all.length]; |
676 |
int indx = 0; |
677 |
for (HoldInstance h : all) { |
678 |
try { |
679 |
instances[indx++] = h.instanceClass(); |
680 |
} catch (IOException ex) { |
681 |
Exceptions.printStackTrace(ex); |
682 |
} catch (ClassNotFoundException ex) { |
683 |
Exceptions.printStackTrace(ex); |
684 |
} |
685 |
} |
686 |
} |
687 |
|
688 |
public void run() { |
689 |
if (all == null) { |
690 |
init(); |
691 |
} |
692 |
defaultProcessObjectsFinal(all); |
693 |
} |
694 |
} |
695 |
R process = new R(); |
696 |
if (precreateInstances) { |
697 |
process.init(); |
698 |
process.instances(); |
699 |
} |
700 |
creationTask = postCreationTask (process); |
658 |
} |
701 |
} |
659 |
|
702 |
|
660 |
/** Default processing of objects. |
703 |
/** Default processing of objects. |
661 |
* @param arr array of objects to process |
704 |
* @param arr array of objects to process |
662 |
*/ |
705 |
*/ |
663 |
private final void defaultProcessObjects (Collection<DataObject> arr) { |
706 |
private final HoldInstance[] defaultProcessObjects (Collection<DataObject> arr) { |
664 |
err.fine("defaultProcessObjects"); |
707 |
err.fine("defaultProcessObjects"); |
665 |
HashSet<FileObject> toRemove; |
708 |
HashSet<FileObject> toRemove; |
666 |
ArrayList<HoldInstance> cookies = new ArrayList<HoldInstance> (); |
709 |
ArrayList<HoldInstance> cookies = new ArrayList<HoldInstance> (); |
Lines 762-767
Link Here
|
762 |
|
805 |
|
763 |
updateWaitFor (all); |
806 |
updateWaitFor (all); |
764 |
|
807 |
|
|
|
808 |
return all; |
809 |
} |
810 |
|
811 |
private void defaultProcessObjectsFinal(HoldInstance[] all) { |
765 |
Object result = null; |
812 |
Object result = null; |
766 |
try { |
813 |
try { |
767 |
result = createInstance (all); |
814 |
result = createInstance (all); |