1 19 20 package org.netbeans.core.windows.services; 21 22 import java.awt.datatransfer.Transferable ; 23 import java.awt.event.ActionEvent ; 24 import javax.swing.AbstractAction ; 25 import org.netbeans.junit.NbTestCase; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.Repository; 28 import org.openide.loaders.DataFolder; 29 import org.openide.loaders.DataObject; 30 import org.openide.util.datatransfer.PasteType; 31 32 35 public class ActionCopyPasteTest extends NbTestCase { 36 37 ToolbarFolderNode toolbar1; 38 ToolbarFolderNode toolbar2; 39 MenuFolderNode menu1; 40 MenuFolderNode menu2; 41 DataObject actionToPaste; 42 43 public ActionCopyPasteTest(String testName) { 44 super (testName); 45 } 46 47 protected void setUp() throws Exception { 48 toolbar1 = new ToolbarFolderNode( createFolder( "Toolbars", "tb1" ) ); 49 toolbar2 = new ToolbarFolderNode( createFolder( "Toolbars", "tb2" ) ); 50 51 menu1 = new MenuFolderNode( createFolder( "Menu", "menu1" ) ); 52 menu2 = new MenuFolderNode( createFolder( "Menu", "menu2" ) ); 53 54 createChildren( toolbar1.getDataObject().getPrimaryFile(), new Class [] { ActionA1.class, ActionA2.class } ); 55 createChildren( menu1.getDataObject().getPrimaryFile(), new Class [] { ActionA1.class, ActionA2.class } ); 56 57 createChildren( toolbar2.getDataObject().getPrimaryFile(), new Class [] { ActionB1.class, ActionB2.class } ); 58 createChildren( menu2.getDataObject().getPrimaryFile(), new Class [] { ActionB1.class, ActionB2.class } ); 59 60 } 61 62 protected boolean runInEQ () { 63 return true; 64 } 65 66 public void testDoNotPasteDuplicateActions() throws Exception { 67 DataObject[] folderChildren = ((DataFolder)toolbar1.getDataObject()).getChildren(); 69 DataObject child1 = folderChildren[0]; 70 Transferable t = child1.getNodeDelegate().clipboardCopy(); 71 PasteType[] types; 72 73 types = toolbar1.getPasteTypes( t ); 74 assertEquals( "Cannot paste an action if the toolbar already contains it.", 0, types.length ); 75 76 types = toolbar2.getPasteTypes( t ); 77 assertTrue( "Pasting to a different folder is ok.", types.length > 0 ); 78 79 types = menu1.getPasteTypes( t ); 80 assertEquals( "Cannot paste an action if the menu already contains it.", 0, types.length ); 81 82 types = menu2.getPasteTypes( t ); 83 assertTrue( "Pasting to a different menu is ok.", types.length > 0 ); 84 85 folderChildren = ((DataFolder)menu1.getDataObject()).getChildren(); 87 child1 = folderChildren[0]; 88 t = child1.getNodeDelegate().clipboardCopy(); 89 90 types = toolbar1.getPasteTypes( t ); 91 assertEquals( "Cannot paste an action if the toolbar already contains it.", 0, types.length ); 92 93 types = toolbar2.getPasteTypes( t ); 94 assertTrue( "Pasting to a different folder is ok.", types.length > 0 ); 95 96 types = menu1.getPasteTypes( t ); 97 assertEquals( "Cannot paste an action if the menu already contains it.", 0, types.length ); 98 99 types = menu2.getPasteTypes( t ); 100 assertTrue( "Pasting to a different menu is ok.", types.length > 0 ); 101 } 102 103 DataFolder createFolder( String parent, String folderName ) throws Exception { 104 FileObject folderObj = Repository.getDefault().getDefaultFileSystem().findResource( parent+"/"+folderName ); 105 if( null != folderObj ) 106 folderObj.delete(); 107 108 FileObject parentFolder = Repository.getDefault().getDefaultFileSystem().findResource( parent ); 109 assertNotNull( parentFolder ); 110 parentFolder.createFolder( folderName ); 111 112 DataFolder res = DataFolder.findFolder( Repository.getDefault().getDefaultFileSystem().findResource( parent+"/"+folderName ) ); 113 assertNotNull( res ); 114 return res; 115 } 116 117 void createChildren( FileObject folder, Class [] actions ) throws Exception { 118 for( int i=0; i<actions.length; i++ ) { 119 folder.createData( actions[i].getName()+".instance" ); 120 } 121 } 122 123 public static class ActionA1 extends AbstractAction { 124 public ActionA1() { 125 super( "actiona1" ); 126 } 127 128 public void actionPerformed(ActionEvent e) {} 129 } 130 131 public static class ActionA2 extends AbstractAction { 132 public ActionA2() { 133 super( "actiona2" ); 134 } 135 136 public void actionPerformed(ActionEvent e) {} 137 } 138 139 public static class ActionB1 extends AbstractAction { 140 public ActionB1() { 141 super( "actionb1" ); 142 } 143 144 public void actionPerformed(ActionEvent e) {} 145 } 146 147 public static class ActionB2 extends AbstractAction { 148 public ActionB2() { 149 super( "actionb2" ); 150 } 151 152 public void actionPerformed(ActionEvent e) {} 153 } 154 } 155 | Popular Tags |