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-2007 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.xml.schema.ui.nodes;
043:
044: import java.io.IOException;
045: import java.lang.reflect.InvocationTargetException;
046: import java.util.Enumeration;
047: import org.netbeans.modules.xml.schema.model.SchemaComponent;
048: import org.netbeans.modules.xml.schema.model.SchemaModel;
049: import org.openide.ErrorManager;
050: import org.openide.nodes.Node;
051:
052: /**
053: * This class provides a wrapper which invokes flush on the schema model
054: * when setValue has been invoked.
055: * @author Chris Webster
056: */
057: public class SchemaModelFlushWrapper extends Node.Property {
058: private Node.Property delegate;
059: private SchemaModel model;
060:
061: public SchemaModelFlushWrapper(SchemaComponent sc,
062: Node.Property delegate) {
063: super (delegate.getValueType());
064: model = sc.getModel();
065: this .delegate = delegate;
066: }
067:
068: @Override
069: public void setValue(Object object) throws IllegalAccessException,
070: IllegalArgumentException, InvocationTargetException {
071: try {
072: model.startTransaction();
073: delegate.setValue(object);
074: } finally {
075: model.endTransaction();
076: }
077: }
078:
079: @Override
080: public void restoreDefaultValue() throws IllegalAccessException,
081: InvocationTargetException {
082: try {
083: model.startTransaction();
084: delegate.restoreDefaultValue();
085: } finally {
086: model.endTransaction();
087: }
088: }
089:
090: @Override
091: public boolean equals(Object object) {
092: return delegate.equals(object);
093: }
094:
095: @Override
096: public void setExpert(boolean expert) {
097: delegate.setExpert(expert);
098: }
099:
100: @Override
101: public void setHidden(boolean hidden) {
102: delegate.setHidden(hidden);
103: }
104:
105: @Override
106: public void setPreferred(boolean preferred) {
107: delegate.setPreferred(preferred);
108: }
109:
110: @Override
111: public void setShortDescription(String text) {
112: delegate.setShortDescription(text);
113: }
114:
115: @Override
116: public Object getValue(String attributeName) {
117: return delegate.getValue(attributeName);
118: }
119:
120: @Override
121: public void setDisplayName(String displayName) {
122: delegate.setDisplayName(displayName);
123: }
124:
125: @Override
126: public void setName(String name) {
127: delegate.setName(name);
128: }
129:
130: @Override
131: public void setValue(String attributeName, Object value) {
132: delegate.setValue(attributeName, value);
133: }
134:
135: @Override
136: public String toString() {
137: return delegate.toString();
138: }
139:
140: @Override
141: public boolean supportsDefaultValue() {
142: return delegate.supportsDefaultValue();
143: }
144:
145: @Override
146: public Object getValue() throws IllegalAccessException,
147: InvocationTargetException {
148: return delegate.getValue();
149: }
150:
151: @Override
152: public String getShortDescription() {
153: return delegate.getShortDescription();
154: }
155:
156: @Override
157: public java.beans.PropertyEditor getPropertyEditor() {
158: return delegate.getPropertyEditor();
159: }
160:
161: @Override
162: public String getName() {
163: return delegate.getName();
164: }
165:
166: @Override
167: public String getHtmlDisplayName() {
168: return delegate.getHtmlDisplayName();
169: }
170:
171: @Override
172: public String getDisplayName() {
173: return delegate.getDisplayName();
174: }
175:
176: @Override
177: public boolean canWrite() {
178: return delegate.canWrite();
179: }
180:
181: @Override
182: public boolean canRead() {
183: return delegate.canRead();
184: }
185:
186: @Override
187: public Enumeration<String> attributeNames() {
188: return delegate.attributeNames();
189: }
190:
191: @Override
192: public Class getValueType() {
193: return delegate.getValueType();
194: }
195:
196: @Override
197: public int hashCode() {
198: return delegate.hashCode();
199: }
200:
201: @Override
202: public boolean isDefaultValue() {
203: return delegate.isDefaultValue();
204: }
205:
206: @Override
207: public boolean isExpert() {
208: return delegate.isExpert();
209: }
210:
211: @Override
212: public boolean isHidden() {
213: return delegate.isHidden();
214: }
215:
216: @Override
217: public boolean isPreferred() {
218: return delegate.isPreferred();
219: }
220:
221: }
|