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 import java.util.*; 18 import javax.swing.*; 19 20 25 public class DataField extends XMLCollectionElement { 26 private transient Package myPackage; 27 28 private DataType refDataType; 29 private InitialValue refInitialValue=new InitialValue(); private Length refLength=new Length(); private Description refDescription=new Description(); private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 34 private XMLAttribute attrName=new XMLAttribute("Name"); 35 private XMLAttribute attrIsArray=new XMLAttribute("IsArray", 37 new String [] { 38 "", 39 "TRUE", 40 "FALSE" 41 },2); 42 43 44 private ExtendedAttributes clonedEAs; 45 46 53 public DataField (DataFields dfs,XMLComplexElement porw) { 54 super(dfs); 55 56 try { 57 if (porw instanceof Package ) { 58 this.myPackage=(Package )porw; 59 refDataType=new DataType((Package )porw); } 61 else { 62 this.myPackage=((WorkflowProcess)porw).getPackage(); 63 refDataType=new DataType(((WorkflowProcess)porw).getPackage()); } 65 } catch (Exception ex) {} 66 67 fillStructure(); 68 } 69 70 74 protected void fillStructure () { 75 super.fillStructure(); 76 attrId.setValue(""); 78 complexStructure.add(attrName); 80 attributes.add(attrName); 81 complexStructure.add(attrIsArray); 82 attributes.add(attrIsArray); 83 refDataType.setRequired(true); 84 complexStructure.add(refDataType); 85 complexStructure.add(refInitialValue); 86 complexStructure.add(refLength); 87 complexStructure.add(refDescription); 88 complexStructure.add(refExtendedAttributes); 89 } 90 91 public XMLPanel getPanel () { 92 clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone(); 93 XMLPanel p=new XMLGroupPanel(this, 94 new XMLElement[] { 95 attrId, 96 attrName, 97 attrIsArray, 98 refDataType, 99 refInitialValue, 100 refLength, 101 refDescription, 102 clonedEAs 103 },toLabel()); 104 105 return p; 106 } 107 108 112 public void fromXML(Node node) { 113 attrIsArray.setValue(""); 114 super.fromXML(node); 115 } 116 117 123 public Object toValue () { 124 return attrName.toValue(); 125 } 126 127 130 public boolean isIDUniqueAndValid (XMLPanel groupPanel) { 131 XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0); 132 String IDToCheck=tp.getText(); 133 XMLComplexElement df=((DataFields)getCollection()).getCollectionElement(IDToCheck); 135 boolean isOK=true; 136 String message=null; 137 String dialogTitle=null; 138 if (df!=null && df!=this) { 139 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique"); 140 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique"); 141 isOK=false; 142 } else if (!XMLCollection.isIdValid(IDToCheck)) { 143 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid"); 144 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid"); 145 isOK=false; 146 } 147 if (!isOK) { 148 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message); 149 ((JTextField)tp.getComponent(2)).requestFocus(); 150 } 151 return isOK; 152 } 153 154 162 public String toString () { 163 return attrId.toString(); 164 } 165 166 173 public boolean isValidEnter (XMLPanel p) { 174 if (clonedEAs!=null) { 175 complexStructure.remove(refExtendedAttributes); 176 refExtendedAttributes=clonedEAs; 177 complexStructure.add(7,refExtendedAttributes); 178 } 179 return true; 180 } 181 182 186 public Collection toComplexTypeValues () { 187 java.util.List l=new ArrayList(); 188 Iterator it=complexStructure.iterator(); 189 while (it.hasNext()) { 190 XMLElement el=(XMLElement)it.next(); 191 if (el instanceof XMLAttribute) { 192 l.add(el.toString()); 193 } else if (el instanceof DataType) { 194 DataType dt=(DataType)el; 195 DataTypes dtt=(DataTypes)dt.get("Type"); 196 Object type=dtt.toValue(); 197 if (type instanceof BasicType) { 198 l.add(el.toValue()+" - "+((XMLAttribute)((BasicType)type).get("Type")).getChoosen()); 199 } else if (type instanceof DeclaredType) { 200 l.add(el.toValue()+" - "+((XMLComplexChoice)((DeclaredType)type).get("SubType")).getChoosen()); 201 } else { 202 l.add(el.toValue()); 203 } 204 } else { 205 l.add(el.toValue()); 206 } 207 } 208 return l; 209 } 210 211 public Package getPackage () { 212 return myPackage; 213 } 214 215 } 216 | Popular Tags |