KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class Application extends XMLCollectionElement {
24    private Description refDescription=new Description(); // min=0
25
// can be FormalParameters or ExternalReference
26
// if fp->must be defined,if er->min=0
27
private XMLComplexChoice refChoice;
28
29    private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); // min=0
30
private XMLAttribute attrName=new XMLAttribute("Name");
31
32    /** Usefull to determine if this application is external to some collection or not.*/
33    private transient Package JavaDoc myPackage=null;
34
35    /** Enables canceling of changes to the extended attributes collection. */
36    private ExtendedAttributes clonedEAs;
37
38    /**
39    * Creates a new instance of the class.
40    *
41    * @param aps The reference to collection of applications where
42    * this instance will be put into.
43    * @param p The package where applications are defined.
44    */

45    public Application (Applications aps,Package JavaDoc p) {
46       super(aps);
47
48       myPackage=p;
49
50       refChoice=new XMLComplexChoice("Choice",
51          new XMLElement[] {new FormalParameters(this,p),
52             new ExternalReference()},0,true) {
53
54             public void setValue (Object JavaDoc v) {
55                super.setValue(v);
56                if (v==choices[1]) {
57                   ((FormalParameters)choices[0]).clear();
58                } else if (v==choices[0]) {
59                   ExternalReference er=(ExternalReference)choices[1];
60                   er.set("xref","");
61                   er.set("location","");
62                   er.set("namespace","");
63                }
64             }
65       };
66
67       // setting the prefix for generation of formal parameters
68
String JavaDoc idPref=getID()+this.ID_DELIMITER+"For";
69       FormalParameters fps=(FormalParameters)refChoice.getChoices()[0];
70       fps.setIDPrefix(idPref);
71
72       fillStructure();
73    }
74
75    /**
76    * Defines the super-class method. Read the explanation for
77    * this method within XMLComplexElement class.
78    */

79    protected void fillStructure () {
80       super.fillStructure();
81       //attrName.setRequired(true);
82
complexStructure.add(attrName);
83       attributes.add(attrName);
84       complexStructure.add(refDescription);
85       complexStructure.add(refChoice);
86       complexStructure.add(refExtendedAttributes);
87    }
88
89    public XMLPanel getPanel () {
90       clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone();
91       return new XMLGroupPanel(this,new XMLElement[] {attrId,attrName,refDescription,refChoice,clonedEAs},toLabel());
92    }
93
94    /**
95    * Overrides super-class method to retreive the value
96    * of this class "Name" attribute.
97    * This is used when displaying instance of this class
98    * within dialog.
99    *
100    * @return The "Name" attribute value of this class.
101    */

102    public String JavaDoc toString () {
103       String JavaDoc disp=attrName.toString();
104       if (disp.trim().length()==0) {
105          disp=attrId.toString();
106       }
107       return disp;
108    }
109
110    /**
111    * Used to determine if application is external to some collection.
112    *
113    * @return Package of application.
114    */

115    public Package JavaDoc getPackage() {
116       return myPackage;
117    }
118
119    public void fromXML(Node node) {
120       processAttributes(node);
121
122       // setting the prefix for generation of formal parameters
123
String JavaDoc idPref=getID()+this.ID_DELIMITER+"For";
124       FormalParameters fps=(FormalParameters)refChoice.getChoices()[0];
125       fps.setIDPrefix(idPref);
126
127       processElements(node);
128
129       ((Applications)myCollection).updateID(getID());
130    }
131
132    /**
133    * Checks if an ID entered by the user is unique.
134    */

135    public boolean isIDUniqueAndValid (XMLPanel groupPanel) {
136       XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0);
137       String JavaDoc IDToCheck=tp.getText();
138       // if there is an element with given ID, return false
139
XMLComplexElement app=getCollection().getCollectionElement(IDToCheck);
140       boolean isOK=true;
141       String JavaDoc message=null;
142       String JavaDoc dialogTitle=null;
143       if (app!=null && app!=this) {
144          message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique");
145          dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique");
146          isOK=false;
147       } else if (!XMLCollection.isIdValid(IDToCheck)) {
148          message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid");
149          dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid");
150          isOK=false;
151       }
152       if (!isOK) {
153          XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message);
154          ((JTextField)tp.getComponent(2)).requestFocus();
155       }
156       return isOK;
157    }
158
159    /**
160      * This method is called only if user doesn't press Cancel button
161      * within the dialog for editing Application properties, so
162      * the changes to the real collection of Applications are applied here.
163      * @param groupPanel The panel for editing parameters.
164      * @return always returns <tt>true</tt>.
165      */

166     public boolean isValidEnter (XMLPanel groupPanel) {
167        if (clonedEAs!=null) {
168           complexStructure.remove(refExtendedAttributes);
169           refExtendedAttributes=clonedEAs;
170           complexStructure.add(4,refExtendedAttributes);
171        }
172        return true;
173     }
174
175 }
176
Popular Tags