01: package net.refractions.udig.catalog.ui.workflow;
02:
03: import java.io.IOException;
04: import java.util.HashMap;
05: import java.util.List;
06: import java.util.Map;
07:
08: import net.refractions.udig.catalog.IService;
09: import net.refractions.udig.catalog.ui.IConnectionErrorHandler;
10: import net.refractions.udig.catalog.ui.internal.Messages;
11: import net.refractions.udig.catalog.ui.workflow.Workflow.State;
12:
13: import org.eclipse.core.runtime.IProgressMonitor;
14:
15: public class ConnectionErrorState extends Workflow.State {
16:
17: Map<IService, Throwable> errors;
18:
19: Map<IService, List<IConnectionErrorHandler>> handlers;
20:
21: public ConnectionErrorState(Map<IService, Throwable> errors) {
22: this .errors = errors;
23: }
24:
25: @Override
26: public void init(IProgressMonitor monitor) throws IOException {
27: super .init(monitor);
28:
29: // process error handling extension point to get the list of
30: // handlers
31: ConnectionErrorHandlerProcessor p = new ConnectionErrorHandlerProcessor();
32: handlers = new HashMap<IService, List<IConnectionErrorHandler>>();
33:
34: for (Map.Entry<IService, Throwable> e : errors.entrySet()) {
35: List<IConnectionErrorHandler> l = p.process(e.getKey(), e
36: .getValue());
37:
38: if (l != null && !l.isEmpty()) {
39: handlers.put(e.getKey(), l);
40: }
41: }
42: }
43:
44: @Override
45: // TODO: process the handlers to try and recover
46: public boolean run(IProgressMonitor monitor) throws IOException {
47: // always return false
48: monitor.beginTask(getName(), 1);
49: monitor.done();
50: return false;
51: }
52:
53: @Override
54: public boolean hasNext() {
55: return true;
56: }
57:
58: @Override
59: public State next() {
60: // always return back to the previous state
61: return getPreviousState();
62: }
63:
64: public Map<IService, List<IConnectionErrorHandler>> getHandlers() {
65: return handlers;
66: }
67:
68: public Map<IService, Throwable> getErrors() {
69: return errors;
70: }
71:
72: @Override
73: public String getName() {
74: return Messages.ConnectionErrorState_error_name;
75: }
76:
77: }
|