1 19 20 package org.openide.windows; 21 22 import java.awt.KeyboardFocusManager ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.logging.Logger ; 26 import javax.swing.ActionMap ; 27 import javax.swing.text.DefaultEditorKit ; 28 29 import junit.framework.*; 30 31 import org.netbeans.junit.*; 32 import org.openide.explorer.*; 33 import org.openide.nodes.AbstractNode; 34 import org.openide.nodes.Children; 35 import org.openide.nodes.FilterNode; 36 import org.openide.nodes.Node; 37 import org.openide.util.Lookup; 38 import org.openide.util.lookup.AbstractLookup; 39 import org.openide.util.lookup.InstanceContent; 40 41 42 43 49 public class TopComponentGetLookupOverridenTest extends TopComponentGetLookupTest { 50 private Logger LOG = Logger.getLogger(TopComponentGetLookupOverridenTest.class + ".TEST-" + getName()); 51 52 public TopComponentGetLookupOverridenTest (java.lang.String testName) { 53 super(testName); 54 } 55 56 58 protected void setUp () { 59 ListingYourComponent tc = new ListingYourComponent (LOG); 60 top = tc; 61 get = tc.delegate; 62 lookup = tc.delegate.getLookup (); 63 } 64 65 66 private static class ListingYourComponent extends TopComponent 67 implements java.beans.PropertyChangeListener { 68 YourComponent delegate; 69 private Logger LOG; 70 71 public ListingYourComponent (Logger l) { 72 delegate = new YourComponent(); 73 LOG = l; 74 75 addPropertyChangeListener (this); 76 delegate.getExplorerManager ().setRootContext (new AbstractNode (new Children.Array ())); 77 java.lang.ref.SoftReference ref = new java.lang.ref.SoftReference (new Object ()); 78 assertGC ("Trying to simulate issue 40842, to GC TopComponent$SynchronizeNodes", ref); 79 80 delegate.getExplorerManager().addPropertyChangeListener(this); 81 } 82 83 private ThreadLocal callbacks = new ThreadLocal (); 84 public void propertyChange (java.beans.PropertyChangeEvent ev) { 85 ExplorerManager manager = delegate.getExplorerManager (); 86 87 LOG.info("propertyChange: " + ev.getPropertyName()); 88 89 if ("activatedNodes".equals (ev.getPropertyName())) { 90 if (Boolean.TRUE.equals (callbacks.get ())) { 91 LOG.info(" it was callback"); 92 return; 93 } 94 try { 95 callbacks.set (Boolean.TRUE); 96 Node[] arr = getActivatedNodes (); 97 98 LOG.info("settings ndoes to zero"); 99 setActivatedNodes (ownNode()); 102 103 104 Children.Array ch = (Children.Array)manager.getRootContext ().getChildren (); 105 for (int i = 0; i < arr.length; i++) { 106 if (arr[i].getParentNode() != manager.getRootContext()) { 107 assertTrue ("If this fails we are in troubles", ch.add (new Node[] { arr[i] })); 108 } 109 } 110 LOG.info("em setSelectedNodes: " + Arrays.asList(arr)); 111 manager.setSelectedNodes (arr); 112 LOG.info("em setSelectedNodes done: " + Arrays.asList(arr)); 113 } catch (java.beans.PropertyVetoException ex) { 114 ex.printStackTrace(); 115 fail (ex.getMessage()); 116 } finally { 117 callbacks.set (null); 118 } 119 } 120 121 } 122 123 public String toString() { 124 return "ListingYourComponent"; 125 } 126 127 128 private static Node[] ownNode() { 129 AbstractNode a = new AbstractNode(Children.LEAF); 130 a.setName("ownNode"); 131 return new Node[] { a }; 132 } 133 } 135 public static class YourComponent extends TopComponent 138 implements ExplorerManager.Provider, Lookup.Provider { 139 private ExplorerManager manager; 140 public YourComponent() { 141 this.manager = new ExplorerManager (); 142 ActionMap map = getActionMap (); 143 map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); 144 map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); 145 map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); 146 map.put("delete", ExplorerUtils.actionDelete(manager, true)); 148 associateLookup (ExplorerUtils.createLookup (manager, map)); 149 } 150 public ExplorerManager getExplorerManager() { 151 return manager; 152 } 153 protected void componentActivated() { 156 ExplorerUtils.activateActions(manager, true); 157 } 158 protected void componentDeactivated() { 159 ExplorerUtils.activateActions(manager, false); 160 } 161 public String toString() { 162 return "YourComponent"; 163 } 164 } } 166 167 | Popular Tags |