KickJava   Java API By Example, From Geeks To Geeks.

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


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.designer.Looks;
10 import org.oddjob.designer.arooa.DesignIH;
11
12 /**
13  * A model for a DesignElement which can contain
14  * multiple child DesignElements of various types.
15  * This model supports both name types, as used in a Map
16  * or unnamed types as used in a List.
17  * <p>
18  * This model is Observable and will update observers when
19  * a child DesignElement changes.
20  */

21 public class MultiTypeTable extends Observable JavaDoc
22 implements DesignDefinition {
23     
24     private final String JavaDoc heading;
25     private final DesignElementType designElement;
26     private int visibleRows = Looks.LIST_ROWS;
27     private boolean named;
28     
29     private final Observer JavaDoc observer = new Observer JavaDoc() {
30         public void update(Observable JavaDoc o, Object JavaDoc arg) {
31             setChanged();
32             notifyObservers();
33         }
34     };
35     
36     public MultiTypeTable(String JavaDoc heading, DesignElementType de) {
37         this.heading = heading;
38         this.designElement = de;
39         designElement.addObserver(observer);
40         for (int i = 0; i < de.childCount(); ++i) {
41             de.children()[i].addObserver(observer);
42         }
43     }
44
45     public String JavaDoc getTitle() {
46         return heading;
47     }
48
49     public DesignElementType getDesignElement() {
50         return designElement;
51     }
52     
53     /* (non-Javadoc)
54      * @see org.oddjob.designer.model.DialogDefinition#accept(org.oddjob.designer.model.DialogProcessor)
55      */

56     public void accept(DesignProcessor processor) {
57         processor.onMulipleTypeTable(this);
58     }
59     
60     /**
61      * @return Returns the named.
62      */

63     public boolean isNamed() {
64         return named;
65     }
66     
67     /**
68      * @param named The named to set.
69      */

70     public MultiTypeTable setNamed(boolean named) {
71         this.named = named;
72         return this;
73     }
74     
75     /* (non-Javadoc)
76      * @see org.oddjob.designer.model.DesignDefinition#isPopulated()
77      */

78     public boolean isPopulated() {
79         DesignIH dih = DesignIH.getHelper(designElement.getClass());
80         return dih.hasDetailData(designElement);
81     }
82
83     public int childCount() {
84         return designElement.childCount();
85     }
86     
87     public String JavaDoc getChildType(int index) {
88         return designElement.children(index).type();
89     }
90
91     public void removeChild(int index) {
92         DesignElementType child = designElement.children()[index];
93         child.deleteObserver(observer);
94         designElement.removeChild(index);
95     }
96     
97     public void insertChild(int index, String JavaDoc type) {
98         DesignElementType nde = designElement.createType(type);
99         if (nde == null) {
100             throw new NullPointerException JavaDoc("[" + designElement + "] couldn't create type ["
101                     + type + "]");
102         }
103         designElement.insertChild(index, nde);
104         nde.addObserver(observer);
105     }
106     
107     public String JavaDoc getChildName(int index) {
108         return designElement.children()[index].getName().attribute();
109     }
110     
111     public void setChildName(int index, String JavaDoc name) {
112         designElement.children()[index].getName().attribute(name);
113     }
114
115     public DesignElement getChildValue(int index) {
116         return designElement.children()[index];
117     }
118     
119     public String JavaDoc[] getSupportedTypes() {
120         return designElement.supportedTypes();
121     }
122     /**
123      * @return Returns the visibleRows.
124      */

125     public int getVisibleRows() {
126         return visibleRows;
127     }
128     /**
129      * @param visibleRows The visibleRows to set.
130      */

131     public MultiTypeTable setVisibleRows(int visibleRows) {
132         this.visibleRows = visibleRows;
133         return this;
134     }
135 }
136
Popular Tags