KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > model > CVSModelElement


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.model;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.jface.operation.IRunnableContext;
16 import org.eclipse.team.core.TeamException;
17 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
18 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
19 import org.eclipse.ui.IWorkingSet;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.model.IWorkbenchAdapter;
22 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
23 import org.eclipse.ui.progress.IElementCollector;
24
25 public abstract class CVSModelElement implements IWorkbenchAdapter, IAdaptable {
26     
27     private IRunnableContext runnableContext;
28     private IWorkingSet workingSet;
29         
30     public IWorkingSet getWorkingSet() {
31         return workingSet;
32     }
33
34     public void setWorkingSet(IWorkingSet workingSet) {
35         this.workingSet = workingSet;
36     }
37
38     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
39         if (adapter == IWorkbenchAdapter.class)
40             return this;
41         if ((adapter == IDeferredWorkbenchAdapter.class) && this instanceof IDeferredWorkbenchAdapter)
42             return this;
43         return null;
44     }
45
46     /**
47      * Returns the runnableContext.
48      * @return ITeamRunnableContext
49      */

50     public IRunnableContext getRunnableContext() {
51         if (runnableContext == null) {
52             return PlatformUI.getWorkbench().getProgressService();
53         }
54         return runnableContext;
55     }
56
57     /**
58      * Sets the runnableContext.
59      * @param runnableContext The runnableContext to set
60      */

61     public void setRunnableContext(IRunnableContext runnableContext) {
62         this.runnableContext = runnableContext;
63     }
64
65     public Object JavaDoc[] getChildren(Object JavaDoc o) {
66         try {
67             return fetchChildren(o, null);
68         } catch (TeamException e) {
69             handle(e);
70         }
71         
72         return new Object JavaDoc[0];
73     }
74     
75     abstract protected Object JavaDoc[] fetchChildren(Object JavaDoc o, IProgressMonitor monitor) throws TeamException;
76         
77     /**
78      * Handle an exception that occurred in CVS model elements by displaying an error dialog.
79      * @param title the title of the error dialog
80      * @param description the description to be displayed
81      * @param e the exception that occurred
82      */

83     protected void handle(final String JavaDoc title, final String JavaDoc description, final Throwable JavaDoc e) {
84        CVSUIPlugin.openError(null, title, description, e, CVSUIPlugin.LOG_NONTEAM_EXCEPTIONS | CVSUIPlugin.PERFORM_SYNC_EXEC);
85     }
86     
87     /**
88      * Helper methed error handler that displayes a generic dialog title and message when displaying an error to the user.
89      * @param t the exception that occurred.
90      */

91     protected void handle(Throwable JavaDoc t) {
92         handle(CVSUIMessages.CVSModelElement_0, CVSUIMessages.CVSModelElement_1, t); //
93
}
94     
95     /**
96      * Handle an exception that occurred while fetching the children for a deferred workbench adapter.
97      * @param collector the collector for the adapter
98      * @param e the exception that occurred
99      */

100     protected void handle(IElementCollector collector, Throwable JavaDoc t) {
101         // TODO: For now, just display a dialog (see bug 65008 and 65741)
102
handle(t);
103     }
104
105 }
106
Popular Tags