1 19 20 package org.netbeans.spi.looks; 21 22 import org.netbeans.junit.*; 23 24 import java.io.IOException ; 25 import javax.swing.Action ; 26 import org.openide.nodes.Node; 27 import org.openide.util.HelpCtx; 28 29 import org.openide.util.Lookup; 30 31 import org.netbeans.spi.looks.*; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.Repository; 35 import org.openide.util.actions.NodeAction; 36 37 38 40 public class DefaultLookValuesTest extends TestBaseValues { 41 42 44 public DefaultLookValuesTest(java.lang.String testName) { 45 super(testName); 46 } 47 48 public static void main(java.lang.String [] args) { 49 junit.textui.TestRunner.run(suite()); 50 } 51 52 public static NbTest suite() { 53 NbTestSuite suite = new NbTestSuite(DefaultLookValuesTest.class); 54 return suite; 55 } 56 57 protected void setUp() throws Exception { 58 59 Look look = createLook(); 60 setTarget( look, new SampleRepObject(), 1 ); 61 setGoldenValues( createGoldenValues() ); 62 63 super.setUp(); 64 } 65 66 protected void tearDown() throws Exception { 67 super.tearDown(); 68 } 69 70 71 73 79 public static final class MyAction extends NodeAction { 80 protected void performAction(Node[] activatedNodes) { 81 } 82 83 protected boolean enable(Node[] activatedNodes) { 84 return false; 85 } 86 87 public String getName() { 88 return getClass().getName(); 89 } 90 91 public HelpCtx getHelpCtx() { 92 return HelpCtx.DEFAULT_HELP; 93 } 94 95 } 96 97 public void testGetActions() throws Exception { 98 99 Action [] actions = look.getActions( representedObject, NO_LOOKUP ); 100 101 if ( actions != null ) { 102 fail( MSSG_UNEXPECTED_VALUE_RETURNED + actions ); 103 } 104 105 String folderName = "Looks/Actions/" + look.getClass().getName().replace( '.', '/' ) + 106 "/" + MyAction.class.getName().replace('.', '-') + ".instance"; 107 108 FileObject fo = FileUtil.createData ( 109 Repository.getDefault ().getDefaultFileSystem().getRoot(), 110 folderName 111 ); 112 113 actions = look.getActions ( representedObject, NO_LOOKUP ); 114 115 assertNotNull ("Not null", actions); 116 assertEquals ("One action", actions.length, 1); 117 assertTrue ("NewAction", actions[0] instanceof MyAction); 118 119 fo.delete (); 120 } 121 122 public void testIconBase() throws Exception { 123 fail( "The test case empty" ); 124 } 125 126 public void testActionBase() throws Exception { 127 fail( "The test case empty" ); 128 } 129 130 132 private static GoldenValue[] createGoldenValues() { 133 return new GoldenValue[] { 134 new GoldenValue( ProxyLook.GET_DISPLAY_NAME, null ), 135 new GoldenValue( ProxyLook.GET_NAME, null ), 136 new GoldenValue( ProxyLook.GET_SHORT_DESCRIPTION, null ), 138 new GoldenValue( ProxyLook.GET_ICON, null ), 139 new GoldenValue( ProxyLook.GET_OPENED_ICON, null ), 140 new GoldenValue( ProxyLook.GET_HELP_CTX, null ), 141 new GoldenValue( ProxyLook.GET_CHILD_OBJECTS, null ), 142 new GoldenValue( ProxyLook.GET_NEW_TYPES, null ), 143 new GoldenValue( ProxyLook.GET_ACTIONS, null ), 144 new GoldenValue( ProxyLook.GET_CONTEXT_ACTIONS, null ), 145 new GoldenValue( ProxyLook.GET_DEFAULT_ACTION, null ), 146 new GoldenValue( ProxyLook.GET_PROPERTY_SETS, null ), 147 new GoldenValue( ProxyLook.GET_CUSTOMIZER, null ), 148 new GoldenValue( ProxyLook.HAS_CUSTOMIZER, Boolean.FALSE ), 149 new GoldenValue( ProxyLook.CAN_RENAME, Boolean.FALSE ), 150 new GoldenValue( ProxyLook.CAN_DESTROY, Boolean.FALSE ), 151 new GoldenValue( ProxyLook.CAN_COPY, Boolean.FALSE ), 152 new GoldenValue( ProxyLook.CAN_CUT, Boolean.FALSE ), 153 new GoldenValue( ProxyLook.GET_PASTE_TYPES, null ), 154 new GoldenValue( ProxyLook.GET_DROP_TYPE, null ), 155 new GoldenValue( ProxyLook.CLIPBOARD_COPY, null ), 156 new GoldenValue( ProxyLook.CLIPBOARD_CUT, null ), 157 new GoldenValue( ProxyLook.DRAG, null ), 158 new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, null ) 159 }; 161 } 162 163 private static Look createLook() { 164 return new DefaultLook( "DefaultLookTest" ) { 165 166 public void attachTo( Object representedObject ) { 167 super.attachTo( representedObject ); 168 169 if ( representedObject instanceof SampleRepObject ) { 170 ((SampleRepObject)representedObject).attach(); 171 } 172 174 } 175 176 public void rename(Object representedObject, String newName, Lookup env ) { 177 if ( representedObject instanceof SampleRepObject ) { 178 ((SampleRepObject)representedObject).setName(); 179 } 180 } 181 182 public void destroy(Object representedObject, Lookup env ) throws IOException { 183 if ( representedObject instanceof SampleRepObject ) { 184 ((SampleRepObject)representedObject).destroy(); 185 } 186 } 187 }; 188 } 189 } 190 | Popular Tags |