KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > SubversionVisibilityQuery


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
20 package org.netbeans.modules.subversion;
21
22 import org.netbeans.modules.versioning.util.VersioningListener;
23 import org.netbeans.modules.versioning.util.VersioningEvent;
24 import org.netbeans.spi.queries.VisibilityQueryImplementation;
25 import org.openide.filesystems.FileUtil;
26 import org.openide.filesystems.FileObject;
27
28 import java.io.*;
29 import java.util.*;
30
31 import javax.swing.event.ChangeListener JavaDoc;
32 import javax.swing.event.ChangeEvent JavaDoc;
33
34 /**
35  * Hides folders that have 'Localy removed' status.
36  *
37  * @author Maros Sandor
38  */

39 public class SubversionVisibilityQuery implements VisibilityQueryImplementation, VersioningListener {
40
41     private List<ChangeListener JavaDoc> listeners = new ArrayList<ChangeListener JavaDoc>();
42     private FileStatusCache cache;
43
44     public SubversionVisibilityQuery() {
45         cache = Subversion.getInstance().getStatusCache();
46         cache.addVersioningListener(this);
47     }
48
49     public boolean isVisible(FileObject fileObject) {
50         if (fileObject.isData()) return true;
51         File file = FileUtil.toFile(fileObject);
52         if(file == null) return true;
53         return cache.getStatus(file).getStatus() != FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY;
54     }
55
56     public synchronized void addChangeListener(ChangeListener JavaDoc l) {
57         ArrayList<ChangeListener JavaDoc> newList = new ArrayList<ChangeListener JavaDoc>(listeners);
58         newList.add(l);
59         listeners = newList;
60     }
61
62     public synchronized void removeChangeListener(ChangeListener JavaDoc l) {
63         ArrayList<ChangeListener JavaDoc> newList = new ArrayList<ChangeListener JavaDoc>(listeners);
64         newList.remove(l);
65         listeners = newList;
66     }
67
68     public void versioningEvent(VersioningEvent event) {
69         if (event.getId() == FileStatusCache.EVENT_FILE_STATUS_CHANGED) {
70             File file = (File) event.getParams()[0];
71             if (file != null && file.isDirectory()) {
72                 FileInformation old = (FileInformation) event.getParams()[1];
73                 FileInformation cur = (FileInformation) event.getParams()[2];
74                 if (old != null && old.getStatus() == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY || cur.getStatus() == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY) {
75                     fireVisibilityChanged();
76                 }
77             }
78         }
79     }
80
81     static boolean isHiddenFolder(FileInformation info, File file) {
82         return file.isDirectory() && info != null && info.getStatus() == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY;
83     }
84     
85     private void fireVisibilityChanged() {
86         ChangeEvent JavaDoc event = new ChangeEvent JavaDoc(this);
87         for (ChangeListener JavaDoc listener : listeners) {
88             listener.stateChanged(event);
89         }
90     }
91 }
92
Popular Tags