KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > ui > SectionNodeView


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.xml.multiview.ui;
20
21 import org.netbeans.modules.xml.multiview.SectionNode;
22 import org.netbeans.modules.xml.multiview.Utils;
23 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject;
24 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.nodes.Children;
27 import org.openide.nodes.Node;
28 import org.openide.util.RequestProcessor;
29
30 import java.util.HashMap JavaDoc;
31
32 /**
33  * A section view for <code>SectionNode</code>.
34  *
35  * @author pfiala
36  */

37 public abstract class SectionNodeView extends SectionView {
38
39     private final XmlMultiViewDataObject dataObject;
40     private SectionNode rootNode = null;
41     private HashMap JavaDoc nodes = new HashMap JavaDoc();
42
43     private final RequestProcessor.Task refreshTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
44         public void run() {
45             getRootNode().refreshSubtree();
46         }
47     });
48
49     private static final int REFRESH_DELAY = 20;
50
51     /**
52      * Constructs new SecionNodeView.
53      * @param dataObject the associated data object.
54      */

55     public SectionNodeView(XmlMultiViewDataObject dataObject) {
56         super();
57         this.dataObject = dataObject;
58     }
59
60     /**
61      * Sets the given <code>rootNode</code> as the root
62      * of this view and adds its associated section node
63      * panel as a section for this.
64      */

65     public void setRootNode(SectionNode rootNode) {
66         this.rootNode = rootNode;
67         Children root = new Children.Array();
68         root.add(new Node[]{rootNode});
69         AbstractNode mainNode = new AbstractNode(root);
70         mainNode.setDisplayName(rootNode.getDisplayName());
71         mainNode.setIconBase(rootNode.getIconBase());
72         setRoot(mainNode);
73         addSection(rootNode.getSectionNodePanel());
74     }
75
76     public XmlMultiViewDataObject getDataObject() {
77         return dataObject;
78     }
79
80     /**
81      * Opens the panel associated with the given <code>node</code>.
82      */

83     public void openSection(Node node) {
84         openPanel(node);
85     }
86
87     /**
88      * Opens the panel representing <code>SecctionNode</code>
89      * identified by the given <code>key</code>.
90      * @param key the key of <code>SectionNode</code>
91      */

92     public void openPanel(Object JavaDoc key) {
93         SectionNode sectionNode = retrieveSectionNode((SectionNode) key);
94         SectionNodePanel sectionNodePanel = sectionNode.getSectionNodePanel();
95         sectionNodePanel.open();
96         setActivePanel(sectionNodePanel);
97         sectionNodePanel.setActive(true);
98         selectNode(sectionNodePanel.getNode());
99         Utils.scrollToVisible(sectionNodePanel);
100     }
101
102     public SectionNode getRootNode() {
103         return rootNode;
104     }
105
106     public void registerNode(SectionNode node) {
107         nodes.put(node, node);
108     }
109
110     public SectionNode retrieveSectionNode(SectionNode node) {
111         SectionNode sectionNode = (SectionNode) nodes.get(node);
112         return sectionNode == null ? rootNode : sectionNode;
113     }
114
115     /**
116      * Recursively refreshes the view starting from the root node.
117      */

118     public void refreshView() {
119         rootNode.refreshSubtree();
120     }
121
122     /**
123      * Schedules refreshing of the view with default delay.
124      * @see #refreshView
125      * @see #REFRESH_DELAY
126      */

127     public void scheduleRefreshView() {
128         refreshTask.schedule(REFRESH_DELAY);
129     }
130
131     public void dataModelPropertyChange(Object JavaDoc source, String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
132         rootNode.dataModelPropertyChange(source, propertyName, oldValue, newValue);
133     }
134
135     public abstract XmlMultiViewDataSynchronizer getModelSynchronizer();
136
137     ;
138 }
Popular Tags