KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > localhistory > LocalHistory


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.localhistory;
20         
21 import java.io.File JavaDoc;
22 import org.netbeans.modules.localhistory.store.LocalHistoryStore;
23 import org.netbeans.modules.localhistory.store.LocalHistoryStoreFactory;
24 import org.netbeans.modules.versioning.spi.VCSAnnotator;
25 import org.netbeans.modules.versioning.spi.VCSInterceptor;
26 import org.openide.cookies.EditCookie;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.loaders.DataObject;
30 import org.openide.loaders.DataObjectNotFoundException;
31
32 /**
33  *
34  * A singleton Local Hisotry manager class, center of the Local History module.
35  * Use {@link #getInstance()} to get access to Local History module functionality.
36  * @author Tomas Stupka
37  */

38 public class LocalHistory {
39       
40     private static LocalHistory instance;
41     private VCSInterceptor vcsInterceptor;
42     private VCSAnnotator vcsAnnotator;
43     private LocalHistoryStore store;
44
45     private static String JavaDoc userDir;
46     
47     public static synchronized LocalHistory getInstance() {
48         if(instance == null) {
49             instance = new LocalHistory();
50         }
51         return instance;
52     }
53     
54     VCSInterceptor getVCSInterceptor() {
55         if(vcsInterceptor == null) {
56             vcsInterceptor = new LocalHistoryVCSInterceptor();
57         }
58         return vcsInterceptor;
59     }
60     
61     VCSAnnotator getVCSAnnotator() {
62         if(vcsAnnotator == null) {
63             vcsAnnotator = new LocalHistoryVCSAnnotator();
64         }
65         return vcsAnnotator;
66     }
67     
68     public LocalHistoryStore getLocalHistoryStore() {
69         if(store == null) {
70             store = LocalHistoryStoreFactory.getInstance().createLocalHistoryStorage();
71         }
72         return store;
73     }
74     
75     private String JavaDoc getUserDir() {
76         if(userDir == null) {
77             userDir = System.getProperty("netbeans.user"); // NOI18N
78
}
79         return userDir;
80     }
81     
82     File JavaDoc isManagedByParent(File JavaDoc file) {
83         File JavaDoc parent = file.getParentFile();
84         while(parent != null) {
85             
86             if(parent.getAbsolutePath().equals(getUserDir())) {
87                 // ignore userdir
88
return null;
89             }
90             
91             file = parent;
92             parent = file.getParentFile();
93         }
94         return file;
95     }
96     
97     boolean isManaged(File JavaDoc file) {
98         if(file.isDirectory()) {
99             return true; // XXX is there something more we could do for folders?
100
}
101         if(Diagnostics.ON) {
102             Diagnostics.println(".isManaged() " + file);
103         }
104         return file.length() <= LocalHistorySettings.getMaxFileSize();
105     }
106     
107 }
108
Popular Tags