KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > components > IfDC


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

4 package org.oddjob.designer.components;
5
6 import java.awt.Component JavaDoc;
7
8 import org.oddjob.designer.factory.DesignFactory;
9 import org.oddjob.designer.factory.SimpleHierarchy;
10 import org.oddjob.designer.model.ComponentAction;
11 import org.oddjob.designer.model.ComponentElement;
12 import org.oddjob.designer.model.DesignComponent;
13 import org.oddjob.designer.model.FormDefinition;
14 import org.oddjob.designer.model.StandardForm;
15 import org.oddjob.designer.model.TransferComponentAction;
16
17 /**
18  *
19  */

20 public class IfDC extends StructuralDC {
21
22     private Component JavaDoc mainForm;
23         
24     private DesignComponent child;
25     private DesignComponent then;
26     private DesignComponent otherwise; // else is reservered
27
private DesignComponent exception;
28     
29     public FormDefinition form() {
30         return new StandardForm(tag())
31                 .addGroup(basePanel());
32     }
33         
34     public SimpleHierarchy availableActions() {
35         return new SimpleHierarchy(ComponentAction.class)
36             .addHierarchy(DesignFactory.childActions(this, "child").setName("Set Child"))
37             .addHierarchy(DesignFactory.childActions(this, "then").setName("Set Then"))
38             .addHierarchy(DesignFactory.childActions(this, "else").setName("Set Else"))
39             .addHierarchy(DesignFactory.childActions(this, "exception").setName("Set Exception"));
40     }
41     
42     /* (non-Javadoc)
43      * @see org.oddjob.designer.model.StructuralDesignComponent#transferActions(java.lang.String)
44      */

45     public ComponentAction[] transferActions(String JavaDoc xml) {
46         return new ComponentAction[] {
47                 new TransferComponentAction(this, xml, "Set Child", "child"),
48                 new TransferComponentAction(this, xml, "Set Then", "then"),
49                 new TransferComponentAction(this, xml, "Set Else", "else"),
50                 new TransferComponentAction(this, xml, "Set Exception", "exception")
51         };
52     }
53     
54     public void deleteChild(DesignComponent child) {
55         if (child == this.child) {
56             this.child = null;
57         }
58         if (child == then) {
59             then = null;
60         }
61         if (child == otherwise) {
62             otherwise = null;
63         }
64         if (child == exception) {
65             exception = null;
66         }
67         super.deleteChild(child);
68     }
69
70     void refreshChildren() {
71         childHelper.removeAllChildren();
72         if (child != null) {
73             childHelper.addChild(child);
74         }
75         if (then != null) {
76             childHelper.addChild(then);
77         }
78         if (otherwise!= null) {
79             childHelper.addChild(otherwise);
80         }
81         if (exception != null) {
82             childHelper.addChild(exception);
83         }
84     }
85     
86     public void addComponentChild(DesignComponent child) {
87         this.child = child;
88         refreshChildren();
89     }
90
91     public Object JavaDoc elementChild() {
92         return ComponentElement.createNested(child);
93     }
94     
95     public void addComponentThen(DesignComponent then) {
96         this.then = then;
97         refreshChildren();
98     }
99     
100     public Object JavaDoc elementThen() {
101         return ComponentElement.createNested(then);
102     }
103     
104     public void addComponentElse(DesignComponent otherwise) {
105         this.otherwise = otherwise;
106         refreshChildren();
107     }
108     
109     public Object JavaDoc elementElse() {
110         return ComponentElement.createNested(otherwise);
111     }
112     
113     public void addComponentException(DesignComponent exception) {
114         this.exception = exception;
115         refreshChildren();
116     }
117     
118     public Object JavaDoc elementException() {
119         return ComponentElement.createNested(exception);
120     }
121     
122 }
123
Popular Tags