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: /*
043: * BooleanProperty.java
044: *
045: * Created on January 5, 2006, 3:21 PM
046: *
047: */
048:
049: package org.netbeans.modules.xml.schema.ui.nodes.schema.properties;
050:
051: import java.beans.PropertyEditor;
052: import java.lang.reflect.InvocationTargetException;
053: import java.util.Collection;
054: import java.util.List;
055: import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
056: import org.netbeans.modules.xml.schema.model.SchemaComponent;
057: import org.netbeans.modules.xml.schema.model.Union;
058: import org.netbeans.modules.xml.schema.ui.basic.editors.MemberTypesEditor;
059: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
060:
061: /**
062: * This class provides property support for properties having boolean values.
063: * It provides support for properties which default to null or to false
064: * when not specified.
065: * @author Ajit Bhate
066: */
067: public class MemberTypesProperty extends BaseSchemaProperty {
068:
069: /**
070: * Creates a new instance of MemberTypesProperty.
071: *
072: * @param component The schema component which property belongs to.
073: * @param property The property name.
074: * @param propDispName The display name of the property.
075: * @param propDesc Short description about the property.
076: * @param isDefaultFalse If the default value for this property is false.
077: * In such case BooleanDefaultFalseEditor will be used as propertyeditor,
078: * BooleanEditor otherwise which supports null as default values.
079: * @throws java.lang.NoSuchMethodException If no getter and setter for the property are found
080: */
081: public MemberTypesProperty(SchemaComponent component,
082: String property, String dispName, String desc)
083: throws NoSuchMethodException {
084: super (component, Collection.class,
085: // The getter method for schema properties start with is
086: component.getClass().getMethod(
087: BaseSchemaProperty.firstLetterToUpperCase(
088: property, "get"), new Class[0]),
089: // component.getClass().getMethod(firstLetterToUpperCase(
090: // property, "set"), new Class[]{Boolean.class}),
091: null, property, dispName, desc, MemberTypesEditor.class);
092: }
093:
094: @SuppressWarnings("unchecked")
095: public void setValue(Object o) throws IllegalAccessException,
096: InvocationTargetException {
097: List<NamedComponentReference<GlobalSimpleType>> oldSelectionRef = (List<NamedComponentReference<GlobalSimpleType>>) getValue();
098: List<NamedComponentReference<GlobalSimpleType>> newSelectionRef = (List<NamedComponentReference<GlobalSimpleType>>) o;
099: int oIdx = 0;
100: int nIdx = 0;
101: Union unoin = (Union) super .getComponent();
102: // try to minimize updates
103: if (oldSelectionRef != null && newSelectionRef != null) {
104: for (; oIdx < oldSelectionRef.size()
105: && nIdx < newSelectionRef.size(); oIdx++) {
106: if (!oldSelectionRef.get(oIdx).equals(
107: newSelectionRef.get(nIdx))) {
108: unoin.removeMemberType(oldSelectionRef.get(oIdx));
109: } else {
110: nIdx++;
111: }
112: }
113: }
114: if (oldSelectionRef != null) {
115: for (int i = oIdx; i < oldSelectionRef.size(); i++)
116: unoin.removeMemberType(oldSelectionRef.get(i));
117: }
118: if (newSelectionRef != null) {
119: for (int i = nIdx; i < newSelectionRef.size(); i++)
120: unoin.addMemberType(newSelectionRef.get(i));
121: }
122: }
123:
124: public PropertyEditor getPropertyEditor() {
125: return new MemberTypesEditor(super.getComponent());
126: }
127:
128: }
|