1 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 ; 32 import javax.swing.event.ChangeEvent ; 33 34 39 public class SubversionVisibilityQuery implements VisibilityQueryImplementation, VersioningListener { 40 41 private List<ChangeListener > listeners = new ArrayList<ChangeListener >(); 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 l) { 57 ArrayList<ChangeListener > newList = new ArrayList<ChangeListener >(listeners); 58 newList.add(l); 59 listeners = newList; 60 } 61 62 public synchronized void removeChangeListener(ChangeListener l) { 63 ArrayList<ChangeListener > newList = new ArrayList<ChangeListener >(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 event = new ChangeEvent (this); 87 for (ChangeListener listener : listeners) { 88 listener.stateChanged(event); 89 } 90 } 91 } 92 | Popular Tags |