KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* DataField.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 org.w3c.dom.*;
17 import java.util.*;
18 import javax.swing.*;
19
20 /**
21 * Represents a WfMC DTD element that has the similar name.
22 *
23 * @see XML
24 */

25 public class DataField extends XMLCollectionElement {
26    private transient Package JavaDoc myPackage;
27
28    private DataType refDataType;
29    private InitialValue refInitialValue=new InitialValue(); // min=0
30
private Length refLength=new Length(); // min=0
31
private Description refDescription=new Description(); // min=0
32
private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); // min=0
33

34    private XMLAttribute attrName=new XMLAttribute("Name");
35    // default="FALSE"
36
private XMLAttribute attrIsArray=new XMLAttribute("IsArray",
37       new String JavaDoc[] {
38          "",
39          "TRUE",
40          "FALSE"
41       },2);
42
43    /** Enables canceling of changes to the extended attributes collection. */
44    private ExtendedAttributes clonedEAs;
45
46    /**
47    * Creates a new instance of the class.
48    *
49    * @param dfs The reference to collection of data fields where
50    * this instance will be put into.
51    * @param porw The class instance which member is this class instance.
52    */

53    public DataField (DataFields dfs,XMLComplexElement porw) {
54       super(dfs);
55
56       try {
57          if (porw instanceof Package JavaDoc) {
58             this.myPackage=(Package JavaDoc)porw;
59             refDataType=new DataType((Package JavaDoc)porw); // must be defined
60
}
61          else {
62             this.myPackage=((WorkflowProcess)porw).getPackage();
63             refDataType=new DataType(((WorkflowProcess)porw).getPackage()); // must be defined
64
}
65       } catch (Exception JavaDoc ex) {}
66
67       fillStructure();
68    }
69
70    /**
71    * Defines the super-class method. Read the explanation for
72    * this method within XMLComplexElement class.
73    */

74    protected void fillStructure () {
75       super.fillStructure();
76       // allow ID to be modified
77
attrId.setValue("");
78       //attrName.setRequired(true);
79
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    /**
109    * Overrides super-class method to return an attribute
110    * specific XML input.
111    */

112    public void fromXML(Node node) {
113       attrIsArray.setValue("");
114       super.fromXML(node);
115    }
116
117    /**
118    * Overrides the super class method to return the value
119    * of it's "Name" attribute value.
120    *
121    * @return The value of this class "Name" attribute.
122    */

123    public Object JavaDoc toValue () {
124       return attrName.toValue();
125    }
126
127    /**
128    * Checks if an ID entered by the user is unique.
129    */

130    public boolean isIDUniqueAndValid (XMLPanel groupPanel) {
131       XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0);
132       String JavaDoc IDToCheck=tp.getText();
133       // if there is an element with given ID, return false
134
XMLComplexElement df=((DataFields)getCollection()).getCollectionElement(IDToCheck);
135       boolean isOK=true;
136       String JavaDoc message=null;
137       String JavaDoc 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    /**
155    * Overrides super-class method to retreive the value
156    * of this class "Id" attribute.
157    * This is used when displaying instance of this class
158    * within dialog.
159    *
160    * @return The "Id" attribute value of this class.
161    */

162    public String JavaDoc toString () {
163       return attrId.toString();
164    }
165
166    /**
167      * This method is called only if user doesn't press Cancel button
168      * within the dialog for editing DataField properties, so
169      * the changes to the real collection of DataField are applied here.
170      * @param p The panel for editing parameters.
171      * @return always returns <tt>true</tt>.
172      */

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    /**
183    * Overrides parent method to display data type details for BasicType and
184    * for DeclaredType.
185    */

186    public Collection toComplexTypeValues () {
187       java.util.List JavaDoc 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 JavaDoc 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 JavaDoc getPackage () {
212       return myPackage;
213    }
214
215 }
216
Popular Tags