KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > tags > SingleFileTagSource


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.tags;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.team.core.TeamException;
18 import org.eclipse.team.internal.ccvs.core.*;
19 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
20 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
21
22 /**
23  * A tag source for a single ICVSFile
24  */

25 public class SingleFileTagSource extends TagSource {
26     
27     public static CVSTag[] fetchTagsFor(ICVSFile file, IProgressMonitor monitor) throws TeamException {
28         Set JavaDoc tagSet = new HashSet JavaDoc();
29         ILogEntry[] entries = file.getLogEntries(monitor);
30         for (int j = 0; j < entries.length; j++) {
31             CVSTag[] tags = entries[j].getTags();
32             for (int k = 0; k < tags.length; k++) {
33                 tagSet.add(tags[k]);
34             }
35         }
36         return (CVSTag[])tagSet.toArray(new CVSTag[tagSet.size()]);
37     }
38     
39     private ICVSFile file;
40     private TagSource parentFolderTagSource;
41     
42     /* package */ /**
43      *
44      */

45     public SingleFileTagSource(ICVSFile file) {
46         this.file = file;
47         parentFolderTagSource = TagSource.create(new ICVSResource[] { file.getParent() });
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.team.internal.ccvs.ui.tags.TagSource#getTags(int)
52      */

53     public CVSTag[] getTags(int type) {
54         return parentFolderTagSource.getTags(type);
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.team.internal.ccvs.ui.tags.TagSource#refresh(org.eclipse.core.runtime.IProgressMonitor)
59      */

60     public CVSTag[] refresh(boolean bestEffort, IProgressMonitor monitor) throws TeamException {
61         CVSTag[] tags = fetchTagsFor(file, monitor);
62         commit(tags, false, monitor);
63         fireChange();
64         return tags;
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.team.internal.ccvs.ui.tags.TagSource#getLocation()
69      */

70     public ICVSRepositoryLocation getLocation() {
71         RepositoryManager mgr = CVSUIPlugin.getPlugin().getRepositoryManager();
72         ICVSRepositoryLocation location = mgr.getRepositoryLocationFor(file);
73         return location;
74     }
75
76     /* (non-Javadoc)
77      * @see org.eclipse.team.internal.ccvs.ui.tags.TagSource#getShortDescription()
78      */

79     public String JavaDoc getShortDescription() {
80         return file.getName();
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.team.internal.ccvs.ui.tags.TagSource#commit(org.eclipse.team.internal.ccvs.core.CVSTag[], boolean, org.eclipse.core.runtime.IProgressMonitor)
85      */

86     public void commit(CVSTag[] tags, boolean replace, IProgressMonitor monitor) throws CVSException {
87         parentFolderTagSource.commit(tags, replace, monitor);
88         fireChange();
89     }
90
91     /* (non-Javadoc)
92      * @see org.eclipse.team.internal.ccvs.ui.tags.TagSource#getCVSResources()
93      */

94     public ICVSResource[] getCVSResources() {
95         return new ICVSResource[] { file };
96     }
97
98 }
99
Popular Tags