1 10 11 package org.enhydra.jawe.xml.elements; 12 13 import org.enhydra.jawe.xml.*; 14 import org.enhydra.jawe.xml.panels.*; 15 16 import org.w3c.dom.*; 17 18 23 public class DeclaredType extends XMLComplexElement { 24 25 private transient TypeDeclarations declaredTypes=null; 26 27 private XMLAttribute attrId=new XMLAttribute("Id"); 29 30 private transient XMLComplexChoice helperElement; 31 32 38 public DeclaredType (Package p) { 39 super(); 40 41 try { 42 declaredTypes=(TypeDeclarations)p.get("TypeDeclarations"); 43 } 44 catch (NullPointerException npe) { 45 } 47 48 helperElement=new XMLComplexChoice("SubType",null,0) { 49 public XMLPanel getPanel () { 50 if (declaredTypes!=null) { 51 choices=declaredTypes.toCollection().toArray(); 52 try { 53 this.setValue(declaredTypes. 56 getDeclaredType(attrId.toValue().toString())); 57 } catch (Exception ex) { 58 } 60 } 61 else { 62 choices=null; 63 } 64 return new XMLComboButtonPanel(this,declaredTypes); 65 } 66 67 public void setReadOnly (boolean ro) { 68 this.isReadOnly=ro; 69 } 70 71 public void setValue (Object v) { 72 super.setValue(v); 73 try { 74 attrId.setValue(((XMLCollectionElement)this.getChoosen()). 75 getID()); 76 } catch (Exception ex) {} 77 } 78 79 }; 80 81 fillStructure(); 82 } 83 84 88 protected void fillStructure () { 89 attrId.setRequired(true); 90 attributes.add(attrId); 91 complexStructure.add(attrId); 92 helperElement.setLabelName(XMLUtil.getLanguageDependentString("SubTypeKey")); 93 helperElement.setRequired(true); 94 complexStructure.add(helperElement); 95 } 96 97 103 public void toXML (Node parent) throws DOMException { 104 Object val=attrId.toValue(); 108 complexStructure.remove(1); 109 super.toXML(parent); 110 complexStructure.add(1,helperElement); 111 } 112 113 119 public void fromXML (Node node) { 120 super.fromXML(node); 121 helperElement.setValue(declaredTypes.getDeclaredType(attrId.toValue().toString())); 123 } 124 125 132 public Object clone () { 133 DeclaredType dt=(DeclaredType)super.clone(); 134 dt.helperElement=new XMLComplexChoice("SubType",null,0) { 135 public XMLPanel getPanel () { 136 if (declaredTypes!=null) { 137 choices=declaredTypes.toCollection().toArray(); 138 } 139 else { 140 choices=null; 141 } 142 return new XMLComboButtonPanel(this,declaredTypes); 143 } 144 }; 145 dt.helperElement.setValue(helperElement.getChoosen()); 146 147 dt.declaredTypes=this.declaredTypes; 148 149 dt.fillStructure(); 150 151 return dt; 152 } 153 154 160 public XMLPanel getPanel () { 161 return helperElement.getPanel(); 162 } 163 164 } 165 | Popular Tags |