001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.project.libraries.ui;
043:
044: import java.net.URL;
045: import java.util.List;
046: import java.util.Map;
047: import java.util.HashMap;
048: import java.beans.PropertyChangeSupport;
049: import java.beans.PropertyChangeListener;
050: import java.beans.PropertyChangeEvent;
051:
052: import org.netbeans.spi.project.libraries.LibraryImplementation;
053: import org.openide.util.WeakListeners;
054:
055: /**
056: *
057: * @author tom
058: */
059: public class ProxyLibraryImplementation implements
060: LibraryImplementation, PropertyChangeListener {
061:
062: private final LibraryImplementation original;
063: private final LibrariesModel model;
064: Map<String, List<URL>> newContents;
065: private String newName;
066: private String newDescription;
067: private PropertyChangeSupport support;
068:
069: public ProxyLibraryImplementation(LibraryImplementation original,
070: LibrariesModel model) {
071: assert original != null && model != null;
072: this .original = original;
073: this .model = model;
074: this .original.addPropertyChangeListener(WeakListeners.create(
075: PropertyChangeListener.class, this , this .original));
076: this .support = new PropertyChangeSupport(this );
077: }
078:
079: public LibraryImplementation getOriginal() {
080: return this .original;
081: }
082:
083: public void addPropertyChangeListener(PropertyChangeListener l) {
084: this .support.addPropertyChangeListener(l);
085: }
086:
087: public void removePropertyChangeListener(PropertyChangeListener l) {
088: this .support.removePropertyChangeListener(l);
089: }
090:
091: public String getType() {
092: return this .original.getType();
093: }
094:
095: public synchronized List<URL> getContent(String volumeType)
096: throws IllegalArgumentException {
097: List<URL> result = null;
098: if (newContents == null
099: || (result = newContents.get(volumeType)) == null) {
100: return this .original.getContent(volumeType);
101: } else {
102: return result;
103: }
104: }
105:
106: public synchronized String getDescription() {
107: if (this .newDescription != null) {
108: return this .newDescription;
109: } else {
110: return this .original.getDescription();
111: }
112: }
113:
114: public synchronized String getName() {
115: if (this .newName != null) {
116: return this .newName;
117: } else {
118: return this .original.getName();
119: }
120: }
121:
122: public synchronized void setContent(String volumeType,
123: List<URL> path) throws IllegalArgumentException {
124: if (this .newContents == null) {
125: this .newContents = new HashMap<String, List<URL>>();
126: }
127: this .newContents.put(volumeType, path);
128: this .model.modifyLibrary(this );
129: this .support.firePropertyChange(PROP_CONTENT, null, null); //NOI18N
130: }
131:
132: public synchronized void setDescription(String text) {
133: String oldDescription = this .newDescription == null ? this .original
134: .getDescription()
135: : this .newDescription;
136: this .newDescription = text;
137: this .model.modifyLibrary(this );
138: this .support.firePropertyChange(PROP_DESCRIPTION,
139: oldDescription, this .newDescription); //NOI18N
140: }
141:
142: public synchronized void setName(String name) {
143: String oldName = this .newName == null ? this .original.getName()
144: : this .newName;
145: this .newName = name;
146: this .model.modifyLibrary(this );
147: this .support.firePropertyChange(PROP_NAME, oldName,
148: this .newName); //NOI18N
149: }
150:
151: public String getLocalizingBundle() {
152: return this .original.getLocalizingBundle();
153: }
154:
155: public void setLocalizingBundle(String resourceName) {
156: throw new UnsupportedOperationException();
157: }
158:
159: public void propertyChange(PropertyChangeEvent evt) {
160: this .support.firePropertyChange(evt.getPropertyName(), evt
161: .getOldValue(), evt.getNewValue());
162: }
163:
164: public final int hashCode() {
165: return this .original.hashCode();
166: }
167:
168: public final boolean equals(Object obj) {
169: if (obj instanceof ProxyLibraryImplementation) {
170: return this .original
171: .equals(((ProxyLibraryImplementation) obj)
172: .getOriginal());
173: } else
174: return false;
175: }
176:
177: public @Override
178: String toString() {
179: return "Proxy[" + original + "]"; // NOI18N
180: }
181:
182: }
|