KickJava   Java API By Example, From Geeks To Geeks.

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


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

4 package org.oddjob.designer.model;
5
6 import org.oddjob.designer.arooa.DesignIH;
7
8 /**
9  * A model for a view onto a DesignElement which can support
10  * one child of different possible types.
11  */

12 public class SingleTypeSelection implements DesignDefinition {
13
14     private final String JavaDoc heading;
15     private final DesignElementType designElement;
16     
17     public SingleTypeSelection(String JavaDoc heading, DesignElementType de) {
18         this.heading = heading;
19         this.designElement = de;
20         
21     }
22     
23     public String JavaDoc getTitle() {
24         return heading;
25     }
26
27     public String JavaDoc[] getOptions() {
28         return designElement.supportedTypes();
29     }
30     
31     public String JavaDoc getSelected() {
32         if (designElement.childCount() == 0) {
33             return null;
34         }
35         return designElement.children(0).type();
36     }
37     
38     public void setSelected(String JavaDoc type) {
39         String JavaDoc oldType = "";
40         if (designElement.childCount() > 0) {
41             oldType = designElement.children(0).type();
42         }
43         if (!"".equals(oldType) && !oldType.equals(type)) {
44             designElement.removeChild(0);
45         }
46         if (!"".equals(type) && !oldType.equals(type)) {
47             DesignElementType newChild = designElement.createType(type);
48             designElement.addChild(newChild);
49         }
50     }
51     
52     public DesignElementType getChildDesignElement() {
53         if (designElement.childCount() > 0) {
54             return designElement.children()[0];
55         }
56         return null;
57     }
58
59     /* (non-Javadoc)
60      * @see org.oddjob.designer.model.DesignDefinition#accept(org.oddjob.designer.model.DesignProcessor)
61      */

62     public void accept(DesignProcessor processor) {
63         processor.onSingleTypeSelection(this);
64     }
65     
66     /* (non-Javadoc)
67      * @see org.oddjob.designer.model.DesignDefinition#isPopulated()
68      */

69     public boolean isPopulated() {
70         DesignIH dih = DesignIH.getHelper(designElement.getClass());
71         return dih.hasDetailData(designElement);
72     }
73 }
74
Popular Tags