KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > editors > InstrumentationLoggingPanel


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.editors;
5
6 import org.dijon.ContainerResource;
7
8 import org.terracotta.dso.editors.xmlbeans.XmlBooleanToggle;
9 import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent;
10 import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
11 import com.terracottatech.config.DsoClientDebugging;
12 import com.terracottatech.config.InstrumentationLogging;
13
14 import java.awt.event.ActionEvent JavaDoc;
15 import java.awt.event.ActionListener JavaDoc;
16
17 public class InstrumentationLoggingPanel extends ConfigurationEditorPanel
18   implements ActionListener JavaDoc,
19              XmlObjectStructureListener
20 {
21   private DsoClientDebugging m_dsoClientDebugging;
22   private InstrumentationLogging m_instrumentationLogging;
23   private XmlBooleanToggle m_class;
24   private XmlBooleanToggle m_locks;
25   private XmlBooleanToggle m_transientRoot;
26   private XmlBooleanToggle m_roots;
27   private XmlBooleanToggle m_distributedMethods;
28
29   public InstrumentationLoggingPanel() {
30     super();
31   }
32
33   public void load(ContainerResource containerRes) {
34     super.load(containerRes);
35
36     m_class = (XmlBooleanToggle)findComponent("Class1");
37     init(m_class, "class1");
38
39     m_locks = (XmlBooleanToggle)findComponent("Locks");
40     init(m_locks, "locks");
41
42     m_transientRoot = (XmlBooleanToggle)findComponent("TransientRoot");
43     init(m_transientRoot, "transient-root");
44
45     m_roots = (XmlBooleanToggle)findComponent("Roots");
46     init(m_roots, "roots");
47
48     m_distributedMethods =
49       (XmlBooleanToggle)findComponent("DistributedMethods");
50     init(m_distributedMethods, "distributed-methods");
51   }
52
53   public void ensureXmlObject() {
54     super.ensureXmlObject();
55
56     if(m_instrumentationLogging == null) {
57       removeListeners();
58       m_instrumentationLogging =
59         m_dsoClientDebugging.addNewInstrumentationLogging();
60       updateChildren();
61       addListeners();
62     }
63   }
64
65   public void actionPerformed(ActionEvent JavaDoc ae) {
66     setDirty();
67   }
68
69   public void structureChanged(XmlObjectStructureChangeEvent ae) {
70     syncModel();
71   }
72
73   private void syncModel() {
74     if(!hasAnySet() &&
75        m_dsoClientDebugging.getInstrumentationLogging() != null)
76     {
77       m_dsoClientDebugging.unsetInstrumentationLogging();
78       m_instrumentationLogging = null;
79       fireXmlObjectStructureChanged();
80       updateChildren();
81     }
82     else {
83       setDirty();
84     }
85   }
86
87   private void fireXmlObjectStructureChanged() {
88     fireXmlObjectStructureChanged(m_dsoClientDebugging);
89   }
90
91   public boolean hasAnySet() {
92     return m_instrumentationLogging != null &&
93           (m_instrumentationLogging.isSetClass1() ||
94            m_instrumentationLogging.isSetHierarchy() ||
95            m_instrumentationLogging.isSetLocks() ||
96            m_instrumentationLogging.isSetTransientRoot() ||
97            m_instrumentationLogging.isSetRoots() ||
98            m_instrumentationLogging.isSetDistributedMethods());
99   }
100
101   private void addListeners() {
102     m_class.addActionListener(this);
103     m_class.addXmlObjectStructureListener(this);
104
105     m_locks.addActionListener(this);
106     m_locks.addXmlObjectStructureListener(this);
107
108     m_transientRoot.addActionListener(this);
109     m_transientRoot.addXmlObjectStructureListener(this);
110
111     m_roots.addActionListener(this);
112     m_roots.addXmlObjectStructureListener(this);
113
114     m_distributedMethods.addActionListener(this);
115     m_distributedMethods.addXmlObjectStructureListener(this);
116   }
117
118   private void removeListeners() {
119     m_class.removeActionListener(this);
120     m_class.removeXmlObjectStructureListener(this);
121
122     m_locks.removeActionListener(this);
123     m_locks.removeXmlObjectStructureListener(this);
124
125     m_transientRoot.removeActionListener(this);
126     m_transientRoot.removeXmlObjectStructureListener(this);
127
128     m_roots.removeActionListener(this);
129     m_roots.removeXmlObjectStructureListener(this);
130
131     m_distributedMethods.removeActionListener(this);
132     m_distributedMethods.removeXmlObjectStructureListener(this);
133   }
134
135   private void updateChildren() {
136     setup(m_class);
137     setup(m_locks);
138     setup(m_transientRoot);
139     setup(m_roots);
140     setup(m_distributedMethods);
141   }
142
143   public void setup(DsoClientDebugging dsoClientDebugging) {
144     removeListeners();
145     setEnabled(true);
146
147     m_dsoClientDebugging = dsoClientDebugging;
148     m_instrumentationLogging =
149       m_dsoClientDebugging != null ?
150         m_dsoClientDebugging.getInstrumentationLogging() : null;
151
152     updateChildren();
153     addListeners();
154   }
155
156   public void tearDown() {
157     removeListeners();
158
159     m_dsoClientDebugging = null;
160     m_instrumentationLogging = null;
161
162     m_class.tearDown();
163     m_locks.tearDown();
164     m_transientRoot.tearDown();
165     m_roots.tearDown();
166     m_distributedMethods.tearDown();
167
168     setEnabled(false);
169   }
170
171   private void init(XmlBooleanToggle toggle, String JavaDoc elementName) {
172     toggle.init(InstrumentationLogging.class, elementName);
173   }
174
175   private void setup(XmlBooleanToggle toggle) {
176     toggle.setup(m_instrumentationLogging);
177   }
178 }
179
Popular Tags