KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ExtendedAttribute.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 javax.swing.*;
14
15 import org.enhydra.jawe.xml.*;
16 import org.enhydra.jawe.xml.panels.*;
17
18 /**
19 * Helper class.
20 */

21 public class Namespace extends XMLComplexElement {
22    private XMLAttribute attrName=new XMLAttribute("Name"); // required
23
private XMLAttribute attrLocation=new XMLAttribute("location"); //required
24

25    /**
26    * Creates a new instance of the class.
27    */

28    public Namespace () {
29       super();
30
31       fillStructure ();
32    }
33
34    /**
35    * Defines the super-class method. Read the explanation for
36    * this method within XMLComplexElement class.
37    */

38    protected void fillStructure () {
39       attrName.setRequired(true);
40       attrLocation.setRequired(true);
41       complexStructure.add(attrName);
42       attributes.add(attrName);
43       complexStructure.add(attrLocation);
44       attributes.add(attrLocation);
45    }
46
47    /**
48    * Prepares the panel for showing extended attribute of
49    * some XML element.
50    *
51    * @return XMLPanel to be shown.
52    */

53    public XMLPanel getPanel () {
54       return new XMLGroupPanel (this,new XMLElement[] {attrName,attrLocation},toLabel());
55    }
56
57    public String JavaDoc toString () {
58       String JavaDoc toRet=XMLUtil.getLanguageDependentString("NameKey")+"="+attrName.toString()+", "+
59           XMLUtil.getLanguageDependentString("locationKey")+"="+attrLocation.toString();
60       if (toRet==null) {
61          return "";
62       } else {
63          return toRet;
64       }
65    }
66
67    /**
68    * Used to create exact copy of instance of this class.
69    * The newly created instance will have all the properties
70    * same as the copied one.
71    *
72    * @return The newly created instance of this class.
73    */

74    public Object JavaDoc clone () {
75       Namespace ns=(Namespace)super.clone();
76       ns.attrName=(XMLAttribute)this.attrName.clone();
77       ns.attrLocation=(XMLAttribute)this.attrLocation.clone();
78       ns.fillStructure();
79       return ns;
80    }
81
82    /**
83     * This method checks if the value of the name attribute is valid.
84     */

85    public boolean isValidEnter (XMLPanel p) {
86       XMLGroupPanel gp=(XMLGroupPanel)p;
87       try {
88          XMLTextPanel tp=(XMLTextPanel)gp.getPanel(0);
89          String JavaDoc nameToCheck=tp.getText();
90          if (!XMLCollection.isIdValid(nameToCheck)) {
91             String JavaDoc message=XMLUtil.getLanguageDependentString("ErrorValueIsNotValid");
92             String JavaDoc dialogTitle=XMLUtil.getLanguageDependentString("Title");
93             XMLPanel.errorMessage(p.getDialog(),dialogTitle,attrName.toLabel()+": ",message);
94             ((JTextField)tp.getComponent(2)).requestFocus();
95             return false;
96          }
97       } catch (Exception JavaDoc ex){}
98
99       return true;
100    }
101
102 }
103
Popular Tags