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 javax.swing.*; 17 import java.util.*; 18 import javax.swing.tree.*; 19 20 25 public class TypeDeclaration extends XMLCollectionElement { 26 27 private DataTypes refType; 28 private Description refDescription=new Description(); private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 30 31 private XMLAttribute attrName=new XMLAttribute("Name"); 32 33 34 private ExtendedAttributes clonedEAs; 35 36 41 public TypeDeclaration(TypeDeclarations tds,Package p) { 42 super(tds); 43 44 refType=new DataTypes(this,p,null,0); 45 46 fillStructure(); 47 } 48 49 53 protected void fillStructure () { 54 super.fillStructure(); 55 complexStructure.add(attrName); 56 attributes.add(attrName); 58 refType.setRequired(true); 59 complexStructure.add(refType); 60 complexStructure.add(refDescription); 61 complexStructure.add(refExtendedAttributes); 62 } 63 64 public XMLPanel getPanel () { 65 clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone(); 66 return new XMLGroupPanel(this,new XMLElement[] {attrId,attrName,refType, 67 refDescription,clonedEAs},toLabel()); 68 } 69 70 78 public String toString () { 79 String disp=attrName.toString(); 80 if (disp.trim().length()==0) { 81 disp=attrId.toString().trim(); 82 } 83 return disp; 84 } 85 86 89 public boolean isIDUniqueAndValid (XMLPanel groupPanel) { 90 XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0); 91 String IDToCheck=tp.getText(); 92 XMLComplexElement td=getCollection().getCollectionElement(IDToCheck); 94 boolean isOK=true; 95 String message=null; 96 String dialogTitle=null; 97 if (td!=null && td!=this) { 98 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique"); 99 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique"); 100 isOK=false; 101 } else if (!XMLCollection.isIdValid(IDToCheck)) { 102 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid"); 103 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid"); 104 isOK=false; 105 } 106 if (!isOK) { 107 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message); 108 ((JTextField)tp.getComponent(2)).requestFocus(); 109 } 110 return isOK; 111 } 112 113 117 public Collection toComplexTypeValues () { 118 java.util.List l=new ArrayList(); 119 Iterator it=complexStructure.iterator(); 120 while (it.hasNext()) { 121 XMLElement el=(XMLElement)it.next(); 122 if (el instanceof XMLAttribute) { 123 l.add(el.toString()); 124 } else if (el instanceof DataTypes) { 125 Object type=((DataTypes)el).toValue(); 126 if (type instanceof BasicType) { 127 l.add(el.toValue()+" - "+((XMLAttribute)((BasicType)type).get("Type")).getChoosen()); 128 } else if (type instanceof DeclaredType) { 129 l.add(el.toValue()+" - "+((XMLComplexChoice)((DeclaredType)type).get("SubType")).getChoosen()); 130 } else { 131 l.add(el.toValue()); 132 } 133 } else { 134 l.add(el.toValue()); 135 } 136 } 137 return l; 138 } 139 140 144 145 152 public boolean isValidEnter (XMLPanel groupPanel) { 153 if (clonedEAs!=null) { 154 complexStructure.remove(refExtendedAttributes); 155 refExtendedAttributes=clonedEAs; 156 complexStructure.add(4,refExtendedAttributes); 157 } 158 return true; 159 } 160 161 public Package getPackage () { 162 return (Package )((TypeDeclarations)getCollection()).getOwner(); 163 } 164 } 165 | Popular Tags |