KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.runtime.jobs.ISchedulingRule;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.team.core.TeamException;
18 import org.eclipse.team.internal.ccvs.core.*;
19 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
20 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
21 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
22 import org.eclipse.ui.model.IWorkbenchAdapter;
23 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
24 import org.eclipse.ui.progress.IElementCollector;
25
26 /**
27  * This class represents an IProject resource in a repository. The children of a
28  * RemoteModule are its versions. A RemoteModule is a child of the
29  * VersionsCategory.
30  */

31 public class RemoteModule extends CVSModelElement implements IAdaptable,
32         IDeferredWorkbenchAdapter {
33     ICVSRemoteFolder folder;
34
35     VersionCategory parent;
36
37     /**
38      * RemoteProject constructor.
39      */

40     public RemoteModule(ICVSRemoteFolder folder, VersionCategory parent) {
41         this.folder = folder;
42         this.parent = parent;
43     }
44
45     /**
46      * Returns an object which is an instance of the given class associated with
47      * this object. Returns <code>null</code> if no such object can be found.
48      */

49     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
50         if (adapter == IWorkbenchAdapter.class)
51             return this;
52         if (adapter == IDeferredWorkbenchAdapter.class)
53             return this;
54         return null;
55     }
56
57     /**
58      * Returns an image to be used for displaying an object in the desktop.
59      *
60      * @param object The object to get an image for.
61      * @param owner The viewer that the image will be used in. The image will be
62      * disposed when this viewer is closed. If the owner is null, a
63      * new image is returned, and the caller is responsible for
64      * disposing it.
65      */

66     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
67         return CVSUIPlugin.getPlugin().getImageDescriptor(
68                 ICVSUIConstants.IMG_PROJECT_VERSION);
69     }
70
71     /**
72      * Returns the name of this element. This will typically be used to assign a
73      * label to this object when displayed in the UI.
74      */

75     public String JavaDoc getLabel(Object JavaDoc o) {
76         return folder.getName();
77     }
78
79     /**
80      * Returns the logical parent of the given object in its tree.
81      */

82     public Object JavaDoc getParent(Object JavaDoc o) {
83         return parent;
84     }
85
86     /**
87      * Return the repository the given element belongs to.
88      */

89     public ICVSRepositoryLocation getRepository(Object JavaDoc o) {
90         return folder.getRepository();
91     }
92
93     /**
94      * (Non-javadoc) For debugging purposes only.
95      */

96     public String JavaDoc toString() {
97         return "RemoteModule(" + folder.getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
98
}
99
100     public ICVSRemoteResource getCVSResource() {
101         return folder;
102     }
103
104     /**
105      * Returns the children of this object. When this object is displayed in a
106      * tree, the returned objects will be this element's children. Returns an
107      * empty enumeration if this object has no children. The children of the
108      * RemoteModule are the versions for that module.
109      *
110      * @see org.eclipse.team.internal.ccvs.ui.model.CVSModelElement#internalGetChildren(java.lang.Object,
111      * org.eclipse.core.runtime.IProgressMonitor)
112      */

113     public Object JavaDoc[] fetchChildren(Object JavaDoc o, IProgressMonitor monitor)
114             throws TeamException {
115         RepositoryManager manager = CVSUIPlugin.getPlugin()
116                 .getRepositoryManager();
117         try {
118             manager.refreshDefinedTags(folder, false /* recurse */, false /* notify */, monitor);
119         } catch (TeamException e) {
120             // continue
121
}
122         CVSTag[] tags = CVSUIPlugin.getPlugin().getRepositoryManager()
123                 .getKnownTags(folder, CVSTag.VERSION);
124         Object JavaDoc[] versions = new Object JavaDoc[tags.length];
125         for (int i = 0; i < versions.length; i++) {
126             versions[i] = folder.forTag(tags[i]);
127         }
128         return versions;
129     }
130
131     public void fetchDeferredChildren(Object JavaDoc o, IElementCollector collector,
132             IProgressMonitor monitor) {
133         try {
134             collector.add(fetchChildren(o, monitor), monitor);
135         } catch (TeamException e) {
136             handle(collector, e);
137         }
138     }
139
140     public boolean isContainer() {
141         return true;
142     }
143
144     public ISchedulingRule getRule(Object JavaDoc element) {
145         return new RepositoryLocationSchedulingRule(folder.getRepository());
146     }
147 }
148
Popular Tags