Lines 40-47
Link Here
|
40 |
*/ |
40 |
*/ |
41 |
package org.openide.filesystems; |
41 |
package org.openide.filesystems; |
42 |
|
42 |
|
|
|
43 |
import java.util.Collection; |
44 |
import java.util.HashSet; |
43 |
import java.util.List; |
45 |
import java.util.List; |
44 |
import java.util.Queue; |
46 |
import java.util.Queue; |
|
|
47 |
import java.util.Set; |
45 |
import java.util.concurrent.ConcurrentLinkedQueue; |
48 |
import java.util.concurrent.ConcurrentLinkedQueue; |
46 |
import org.openide.util.Exceptions; |
49 |
import org.openide.util.Exceptions; |
47 |
import org.openide.util.RequestProcessor; |
50 |
import org.openide.util.RequestProcessor; |
Lines 77-83
Link Here
|
77 |
} |
80 |
} |
78 |
} |
81 |
} |
79 |
|
82 |
|
80 |
final void dispatchEvent(FileEvent fe, Op operation) { |
83 |
final void dispatchEvent(FileEvent fe, Op operation, Collection<Runnable> postNotify) { |
81 |
List<FileChangeListener> fcls; |
84 |
List<FileChangeListener> fcls; |
82 |
|
85 |
|
83 |
synchronized (this) { |
86 |
synchronized (this) { |
Lines 89-102
Link Here
|
89 |
} |
92 |
} |
90 |
|
93 |
|
91 |
for (FileChangeListener l : fcls) { |
94 |
for (FileChangeListener l : fcls) { |
92 |
dispatchEvent(l, fe, operation); |
95 |
dispatchEvent(l, fe, operation, postNotify); |
93 |
} |
96 |
} |
94 |
} |
97 |
} |
95 |
|
98 |
|
96 |
final static void dispatchEvent(final FileChangeListener fcl, final FileEvent fe, final Op operation) { |
99 |
final static void dispatchEvent(final FileChangeListener fcl, final FileEvent fe, final Op operation, Collection<Runnable> postNotify) { |
97 |
boolean async = fe.isAsynchronous(); |
100 |
boolean async = fe.isAsynchronous(); |
98 |
DispatchEventWrapper dw = new DispatchEventWrapper(fcl, fe, operation); |
101 |
DispatchEventWrapper dw = new DispatchEventWrapper(fcl, fe, operation); |
99 |
dw.dispatchEvent(async); |
102 |
dw.dispatchEvent(async, postNotify); |
100 |
} |
103 |
} |
101 |
|
104 |
|
102 |
/** @return true if there is a listener |
105 |
/** @return true if there is a listener |
Lines 114-130
Link Here
|
114 |
this.fe =fe; |
117 |
this.fe =fe; |
115 |
this.operation =operation; |
118 |
this.operation =operation; |
116 |
} |
119 |
} |
117 |
void dispatchEvent(boolean async) { |
120 |
void dispatchEvent(boolean async, Collection<Runnable> postNotify) { |
118 |
if (async) { |
121 |
if (async) { |
119 |
q.offer(this); |
122 |
q.offer(this); |
120 |
task.schedule(300); |
123 |
task.schedule(300); |
121 |
} else { |
124 |
} else { |
122 |
dispatchEventImpl(fcl, fe, operation); |
125 |
dispatchEventImpl(fcl, fe, operation, postNotify); |
123 |
} |
126 |
} |
124 |
} |
127 |
} |
125 |
|
128 |
|
126 |
private void dispatchEventImpl(FileChangeListener fcl, FileEvent fe, Op operation) { |
129 |
private void dispatchEventImpl(FileChangeListener fcl, FileEvent fe, Op operation, Collection<Runnable> postNotify) { |
127 |
try { |
130 |
try { |
|
|
131 |
fe.setPostNotify(postNotify); |
128 |
switch (operation) { |
132 |
switch (operation) { |
129 |
case DATA_CREATED: |
133 |
case DATA_CREATED: |
130 |
fcl.fileDataCreated(fe); |
134 |
fcl.fileDataCreated(fe); |
Lines 149-154
Link Here
|
149 |
} |
153 |
} |
150 |
} catch (RuntimeException x) { |
154 |
} catch (RuntimeException x) { |
151 |
Exceptions.printStackTrace(x); |
155 |
Exceptions.printStackTrace(x); |
|
|
156 |
} finally { |
157 |
fe.setPostNotify(null); |
152 |
} |
158 |
} |
153 |
} |
159 |
} |
154 |
|
160 |
|
Lines 158-167
Link Here
|
158 |
private static RequestProcessor.Task task = RP.create(new Runnable() { |
164 |
private static RequestProcessor.Task task = RP.create(new Runnable() { |
159 |
public void run() { |
165 |
public void run() { |
160 |
DispatchEventWrapper dw = q.poll(); |
166 |
DispatchEventWrapper dw = q.poll(); |
|
|
167 |
Set<Runnable> post = new HashSet<Runnable>(); |
161 |
while (dw != null) { |
168 |
while (dw != null) { |
162 |
dw.dispatchEvent(false); |
169 |
dw.dispatchEvent(false, post); |
163 |
dw = q.poll(); |
170 |
dw = q.poll(); |
164 |
} |
171 |
} |
|
|
172 |
for (Runnable r : post) { |
173 |
r.run(); |
174 |
} |
165 |
} |
175 |
} |
166 |
}); |
176 |
}); |
167 |
} |
177 |
} |