1 19 20 package org.openide.explorer; 21 22 import java.util.logging.Level ; 23 import org.netbeans.junit.*; 24 import junit.textui.TestRunner; 25 import org.openide.explorer.*; 26 import org.openide.nodes.Node; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.AbstractNode; 29 import java.util.Collections ; 30 import java.util.Arrays ; 31 import java.awt.BorderLayout ; 32 import org.openide.explorer.view.BeanTreeView; 33 import javax.swing.JLabel ; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.io.NbMarshalledObject; 36 37 39 public class ExplorerActionsTest extends NbTestCase { 40 static { 41 Object x = ActionsInfraHid.UT; 43 } 44 45 private static javax.swing.Action delete = org.openide.util.actions.SystemAction.get ( 46 org.openide.actions.DeleteAction.class 47 ); 48 49 public ExplorerActionsTest (String name) { 50 super(name); 51 } 52 53 protected Level logLevel() { 54 return Level.FINER; 55 } 56 57 protected boolean runInEQ() { 58 return true; 59 } 60 61 public void testGlobalStateInExplorerActionsIsImportant () throws Exception { 62 EP panel = new EP (null); 63 ExplorerPanel.setConfirmDelete(false); 64 65 doDelete (panel); 66 } 67 68 public void testGlobalStateCanBeOverriden () throws Exception { 69 ExplorerActions actions = new ExplorerActions (); 70 actions.setConfirmDelete (false); 71 72 ExplorerPanel.setConfirmDelete(true); 73 EP panel = new EP (actions); 74 75 doDelete (panel); 76 } 77 78 public void testGlobalStateOnDeserializedPanel () throws Exception { 79 EP panel = new EP (null); 80 ExplorerPanel.setConfirmDelete(false); 81 setupExplorerManager (panel.getExplorerManager()); 82 83 NbMarshalledObject mar = new NbMarshalledObject (panel); 84 Object obj = mar.get (); 85 EP deserializedPanel = (EP) obj; 86 87 ActionsInfraHid.UT.setActivated (deserializedPanel); 89 deserializedPanel.componentActivated(); 90 91 ActionsInfraHid.UT.setCurrentNodes (deserializedPanel.getExplorerManager().getRootContext ().getChildren ().getNodes ()); 92 93 delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "")); 96 } 97 98 99 100 private void doDelete (EP panel) throws Exception { 101 setupExplorerManager (panel.getExplorerManager()); 102 ActionsInfraHid.UT.setActivated (panel); 104 panel.componentActivated(); 105 106 ActionsInfraHid.UT.setCurrentNodes (panel.getExplorerManager().getSelectedNodes()); 107 assertTrue ("Delete is allowed", delete.isEnabled()); 108 109 delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "")); 112 } 113 114 private static class RootNode extends AbstractNode { 115 public RootNode () { 116 super (new Children.Array ()); 117 } 118 public Node.Handle getHandle () { 119 return new H (); 120 } 121 private static class H implements Node.Handle { 122 H() {} 123 static final long serialVersionUID = -5158460093499159177L; 124 public Node getNode () throws java.io.IOException { 125 Node n = new RootNode (); 126 n.getChildren().add (new Node[] { 127 new Del ("H1"), new Del ("H2") 128 }); 129 return n; 130 } 131 } 132 } 133 134 private static class Del extends AbstractNode { 135 public Del (String name) { 136 super (Children.LEAF); 137 setName (name); 138 } 139 public boolean canDestroy () { 140 return true; 141 } 142 } 143 144 147 private static void setupExplorerManager (ExplorerManager em) throws Exception { 148 AbstractNode root = new RootNode (); 149 Node[] arr = new Node[] { 150 new Del ("1"), new Del ("2") 151 }; 152 root.getChildren().add (arr); 153 154 em.setRootContext(root); 155 em.setSelectedNodes(root.getChildren().getNodes()); 156 157 assertEquals ( 158 "Same nodes selected", 159 Arrays.asList (arr), 160 Arrays.asList (root.getChildren ().getNodes ()) 161 ); 162 } 163 164 166 private static class EP extends ExplorerPanel { 167 private ExplorerActions actions; 168 Node rootNode = null; 169 170 public EP () { 171 } 172 173 public EP (ExplorerActions actions) { 174 this.actions = actions; 175 } 176 177 public void componentActivated () { 178 super.componentActivated (); 179 if (actions != null) { 180 actions.attach(getExplorerManager ()); 181 } 182 } 183 184 } 185 } 186 | Popular Tags |