KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > propertysheet > PropertySheetView


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.openide.explorer.propertysheet;
20
21 import org.openide.explorer.*;
22 import org.openide.explorer.ExplorerManager.Provider;
23 import org.openide.nodes.Node;
24 import org.openide.nodes.Node.Property;
25
26 import java.beans.*;
27
28 import javax.swing.*;
29
30
31 /** An Explorer view displaying a {@link PropertySheet} - e.g. table with
32  * properties for currently selected {@link Node}
33  *
34  * <p>
35  * This class is a <q>view</q>
36  * to use it properly you need to add it into a component which implements
37  * {@link Provider}. Good examples of that can be found
38  * in {@link ExplorerUtils}. Then just use
39  * {@link Provider#getExplorerManager} call to get the {@link ExplorerManager}
40  * and control its state.
41  * </p>
42  * <p>
43  * There can be multiple <q>views</q> under one container implementing {@link Provider}. Select from
44  * range of predefined ones or write your own:
45  * </p>
46  * <ul>
47  * <li>{@link org.openide.explorer.view.BeanTreeView} - shows a tree of nodes</li>
48  * <li>{@link org.openide.explorer.view.ContextTreeView} - shows a tree of nodes without leaf nodes</li>
49  * <li>{@link org.openide.explorer.view.ListView} - shows a list of nodes</li>
50  * <li>{@link org.openide.explorer.view.IconView} - shows a rows of nodes with bigger icons</li>
51  * <li>{@link org.openide.explorer.view.ChoiceView} - creates a combo box based on the explored nodes</li>
52  * <li>{@link org.openide.explorer.view.TreeTableView} - shows tree of nodes together with a set of their {@link Property}</li>
53  * <li>{@link org.openide.explorer.view.MenuView} - can create a {@link JMenu} structure based on structure of {@link Node}s</li>
54  * </ul>
55  * <p>
56  * All of these views use {@link ExplorerManager#find} to walk up the AWT hierarchy and locate the
57  * {@link ExplorerManager} to use as a controler. They attach as listeners to
58  * it and also call its setter methods to update the shared state based on the
59  * user action. Not all views make sence together, but for example
60  * {@link org.openide.explorer.view.ContextTreeView} and {@link org.openide.explorer.view.ListView} were designed to complement
61  * themselves and behaves like windows explorer. The {@link org.openide.explorer.propertysheet.PropertySheetView}
62  * for example should be able to work with any other view.
63  * </p>
64  *
65 * @author Jan Jancura, Jaroslav Tulach, Ian Formanek
66 */

67 public class PropertySheetView extends PropertySheet {
68     /** generated Serialized Version UID */
69     static final long serialVersionUID = -7568245745904766160L;
70
71     /** helper flag for avoiding multiple initialization of the GUI */
72     transient private boolean guiInitialized = false;
73
74     /** The Listener that tracks changes in explorerManager */
75     transient private PropertyIL managerListener;
76
77     /** manager to use */
78     transient private ExplorerManager explorerManager;
79
80     public PropertySheetView() {
81         // setPreferredSize(new Dimension (200, 300));
82
}
83
84     /** Initializes the GUI of the view */
85     private void initializeGUI() {
86         guiInitialized = true;
87
88         // (TDB) extra border deleted
89
// setBorder (new javax.swing.border.EtchedBorder());
90
managerListener = new PropertyIL();
91     }
92
93     /* Initializes the sheet.
94     */

95     public void addNotify() {
96         super.addNotify();
97
98         explorerManager = ExplorerManager.find(this);
99
100         if (!guiInitialized) {
101             initializeGUI();
102         }
103
104         // add propertyChange listeners to the explorerManager
105
explorerManager.addPropertyChangeListener(managerListener);
106         setNodes(explorerManager.getSelectedNodes());
107     }
108
109     /* Deinitializes the sheet.
110     */

111     public void removeNotify() {
112         super.removeNotify();
113
114         if (explorerManager != null) { //[PENDING] patch for bug in JDK1.3 Window
115
explorerManager.removePropertyChangeListener(managerListener);
116             explorerManager = null;
117             setNodes(new Node[0]);
118         }
119     }
120
121     // INNER CLASSES ***************************************************************************
122

123     /**
124     * The inner adaptor class for listening to the ExplorerManager's property and
125     * vetoable changes.
126     */

127     class PropertyIL implements PropertyChangeListener {
128         public void propertyChange(PropertyChangeEvent evt) {
129             if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
130                 setNodes((Node[]) evt.getNewValue());
131             }
132         }
133     }
134 }
135
Popular Tags