KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > ModelEventMediator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * ModelEventMediator.java
22  *
23  * Created on September 15, 2006, 8:26 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe;
30
31 import java.beans.PropertyChangeEvent JavaDoc;
32 import java.beans.PropertyChangeListener JavaDoc;
33 import javax.swing.SwingUtilities JavaDoc;
34 import org.netbeans.modules.xml.axi.AXIComponent;
35
36 /**
37  *
38  * @author girix
39  */

40 public abstract class ModelEventMediator implements PropertyChangeListener JavaDoc{
41     
42     ABEBaseDropPanel uiPeer;
43     AXIComponent modelPeer;
44     /** Creates a new instance of ModelEventMediator */
45     protected ModelEventMediator(ABEBaseDropPanel uiPeer, AXIComponent modelPeer) {
46         this.uiPeer = uiPeer;
47         this.modelPeer = modelPeer;
48         
49         uiPeer.addPropertyChangeListener(ABEBaseDropPanel.PROP_COMPONENT_REMOVED,
50                 new PropertyChangeListener JavaDoc(){
51             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
52                 if(evt.getPropertyName().equals(ABEBaseDropPanel.PROP_COMPONENT_REMOVED))
53                     cleanUp();
54             }
55         });
56     }
57     
58     public abstract void _propertyChange(PropertyChangeEvent JavaDoc pce);
59     
60     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
61         if(hasPathToTC()){
62             //if the UI peer has the top frame then only despatch the event
63
_propertyChange(evt);
64         }else{
65             //Else remove myself
66
cleanUp();
67         }
68     }
69     
70     protected boolean hasPathToTC() {
71         if(uiPeer != null)
72             return (SwingUtilities.getAncestorOfClass(InstanceDesignerPanel.class, uiPeer) != null);
73         else{
74             modelPeer = null;
75             return false;
76         }
77     }
78     
79     protected void cleanUp(){
80         if(modelPeer != null){
81             if(modelPeer.getModel() != null)
82                 modelPeer.removePropertyChangeListener(this);
83         }
84         modelPeer = null;
85         uiPeer = null;
86     }
87     
88 }
89
Popular Tags