1 19 20 package org.netbeans.modules.xml.multiview.ui; 21 22 import org.netbeans.modules.xml.multiview.SectionNode; 23 import org.netbeans.modules.xml.multiview.Utils; 24 import org.openide.nodes.Node; 25 26 import javax.swing.*; 27 import javax.swing.border.Border ; 28 import javax.swing.border.CompoundBorder ; 29 import javax.swing.border.EmptyBorder ; 30 import java.awt.*; 31 import java.beans.PropertyChangeListener ; 32 import java.beans.PropertyChangeEvent ; 33 34 40 public class SectionNodePanel extends SectionPanel { 41 42 public SectionNodePanel(final SectionNode node) { 43 super(node.getSectionNodeView(), node, node.getDisplayName(), node); 44 if (node.getKey() instanceof SectionView) { 45 setInnerViewMode(); 47 } else if (node.isExpanded()) { 48 setExpandedViewMode(); 49 } 50 node.addPropertyChangeListener(new PropertyChangeListener () { 51 public void propertyChange(PropertyChangeEvent evt) { 52 if (Node.PROP_DISPLAY_NAME.equals(evt.getPropertyName())) { 53 setTitle(node.getDisplayName()); 54 } 55 } 56 }); 57 } 58 59 63 protected void setExpandedViewMode() { 64 getTitleButton().setVisible(true); 65 getFoldButton().setVisible(false); 66 getHeaderSeparator().setVisible(false); 67 Border emptyBorder = new EmptyBorder (0, 4, 4, 4); 68 Border lineBorder; 69 lineBorder = new JTextField().getBorder(); 70 71 setBorder(new CompoundBorder (emptyBorder, new CompoundBorder (lineBorder, emptyBorder))); 72 openInnerPanel(); 73 getFillerLine().setVisible(false); 74 getFillerEnd().setVisible(false); 75 } 76 77 81 protected void setInnerViewMode() { 82 getTitleButton().setVisible(false); 83 getFoldButton().setVisible(false); 84 getHeaderSeparator().setVisible(false); 85 openInnerPanel(); 86 getFillerLine().setVisible(false); 87 getFillerEnd().setVisible(false); 88 } 89 90 95 protected SectionInnerPanel createInnerpanel() { 96 SectionInnerPanel innerPanel = ((SectionNode) getNode()).createInnerPanel(); 97 if (innerPanel == null) { 98 innerPanel = new BoxPanel(((SectionNode) getNode()).getSectionNodeView()); 101 } 102 return innerPanel; 103 } 104 105 protected void openInnerPanel() { 106 super.openInnerPanel(); 107 Node[] childNodes = ((SectionNode) getNode()).getChildren().getNodes(); 108 if (childNodes != null && childNodes.length > 0) { 109 final SectionNodePanel panel = ((SectionNode) childNodes[0]).getSectionNodePanel(); 110 panel.getFoldButton().setSelected(true); 111 panel.openInnerPanel(); 112 } 113 } 114 115 protected void closeInnerPanel() { 116 if (getFoldButton().isVisible()) { 117 if (getSectionView().getActivePanel() == this) { 118 Container parent = getParent(); 119 while (parent != null) { 120 if (parent instanceof SectionPanel) { 121 final SectionPanel sectionPanel = (SectionPanel) parent; 122 Utils.runInAwtDispatchThread(new Runnable () { 123 public void run() { 124 sectionPanel.setActive(true); 125 } 126 }); 127 break; 128 } else { 129 parent = parent.getParent(); 130 } 131 } 132 } 133 super.closeInnerPanel(); 134 } 135 } 136 137 140 public void open() { 141 Node parentNode = getNode().getParentNode(); 142 if (parentNode instanceof SectionNode) { 143 ((SectionNode) parentNode).getSectionNodePanel().open(); 144 } 145 if (getInnerPanel() == null) { 146 super.open(); 147 } 148 } 149 } 150 | Popular Tags |