KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > navigator > WSDLNavigatorPanel


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 package org.netbeans.modules.xml.wsdl.ui.navigator;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.util.Collection JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import org.netbeans.spi.navigator.NavigatorPanel;
26 import org.openide.loaders.DataObject;
27 import org.openide.util.Lookup;
28 import org.openide.util.LookupEvent;
29 import org.openide.util.LookupListener;
30 import org.openide.util.NbBundle;
31 import org.openide.windows.TopComponent;
32
33 /**
34  * An implementation of NavigatorPanel for WSDL navigator.
35  *
36  * @author Marek Fukala
37  * @author Nathan Fiedler
38  */

39 public class WSDLNavigatorPanel implements LookupListener, NavigatorPanel {
40     private WSDLNavigatorContent navigator;
41     private Lookup.Result selection;
42
43     /**
44      * Public nullary constructor needed for system to instantiate the provider.
45      */

46     public WSDLNavigatorPanel() {
47     }
48
49     public String JavaDoc getDisplayHint() {
50         return NbBundle.getMessage(WSDLNavigatorPanel.class,
51                 "LBL_WSDLNavigatorPanel_Hint");
52     }
53
54     public String JavaDoc getDisplayName() {
55         return NbBundle.getMessage(WSDLNavigatorPanel.class,
56                 "LBL_WSDLNavigatorPanel_Name");
57     }
58
59     public JComponent JavaDoc getComponent() {
60         if (navigator == null) {
61             navigator = new WSDLNavigatorContent();
62         }
63         return navigator;
64     }
65
66     public Lookup getLookup() {
67         return null;
68     }
69
70     public void panelActivated(Lookup context) {
71         getComponent();
72         TopComponent.getRegistry().addPropertyChangeListener(navigator);
73         selection = context.lookup(new Lookup.Template(DataObject.class));
74         selection.addLookupListener(this);
75         resultChanged(null);
76         // hack to init selection if any
77
navigator.propertyChange(new PropertyChangeEvent JavaDoc(this,
78                 TopComponent.getRegistry().PROP_ACTIVATED_NODES, false, true));
79     }
80
81     public void panelDeactivated() {
82         TopComponent.getRegistry().removePropertyChangeListener(navigator);
83         selection.removeLookupListener(this);
84         selection = null;
85         // If we set navigator to null its parent tc ref goes away.
86
//navigator = null;
87
}
88
89     public void resultChanged(LookupEvent ev) {
90         Collection JavaDoc selected = selection.allInstances();
91         if (selected.size() == 1) {
92             DataObject dobj = (DataObject) selected.iterator().next();
93             navigator.navigate(dobj);
94         }
95     }
96 }
97
Popular Tags