001: package net.refractions.udig.catalog.ui;
002:
003: import java.io.IOException;
004:
005: import net.refractions.udig.catalog.IService;
006:
007: import org.eclipse.core.runtime.IProgressMonitor;
008: import org.eclipse.swt.widgets.Composite;
009: import org.eclipse.swt.widgets.Control;
010:
011: /**
012: * A class which is used to handle an error which occurs when attempting to connection to a service.
013: * <p>
014: * Connection error handlers have the following responsibilites:
015: * <ul>
016: * <li>Determining from a throwable object, if they can handle the error.
017: * <li>Providing a ui which provides feedback about an error, and possibly a way to recover from
018: * it.
019: * </ul>
020: * </p>
021: * <p>
022: * Connection error handlers are contributed by extending the
023: * net.refractions.catalog.ui.connectionErrorHandler extension point.
024: * </p>
025: * <p>
026: * Subclasses may overide the following methods.
027: * <ul>
028: * <li>canHandle(Throwable)
029: * <li>canRecover()
030: * <li>create(Composite)
031: * </ul>
032: * </p>
033: *
034: * @author Justin Deoliveira,Refractions Research Inc.,jdeolive@refractions.net
035: */
036: public abstract class IConnectionErrorHandler {
037:
038: /** extension point id * */
039: public static final String XPID = "net.refractions.catalog.ui.connectionErrorHandler"; //$NON-NLS-1$
040:
041: /** name of handler, used in ui when more then one available * */
042: private String name;
043:
044: /** the control used by the handler * */
045: private Control control;
046:
047: /** the error * */
048: private Throwable t;
049:
050: /** the service handle * */
051: private IService service;
052:
053: /**
054: * Sets the name for the handler. This name will be used to identify the handler in cases where
055: * multiple handlers may wish to handle a single error.
056: *
057: * @param name The name of the handler.
058: */
059: public void setName(String name) {
060: this .name = name;
061: }
062:
063: /**
064: * Return the name of the handler. This name will be used to identify the handler in cases where
065: * multiple handlers may wish to handle a single error.
066: *
067: * @return The name of the handler.
068: */
069: public String getName() {
070: return name;
071: }
072:
073: /**
074: * Sets the error being handled.
075: *
076: * @param t The throwable object representing the error.
077: */
078: public void setThrowable(Throwable t) {
079: this .t = t;
080: }
081:
082: /**
083: * @return the error being handled.
084: */
085: public Throwable getThrowable() {
086: return t;
087: }
088:
089: /**
090: * @return the service being connected to.
091: */
092: public IService getService() {
093: return service;
094: }
095:
096: /**
097: * @param service The service being connected to.
098: */
099: public void setService(IService service) {
100: this .service = service;
101: }
102:
103: /**
104: * @return the control used by the handler to provide feedback / recover from the error.
105: */
106: public Control getControl() {
107: return control;
108: }
109:
110: /**
111: * Creates the control used by the handler to provide feedback / recover from the error.
112: *
113: * @param parent The parent widget.
114: */
115: public void createControl(Composite parent) {
116: if (control != null && !control.isDisposed()) {
117: control.dispose();
118: }
119:
120: control = create(parent);
121: }
122:
123: /**
124: * Determines if the handler is done handling the error, and another connection may be
125: * attempted. If the handler does not have the ability to recover from a connection error (ie.
126: * canRecover() return false), this method should return false.
127: *
128: * @return true if the error has been handled, otherwise.
129: */
130: public boolean isComplete() {
131: return false;
132: }
133:
134: /**
135: * Determines if the handler has the ability to recover from the error so that another
136: * connection may be attempted.
137: *
138: * @return True if the handler will try to recover, otherwise false.
139: */
140: public boolean canRecover() {
141: return false;
142: }
143:
144: /**
145: * This method is called in the event in which a handler can recover from a connection error.
146: * This method blocks and allows the handler to make remote connections.
147: *
148: * @param monitor A progress monitor.
149: * @throws IOException
150: */
151: public void recover(IProgressMonitor monitor) throws IOException {
152: // do nothing
153: }
154:
155: /**
156: * Determines if the handler can handle the error in question.
157: *
158: * @param t The error in question.
159: * @return True if the handler can handle, otherwise false.
160: */
161: public abstract boolean canHandle(IService service, Throwable t);
162:
163: /**
164: * @param parent
165: * @return
166: */
167: protected abstract Control create(Composite parent);
168:
169: }
|