001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package org.terracotta.dso.editors;
005:
006: import org.eclipse.core.resources.IProject;
007: import org.eclipse.swt.SWT;
008: import org.eclipse.swt.custom.ScrolledComposite;
009: import org.eclipse.swt.graphics.Image;
010: import org.eclipse.swt.widgets.Composite;
011: import org.eclipse.swt.widgets.TabFolder;
012: import org.eclipse.swt.widgets.TabItem;
013: import org.terracotta.dso.TcPlugin;
014: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent;
015: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
016:
017: import com.terracottatech.config.Application;
018: import com.terracottatech.config.DsoApplication;
019: import com.terracottatech.config.TcConfigDocument.TcConfig;
020:
021: public class DsoApplicationPanel extends ConfigurationEditorPanel
022: implements ConfigurationEditorRoot, XmlObjectStructureListener {
023: private IProject m_project;
024: private TcConfig m_config;
025: private Application m_application;
026: private DsoApplication m_dsoApp;
027: private Layout m_layout;
028:
029: public DsoApplicationPanel(Composite parent, int style) {
030: super (parent, style);
031: m_layout = new Layout(this );
032: }
033:
034: public void structureChanged(XmlObjectStructureChangeEvent e) {/**/
035: }
036:
037: private void addListeners() {
038: m_layout.m_instrumentedClasses
039: .addXmlObjectStructureListener(this );
040: m_layout.m_transientFields.addXmlObjectStructureListener(this );
041: m_layout.m_locks.addXmlObjectStructureListener(this );
042: m_layout.m_roots.addXmlObjectStructureListener(this );
043: m_layout.m_distributedMethods
044: .addXmlObjectStructureListener(this );
045: m_layout.m_bootClasses.addXmlObjectStructureListener(this );
046: }
047:
048: private void removeListeners() {
049: m_layout.m_instrumentedClasses
050: .removeXmlObjectStructureListener(this );
051: m_layout.m_transientFields
052: .removeXmlObjectStructureListener(this );
053: m_layout.m_locks.removeXmlObjectStructureListener(this );
054: m_layout.m_roots.removeXmlObjectStructureListener(this );
055: m_layout.m_distributedMethods
056: .removeXmlObjectStructureListener(this );
057: m_layout.m_bootClasses.removeXmlObjectStructureListener(this );
058: }
059:
060: public void ensureXmlObject() {
061: if (m_dsoApp == null) {
062: removeListeners();
063: if (m_application == null) {
064: m_application = m_config.addNewApplication();
065: }
066: m_dsoApp = m_application.addNewDso();
067: initPanels();
068: addListeners();
069: }
070: }
071:
072: public void setupInternal() {
073: TcPlugin plugin = TcPlugin.getDefault();
074:
075: m_config = plugin.getConfiguration(m_project);
076: m_application = m_config != null ? m_config.getApplication()
077: : null;
078: m_dsoApp = m_application != null ? m_application.getDso()
079: : null;
080:
081: initPanels();
082: }
083:
084: private void initPanels() {
085: m_layout.m_instrumentedClasses.setup(m_project, m_dsoApp);
086: m_layout.m_transientFields.setup(m_project, m_dsoApp);
087: m_layout.m_locks.setup(m_project, m_dsoApp);
088: m_layout.m_roots.setup(m_project, m_dsoApp);
089: m_layout.m_distributedMethods.setup(m_project, m_dsoApp);
090: m_layout.m_bootClasses.setup(m_project, m_dsoApp);
091: }
092:
093: public void updateInstrumentedClassesPanel() {
094: m_layout.m_instrumentedClasses.updateModel();
095: }
096:
097: public void updateTransientsPanel() {
098: m_layout.m_transientFields.updateModel();
099: }
100:
101: public void updateLocksPanel() {
102: m_layout.m_locks.updateModel();
103: }
104:
105: public void updateRootsPanel() {
106: m_layout.m_roots.updateModel();
107: }
108:
109: public void updateDistributedMethodsPanel() {
110: m_layout.m_distributedMethods.updateModel();
111: }
112:
113: public void updateBootClassesPanel() {
114: m_layout.m_bootClasses.updateModel();
115: }
116:
117: public void setup(IProject project) {
118: m_project = project;
119:
120: setEnabled(true);
121: removeListeners();
122: setupInternal();
123: addListeners();
124: }
125:
126: public IProject getProject() {
127: return m_project;
128: }
129:
130: public void tearDown() {
131: removeListeners();
132:
133: m_layout.m_instrumentedClasses.tearDown();
134: m_layout.m_transientFields.tearDown();
135: m_layout.m_locks.tearDown();
136: m_layout.m_roots.tearDown();
137: m_layout.m_distributedMethods.tearDown();
138: m_layout.m_bootClasses.tearDown();
139:
140: setEnabled(false);
141: }
142:
143: private static class Layout {
144: private static final String ROOTS_ICON = "/com/tc/admin/icons/hierarchicalLayout.gif";
145: private static final String LOCKS_ICON = "/com/tc/admin/icons/deadlock_view.gif";
146: private static final String TRANSIENT_FIELDS_ICON = "/com/tc/admin/icons/transient.gif";
147: private static final String INSTRUMENTED_CLASSES_ICON = "/com/tc/admin/icons/class_obj.gif";
148: private static final String DISTRIBUTED_METHODS_ICON = "/com/tc/admin/icons/jmeth_obj.gif";
149: private static final String BOOT_CLASSES_ICON = "/com/tc/admin/icons/jar_obj.gif";
150: private static final String ROOTS = "Roots";
151: private static final String LOCKS = "Locks";
152: private static final String TRANSIENT_FIELDS = "Transient Fields";
153: private static final String INSTRUMENTED_CLASSES = "Instrumented Classes";
154: private static final String DISTRIBUTED_METHODS = "Distributed Methods";
155: private static final String BOOT_CLASSES = "Boot Classes";
156: private RootsPanel m_roots;
157: private LocksPanel m_locks;
158: private TransientFieldsPanel m_transientFields;
159: private InstrumentedClassesPanel m_instrumentedClasses;
160: private DistributedMethodsPanel m_distributedMethods;
161: private BootClassesPanel m_bootClasses;
162: private final TabFolder m_tabFolder;
163:
164: public void reset() {
165: // not implemented
166: }
167:
168: private Layout(Composite parent) {
169: m_tabFolder = new TabFolder(parent, SWT.BORDER);
170:
171: TabItem rootsTab = new TabItem(m_tabFolder, SWT.NONE);
172: rootsTab.setText(ROOTS);
173: rootsTab.setImage(new Image(parent.getDisplay(), this
174: .getClass().getResourceAsStream(ROOTS_ICON)));
175: ScrolledComposite scroll = new ScrolledComposite(
176: m_tabFolder, SWT.V_SCROLL);
177: m_roots = new RootsPanel(scroll, SWT.NONE);
178: rootsTab.setControl(scroll);
179: scroll.setContent(m_roots);
180: scroll.setExpandHorizontal(true);
181: scroll.setExpandVertical(true);
182: scroll.setMinSize(m_roots.computeSize(SWT.DEFAULT,
183: SWT.DEFAULT));
184:
185: TabItem locksTab = new TabItem(m_tabFolder, SWT.NONE);
186: locksTab.setText(LOCKS);
187: locksTab.setImage(new Image(parent.getDisplay(), this
188: .getClass().getResourceAsStream(LOCKS_ICON)));
189: scroll = new ScrolledComposite(m_tabFolder, SWT.V_SCROLL);
190: m_locks = new LocksPanel(scroll, SWT.NONE);
191: locksTab.setControl(scroll);
192: scroll.setContent(m_locks);
193: scroll.setExpandHorizontal(true);
194: scroll.setExpandVertical(true);
195: scroll.setMinSize(m_locks.computeSize(SWT.DEFAULT,
196: SWT.DEFAULT));
197:
198: TabItem transientFieldsTab = new TabItem(m_tabFolder,
199: SWT.NONE);
200: transientFieldsTab.setText(TRANSIENT_FIELDS);
201: transientFieldsTab.setImage(new Image(parent.getDisplay(),
202: this .getClass().getResourceAsStream(
203: TRANSIENT_FIELDS_ICON)));
204: scroll = new ScrolledComposite(m_tabFolder, SWT.V_SCROLL);
205: m_transientFields = new TransientFieldsPanel(scroll,
206: SWT.NONE);
207: transientFieldsTab.setControl(scroll);
208: scroll.setContent(m_transientFields);
209: scroll.setExpandHorizontal(true);
210: scroll.setExpandVertical(true);
211: scroll.setMinSize(m_transientFields.computeSize(
212: SWT.DEFAULT, SWT.DEFAULT));
213:
214: TabItem instrumentedClassesTab = new TabItem(m_tabFolder,
215: SWT.NONE);
216: instrumentedClassesTab.setText(INSTRUMENTED_CLASSES);
217: instrumentedClassesTab.setImage(new Image(parent
218: .getDisplay(), this .getClass().getResourceAsStream(
219: INSTRUMENTED_CLASSES_ICON)));
220: scroll = new ScrolledComposite(m_tabFolder, SWT.V_SCROLL);
221: m_instrumentedClasses = new InstrumentedClassesPanel(
222: scroll, SWT.NONE);
223: instrumentedClassesTab.setControl(scroll);
224: scroll.setContent(m_instrumentedClasses);
225: scroll.setExpandHorizontal(true);
226: scroll.setExpandVertical(true);
227: scroll.setMinSize(m_instrumentedClasses.computeSize(
228: SWT.DEFAULT, SWT.DEFAULT));
229:
230: TabItem distributedMethodsTab = new TabItem(m_tabFolder,
231: SWT.NONE);
232: distributedMethodsTab.setText(DISTRIBUTED_METHODS);
233: distributedMethodsTab.setImage(new Image(parent
234: .getDisplay(), this .getClass().getResourceAsStream(
235: DISTRIBUTED_METHODS_ICON)));
236: scroll = new ScrolledComposite(m_tabFolder, SWT.V_SCROLL);
237: m_distributedMethods = new DistributedMethodsPanel(scroll,
238: SWT.NONE);
239: distributedMethodsTab.setControl(scroll);
240: scroll.setContent(m_distributedMethods);
241: scroll.setExpandHorizontal(true);
242: scroll.setExpandVertical(true);
243: scroll.setMinSize(m_distributedMethods.computeSize(
244: SWT.DEFAULT, SWT.DEFAULT));
245:
246: TabItem bootClassesTab = new TabItem(m_tabFolder, SWT.NONE);
247: bootClassesTab.setText(BOOT_CLASSES);
248: bootClassesTab
249: .setImage(new Image(parent.getDisplay(), this
250: .getClass().getResourceAsStream(
251: BOOT_CLASSES_ICON)));
252: scroll = new ScrolledComposite(m_tabFolder, SWT.V_SCROLL);
253: m_bootClasses = new BootClassesPanel(scroll, SWT.NONE);
254: bootClassesTab.setControl(scroll);
255: scroll.setContent(m_bootClasses);
256: scroll.setExpandHorizontal(true);
257: scroll.setExpandVertical(true);
258: scroll.setMinSize(m_bootClasses.computeSize(SWT.DEFAULT,
259: SWT.DEFAULT));
260:
261: m_tabFolder.pack();
262: m_tabFolder.setSelection(rootsTab);
263: }
264: }
265:
266: public void transientFieldsChanged(IProject project) {
267: if (project.equals(getProject())) {
268: m_layout.m_transientFields.setup(m_project, m_dsoApp);
269: }
270: }
271:
272: public void bootClassesChanged(IProject project) {
273: if (project.equals(getProject())) {
274: m_layout.m_bootClasses.setup(m_project, m_dsoApp);
275: }
276: }
277:
278: public void distributedMethodsChanged(IProject project) {
279: if (project.equals(getProject())) {
280: m_layout.m_distributedMethods.setup(m_project, m_dsoApp);
281: }
282: }
283:
284: public void instrumentationRulesChanged(IProject project) {
285: if (project.equals(getProject())) {
286: m_layout.m_instrumentedClasses.setup(m_project, m_dsoApp);
287: }
288: }
289:
290: public void namedLocksChanged(IProject project) {
291: if (project.equals(getProject())) {
292: m_layout.m_locks.setup(m_project, m_dsoApp);
293: }
294: }
295:
296: public void autolocksChanged(IProject project) {
297: if (project.equals(getProject())) {
298: m_layout.m_locks.setup(m_project, m_dsoApp);
299: }
300: }
301:
302: public void rootsChanged(IProject project) {
303: if (project.equals(getProject())) {
304: m_layout.m_roots.setup(m_project, m_dsoApp);
305: }
306: }
307:
308: }
|