KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
20 import org.eclipse.ui.model.IWorkbenchAdapter;
21 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
22 import org.eclipse.ui.progress.IElementCollector;
23
24 public class VersionCategory extends CVSModelElement implements IAdaptable,
25         IDeferredWorkbenchAdapter {
26     private ICVSRepositoryLocation repository;
27
28     /**
29      * ProjectVersionsCategory constructor.
30      */

31     public VersionCategory(ICVSRepositoryLocation repo) {
32         super();
33         this.repository = repo;
34     }
35
36     /**
37      * Returns an object which is an instance of the given class associated with
38      * this object. Returns <code>null</code> if no such object can be found.
39      */

40     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
41         if (adapter == IWorkbenchAdapter.class)
42             return this;
43         if (adapter == IDeferredWorkbenchAdapter.class)
44             return this;
45         return null;
46     }
47
48     /**
49      * Returns the children of this object. When this object is displayed in a
50      * tree, the returned objects will be this element's children. Returns an
51      * empty enumeration if this object has no children.
52      */

53     public Object JavaDoc[] fetchChildren(Object JavaDoc o, IProgressMonitor monitor)
54             throws TeamException {
55         if (CVSUIPlugin.getPlugin().getRepositoryManager()
56                 .isDisplayingProjectVersions(repository)) {
57             return getProjectVersionChildren(o, monitor);
58         } else {
59             return getVersionTagChildren(o, monitor);
60         }
61     }
62
63     /*
64      * Return the children as a list of versions whose children are projects
65      */

66     private Object JavaDoc[] getVersionTagChildren(Object JavaDoc o, IProgressMonitor monitor)
67             throws CVSException {
68         CVSTag[] tags = CVSUIPlugin.getPlugin().getRepositoryManager()
69                 .getKnownTags(repository, getWorkingSet(), CVSTag.VERSION, monitor);
70         CVSTagElement[] versionElements = new CVSTagElement[tags.length];
71         for (int i = 0; i < tags.length; i++) {
72             versionElements[i] = new CVSTagElement(tags[i], repository);
73         }
74         return versionElements;
75     }
76
77     /*
78      * Return the children as a list of projects whose children ar project
79      * versions
80      */

81     private Object JavaDoc[] getProjectVersionChildren(Object JavaDoc o,
82             IProgressMonitor monitor) throws TeamException {
83
84         ICVSRemoteResource[] resources = CVSUIPlugin.getPlugin()
85                 .getRepositoryManager().getFoldersForTag(repository,
86                         CVSTag.DEFAULT, monitor);
87         if (getWorkingSet() != null)
88             resources = CVSUIPlugin.getPlugin().getRepositoryManager()
89                     .filterResources(getWorkingSet(), resources);
90         Object JavaDoc[] modules = new Object JavaDoc[resources.length];
91         for (int i = 0; i < resources.length; i++) {
92             modules[i] = new RemoteModule((ICVSRemoteFolder) resources[i],
93                     VersionCategory.this);
94         }
95         return modules;
96     }
97
98     /**
99      * Returns an image descriptor to be used for displaying an object in the
100      * workbench. Returns null if there is no appropriate image.
101      *
102      * @param object The object to get an image descriptor for.
103      */

104     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
105         return CVSUIPlugin.getPlugin().getImageDescriptor(
106                 ICVSUIConstants.IMG_VERSIONS_CATEGORY);
107     }
108
109     /**
110      * Returns the name of this element. This will typically be used to assign a
111      * label to this object when displayed in the UI. Returns an empty string if
112      * there is no appropriate name for this object.
113      *
114      * @param object The object to get a label for.
115      */

116     public String JavaDoc getLabel(Object JavaDoc o) {
117         return CVSUIMessages.VersionCategory_Versions_1;
118     }
119
120     /**
121      * Returns the logical parent of the given object in its tree. Returns null
122      * if there is no parent, or if this object doesn't belong to a tree.
123      *
124      * @param object The object to get the parent for.
125      */

126     public Object JavaDoc getParent(Object JavaDoc o) {
127         return repository;
128     }
129
130     /**
131      * Return the repository the given element belongs to.
132      */

133     public ICVSRepositoryLocation getRepository(Object JavaDoc o) {
134         return repository;
135     }
136
137     public void fetchDeferredChildren(Object JavaDoc o, IElementCollector collector,
138             IProgressMonitor monitor) {
139         try {
140             collector.add(fetchChildren(o, monitor), monitor);
141         } catch (TeamException e) {
142             handle(collector, e);
143         }
144     }
145
146     public boolean isContainer() {
147         return true;
148     }
149
150     public ISchedulingRule getRule(Object JavaDoc element) {
151         return new RepositoryLocationSchedulingRule(repository);
152     }
153 }
154
Popular Tags