KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > model > DesignElementType


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.model;
5
6 import java.util.Observable JavaDoc;
7 import java.util.Observer JavaDoc;
8
9 import org.oddjob.arooa.reflect.IntrospectionHelper;
10 import org.oddjob.designer.arooa.DesignIH;
11 import org.oddjob.designer.elements.simple.SimpleTextAttribute;
12
13
14
15 /**
16  * A DesignElementType is a DesignElement which can be created
17  * from a factory. These are the configuration elements for the
18  * ValueType objects that appear in Variables and Lists.
19  *
20  * @author Rob Gordon.
21  */

22 abstract public class DesignElementType extends DesignAdult
23 implements DesignElement {
24
25     protected Observer JavaDoc detailObserver = new Observer JavaDoc() {
26         public void update(Observable JavaDoc o, Object JavaDoc arg) {
27             setChanged();
28             notifyObservers(DEObservable.detailChanged(o));
29         };
30     };
31     
32     /**
33      * This is here so that all DesignElementType objects can be
34      * used as named values (in variables for instance).
35      * Probably there should be a better way.
36      */

37     private SimpleTextAttribute name;
38         
39     /**
40      * The name of the type used to create this DesignElementType
41      * in a factory. This is the element name when this is
42      * serialized to XML.
43      */

44     private String JavaDoc type;
45
46     /**
47      * Constructor.
48      */

49     public DesignElementType() {
50         setName(new SimpleTextAttribute());
51     }
52     
53     /**
54      * Set the type. This will be called by the factory after
55      * creation.
56      *
57      * @param type
58      */

59     public void type(String JavaDoc type) {
60         this.type = type;
61     }
62     
63     /**
64      * Get the type. This is used as the element name.
65      *
66      * @return The type.
67      */

68     public String JavaDoc type() {
69         return type;
70     }
71     
72     /**
73      * Set the name.
74      *
75      * @param name The name.
76      */

77     public void setName(SimpleTextAttribute name) {
78         name.addObserver(detailObserver);
79         this.name = name;
80     }
81     
82     /**
83      * Get the name.
84      *
85      * @return The name.
86      */

87     public SimpleTextAttribute getName() {
88         return name;
89     }
90
91     public boolean hasDetail() {
92         try {
93             getClass().getDeclaredMethod("detail", new Class JavaDoc[0]);
94             return true;
95         } catch (NoSuchMethodException JavaDoc e) {
96             return false;
97         }
98     }
99     
100     /**
101      * The method is overridden by sub classes which have a detailed
102      * definition for their configuration.
103      *
104      * @return The DesignDefinition for their configuration.
105      */

106     public DesignDefinition detail() {
107         throw new IllegalStateException JavaDoc("Check hasDetail first!");
108     }
109         
110     /**
111      * Clear the DesignElement of Data. This method will be called when a selection
112      * changes.
113      */

114     public void clear() {
115         name.clear();
116         clearChildren();
117     }
118 }
119
Popular Tags