KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > SchemaModelFlushWrapper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.xml.schema.abe.nodes;
22
23 import java.io.IOException JavaDoc;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import org.netbeans.modules.xml.axi.AXIComponent;
27 import org.netbeans.modules.xml.axi.AXIModel;
28 import org.netbeans.modules.xml.axi.AXIType;
29 import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
30 import org.openide.ErrorManager;
31 import org.openide.nodes.Node;
32
33
34 /**
35  * This class provides a wrapper which invokes flush on the schema model
36  * when setValue has been invoked.
37  * @author Chris Webster
38  */

39 public class SchemaModelFlushWrapper extends Node.Property {
40     private Node.Property delegate;
41     private AXIModel model;
42     private boolean readOnly = false;
43     AXIComponent axiComponent;
44     private InstanceUIContext context;
45     
46     public SchemaModelFlushWrapper(AXIComponent sc, Node.Property delegate, InstanceUIContext context) {
47         super(delegate.getValueType());
48         this.context = context;
49         model = sc.getModel();
50         this.delegate = delegate;
51         this.axiComponent = sc;
52     }
53     
54     @Override JavaDoc
55     public void setValue(Object JavaDoc object) throws IllegalAccessException JavaDoc,
56             IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
57         try {
58             context.setUserInducedEventMode(true);
59             model.startTransaction();
60             delegate.setValue(object);
61         } finally {
62             model.endTransaction();
63         }
64     }
65     
66     @Override JavaDoc
67     public void restoreDefaultValue() throws IllegalAccessException JavaDoc,
68             InvocationTargetException JavaDoc {
69         try {
70             model.startTransaction();
71             delegate.restoreDefaultValue();
72         } finally {
73             model.endTransaction();
74         }
75     }
76     
77     @Override JavaDoc
78     public boolean equals(Object JavaDoc object) {
79         return delegate.equals(object);
80     }
81
82     @Override JavaDoc
83     public void setExpert(boolean expert) {
84         delegate.setExpert(expert);
85     }
86
87     @Override JavaDoc
88     public void setHidden(boolean hidden) {
89         delegate.setHidden(hidden);
90     }
91
92     @Override JavaDoc
93     public void setPreferred(boolean preferred) {
94         delegate.setPreferred(preferred);
95     }
96
97     @Override JavaDoc
98     public void setShortDescription(String JavaDoc text) {
99         delegate.setShortDescription(text);
100     }
101
102     @Override JavaDoc
103     public Object JavaDoc getValue(String JavaDoc attributeName) {
104         return delegate.getValue(attributeName);
105     }
106
107     @Override JavaDoc
108     public void setDisplayName(String JavaDoc displayName) {
109         delegate.setDisplayName(displayName);
110     }
111
112     @Override JavaDoc
113     public void setName(String JavaDoc name) {
114         delegate.setName(name);
115     }
116
117     @Override JavaDoc
118     public void setValue(String JavaDoc attributeName, Object JavaDoc value) {
119         delegate.setValue(attributeName, value);
120     }
121
122     @Override JavaDoc
123     public String JavaDoc toString() {
124         return delegate.toString();
125     }
126
127     @Override JavaDoc
128     public boolean supportsDefaultValue() {
129         return delegate.supportsDefaultValue();
130     }
131
132     @Override JavaDoc
133     public Object JavaDoc getValue() throws IllegalAccessException JavaDoc,
134     InvocationTargetException JavaDoc {
135         return delegate.getValue();
136     }
137
138     @Override JavaDoc
139     public String JavaDoc getShortDescription() {
140         return delegate.getShortDescription();
141     }
142
143     @Override JavaDoc
144     public java.beans.PropertyEditor JavaDoc getPropertyEditor() {
145         return delegate.getPropertyEditor();
146     }
147
148     @Override JavaDoc
149     public String JavaDoc getName() {
150         return delegate.getName();
151     }
152
153     @Override JavaDoc
154     public String JavaDoc getHtmlDisplayName() {
155         return delegate.getHtmlDisplayName();
156     }
157
158     @Override JavaDoc
159     public String JavaDoc getDisplayName() {
160         return delegate.getDisplayName();
161     }
162     
163     @Override JavaDoc
164     public boolean canWrite() {
165         if( (axiComponent != null) && (axiComponent.getModel() != null) )
166             return !(axiComponent.isReadOnly());
167         return true;
168     }
169
170     @Override JavaDoc
171     public boolean canRead() {
172         return delegate.canRead();
173     }
174
175     @Override JavaDoc
176     public Enumeration JavaDoc<String JavaDoc> attributeNames() {
177         return delegate.attributeNames();
178     }
179    
180     @Override JavaDoc
181     public Class JavaDoc getValueType() {
182         return delegate.getValueType();
183     }
184    
185     @Override JavaDoc
186     public int hashCode() {
187         return delegate.hashCode();
188     }
189
190     @Override JavaDoc
191     public boolean isDefaultValue() {
192         return delegate.isDefaultValue();
193     }
194     
195     @Override JavaDoc
196     public boolean isExpert() {
197         return delegate.isExpert();
198     }
199
200     @Override JavaDoc
201     public boolean isHidden() {
202         return delegate.isHidden();
203     }
204
205     @Override JavaDoc
206     public boolean isPreferred() {
207         return delegate.isPreferred();
208     }
209     
210 }
211
Popular Tags