KickJava   Java API By Example, From Geeks To Geeks.

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


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.XmlObjectStructureChangeEvent;
9 import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
10 import com.terracottatech.config.Client;
11 import com.terracottatech.config.DsoClientData;
12
13 import javax.swing.event.ChangeEvent JavaDoc;
14 import javax.swing.event.ChangeListener JavaDoc;
15
16 public class DsoClientDataPanel extends ConfigurationEditorPanel
17   implements ChangeListener JavaDoc,
18              XmlObjectStructureListener
19 {
20   private Client m_client;
21   private DsoClientData m_dsoClientData;
22   private DsoClientDebuggingPanel m_dsoClientDebugging;
23
24   public void load(ContainerResource containerRes) {
25     super.load(containerRes);
26
27     m_dsoClientDebugging =
28       (DsoClientDebuggingPanel)findComponent("DsoClientDebugging");
29   }
30
31   public void ensureXmlObject() {
32     super.ensureXmlObject();
33
34     if(m_dsoClientData == null) {
35       removeListeners();
36       m_dsoClientData = m_client.addNewDso();
37       updateChildren();
38       addListeners();
39     }
40   }
41   
42   public boolean hasAnySet() {
43     return m_dsoClientData != null && m_dsoClientData.isSetDebugging();
44   }
45   
46   public void structureChanged(XmlObjectStructureChangeEvent e) {
47     syncModel();
48   }
49
50   public void stateChanged(ChangeEvent e) {
51     setDirty();
52   }
53   
54   private void syncModel() {
55     if(!hasAnySet() && m_client.getDso() != null) {
56       m_client.unsetDso();
57       m_dsoClientData = null;
58       fireXmlObjectStructureChanged();
59       updateChildren();
60     }
61     else {
62       setDirty();
63     }
64   }
65   
66   private void fireXmlObjectStructureChanged() {
67     fireXmlObjectStructureChanged(m_client);
68   }
69   
70   private void addListeners() {
71     m_dsoClientDebugging.addXmlObjectStructureListener(this);
72   }
73   
74   private void removeListeners() {
75     m_dsoClientDebugging.removeXmlObjectStructureListener(this);
76   }
77   
78   private void updateChildren() {
79     m_dsoClientDebugging.setup(m_dsoClientData);
80   }
81   
82   public void setup(Client client) {
83     removeListeners();
84     setEnabled(true);
85     
86     m_client = client;
87     m_dsoClientData = m_client != null ? m_client.getDso() : null;
88     
89     updateChildren();
90     addListeners();
91   }
92   
93   public void tearDown() {
94     removeListeners();
95     m_dsoClientDebugging.tearDown();
96     setEnabled(false);
97   }
98 }
99
Popular Tags