KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > spi > VersioningSystem


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.versioning.spi;
20
21 import java.io.File JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.util.*;
25
26 /**
27  * Base class for a versioning system that integrates into IDE.
28  *
29  * A versioning system provides these services:
30  * - annotations (coloring, actions)
31  * - file system handler
32  * - diff provider
33  *
34  * @author Maros Sandor
35  */

36 public abstract class VersioningSystem {
37
38     /**
39      * Indicates to the Versioning manager that the layout of versioned files may have changed. Previously unversioned
40      * files became versioned, versioned files became unversioned or the versioning system for some files changed.
41      * The manager will flush any caches that may be holding such information.
42      * A versioning system usually needs to fire this after an Import action.
43      */

44     public static final String JavaDoc PROP_VERSIONED_ROOTS = "null VCS.VersionedFilesChanged";
45
46     /**
47      * The NEW value is a Set of Files whose versioning status changed. This event is used to re-annotate files, re-fetch
48      * original content of files and generally refresh all components that are connected to these files.
49      */

50     public static final String JavaDoc PROP_STATUS_CHANGED = "Set<File> VCS.StatusChanged";
51
52     /**
53      * Used to signal the Versioning manager that some annotations changed. Note that this event is NOT required in case
54      * the status of the file changes in which case annotations are updated automatically. Use this event to force annotations
55      * refresh in special cases, for example when the format of annotations changes.
56      * Use null as new value to force refresh of all annotations.
57      */

58     public static final String JavaDoc PROP_ANNOTATIONS_CHANGED = "Set<File> VCS.AnnotationsChanged";
59     
60     protected final PropertyChangeSupport JavaDoc support = new PropertyChangeSupport JavaDoc(this);
61
62     /**
63      * Short name of the versioning system, it will be used as popup menu label, label in tooltips, etc.
64      * Examples: CVS, Subversion, Mercurial, Teamware, SourceSafe, VSS, Clearcase, Local History
65      *
66      * @return String short display name of the versioning system.
67      */

68     public abstract String JavaDoc getDisplayName();
69     
70     /**
71      * Tests whether the file is managed by this versioning system. If it is, the method should return the topmost
72      * parent of the file that is still versioned.
73      * For example (for CVS) if all your CVS checkouts are in a directory /home/johndoe/projects/cvscheckouts/... then for all files
74      * that are under "cvscheckouts" directory and for the directory itselft this method should
75      * return "/home/johndoe/projects/cvscheckouts/" and for all other files return null.
76      *
77      * @param file a file
78      * @return File the file itself or one of its parents or null if the supplied file is NOT managed by this versioning system
79      */

80     public File JavaDoc getTopmostManagedParent(File JavaDoc file) {
81         return null;
82     }
83     
84     /**
85      * Retrieves a VCSAnnotator implementation if this versioning system provides one.
86      *
87      * @return a VCSAnnotator implementation or null
88      */

89     public VCSAnnotator getVCSAnnotator() {
90         return null;
91     }
92
93     /**
94      * Retrieves a VCSInterceptor implementation if this versioning system provides one.
95      *
96      * @return a VCSInterceptor implementation or null
97      */

98     public VCSInterceptor getVCSInterceptor() {
99         return null;
100     }
101
102     /**
103      * Provides the diff algorithm with the original content of a file.
104      * For version control systems that support keyword expansion, the returned stream must expand all keywords so the
105      * diff will not report any differences in keywords.
106      * An implementing class must only return null if it does not provide original content for the file in which
107      * case the system queries other providers. For CVS provider, for example, this means that it should return null if
108      * the file is not managed by CVS and return a valid instance of OriginalContent otherwise. Later when diff asks for the original
109      * content Reader and the content is not available, it can return null.
110      *
111      * @param workingCopy a File in the working copy
112      * @return OriginalContent a wrapper for the original content of the working file or null if this file is not managed by this versioning system
113      */

114     public OriginalContent getVCSOriginalContent(File JavaDoc workingCopy) {
115         return null;
116     }
117
118     /**
119      * Adds a listener for change events.
120      *
121      * @param listener a PropertyChangeListener
122      */

123     public final void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
124         support.addPropertyChangeListener(listener);
125     }
126
127     /**
128      * Removes a listener for change events.
129      *
130      * @param listener a PropertyChangeListener
131      */

132     public final void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
133         support.removePropertyChangeListener(listener);
134     }
135
136     /**
137      * Helper method to signal that annotations of a set of files changed. Do NOT fire this event when changes in
138      * annotations are caused by changes of status. Status change event will refresh annotations automatically.
139      *
140      * @param files set of files whose annotations changed or null if the change affects all files
141      */

142     protected final void fireAnnotationsChanged(Set<File JavaDoc> files) {
143         support.firePropertyChange(PROP_ANNOTATIONS_CHANGED, null, files);
144     }
145     
146     /**
147      * Helper method to signal that status of a set of files changed. Status change event will refresh annotations automatically.
148      *
149      * @param files set of files whose status changed or null if all files changed status
150      */

151     protected final void fireStatusChanged(Set<File JavaDoc> files) {
152         support.firePropertyChange(PROP_STATUS_CHANGED, null, files);
153     }
154
155     /**
156      * Helper method to signal that the versioning system started to manage some previously unversioned files
157      * (those files were imported into repository).
158      */

159     protected final void fireVersionedFilesChanged() {
160         support.firePropertyChange(PROP_VERSIONED_ROOTS, null, null);
161     }
162     
163     /**
164      * Helper method to signal that status of a file changed. Status change event will refresh its annotations automatically.
165      *
166      * @param file a file whose status changed
167      */

168     protected final void fireStatusChanged(File JavaDoc file) {
169         fireStatusChanged(new HashSet<File JavaDoc>(Arrays.asList(file)));
170     }
171 }
172
Popular Tags