KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > text > navigator > XMLNavigatorPanel


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
20 package org.netbeans.modules.xml.text.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
31 /** An implementation of NavigatorPanel for XML navigator.
32  *
33  * @author Marek Fukala
34  * @version 1.0
35  */

36 public class XMLNavigatorPanel implements NavigatorPanel {
37
38     private NavigatorContent navigator = NavigatorContent.getDefault();
39     
40     private Lookup.Result selection;
41     private final LookupListener selectionListener = new LookupListener() {
42         public void resultChanged(LookupEvent ev) {
43             navigate(selection.allInstances());
44         }
45     };
46     
47     /** public no arg constructor needed for system to instantiate the provider. */
48     public XMLNavigatorPanel() {
49     }
50     
51     public String JavaDoc getDisplayHint() {
52         return NbBundle.getMessage(XMLNavigatorPanel.class, "XML_files_navigator");
53     }
54     
55     public String JavaDoc getDisplayName() {
56         return NbBundle.getMessage(XMLNavigatorPanel.class, "XML_View");
57     }
58     
59     public JComponent JavaDoc getComponent() {
60         return navigator;
61     }
62     
63     public Lookup getLookup() {
64         return null;
65     }
66     
67     public void panelActivated(Lookup context) {
68         selection = context.lookup(new Lookup.Template(DataObject.class));
69         selection.addLookupListener(selectionListener);
70         selectionListener.resultChanged(null);
71     }
72     
73     public void panelDeactivated() {
74         selection.removeLookupListener(selectionListener);
75         selection = null;
76         navigator.release(); //hide the UI
77
}
78     
79     public void navigate(Collection JavaDoc/*<DataObject>*/ selectedFiles) {
80         if(selectedFiles.size() == 1) {
81             DataObject d = (DataObject) selectedFiles.iterator().next();
82             navigator.navigate(d);
83         }
84     }
85     
86 }
87
Popular Tags