1 19 20 package org.netbeans.modules.project.libraries.ui; 21 22 import java.net.URL ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.HashMap ; 26 import java.beans.PropertyChangeSupport ; 27 import java.beans.PropertyChangeListener ; 28 import java.beans.PropertyChangeEvent ; 29 30 import org.netbeans.spi.project.libraries.LibraryImplementation; 31 import org.openide.util.WeakListeners; 32 36 public class ProxyLibraryImplementation implements LibraryImplementation, PropertyChangeListener { 37 38 private final LibraryImplementation original; 39 private final LibrariesModel model; 40 private Map <String ,List <URL >> newContents; 41 private String newName; 42 private String newDescription; 43 private PropertyChangeSupport support; 44 45 46 public ProxyLibraryImplementation (LibraryImplementation original, LibrariesModel model) { 47 assert original != null && model != null; 48 this.original = original; 49 this.model = model; 50 this.original.addPropertyChangeListener(WeakListeners.create(PropertyChangeListener .class, this, this.original)); 51 this.support = new PropertyChangeSupport (this); 52 } 53 54 public LibraryImplementation getOriginal () { 55 return this.original; 56 } 57 58 public void addPropertyChangeListener(PropertyChangeListener l) { 59 this.support.addPropertyChangeListener(l); 60 } 61 62 public void removePropertyChangeListener(PropertyChangeListener l) { 63 this.support.removePropertyChangeListener(l); 64 } 65 66 public String getType() { 67 return this.original.getType (); 68 } 69 70 71 public synchronized List <URL > getContent(String volumeType) throws IllegalArgumentException { 72 List <URL > result = null; 73 if (newContents == null || (result = newContents.get(volumeType)) == null) { 74 return this.original.getContent (volumeType); 75 } 76 else { 77 return result; 78 } 79 } 80 81 public synchronized String getDescription() { 82 if (this.newDescription != null) { 83 return this.newDescription; 84 } 85 else { 86 return this.original.getDescription(); 87 } 88 } 89 90 public synchronized String getName() { 91 if (this.newName != null) { 92 return this.newName; 93 } 94 else { 95 return this.original.getName (); 96 } 97 } 98 99 public synchronized void setContent(String volumeType, List <URL > path) throws IllegalArgumentException { 100 if (this.newContents == null) { 101 this.newContents = new HashMap <String ,List <URL >>(); 102 } 103 this.newContents.put (volumeType, path); 104 this.model.modifyLibrary(this); 105 this.support.firePropertyChange(PROP_CONTENT,null,null); } 107 108 public synchronized void setDescription(String text) { 109 String oldDescription = this.newDescription == null ? this.original.getDescription() : this.newDescription; 110 this.newDescription = text; 111 this.model.modifyLibrary(this); 112 this.support.firePropertyChange(PROP_DESCRIPTION,oldDescription,this.newDescription); } 114 115 public synchronized void setName(String name) { 116 String oldName = this.newName == null ? this.original.getName() : this.newName; 117 this.newName = name; 118 this.model.modifyLibrary(this); 119 this.support.firePropertyChange(PROP_NAME,oldName,this.newName); } 121 122 123 public String getLocalizingBundle() { 124 return this.original.getLocalizingBundle(); 125 } 126 127 public void setLocalizingBundle(String resourceName) { 128 throw new UnsupportedOperationException (); 129 } 130 131 public void propertyChange(PropertyChangeEvent evt) { 132 this.support.firePropertyChange(evt.getPropertyName(),evt.getOldValue(),evt.getNewValue()); 133 } 134 135 136 public final int hashCode() { 137 return this.original.hashCode(); 138 } 139 140 public final boolean equals(Object obj) { 141 if (obj instanceof ProxyLibraryImplementation) { 142 return this.original.equals(((ProxyLibraryImplementation)obj).getOriginal()); 143 } 144 else 145 return false; 146 } 147 148 public final String toString() { 149 return "Proxy for: " + this.original.toString(); } 151 152 } 153 | Popular Tags |