1 19 20 26 27 package org.netbeans.modules.xml.schema.ui.nodes.schema.properties; 28 29 import java.beans.PropertyEditor ; 30 import java.lang.reflect.InvocationTargetException ; 31 import java.util.Collection ; 32 import java.util.List ; 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 45 public class MemberTypesProperty extends BaseSchemaProperty { 46 47 59 public MemberTypesProperty(SchemaComponent component, String property, 60 String dispName, String desc) 61 throws NoSuchMethodException { 62 super(component, 63 Collection .class, 64 component.getClass().getMethod(BaseSchemaProperty. 66 firstLetterToUpperCase(property, "get"), new Class [0]), 67 null, 70 property, 71 dispName, 72 desc, 73 MemberTypesEditor.class 74 ); 75 } 76 77 @SuppressWarnings ("unchecked") 78 public void setValue(Object o) throws IllegalAccessException , InvocationTargetException { 79 List <NamedComponentReference<GlobalSimpleType>> oldSelectionRef = 80 (List <NamedComponentReference<GlobalSimpleType>>) getValue(); 81 List <NamedComponentReference<GlobalSimpleType>> newSelectionRef = 82 (List <NamedComponentReference<GlobalSimpleType>>) o; 83 int oIdx = 0; 84 int nIdx = 0; 85 Union unoin = (Union)super.getComponent(); 86 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 getPropertyEditor() { 107 return new MemberTypesEditor(super.getComponent()); 108 } 109 110 } 111 | Popular Tags |