KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > merge > TagRootElement


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.merge;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.team.internal.ccvs.core.CVSTag;
21 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
22 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
23 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
24 import org.eclipse.team.internal.ccvs.ui.Policy;
25 import org.eclipse.ui.model.IWorkbenchAdapter;
26
27 public class TagRootElement implements IWorkbenchAdapter, IAdaptable {
28     private ICVSFolder project;
29     private List JavaDoc cachedTags;
30     private int typeOfTagRoot;
31     
32     public TagRootElement(ICVSFolder project, int typeOfTagRoot) {
33         this.typeOfTagRoot = typeOfTagRoot;
34         this.project = project;
35     }
36     
37     public TagRootElement(ICVSFolder project, int typeOfTagRoot, CVSTag[] tags) {
38         this(project, typeOfTagRoot);
39         add(tags);
40     }
41     
42     public Object JavaDoc[] getChildren(Object JavaDoc o) {
43         CVSTag[] childTags = new CVSTag[0];
44         if(cachedTags==null) {
45             if(typeOfTagRoot==CVSTag.BRANCH) {
46                 childTags = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownTags(project, CVSTag.BRANCH);
47             } else if(typeOfTagRoot==CVSTag.VERSION) {
48                 childTags = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownTags(project, CVSTag.VERSION);
49             }else if(typeOfTagRoot==CVSTag.DATE){
50                 childTags = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownTags(project, CVSTag.DATE);
51             }
52         } else {
53             childTags = getTags();
54         }
55         TagElement[] result = new TagElement[childTags.length];
56         for (int i = 0; i < childTags.length; i++) {
57             result[i] = new TagElement(childTags[i]);
58         }
59         return result;
60     }
61     public void removeAll() {
62         if(cachedTags!=null) {
63             cachedTags.clear();
64         }
65     }
66     public void add(CVSTag tag){
67         if(cachedTags==null) {
68             cachedTags = new ArrayList JavaDoc();
69         }
70         cachedTags.add(tag);
71     }
72     public void add(CVSTag[] tags) {
73         if(cachedTags==null) {
74             cachedTags = new ArrayList JavaDoc(tags.length);
75         }
76         cachedTags.addAll(Arrays.asList(tags));
77     }
78     public void remove(CVSTag tag) {
79         if(cachedTags!=null) {
80             cachedTags.remove(tag);
81         }
82     }
83     public CVSTag[] getTags() {
84         if(cachedTags!=null) {
85             return (CVSTag[]) cachedTags.toArray(new CVSTag[cachedTags.size()]);
86         } else {
87             return new CVSTag[0];
88         }
89     }
90     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
91         if (adapter == IWorkbenchAdapter.class) return this;
92         return null;
93     }
94     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
95         if(typeOfTagRoot==CVSTag.BRANCH) {
96             return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_BRANCHES_CATEGORY);
97         } else if(typeOfTagRoot==CVSTag.DATE){
98             return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_DATES_CATEGORY);
99         }else {
100             return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_VERSIONS_CATEGORY);
101         }
102     }
103     public String JavaDoc getLabel(Object JavaDoc o) {
104         if(typeOfTagRoot==CVSTag.BRANCH) {
105             return Policy.bind("MergeWizardEndPage.branches"); //$NON-NLS-1$
106
} else if(typeOfTagRoot==CVSTag.DATE){
107             return Policy.bind("TagRootElement.0"); //$NON-NLS-1$
108
}else {
109             return Policy.bind("VersionsElement.versions"); //$NON-NLS-1$
110
}
111     }
112     public Object JavaDoc getParent(Object JavaDoc o) {
113         return null;
114     }
115     /**
116      * Gets the typeOfTagRoot.
117      * @return Returns a int
118      */

119     public int getTypeOfTagRoot() {
120         return typeOfTagRoot;
121     }
122
123 }
124
Popular Tags