1 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 ; 31 32 37 public abstract class SectionNodeView extends SectionView { 38 39 private final XmlMultiViewDataObject dataObject; 40 private SectionNode rootNode = null; 41 private HashMap nodes = new HashMap (); 42 43 private final RequestProcessor.Task refreshTask = RequestProcessor.getDefault().create(new Runnable () { 44 public void run() { 45 getRootNode().refreshSubtree(); 46 } 47 }); 48 49 private static final int REFRESH_DELAY = 20; 50 51 55 public SectionNodeView(XmlMultiViewDataObject dataObject) { 56 super(); 57 this.dataObject = dataObject; 58 } 59 60 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 83 public void openSection(Node node) { 84 openPanel(node); 85 } 86 87 92 public void openPanel(Object 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 118 public void refreshView() { 119 rootNode.refreshSubtree(); 120 } 121 122 127 public void scheduleRefreshView() { 128 refreshTask.schedule(REFRESH_DELAY); 129 } 130 131 public void dataModelPropertyChange(Object source, String propertyName, Object oldValue, Object newValue) { 132 rootNode.dataModelPropertyChange(source, propertyName, oldValue, newValue); 133 } 134 135 public abstract XmlMultiViewDataSynchronizer getModelSynchronizer(); 136 137 ; 138 } | Popular Tags |