KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > nodes > JaxWsClientRootChildren


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.websvc.core.jaxws.nodes;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
26 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
27 import org.openide.filesystems.FileObject;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import org.openide.util.RequestProcessor;
32
33 public class JaxWsClientRootChildren extends Children.Keys {
34     JaxWsModel jaxWsModel;
35     Client[] clients;
36     JaxWsListener listener;
37     FileObject srcRoot;
38     
39     private RequestProcessor.Task updateNodeTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
40         public void run() {
41             updateKeys();
42         }
43     });
44     
45     public JaxWsClientRootChildren(JaxWsModel jaxWsModel, FileObject srcRoot) {
46         this.jaxWsModel = jaxWsModel;
47         this.srcRoot=srcRoot;
48     }
49     
50     protected void addNotify() {
51         super.addNotify();
52         listener = new JaxWsListener();
53         jaxWsModel.addPropertyChangeListener(listener);
54         updateKeys();
55     }
56     
57     protected void removeNotify() {
58         setKeys(Collections.EMPTY_SET);
59         jaxWsModel.removePropertyChangeListener(listener);
60         super.removeNotify();
61     }
62        
63     private void updateKeys() {
64         List JavaDoc keys = new ArrayList JavaDoc();
65         clients = jaxWsModel.getClients();
66         if (clients != null) {
67             for (int i = 0; i < clients.length; i++) {
68                 keys.add(clients[i]);
69             }
70         }
71         setKeys(keys);
72     }
73
74     protected Node[] createNodes(Object JavaDoc key) {
75         if(key instanceof Client) {
76             return new Node[] {new JaxWsClientNode(jaxWsModel, (Client)key, srcRoot)};
77         }
78         return new Node[0];
79     }
80     
81     class JaxWsListener implements PropertyChangeListener JavaDoc {
82         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
83             updateNodeTask.schedule(2000);
84         }
85     }
86
87 }
88
Popular Tags