KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
14 import com.ibm.icu.text.SimpleDateFormat;
15 import java.util.Date JavaDoc;
16 import java.util.Locale JavaDoc;
17 import com.ibm.icu.util.TimeZone;
18
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.jobs.ISchedulingRule;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.osgi.util.NLS;
23 import org.eclipse.team.core.TeamException;
24 import org.eclipse.team.internal.ccvs.core.*;
25 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
26 import org.eclipse.team.internal.ccvs.ui.*;
27 import org.eclipse.team.internal.ccvs.ui.Policy;
28 import org.eclipse.team.internal.ccvs.ui.operations.FetchMembersOperation;
29 import org.eclipse.team.internal.ccvs.ui.operations.FetchMembersOperation.RemoteFolderFilter;
30 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
31 import org.eclipse.ui.progress.IElementCollector;
32
33 public class CVSTagElement extends CVSModelElement implements IDeferredWorkbenchAdapter {
34     CVSTag tag;
35     ICVSRepositoryLocation root;
36
37     private static final String JavaDoc REPO_VIEW_LONG_FORAMT = "dd MMM yyyy HH:mm:ss"; //$NON-NLS-1$
38
private static final String JavaDoc REPO_VIEW_SHORT_FORMAT = "dd MMM yyyy"; //$NON-NLS-1$
39
private static final String JavaDoc TIME_ONLY_COLUMN_FORMAT = "HH:mm:ss"; //$NON-NLS-1$
40
private static SimpleDateFormat localLongFormat = new SimpleDateFormat(REPO_VIEW_LONG_FORAMT,Locale.getDefault());
41     private static SimpleDateFormat localShortFormat = new SimpleDateFormat(REPO_VIEW_SHORT_FORMAT,Locale.getDefault());
42     private static SimpleDateFormat timeColumnFormat = new SimpleDateFormat(TIME_ONLY_COLUMN_FORMAT, Locale.getDefault());
43
44     static synchronized public String JavaDoc toDisplayString(Date JavaDoc date){
45         String JavaDoc localTime = timeColumnFormat.format(date);
46         timeColumnFormat.setTimeZone(TimeZone.getDefault());
47         if(localTime.equals("00:00:00")){ //$NON-NLS-1$
48
return localShortFormat.format(date);
49         }
50         return localLongFormat.format(date);
51     }
52     
53     public CVSTagElement(CVSTag tag, ICVSRepositoryLocation root) {
54         this.tag = tag;
55         this.root = root;
56     }
57
58     public ICVSRepositoryLocation getRoot() {
59         return root;
60     }
61
62     public CVSTag getTag() {
63         return tag;
64     }
65
66     public boolean equals(Object JavaDoc o) {
67         if (!(o instanceof CVSTagElement))
68             return false;
69         CVSTagElement t = (CVSTagElement) o;
70         if (!tag.equals(t.tag))
71             return false;
72         return root.equals(t.root);
73     }
74
75     public int hashCode() {
76         return root.hashCode() ^ tag.hashCode();
77     }
78
79     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
80         if (!(object instanceof CVSTagElement))
81             return null;
82         if (tag.getType() == CVSTag.BRANCH || tag.getType() == CVSTag.HEAD) {
83             return CVSUIPlugin.getPlugin().getImageDescriptor(
84                 ICVSUIConstants.IMG_TAG);
85         } else if (tag.getType() == CVSTag.VERSION) {
86             return CVSUIPlugin.getPlugin().getImageDescriptor(
87                 ICVSUIConstants.IMG_PROJECT_VERSION);
88         } else {
89             // This could be a Date tag
90
return CVSUIPlugin.getPlugin().getImageDescriptor(
91                     ICVSUIConstants.IMG_DATE);
92         }
93     }
94     public String JavaDoc getLabel(Object JavaDoc o) {
95         if (!(o instanceof CVSTagElement))
96             return null;
97         CVSTag aTag = ((CVSTagElement) o).tag;
98         if(aTag.getType() == CVSTag.DATE){
99             Date JavaDoc date = tag.asDate();
100             if (date != null){
101                 return toDisplayString(date);
102             }
103         }
104         return aTag.getName();
105     }
106     
107     public String JavaDoc toString() {
108         return tag.getName();
109     }
110     
111     public Object JavaDoc getParent(Object JavaDoc o) {
112         if (!(o instanceof CVSTagElement))
113             return null;
114         return ((CVSTagElement) o).root;
115     }
116
117     protected Object JavaDoc[] fetchChildren(Object JavaDoc o, IProgressMonitor monitor) throws TeamException {
118         ICVSRemoteResource[] children = CVSUIPlugin.getPlugin().getRepositoryManager().getFoldersForTag(root, tag, monitor);
119         if (getWorkingSet() != null)
120             children = CVSUIPlugin.getPlugin().getRepositoryManager().filterResources(getWorkingSet(), children);
121         return children;
122     }
123     
124     public void fetchDeferredChildren(Object JavaDoc o, IElementCollector collector, IProgressMonitor monitor) {
125         if (tag.getType() == CVSTag.HEAD || tag.getType() == CVSTag.DATE) {
126             try {
127                 monitor = Policy.monitorFor(monitor);
128                 RemoteFolder folder = new RemoteFolder(null, root, ICVSRemoteFolder.REPOSITORY_ROOT_FOLDER_NAME, tag);
129                 monitor.beginTask(NLS.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren, new String JavaDoc[] { root.toString() }), 100);
130                 FetchMembersOperation operation = new FetchMembersOperation(null, folder, collector);
131                 operation.setFilter(new RemoteFolderFilter() {
132                     public ICVSRemoteResource[] filter(ICVSRemoteResource[] folders) {
133                         return CVSUIPlugin.getPlugin().getRepositoryManager().filterResources(getWorkingSet(), folders);
134                     }
135                 });
136                 operation.run(Policy.subMonitorFor(monitor, 100));
137             } catch (final InvocationTargetException JavaDoc e) {
138                 handle(collector, e);
139             } catch (InterruptedException JavaDoc e) {
140                 // Cancelled by the user;
141
} finally {
142                 monitor.done();
143             }
144         } else {
145             try {
146                 collector.add(fetchChildren(o, monitor), monitor);
147             } catch (TeamException e) {
148                 handle(collector, e);
149             }
150         }
151     }
152
153     public ISchedulingRule getRule(Object JavaDoc element) {
154         return new RepositoryLocationSchedulingRule(root);
155     }
156     
157     public boolean isContainer() {
158         return true;
159     }
160 }
161
Popular Tags