KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > schema > properties > MemberTypesProperty


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  * BooleanProperty.java
22  *
23  * Created on January 5, 2006, 3:21 PM
24  *
25  */

26
27 package org.netbeans.modules.xml.schema.ui.nodes.schema.properties;
28
29 import java.beans.PropertyEditor JavaDoc;
30 import java.lang.reflect.InvocationTargetException JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.List JavaDoc;
33 import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
34 import org.netbeans.modules.xml.schema.model.SchemaComponent;
35 import org.netbeans.modules.xml.schema.model.Union;
36 import org.netbeans.modules.xml.schema.ui.basic.editors.MemberTypesEditor;
37 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
38
39 /**
40  * This class provides property support for properties having boolean values.
41  * It provides support for properties which default to null or to false
42  * when not specified.
43  * @author Ajit Bhate
44  */

45 public class MemberTypesProperty extends BaseSchemaProperty {
46     
47     /**
48      * Creates a new instance of MemberTypesProperty.
49      *
50      * @param component The schema component which property belongs to.
51      * @param property The property name.
52      * @param propDispName The display name of the property.
53      * @param propDesc Short description about the property.
54      * @param isDefaultFalse If the default value for this property is false.
55      * In such case BooleanDefaultFalseEditor will be used as propertyeditor,
56      * BooleanEditor otherwise which supports null as default values.
57      * @throws java.lang.NoSuchMethodException If no getter and setter for the property are found
58      */

59     public MemberTypesProperty(SchemaComponent component, String JavaDoc property,
60             String JavaDoc dispName, String JavaDoc desc)
61             throws NoSuchMethodException JavaDoc {
62         super(component,
63                 Collection JavaDoc.class,
64                 // The getter method for schema properties start with is
65
component.getClass().getMethod(BaseSchemaProperty.
66                 firstLetterToUpperCase(property, "get"), new Class JavaDoc[0]),
67 // component.getClass().getMethod(firstLetterToUpperCase(
68
// property, "set"), new Class[]{Boolean.class}),
69
null,
70                 property,
71                 dispName,
72                 desc,
73                 MemberTypesEditor.class
74                 );
75     }
76     
77     @SuppressWarnings JavaDoc("unchecked")
78     public void setValue(Object JavaDoc o) throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
79         List JavaDoc<NamedComponentReference<GlobalSimpleType>> oldSelectionRef =
80                 (List JavaDoc<NamedComponentReference<GlobalSimpleType>>) getValue();
81         List JavaDoc<NamedComponentReference<GlobalSimpleType>> newSelectionRef =
82                 (List JavaDoc<NamedComponentReference<GlobalSimpleType>>) o;
83         int oIdx = 0;
84         int nIdx = 0;
85         Union unoin = (Union)super.getComponent();
86         // try to minimize updates
87
if(oldSelectionRef!= null && newSelectionRef != null) {
88             for (;oIdx<oldSelectionRef.size()&&nIdx<newSelectionRef.size();oIdx++) {
89                 if(!oldSelectionRef.get(oIdx).equals(newSelectionRef.get(nIdx))) {
90                     unoin.removeMemberType(oldSelectionRef.get(oIdx));
91                 } else {
92                     nIdx++;
93                 }
94             }
95         }
96         if(oldSelectionRef!=null) {
97             for(int i=oIdx;i<oldSelectionRef.size();i++)
98                 unoin.removeMemberType(oldSelectionRef.get(i));
99         }
100         if(newSelectionRef!=null) {
101             for(int i=nIdx;i<newSelectionRef.size();i++)
102                 unoin.addMemberType(newSelectionRef.get(i));
103         }
104     }
105
106     public PropertyEditor JavaDoc getPropertyEditor() {
107         return new MemberTypesEditor(super.getComponent());
108     }
109     
110 }
111
Popular Tags