1 19 20 21 package org.openide.explorer; 22 23 import java.util.Arrays ; 24 25 import junit.framework.Test; 26 import junit.framework.TestSuite; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.junit.NbTestSuite; 29 30 import javax.swing.Action ; 31 import javax.swing.ActionMap ; 32 import javax.swing.JMenu ; 33 import javax.swing.text.DefaultEditorKit ; 34 35 import org.openide.actions.CopyAction; 36 import org.openide.actions.CutAction; 37 import org.openide.nodes.Children; 38 import org.openide.nodes.Node; 39 import org.openide.nodes.AbstractNode; 40 import org.openide.util.actions.SystemAction; 41 import org.openide.util.ContextAwareAction; 42 import org.openide.util.Lookup; 43 import org.openide.util.Utilities; 44 import org.openide.util.datatransfer.PasteType; 45 46 47 54 public class ExplorerActionsImplTest extends ExplorerPanelTest { 55 56 public ExplorerActionsImplTest(java.lang.String testName) { 57 super(testName); 58 } 59 60 public static void main(java.lang.String [] args) { 61 junit.textui.TestRunner.run(suite()); 62 } 63 64 public static Test suite() { 65 TestSuite suite = new NbTestSuite(ExplorerActionsImplTest.class); 66 return suite; 67 } 68 69 71 protected Object [] createManagerAndContext (boolean confirm) { 72 ExplorerManager em = new ExplorerManager (); 73 ActionMap map = new ActionMap (); 74 map.put (DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(em)); 75 map.put (DefaultEditorKit.cutAction, ExplorerUtils.actionCut(em)); 76 map.put (DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(em)); 77 map.put ("delete", ExplorerUtils.actionDelete(em, confirm)); 78 79 return new Object [] { em, org.openide.util.lookup.Lookups.singleton(map) }; 80 } 81 82 84 protected void stopActions(ExplorerManager em) { 85 ExplorerUtils.activateActions (em, false); 86 } 87 89 protected void startActions (ExplorerManager em) { 90 ExplorerUtils.activateActions (em, true); 91 } 92 93 94 public void testActionDeleteDoesNotAffectStateOfPreviousInstances () throws Exception { 95 ExplorerManager em = new ExplorerManager (); 96 Action a1 = ExplorerUtils.actionDelete(em, false); 97 Action a2 = ExplorerUtils.actionDelete(em, true); 98 99 Node node = new AbstractNode (Children.LEAF) { 100 public boolean canDestroy () { 101 return true; 102 } 103 }; 104 em.setRootContext(node); 105 em.setSelectedNodes(new Node[] { node }); 106 107 assertTrue ("A1 enabled", a1.isEnabled()); 108 assertTrue ("A2 enabled", a2.isEnabled()); 109 110 a1.actionPerformed (new java.awt.event.ActionEvent (this, 0, "")); 112 } 113 } 114 | Popular Tags |