KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > AbstractChildren


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  * AbstractChildren.java
22  *
23  * Created on April 26, 2006, 12:54 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
29
30 import java.util.Collection JavaDoc;
31 import java.util.Collections JavaDoc;
32
33 import javax.swing.SwingUtilities JavaDoc;
34
35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
36 import org.netbeans.modules.xml.xam.Component;
37 import org.netbeans.modules.xml.xam.ComponentEvent;
38 import org.netbeans.modules.xml.xam.ComponentListener;
39 import org.openide.nodes.Children;
40
41
42 /**
43  *
44  * @author radval
45  */

46 public abstract class AbstractChildren extends Children.Keys implements ComponentListener {
47     
48     
49     private WSDLComponent mElement;
50
51         
52     /** Creates a new instance of AbstractChildren */
53     public AbstractChildren(WSDLComponent wsdlComponent) {
54         this.mElement = wsdlComponent;
55         mElement.getModel().addComponentListener(this);
56     }
57     
58     public WSDLComponent getWSDLComponent() {
59             return this.mElement;
60     }
61     
62     protected void refreshChildren() {
63     }
64     
65     
66     public void childrenAdded(ComponentEvent evt) {
67         if(!isSameAsMyWSDLElement((Component) evt.getSource())) {
68             return;
69         }
70         
71         Runnable JavaDoc run = new Runnable JavaDoc() {
72             public void run() {
73                 refreshChildren();
74             }
75         };
76         
77         SwingUtilities.invokeLater(run);
78         
79         
80     }
81
82     public void childrenDeleted(ComponentEvent evt) {
83         if(!isSameAsMyWSDLElement((Component) evt.getSource())) {
84             return;
85         }
86         removeChild(evt.getSource());
87
88     }
89
90     public void valueChanged(ComponentEvent evt) {
91         if(!isSameAsMyWSDLElement((Component) evt.getSource())) {
92             return;
93         }
94         Runnable JavaDoc run = new Runnable JavaDoc() {
95             public void run() {
96                 refreshChildren();
97             }
98         };
99         
100         SwingUtilities.invokeLater(run);
101     }
102     
103     
104     private void removeChild(Object JavaDoc key) {
105         Runnable JavaDoc run = new Runnable JavaDoc() {
106             public void run() {
107                 refreshChildren();
108             }
109         };
110         
111         SwingUtilities.invokeLater(run);
112         
113     }
114
115     protected void addNotify() {
116         super.addNotify();
117         refreshChildren();
118     }
119
120     protected void removeNotify() {
121         super.removeNotify();
122         super.nodes.clear();
123         refresh();
124     }
125         
126    /**
127      * call this method before any method of XMLElementListener to check
128      * if this is the same source.
129      * @param node
130      * @return
131      */

132     protected boolean isSameAsMyWSDLElement(Component node) {
133             if(node != null && node.equals(getWSDLComponent())) {
134                     return true;
135             }
136
137
138             return false;
139     }
140         
141     
142     protected Collection JavaDoc getKeys() {
143         return Collections.EMPTY_LIST;
144     }
145     
146
147 }
148
Popular Tags