KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.team.internal.ccvs.ui.model;
12
13  
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.core.runtime.IAdaptable;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.team.internal.ccvs.core.CVSTag;
23 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
24 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
25 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
26 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
27 import org.eclipse.team.internal.ccvs.ui.Policy;
28 import org.eclipse.ui.model.IWorkbenchAdapter;
29
30 public class GroupedByVersionCategory extends CVSModelElement implements IAdaptable {
31     private ICVSRepositoryLocation repository;
32     
33     /**
34      * ProjectVersionsCategory constructor.
35      */

36     public GroupedByVersionCategory(ICVSRepositoryLocation repo) {
37         super();
38         this.repository = repo;
39     }
40     
41     /**
42      * Returns an object which is an instance of the given class
43      * associated with this object. Returns <code>null</code> if
44      * no such object can be found.
45      */

46     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
47         if (adapter == IWorkbenchAdapter.class) return this;
48         return null;
49     }
50     
51     /**
52      * Returns the children of this object. When this object
53      * is displayed in a tree, the returned objects will be this
54      * element's children. Returns an empty enumeration if this
55      * object has no children.
56      *
57      * XXX This method looks wrong to me somehow
58      */

59     public Object JavaDoc[] fetchChildren(Object JavaDoc o, IProgressMonitor monitor) {
60         //String -> CTags[]
61
Map JavaDoc mappings = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownProjectsAndVersions(repository);
62         Map JavaDoc remoteVersionModules = new HashMap JavaDoc();
63         for (Iterator JavaDoc it = mappings.keySet().iterator(); it.hasNext();) {
64             String JavaDoc project = (String JavaDoc) it.next();
65             CVSTag[] versions = (CVSTag[])((HashSet JavaDoc)mappings.get(project)).toArray(new CVSTag[0]);
66             for (int i = 0; i < versions.length; i++) {
67                 CVSTag tag = versions[i];
68                 RemoteVersionModule module = (RemoteVersionModule)remoteVersionModules.get(tag);
69                 if(module==null) {
70                     module = new RemoteVersionModule(tag, this);
71                     remoteVersionModules.put(tag, module);
72                 }
73                 module.addProject(new RemoteFolder(null, repository, project, tag));
74             }
75         }
76         return (RemoteVersionModule[])remoteVersionModules.values().toArray(new RemoteVersionModule[0]);
77     }
78
79     /**
80      * Returns an image descriptor to be used for displaying an object in the workbench.
81      * Returns null if there is no appropriate image.
82      *
83      * @param object The object to get an image descriptor for.
84      */

85     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
86         return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_VERSIONS_CATEGORY);
87     }
88
89     /**
90      * Returns the name of this element. This will typically
91      * be used to assign a label to this object when displayed
92      * in the UI. Returns an empty string if there is no appropriate
93      * name for this object.
94      *
95      * @param object The object to get a label for.
96      */

97     public String JavaDoc getLabel(Object JavaDoc o) {
98         return Policy.bind("GroupedByVersionCategory.Versions_1"); //$NON-NLS-1$
99
}
100
101     /**
102      * Returns the logical parent of the given object in its tree.
103      * Returns null if there is no parent, or if this object doesn't
104      * belong to a tree.
105      *
106      * @param object The object to get the parent for.
107      */

108     public Object JavaDoc getParent(Object JavaDoc o) {
109         return repository;
110     }
111     
112     /**
113      * Return the repository the given element belongs to.
114      */

115     public ICVSRepositoryLocation getRepository(Object JavaDoc o) {
116         return repository;
117     }
118 }
119
Popular Tags