KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > elements > TypeDeclaration


1 /* TypeDeclaration.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

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 /**
21 * Represents a WfMC DTD element that has the similar name.
22 *
23 * @see XML
24 */

25 public class TypeDeclaration extends XMLCollectionElement {
26
27    private DataTypes refType;
28    private Description refDescription=new Description(); // min=0
29
private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this);
30
31    private XMLAttribute attrName=new XMLAttribute("Name");
32
33    /** Enables canceling of changes to the extended attributes collection. */
34    private ExtendedAttributes clonedEAs;
35
36    /**
37    * Creates a new instance of the class.
38    * @param tds The reference to collection of type declarations where
39    * this instance will be put into.
40    */

41    public TypeDeclaration(TypeDeclarations tds,Package JavaDoc p) {
42       super(tds);
43
44       refType=new DataTypes(this,p,null,0);
45
46       fillStructure();
47    }
48
49    /**
50    * Defines the super-class method. Read the explanation for
51    * this method within XMLComplexElement class.
52    */

53    protected void fillStructure () {
54       super.fillStructure();
55       complexStructure.add(attrName);
56       //attrName.setRequired(true);
57
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    /**
71    * Overrides super-class method to retreive the value
72    * of this class "Name" attribute.
73    * This is used when displaying instance of this class
74    * within dialog.
75    *
76    * @return The "Name" attribute value of this class.
77    */

78    public String JavaDoc toString () {
79       String JavaDoc disp=attrName.toString();
80       if (disp.trim().length()==0) {
81          disp=attrId.toString().trim();
82       }
83       return disp;
84    }
85
86    /**
87    * Checks if an ID entered by the user is unique.
88    */

89    public boolean isIDUniqueAndValid (XMLPanel groupPanel) {
90       XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0);
91       String JavaDoc IDToCheck=tp.getText();
92       // if there is an element with given ID, return false
93
XMLComplexElement td=getCollection().getCollectionElement(IDToCheck);
94       boolean isOK=true;
95       String JavaDoc message=null;
96       String JavaDoc 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    /**
114    * Overrides parent method to display data type details for BasicType and
115    * for DeclaredType.
116    */

117    public Collection toComplexTypeValues () {
118       java.util.List JavaDoc 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 JavaDoc 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 /*
141     private Description refDescription=new Description(); // min=0
142     private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this);
143 */

144
145    /**
146      * This method is called only if user doesn't press Cancel button
147      * within the dialog for editing TypeDeclaration properties, so
148      * the changes to the real collection of TypeDeclaration are applied here.
149      * @param groupPanel The panel for editing parameters.
150      * @return always returns <tt>true</tt>.
151      */

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 JavaDoc getPackage () {
162        return (Package JavaDoc)((TypeDeclarations)getCollection()).getOwner();
163     }
164 }
165
Popular Tags