01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package org.pentaho.designstudio.controls;
14:
15: import org.eclipse.jface.util.ListenerList;
16: import org.eclipse.jface.util.SafeRunnable;
17: import org.eclipse.swt.widgets.Composite;
18:
19: public class XMLAwareComposite extends Composite implements
20: IXmlModifier, IXmlModificationListener {
21:
22: private ListenerList xmlListeners = new ListenerList(1);
23:
24: public XMLAwareComposite(Composite parent, int style) {
25: super (parent, style);
26: if (parent instanceof IXmlModificationListener) {
27: addXmlModificationListener((IXmlModificationListener) parent);
28: }
29: }
30:
31: public void addXmlModificationListener(
32: IXmlModificationListener listener) {
33: xmlListeners.add(listener);
34: }
35:
36: public void removeXmlModificationListener(
37: IXmlModificationListener listener) {
38: xmlListeners.remove(listener);
39: }
40:
41: public void fireXmlModificationEvent(
42: final XmlModificationEvent event) {
43: Object[] listeners = xmlListeners.getListeners();
44: for (int i = 0; i < listeners.length; ++i) {
45: final IXmlModificationListener l = (IXmlModificationListener) listeners[i];
46: SafeRunnable.run(new SafeRunnable() {
47: public void run() {
48: l.contentChanged(event);
49: }
50: });
51: }
52: }
53:
54: public void contentChanged(XmlModificationEvent event) {
55: fireXmlModificationEvent(event);
56: }
57:
58: }
|