KickJava   Java API By Example, From Geeks To Geeks.

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


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.Structural;
9 import org.oddjob.designer.arooa.ElementWrapper;
10 import org.oddjob.designer.elements.SimpleDE;
11 import org.oddjob.designer.factory.DesignFactory;
12 import org.oddjob.designer.factory.SimpleHierarchy;
13 import org.oddjob.designer.model.ComponentAction;
14 import org.oddjob.designer.model.DesignComponent;
15 import org.oddjob.designer.model.ElementField;
16 import org.oddjob.designer.model.FieldGroup;
17 import org.oddjob.designer.model.FormDefinition;
18 import org.oddjob.designer.model.StandardForm;
19 import org.oddjob.designer.model.StructuralDesignComponent;
20 import org.oddjob.designer.model.TransferComponentAction;
21 import org.oddjob.structural.ChildHelper;
22 import org.oddjob.structural.StructuralListener;
23
24 /**
25  * This represents the root of the hierachy. It doesn't extend
26  * BaseDC because it doesn't have a name.
27  */

28 public final class RootDC
29 implements Structural, StructuralDesignComponent {
30
31     private SimpleDE idField = new SimpleDE();
32
33     private Component JavaDoc mainForm;
34
35     private transient ChildHelper childHelper = new ChildHelper(this);
36
37     /**
38      * @return Returns the id.
39      */

40     public SimpleDE getId() {
41         return idField;
42     }
43     /**
44      * @param id The id to set.
45      */

46     public void setId(SimpleDE id) {
47         this.idField = id;
48     }
49     
50     /*
51      * (non-Javadoc)
52      *
53      * @see org.oddjob.Structural#addStructuralListener(org.oddjob.structural.StructuralListener)
54      */

55     public void addStructuralListener(StructuralListener listener) {
56         childHelper.addStructuralListener(listener);
57     }
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see org.oddjob.Structural#removeStructuralListener(org.oddjob.structural.StructuralListener)
63      */

64     public void removeStructuralListener(StructuralListener listener) {
65         childHelper.removeStructuralListener(listener);
66     }
67
68     public void deleteChild(DesignComponent child) {
69         childHelper.removeChild(child);
70     }
71
72     /* (non-Javadoc)
73      * @see org.oddjob.designer.model.StructuralDesignComponent#replaceChild(org.oddjob.designer.model.DesignComponent, org.oddjob.designer.model.DesignComponent)
74      */

75     public void replaceChild(DesignComponent child, DesignComponent replacement) {
76         childHelper.replaceChild(child, replacement);
77     }
78
79     public String JavaDoc name() {
80         return "Oddjob";
81     }
82     
83     public void name(String JavaDoc name) {
84         throw new UnsupportedOperationException JavaDoc("Root can't have name set!");
85     }
86     
87     public String JavaDoc tag() {
88         return "oddjob";
89     }
90
91     public void tag(String JavaDoc tag) {
92         throw new UnsupportedOperationException JavaDoc("Root can't have tag set!");
93     }
94     
95     public FormDefinition form() {
96         return new StandardForm(tag())
97             .addGroup(
98                     new FieldGroup("General")
99                     .add(new ElementField("Id", idField)));
100     }
101
102     public ElementWrapper[] elements() {
103         Object JavaDoc[] children = childHelper.getChildren();
104         ElementWrapper[] results = new ElementWrapper[children.length];
105         for (int i = 0; i < children.length; ++i) {
106             DesignComponent dc = (DesignComponent) children[i];
107             ElementWrapper wrapper = new ElementWrapper(
108                     dc.tag(), dc);
109             results[i] = wrapper;
110         }
111         return results;
112     }
113
114     public SimpleHierarchy availableActions() {
115         return new SimpleHierarchy(ComponentAction.class)
116             .addHierarchy(DesignFactory.childActions(this, "").setName("Set Job"));
117     }
118     
119     /* (non-Javadoc)
120      * @see org.oddjob.designer.model.StructuralDesignComponent#transferActions(java.lang.String)
121      */

122     public ComponentAction[] transferActions(String JavaDoc xml) {
123         return new ComponentAction[] {
124                 new TransferComponentAction(this, xml, "Set Job", "")
125         };
126     }
127
128     public void addComponent(Object JavaDoc child) {
129         childHelper.removeAllChildren();
130         childHelper.addChild(child);
131     }
132
133 }
134
Popular Tags