Lines 13-30
Link Here
|
13 |
|
13 |
|
14 |
package org.openide.nodes; |
14 |
package org.openide.nodes; |
15 |
|
15 |
|
|
|
16 |
import java.awt.event.ActionEvent; |
16 |
import java.beans.*; |
17 |
import java.beans.*; |
17 |
import java.util.*; |
18 |
import java.util.*; |
|
|
19 |
import javax.swing.AbstractAction; |
20 |
import javax.swing.Action; |
18 |
|
21 |
|
19 |
import junit.textui.TestRunner; |
22 |
import junit.textui.TestRunner; |
20 |
import org.netbeans.junit.NbTestCase; |
23 |
import org.netbeans.junit.NbTestCase; |
21 |
import org.netbeans.junit.NbTestSuite; |
24 |
import org.netbeans.junit.NbTestSuite; |
|
|
25 |
import org.openide.actions.OpenAction; |
26 |
import org.openide.actions.PropertiesAction; |
22 |
|
27 |
|
23 |
import org.openide.nodes.*; |
28 |
import org.openide.nodes.*; |
24 |
import org.openide.util.actions.SystemAction; |
29 |
import org.openide.util.actions.SystemAction; |
25 |
|
30 |
|
26 |
/** Checking some of the behaviour of Node. |
31 |
/** Checking some of the behaviour of Node (and AbstractNode). |
27 |
* @author Jaroslav Tulach |
32 |
* @author Jaroslav Tulach, Jesse Glick |
28 |
*/ |
33 |
*/ |
29 |
public class NodeTest extends NbTestCase { |
34 |
public class NodeTest extends NbTestCase { |
30 |
|
35 |
|
Lines 38-44
Link Here
|
38 |
|
43 |
|
39 |
public void testGetActions () throws Exception { |
44 |
public void testGetActions () throws Exception { |
40 |
final SystemAction[] arr1 = { |
45 |
final SystemAction[] arr1 = { |
41 |
SystemAction.get (org.openide.actions.PropertiesAction.class) |
46 |
SystemAction.get (PropertiesAction.class) |
42 |
}; |
47 |
}; |
43 |
final SystemAction[] arr2 = { |
48 |
final SystemAction[] arr2 = { |
44 |
}; |
49 |
}; |
Lines 57-62
Link Here
|
57 |
assertEquals ("getActions(false) properly delegates to getActions()", arr1, an.getActions (false)); |
62 |
assertEquals ("getActions(false) properly delegates to getActions()", arr1, an.getActions (false)); |
58 |
assertEquals ("getActions(true) properly delegates to getContextActions()", arr2, an.getActions (true)); |
63 |
assertEquals ("getActions(true) properly delegates to getContextActions()", arr2, an.getActions (true)); |
59 |
|
64 |
|
|
|
65 |
} |
66 |
|
67 |
public void testPreferredAction() throws Exception { |
68 |
final SystemAction a1 = SystemAction.get(PropertiesAction.class); |
69 |
final Action a2 = new AbstractAction() { |
70 |
public void actionPerformed(ActionEvent ev) {} |
71 |
}; |
72 |
final SystemAction a3 = SystemAction.get(OpenAction.class); |
73 |
final Action a4 = new AbstractAction() { |
74 |
public void actionPerformed(ActionEvent ev) {} |
75 |
}; |
76 |
// Old code: |
77 |
Node n1 = new AbstractNode(Children.LEAF) { |
78 |
{ |
79 |
setDefaultAction(a1); |
80 |
} |
81 |
}; |
82 |
Node n2 = new AbstractNode(Children.LEAF) { |
83 |
public SystemAction getDefaultAction() { |
84 |
return a1; |
85 |
} |
86 |
}; |
87 |
// New code: |
88 |
Node n3 = new AbstractNode(Children.LEAF) { |
89 |
{ |
90 |
setPreferredAction(a1); |
91 |
} |
92 |
}; |
93 |
Node n4 = new AbstractNode(Children.LEAF) { |
94 |
public Action getPreferredAction() { |
95 |
return a1; |
96 |
} |
97 |
}; |
98 |
Node n5 = new AbstractNode(Children.LEAF) { |
99 |
{ |
100 |
setPreferredAction(a2); |
101 |
} |
102 |
}; |
103 |
Node n6 = new AbstractNode(Children.LEAF) { |
104 |
public Action getPreferredAction() { |
105 |
return a2; |
106 |
} |
107 |
}; |
108 |
// Wacko code: |
109 |
Node n7 = new AbstractNode(Children.LEAF) { |
110 |
{ |
111 |
setDefaultAction(a1); |
112 |
} |
113 |
public SystemAction getDefaultAction() { |
114 |
return a3; |
115 |
} |
116 |
}; |
117 |
Node n8 = new AbstractNode(Children.LEAF) { |
118 |
{ |
119 |
setPreferredAction(a2); |
120 |
} |
121 |
public Action getPreferredAction() { |
122 |
return a4; |
123 |
} |
124 |
}; |
125 |
assertEquals(a1, n1.getDefaultAction()); |
126 |
assertEquals(a1, n1.getPreferredAction()); |
127 |
assertEquals(a1, n2.getDefaultAction()); |
128 |
assertEquals(a1, n2.getPreferredAction()); |
129 |
assertEquals(a1, n3.getDefaultAction()); |
130 |
assertEquals(a1, n3.getPreferredAction()); |
131 |
assertEquals(a1, n4.getDefaultAction()); |
132 |
assertEquals(a1, n4.getPreferredAction()); |
133 |
assertEquals(null, n5.getDefaultAction()); |
134 |
assertEquals(a2, n5.getPreferredAction()); |
135 |
assertEquals(null, n6.getDefaultAction()); |
136 |
assertEquals(a2, n6.getPreferredAction()); |
137 |
assertEquals(a3, n7.getDefaultAction()); |
138 |
assertEquals(a3, n7.getPreferredAction()); |
139 |
assertEquals(null, n8.getDefaultAction()); |
140 |
assertEquals(a4, n8.getPreferredAction()); |
60 |
} |
141 |
} |
61 |
|
142 |
|
62 |
} |
143 |
} |