1 19 20 package org.openide.filesystems; 21 22 import java.awt.Image ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.beans.PropertyChangeSupport ; 26 import java.beans.PropertyVetoException ; 27 import java.beans.VetoableChangeListener ; 28 import java.io.IOException ; 29 import java.io.Serializable ; 30 import java.text.MessageFormat ; 31 import java.util.List ; 32 import java.util.Set ; 33 import org.openide.util.NbBundle; 34 import org.openide.util.actions.SystemAction; 35 36 50 public abstract class FileSystem implements Serializable { 51 52 static final long serialVersionUID = -8931487924240189180L; 53 54 55 public static final String PROP_VALID = "valid"; 57 61 @Deprecated 62 public static final String PROP_HIDDEN = "hidden"; 64 68 @Deprecated 69 public static final String PROP_SYSTEM_NAME = "systemName"; 71 74 public static final String PROP_DISPLAY_NAME = "displayName"; 76 77 public static final String PROP_ROOT = "root"; 79 80 public static final String PROP_READ_ONLY = "readOnly"; 82 83 static final String PROP_CAPABILITIES = "capabilities"; 85 86 private static Object internLock = new Object (); 87 private transient static ThreadLocal <EventControl> thrLocal = new ThreadLocal <EventControl>(); 88 89 90 private static final Status STATUS_NONE = new Status() { 91 public String annotateName(String name, Set <? extends FileObject> files) { 92 return name; 93 } 94 95 public Image annotateIcon(Image icon, int iconType, Set <? extends FileObject> files) { 96 return icon; 97 } 98 }; 99 100 104 transient private boolean valid = false; 105 106 109 transient boolean assigned = false; 110 111 112 private transient Repository repository = null; 113 private transient FCLSupport fclSupport; 114 115 117 @Deprecated private FileSystemCapability capability; 120 121 122 private transient PropertyChangeListener capabilityListener; 123 124 125 private boolean hidden = false; 126 127 128 private String systemName = "".intern(); 130 131 private transient ListenerList<FileStatusListener> fileStatusList; 132 private transient ListenerList<VetoableChangeListener > vetoableChangeList; 133 private transient PropertyChangeSupport changeSupport; 134 135 136 public FileSystem() { 137 } 138 139 150 public void refresh(boolean expected) { 151 } 152 153 157 public final boolean isValid() { 158 return valid; 159 } 160 161 164 final void setValid(boolean v) { 165 if (v != valid) { 166 valid = v; 167 firePropertyChange( 168 PROP_VALID, (!v) ? Boolean.TRUE : Boolean.FALSE, v ? Boolean.TRUE : Boolean.FALSE, Boolean.FALSE 169 ); 170 } 171 } 172 173 179 @Deprecated 180 public final void setHidden(boolean hide) { 181 if (hide != hidden) { 182 hidden = hide; 183 firePropertyChange(PROP_HIDDEN, (!hide) ? Boolean.TRUE : Boolean.FALSE, hide ? Boolean.TRUE : Boolean.FALSE); 184 } 185 } 186 187 190 @Deprecated 191 public final boolean isHidden() { 192 return hidden; 193 } 194 195 208 @Deprecated 209 protected boolean isPersistent() { 210 return false; 211 } 212 213 225 public abstract String getDisplayName(); 226 227 246 @Deprecated 247 public final String getSystemName() { 248 return systemName; 249 } 250 251 264 @Deprecated 265 protected final void setSystemName(String name) throws PropertyVetoException { 266 synchronized (Repository.class) { 267 if (systemName.equals(name)) { 268 return; 269 } 270 271 fireVetoableChange(PROP_SYSTEM_NAME, systemName, name); 274 275 String old = systemName; 276 systemName = name.intern(); 277 278 firePropertyChange(PROP_SYSTEM_NAME, old, systemName); 279 280 282 firePropertyChange(PROP_DISPLAY_NAME, null, null); 283 } 284 } 285 286 289 public final boolean isDefault() { 290 return this == ExternalUtil.getRepository().getDefaultFileSystem(); 291 } 292 293 296 public abstract boolean isReadOnly(); 297 298 302 public abstract FileObject getRoot(); 303 304 323 @Deprecated 324 public FileObject find(String aPackage, String name, String ext) { 325 assert FileUtil.assertDeprecatedMethod(); 326 327 StringBuffer bf = new StringBuffer (); 328 329 if (!aPackage.equals("")) { 332 String p = aPackage.replace('.', '/'); 333 bf.append(p); 334 bf.append('/'); 335 } 336 337 if (name != null) { 339 bf.append(name); 340 } 341 342 if (ext != null) { 344 bf.append('.'); 345 bf.append(ext); 346 } 347 348 return findResource(bf.toString()); 349 } 350 351 356 public abstract FileObject findResource(String name); 357 358 367 public abstract SystemAction[] getActions(); 368 369 public SystemAction[] getActions(Set <FileObject> foSet) { 370 return this.getActions(); 371 } 372 373 378 private void readObject(java.io.ObjectInputStream in) 379 throws java.io.IOException , java.lang.ClassNotFoundException { 380 in.defaultReadObject(); 381 382 if (capability != null) { 383 capability.addPropertyChangeListener(getCapabilityChangeListener()); 384 } 385 } 386 387 public String toString() { 388 return getSystemName() + "[" + super.toString() + "]"; } 390 391 405 @Deprecated 406 public void prepareEnvironment(Environment env) throws EnvironmentNotSupportedException { 407 throw new EnvironmentNotSupportedException(this); 408 } 409 410 417 public Status getStatus() { 418 return STATUS_NONE; 419 } 420 421 425 @Deprecated 426 public final FileSystemCapability getCapability() { 427 if (capability == null) { 428 capability = new FileSystemCapability.Bean(); 429 capability.addPropertyChangeListener(getCapabilityChangeListener()); 430 } 431 432 return capability; 433 } 434 435 440 @Deprecated 441 protected final void setCapability(FileSystemCapability capability) { 442 if (this.capability != null) { 443 this.capability.removePropertyChangeListener(getCapabilityChangeListener()); 444 } 445 446 this.capability = capability; 447 448 if (this.capability != null) { 449 this.capability.addPropertyChangeListener(getCapabilityChangeListener()); 450 } 451 } 452 453 469 public final void runAtomicAction(final AtomicAction run) 470 throws IOException { 471 getEventControl().runAtomicAction(run); 472 } 473 474 482 void beginAtomicAction(FileSystem.AtomicAction run) { 483 getEventControl().beginAtomicAction(run); 484 } 485 486 void beginAtomicAction() { 487 beginAtomicAction(null); 488 } 489 490 496 void finishAtomicAction() { 497 getEventControl().finishAtomicAction(); 498 } 499 500 505 void dispatchEvent(EventDispatcher run) { 506 getEventControl().dispatchEvent(run); 507 } 508 509 510 private synchronized PropertyChangeListener getCapabilityChangeListener() { 511 if (capabilityListener == null) { 512 capabilityListener = new PropertyChangeListener () { 513 public void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent) { 514 firePropertyChange( 515 PROP_CAPABILITIES, propertyChangeEvent.getOldValue(), propertyChangeEvent.getNewValue() 516 ); 517 } 518 }; 519 } 520 521 return capabilityListener; 522 } 523 524 private final EventControl getEventControl() { 525 EventControl evnCtrl = thrLocal.get(); 526 527 if (evnCtrl == null) { 528 thrLocal.set(evnCtrl = new EventControl()); 529 } 530 531 return evnCtrl; 532 } 533 534 540 public final void addFileStatusListener(FileStatusListener listener) { 541 synchronized (internLock) { 542 if (getStatus() == STATUS_NONE) { 544 return; 545 } 546 547 if (fileStatusList == null) { 548 fileStatusList = new ListenerList<FileStatusListener>(); 549 } 550 551 fileStatusList.add(listener); 552 } 553 } 554 555 558 public final void removeFileStatusListener(FileStatusListener listener) { 559 if (fileStatusList == null) { 560 return; 561 } 562 563 fileStatusList.remove(listener); 564 } 565 566 570 protected final void fireFileStatusChanged(FileStatusEvent event) { 571 if (fileStatusList == null) { 572 return; 573 } 574 575 List <FileStatusListener> listeners = fileStatusList.getAllListeners(); 576 dispatchEvent(new FileStatusDispatcher(listeners, event)); 577 } 578 579 582 public final void addVetoableChangeListener(VetoableChangeListener listener) { 583 synchronized (internLock) { 584 if (vetoableChangeList == null) { 585 vetoableChangeList = new ListenerList<VetoableChangeListener >(); 586 } 587 588 vetoableChangeList.add(listener); 589 } 590 } 591 592 595 public final void removeVetoableChangeListener(VetoableChangeListener listener) { 596 if (vetoableChangeList == null) { 597 return; 598 } 599 600 vetoableChangeList.remove(listener); 601 } 602 603 609 protected final void fireVetoableChange(String name, Object o, Object n) 610 throws PropertyVetoException { 611 if (vetoableChangeList == null) { 612 return; 613 } 614 615 PropertyChangeEvent e = null; 616 617 for (VetoableChangeListener l : vetoableChangeList.getAllListeners()) { 618 if (e == null) { 619 e = new PropertyChangeEvent (this, name, o, n); 620 } 621 622 l.vetoableChange(e); 623 } 624 } 625 626 629 public final void addPropertyChangeListener(PropertyChangeListener listener) { 630 synchronized (internLock) { 631 if (changeSupport == null) { 632 changeSupport = new PropertyChangeSupport (this); 633 } 634 } 635 636 changeSupport.addPropertyChangeListener(listener); 637 } 638 639 642 public final void removePropertyChangeListener(PropertyChangeListener listener) { 643 if (changeSupport != null) { 644 changeSupport.removePropertyChangeListener(listener); 645 } 646 } 647 648 653 protected final void firePropertyChange(String name, Object o, Object n) { 654 firePropertyChange(name, o, n, null); 655 } 656 657 final void firePropertyChange(String name, Object o, Object n, Object propagationId) { 658 if (changeSupport == null) { 659 return; 660 } 661 662 if ((o != null) && (n != null) && o.equals(n)) { 663 return; 664 } 665 666 PropertyChangeEvent e = new PropertyChangeEvent (this, name, o, n); 667 e.setPropagationId(propagationId); 668 changeSupport.firePropertyChange(e); 669 } 670 671 677 public void addNotify() { 678 } 679 680 687 public void removeNotify() { 688 } 689 690 694 static String getString(String s) { 695 698 return NbBundle.getBundle( 699 "org.openide.filesystems.Bundle", java.util.Locale.getDefault(), FileSystem.class.getClassLoader() 700 ).getString(s); 701 } 702 703 708 static String getString(String s, Object obj) { 709 return MessageFormat.format(getString(s), new Object [] { obj }); 710 } 711 712 718 static String getString(String s, Object obj1, Object obj2) { 719 return MessageFormat.format(getString(s), new Object [] { obj1, obj2 }); 720 } 721 722 729 static String getString(String s, Object obj1, Object obj2, Object obj3) { 730 return MessageFormat.format(getString(s), new Object [] { obj1, obj2, obj3 }); 731 } 732 733 737 final Repository getRepository() { 738 return repository; 739 } 740 741 void setRepository(Repository rep) { 742 repository = rep; 743 } 744 745 final FCLSupport getFCLSupport() { 746 synchronized (FCLSupport.class) { 747 if (fclSupport == null) { 748 fclSupport = new FCLSupport(); 749 } 750 } 751 752 return fclSupport; 753 } 754 755 759 public final void addFileChangeListener(FileChangeListener fcl) { 760 getFCLSupport().addFileChangeListener(fcl); 761 } 762 763 767 public final void removeFileChangeListener(FileChangeListener fcl) { 768 getFCLSupport().removeFileChangeListener(fcl); 769 } 770 771 784 public static interface AtomicAction { 785 790 public void run() throws IOException ; 791 } 792 793 798 public static interface Status { 799 805 public String annotateName(String name, Set <? extends FileObject> files); 806 807 816 public Image annotateIcon(Image icon, int iconType, Set <? extends FileObject> files); 817 } 818 819 833 public static interface HtmlStatus extends Status { 834 853 public String annotateNameHtml(String name, Set <? extends FileObject> files); 854 } 855 856 861 @Deprecated 862 public static abstract class Environment extends Object { 863 public Environment() { 864 assert FileUtil.assertDeprecatedMethod(); 865 } 866 867 871 @Deprecated 872 public void addClassPath(String classPathElement) { 873 } 874 } 875 876 878 static abstract class EventDispatcher extends Object implements Runnable { 879 public final void run() { 880 dispatch(false); 881 } 882 883 886 protected abstract void dispatch(boolean onlyPriority); 887 888 889 protected abstract void setAtomicActionLink(EventControl.AtomicActionLink propID); 890 } 891 892 private static class FileStatusDispatcher extends EventDispatcher { 893 private List <FileStatusListener> listeners; 894 private FileStatusEvent fStatusEvent; 895 896 public FileStatusDispatcher(List <FileStatusListener> listeners, FileStatusEvent fStatusEvent) { 897 this.listeners = listeners; 898 this.fStatusEvent = fStatusEvent; 899 } 900 901 protected void dispatch(boolean onlyPriority) { 902 if (onlyPriority) { 903 return; 904 } 905 906 for (FileStatusListener fStatusListener : listeners) { 907 fStatusListener.annotationChanged(fStatusEvent); 908 } 909 } 910 911 protected void setAtomicActionLink(EventControl.AtomicActionLink propID) { 912 913 } 914 } 915 } 916 | Popular Tags |