1 19 package org.netbeans.modules.versioning.system.cvss; 20 21 import org.netbeans.spi.queries.VisibilityQueryImplementation; 22 import org.netbeans.modules.versioning.util.VersioningListener; 23 import org.netbeans.modules.versioning.util.VersioningEvent; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileUtil; 26 27 import javax.swing.event.ChangeListener ; 28 import javax.swing.event.ChangeEvent ; 29 import java.util.*; 30 import java.io.File ; 31 32 37 public class CvsVisibilityQuery implements VisibilityQueryImplementation, VersioningListener { 38 39 private List<ChangeListener > listeners = new ArrayList<ChangeListener >(); 40 41 public CvsVisibilityQuery() { 42 CvsVersioningSystem.getInstance().getStatusCache().addVersioningListener(this); 43 } 44 45 public boolean isVisible(FileObject fileObject) { 46 if (fileObject.isData()) return true; 47 File file = FileUtil.toFile(fileObject); 48 return file == null || !isHiddenFolder(file); 49 } 50 51 public synchronized void addChangeListener(ChangeListener l) { 52 ArrayList<ChangeListener > newList = new ArrayList<ChangeListener >(listeners); 53 newList.add(l); 54 listeners = newList; 55 } 56 57 public synchronized void removeChangeListener(ChangeListener l) { 58 ArrayList<ChangeListener > newList = new ArrayList<ChangeListener >(listeners); 59 newList.remove(l); 60 listeners = newList; 61 } 62 63 public void versioningEvent(VersioningEvent event) { 64 if (event.getId() == FileStatusCache.EVENT_FILE_STATUS_CHANGED) { 65 File file = (File ) event.getParams()[0]; 66 if (file == null) return; 67 File parent = file.getParentFile(); 68 if (parent == null) return; 69 File marker = new File (parent, "CVS/.nb-removed"); 70 if (marker.exists()) { 71 fireVisibilityChanged(); 72 } 73 } 74 } 75 76 static boolean isHiddenFolder(File file) { 77 File marker = new File (file, "CVS/.nb-removed"); 78 if (marker.exists()) { 79 File [] files = file.listFiles(); 80 for (File child : files) { 81 if (child.lastModified() > marker.lastModified() && !CvsVersioningSystem.FILENAME_CVS.equals(child.getName())) { 82 marker.delete(); 83 return false; 84 } 85 } 86 return true; 87 } else { 88 return false; 89 } 90 } 91 92 private void fireVisibilityChanged() { 93 ChangeEvent event = new ChangeEvent (this); 94 for (ChangeListener listener : listeners) { 95 listener.stateChanged(event); 96 } 97 } 98 } 99 | Popular Tags |