KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.xml.schema.abe.nodes.properties;
21
22 import java.lang.reflect.InvocationTargetException JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.xml.axi.AXIComponent;
25 import org.netbeans.modules.xml.schema.model.SchemaModel;
26 import org.netbeans.modules.xml.xam.ui.XAMUtils;
27 import org.openide.nodes.PropertySupport;
28
29 /**
30  * This class provides property support for properties having global references.
31  * @author Ajit Bhate
32  */

33 public class GlobalReferenceProperty extends PropertySupport.Reflection {
34     
35     private List JavaDoc<Class JavaDoc> filterTypes;
36     private String JavaDoc referenceTypeDisplayName;
37     private String JavaDoc typeDisplayName;
38
39     /**
40      * Creates a new instance of GlobalReferenceProperty.
41      *
42      *
43      * @param component The schema component which property belongs to.
44      * @param property The property name.
45      * @param propDispName The display name of the property.
46      * @param propDesc Short description about the property.
47      * @param isPrimitive distinguish between int and Integer. temporary property
48      * Assumes that the property editor is default editor for Integer.
49      * If special editor needed, subclasses and instances must set it explicitly.
50      * @throws java.lang.NoSuchMethodException If no getter and setter for the property are found
51      */

52     public GlobalReferenceProperty(AXIComponent component,
53             String JavaDoc property, String JavaDoc dispName, String JavaDoc desc,
54             String JavaDoc typeDisplayName, String JavaDoc referenceTypeDisplayName,
55             Class JavaDoc referenceType, List JavaDoc<Class JavaDoc> filterTypes)
56             throws NoSuchMethodException JavaDoc {
57         super(component,referenceType,property);
58         super.setName(property);
59         super.setDisplayName(dispName);
60         super.setShortDescription(desc);
61         this.filterTypes = filterTypes;
62         this.referenceTypeDisplayName = referenceTypeDisplayName;
63         this.typeDisplayName = typeDisplayName;
64     }
65
66     protected AXIComponent getComponent() {
67         return (AXIComponent) instance;
68     }
69
70     protected void setComponent(AXIComponent sc) {
71         instance = sc;
72     }
73     
74     
75     /**
76      * This api determines if this property is editable
77      * @return Returns true if the property is editable, false otherwise.
78      */

79     @Override JavaDoc
80     public boolean canWrite() {
81         // Check for null model since component may have been removed.
82
if(getComponent()== null ||
83                 (getComponent().getModel() == null))
84             return false;
85         SchemaModel model = getComponent().getModel().getSchemaModel();
86         return XAMUtils.isWritable(model);
87     }
88     
89     // Methods to support restore to default
90
/**
91      * This api determines if this property has default value.
92      * If the property value is null, its considered as default value.
93      * Subclasses can override if different behaviour expected.
94      * @return Returns true if the property is default value, false otherwise.
95      */

96     @Override JavaDoc
97     public boolean isDefaultValue () {
98         try {
99             return getValue()==null;
100         } catch (IllegalArgumentException JavaDoc ex) {
101         } catch (InvocationTargetException JavaDoc ex) {
102         } catch (IllegalAccessException JavaDoc ex) {
103         }
104         return false;
105     }
106     
107     /**
108      * This api determines if this property supports resetting default value.
109      * Overriden to return false always.
110      * Subclasses can override if different behaviour expected.
111      */

112     @Override JavaDoc
113     public boolean supportsDefaultValue () {
114         return false;
115     }
116
117     /**
118      * This method returns the property editor.
119      * Overridden to return special editor.
120      */

121     @Override JavaDoc
122     public java.beans.PropertyEditor JavaDoc getPropertyEditor() {
123         return new GlobalReferenceEditor(
124                 getComponent(), typeDisplayName,
125                 getDisplayName(), referenceTypeDisplayName, filterTypes);
126     }
127     
128 }
129
Popular Tags