KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > navigator > ABENavigatorPanel


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.schema.abe.navigator;
21
22 import java.util.Collection JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import org.netbeans.spi.navigator.NavigatorPanel;
25 import org.openide.loaders.DataObject;
26 import org.openide.util.Lookup;
27 import org.openide.util.LookupEvent;
28 import org.openide.util.LookupListener;
29 import org.openide.util.NbBundle;
30 import org.openide.windows.TopComponent;
31
32 /**
33  * An implementation of NavigatorPanel for ABE view.
34  *
35  * @author Chris Webster
36  */

37 public class ABENavigatorPanel implements LookupListener, NavigatorPanel {
38     private NavigatorContent navigator;
39     private Lookup.Result selection;
40     private DataObject dobj;
41
42     public String JavaDoc getDisplayHint() {
43         return NbBundle.getMessage(ABENavigatorPanel.class,
44                 "LBL_NavigatorPanel_Hint");
45     }
46
47     public String JavaDoc getDisplayName() {
48         return NbBundle.getMessage(ABENavigatorPanel.class,
49                 "LBL_NavigatorPanel_Name");
50     }
51
52     public JComponent JavaDoc getComponent() {
53     if (navigator == null) {
54         navigator = new NavigatorContent();
55     }
56     return navigator;
57     }
58
59     public Lookup getLookup() {
60         return null;
61     }
62
63     public void panelActivated(Lookup context) {
64     getComponent();
65         TopComponent.getRegistry().addPropertyChangeListener(navigator);
66         selection = context.lookup(new Lookup.Template(DataObject.class));
67         selection.addLookupListener(this);
68         resultChanged(null);
69     }
70
71     public void panelDeactivated() {
72         TopComponent.getRegistry().removePropertyChangeListener(navigator);
73         selection.removeLookupListener(this);
74         selection = null;
75         navigator = null;
76     dobj = null;
77     }
78
79     public void resultChanged(LookupEvent ev) {
80         Collection JavaDoc selected = selection.allInstances();
81         if (selected.size() == 1) {
82         DataObject olddobj = dobj;
83             dobj = (DataObject) selected.iterator().next();
84         if (olddobj != dobj) {
85         navigator.show(dobj);
86         }
87         }
88     }
89 }
90
Popular Tags