Revision 866 org.gvsig.proj/branches/refactor2018/org.gvsig.proj/org.gvsig.proj.swing/org.gvsig.proj.swing.impl/src/main/java/org/gvsig/proj/swing/impl/tree/GroupLoader.java
GroupLoader.java | ||
---|---|---|
1 | 1 |
package org.gvsig.proj.swing.impl.tree; |
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 |
import java.util.concurrent.ExecutionException; |
|
5 | 4 |
|
6 |
import javax.swing.SwingWorker; |
|
7 | 5 |
import javax.swing.tree.TreeNode; |
8 | 6 |
|
9 |
import org.slf4j.Logger; |
|
10 |
import org.slf4j.LoggerFactory; |
|
11 |
|
|
12 |
public abstract class GroupLoader extends SwingWorker<ArrayList<TreeNode>, TreeNode> { |
|
13 |
private static Logger logger = LoggerFactory.getLogger(GroupLoader.class); |
|
14 |
protected AsyncLoadedGroup caller; |
|
15 |
public GroupLoader(AsyncLoadedGroup caller) { |
|
16 |
this.caller = caller; |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
protected void done() { |
|
21 |
super.done(); |
|
22 |
if (!isCancelled()) { |
|
23 |
try { |
|
24 |
ArrayList<TreeNode> result = get(); |
|
25 |
this.caller.loaded(result, this); |
|
26 |
} catch (InterruptedException | ExecutionException e) { |
|
27 |
logger.debug(e.getMessage(), e); |
|
28 |
} |
|
29 |
} |
|
30 |
else { |
|
31 |
this.caller.cancelled(this); |
|
32 |
} |
|
33 |
} |
|
34 |
} |
|
7 |
/** |
|
8 |
* Loads the children of a loaded group |
|
9 |
* |
|
10 |
* @author Cesar Martinez Izquierdo |
|
11 |
*/ |
|
12 |
public interface GroupLoader { |
|
13 |
|
|
14 |
/** |
|
15 |
* Start loading the children, which can happen immediately or |
|
16 |
* be done asynchronously |
|
17 |
*/ |
|
18 |
void execute(); |
|
19 |
|
|
20 |
/** |
|
21 |
* Attempts to cancel the loading process |
|
22 |
* @return |
|
23 |
*/ |
|
24 |
void cancel(); |
|
25 |
|
|
26 |
/** |
|
27 |
* Whether the loading process has been cancelled |
|
28 |
* |
|
29 |
* @return |
|
30 |
*/ |
|
31 |
boolean isCancelled(); |
|
32 |
|
|
33 |
/** |
|
34 |
* Creates an instance of a node to be displayed as temporary child |
|
35 |
* while data is loading |
|
36 |
* |
|
37 |
* @return A TreeNode instance or null if no loading node is needed |
|
38 |
*/ |
|
39 |
TreeNode createLoadingNode(); |
|
40 |
|
|
41 |
} |
Also available in: Unified diff