KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ExternalPackage.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 java.util.*;
17 import java.io.*;
18 import java.net.URL JavaDoc;
19
20 /**
21 * Represents a WfMC DTD element that has the similar name.
22 *
23 * @see XML
24 */

25 public class ExternalPackage extends XMLComplexElement {
26    private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); // min=0
27

28    private XMLAttribute attrHref;
29
30    /** Enables canceling of changes to the extended attributes collection. */
31    private ExtendedAttributes clonedEAs;
32
33    private ExternalPackages myOwner=null;
34    /**
35    * Creates a new instance of the class.
36    *
37    */

38    public ExternalPackage (ExternalPackages eps) {
39       super();
40
41       myOwner=eps;
42       attrHref=new ExternalPackage.AttrHref("href");
43
44       fillStructure();
45    }
46
47    /**
48    * Defines the super-class method. Read the explanation for
49    * this method within XMLComplexElement class.
50    */

51    protected void fillStructure () {
52       super.fillStructure();
53
54       attrHref.setRequired(true);
55       complexStructure.add(attrHref);
56       attributes.add(attrHref);
57       complexStructure.add(refExtendedAttributes);
58    }
59
60    public XMLPanel getPanel () {
61       if (attrHref!=null && attrHref.toString().trim().length()>0) {
62          attrHref.setReadOnly(true);
63       }
64       clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone();
65       return new XMLGroupPanel(this,new XMLElement[] {attrHref,clonedEAs},toLabel());
66    }
67
68    /**
69    * Overrides <code>toString</code> method to return the
70    * path to some external file. This string is used to
71    * visually display the path name into dialog.
72    *
73    * @return The string that represents a path to some file.
74    */

75    public String JavaDoc toString () {
76       return attrHref.toString();
77    }
78
79    public Package JavaDoc getMyPackage() {
80       return (Package JavaDoc)((ExternalPackages)myOwner).getOwner();
81    }
82
83    public ExternalPackages getOwner () {
84       return myOwner;
85    }
86
87    /**
88      * This method is called only if user doesn't press Cancel button
89      * within the dialog for editing ExternalPackage properties, so
90      * the changes to the real collection of ExternalPackage are applied here.
91      * @param groupPanel The panel for editing parameters.
92      * @return always returns <tt>true</tt>.
93      */

94     public boolean isValidEnter (XMLPanel groupPanel) {
95        if (clonedEAs!=null) {
96           complexStructure.remove(refExtendedAttributes);
97           refExtendedAttributes=clonedEAs;
98           complexStructure.add(1,refExtendedAttributes);
99        }
100        return true;
101     }
102
103     public class AttrHref extends XMLAttribute {
104        AttrHref (String JavaDoc name) {
105           super(name);
106        }
107
108        public void setValue (Object JavaDoc v) {
109           try {
110              Path path=new Path(v.toString());
111              String JavaDoc repBS=Path.getRelativePath(
112                    path,
113                    new Path(((Package JavaDoc)myOwner.getOwner()).getXMLInterface().getParentDirectory((Package JavaDoc)myOwner.getOwner())));
114              value=XMLUtil.replaceBackslashesWithSlashes(repBS);
115           } catch (Exception JavaDoc ex2) {
116              value=v;
117           }
118        }
119
120        public void setPathDirectly (String JavaDoc path) {
121           value=XMLUtil.replaceBackslashesWithSlashes(path);
122        }
123
124        public XMLPanel getPanel () {
125           return new XMLLocationPanel(this,XMLPanel.BOX_LAYOUT,0);
126        }
127     }
128
129 }
130
Popular Tags