KickJava   Java API By Example, From Geeks To Geeks.

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


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
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.jface.viewers.ViewerSorter;
20 import org.eclipse.team.internal.ccvs.core.CVSTag;
21 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
22 import org.eclipse.ui.model.IWorkbenchAdapter;
23
24 public class ProjectElement implements IAdaptable, IWorkbenchAdapter {
25     ICVSFolder project;
26     TagRootElement branches;
27     TagRootElement versions;
28     TagRootElement dates;
29     int includeFlags;
30     
31     public static final int INCLUDE_HEAD_TAG = 1;
32     public static final int INCLUDE_BASE_TAG = 2;
33     public static final int INCLUDE_BRANCHES = 4;
34     public static final int INCLUDE_VERSIONS = 8;
35     public static final int INCLUDE_DATES = 16;
36     public static final int INCLUDE_ALL_TAGS = INCLUDE_HEAD_TAG | INCLUDE_BASE_TAG | INCLUDE_BRANCHES | INCLUDE_VERSIONS | INCLUDE_DATES;
37
38     public static class ProjectElementSorter extends ViewerSorter {
39         /*
40          * The order in the diaog should be HEAD, Branches, Versions, Dates, BASE
41          */

42         public int category(Object JavaDoc element) {
43             if (element instanceof TagElement) {
44                 CVSTag tag = ((TagElement)element).getTag();
45                 if (tag == CVSTag.DEFAULT) return 1;
46                 if (tag == CVSTag.BASE) return 5;
47                 if (tag.getType() == CVSTag.BRANCH) return 2;
48                 if (tag.getType() == CVSTag.VERSION) return 3;
49                 if (tag.getType() == CVSTag.DATE) return 4;
50             } else if (element instanceof TagRootElement) {
51                 if(((TagRootElement)element).getTypeOfTagRoot() == CVSTag.BRANCH) return 2;
52                 if(((TagRootElement)element).getTypeOfTagRoot() == CVSTag.VERSION) return 3;
53                 if(((TagRootElement)element).getTypeOfTagRoot() == CVSTag.DATE) return 4;
54             }
55             return 0;
56         }
57         public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
58             int cat1 = category(e1);
59             int cat2 = category(e2);
60             if (cat1 != cat2) return cat1 - cat2;
61             // Sort version tags in reverse order
62
if (e1 instanceof TagElement){
63                 CVSTag tag1 = ((TagElement)e1).getTag();
64                 int type = tag1.getType();
65                 if(type == CVSTag.VERSION) {
66                     return -1 * super.compare(viewer, e1, e2);
67                 }else if(type == CVSTag.DATE){
68                     return -1*tag1.compareTo(((TagElement)e2).getTag());
69                 }
70             }
71             return super.compare(viewer, e1, e2);
72         }
73     }
74         
75     public ProjectElement(ICVSFolder project, int includeFlags) {
76         this.project = project;
77         this.includeFlags = includeFlags;
78         if (this.includeFlags == 0) this.includeFlags = INCLUDE_ALL_TAGS;
79         if ((includeFlags & INCLUDE_BRANCHES) > 0) {
80             branches = new TagRootElement(project, CVSTag.BRANCH);
81         }
82         if ((includeFlags & INCLUDE_VERSIONS) > 0) {
83             versions = new TagRootElement(project, CVSTag.VERSION);
84         }
85         if ((includeFlags & INCLUDE_DATES) > 0) {
86             dates = new TagRootElement(project, CVSTag.DATE);
87         }
88     }
89     
90     public Object JavaDoc[] getChildren(Object JavaDoc o) {
91         ArrayList JavaDoc children = new ArrayList JavaDoc(4);
92         if ((includeFlags & INCLUDE_HEAD_TAG) > 0) {
93             children.add(new TagElement(CVSTag.DEFAULT));
94         }
95         if ((includeFlags & INCLUDE_BASE_TAG) > 0) {
96             children.add(new TagElement(CVSTag.BASE));
97         }
98         if ((includeFlags & INCLUDE_BRANCHES) > 0) {
99             children.add(branches);
100         }
101         if ((includeFlags & INCLUDE_VERSIONS) > 0) {
102             children.add(versions);
103         }
104         if ((includeFlags & INCLUDE_DATES) > 0) {
105             children.add(dates);
106         }
107         return children.toArray(new Object JavaDoc[children.size()]);
108     }
109     public int getIncludeFlags() {
110         return includeFlags;
111     }
112     public TagRootElement getBranches() {
113         return branches;
114     }
115     public TagRootElement getVersions() {
116         return versions;
117     }
118     public TagRootElement getDates(){
119         return dates;
120     }
121     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
122         if (adapter == IWorkbenchAdapter.class) return this;
123         return null;
124     }
125     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
126         return null;
127     }
128     public String JavaDoc getLabel(Object JavaDoc o) {
129         return null;
130     }
131     public Object JavaDoc getParent(Object JavaDoc o) {
132         return null;
133     }
134 }
135
Popular Tags