1 19 20 package org.openide.util.actions; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.List ; 27 import javax.swing.Action ; 28 import org.netbeans.junit.NbTestCase; 29 import org.openide.cookies.OpenCookie; 30 import org.openide.cookies.SaveCookie; 31 import org.openide.nodes.AbstractNode; 32 import org.openide.nodes.Children; 33 import org.openide.nodes.CookieSet; 34 import org.openide.nodes.FilterNode; 35 import org.openide.nodes.Node; 36 import org.openide.nodes.NodeEvent; 37 import org.openide.nodes.NodeListener; 38 import org.openide.nodes.NodeMemberEvent; 39 import org.openide.nodes.NodeReorderEvent; 40 import org.openide.util.HelpCtx; 41 import org.openide.util.lookup.AbstractLookup; 42 import org.openide.util.lookup.ProxyLookup; 43 44 47 public class CookieAction84636Test extends NbTestCase 48 implements NodeListener, PropertyChangeListener { 49 50 public CookieAction84636Test(String name) { 51 super(name); 52 } 53 54 private SimpleCookieAction a1; 55 private CookieNode n1; 56 57 protected void setUp() throws Exception { 58 a1 = SystemAction.get(SimpleCookieAction.class); 59 n1 = new CookieNode(); 60 n1.setName("n1"); 61 } 62 63 protected boolean runInEQ() { 64 return true; 65 } 66 67 public void testBasicUsage() throws Exception { 68 a1.addPropertyChangeListener(this); 69 70 FilterNode f1 = new FilterNode(n1); 71 72 f1.addPropertyChangeListener(this); 73 f1.addNodeListener(this); 74 Action context = a1.createContextAwareInstance(f1.getLookup()); 75 76 77 } 78 79 public void propertyChange(PropertyChangeEvent evt) { 80 } 81 82 public void childrenAdded(NodeMemberEvent ev) { 83 } 84 85 public void childrenRemoved(NodeMemberEvent ev) { 86 } 87 88 public void childrenReordered(NodeReorderEvent ev) { 89 } 90 91 public void nodeDestroyed(NodeEvent ev) { 92 } 93 94 95 public static class SimpleCookieAction extends CookieAction { 96 protected int mode() { 97 return MODE_EXACTLY_ONE; 98 } 99 protected Class [] cookieClasses() { 100 return new Class [] {OpenCookie.class}; 101 } 102 public static final List runOn = new ArrayList (); protected void performAction(Node[] activatedNodes) { 104 runOn.add(Arrays.asList(activatedNodes)); 105 } 106 public String getName() { 107 return "SimpleCookieAction"; 108 } 109 public HelpCtx getHelpCtx() { 110 return null; 111 } 112 protected boolean asynchronous() { 113 return false; 114 } 115 116 private boolean called = false; 117 protected boolean enable(Node[] activatedNodes) { 118 boolean retValue; 119 if (called) { 120 fail("Called already!"); 121 } 122 called =true; 123 124 retValue = super.enable(activatedNodes); 125 return retValue; 126 } 127 } 128 129 private static final class CookieNode extends AbstractNode { 130 private static final class Open implements OpenCookie { 131 public void open() { 132 } 134 } 135 public CookieNode() { 136 super(Children.LEAF); 137 getCookieSet().add(new Open()); 138 } 139 public void setHasCookie(boolean b) { 140 if (b && getCookie(OpenCookie.class) == null) { 141 getCookieSet().add(new Open()); 142 } else if (!b) { 143 OpenCookie o = getCookie(OpenCookie.class); 144 if (o != null) { 145 getCookieSet().remove(o); 146 } 147 } 148 } 149 } 150 151 } 152 153 | Popular Tags |