Lines 50-55
Link Here
|
50 |
import java.awt.KeyboardFocusManager; |
50 |
import java.awt.KeyboardFocusManager; |
51 |
import java.awt.event.ActionEvent; |
51 |
import java.awt.event.ActionEvent; |
52 |
import java.beans.FeatureDescriptor; |
52 |
import java.beans.FeatureDescriptor; |
|
|
53 |
import java.beans.PropertyChangeEvent; |
54 |
import java.beans.PropertyChangeListener; |
53 |
import java.util.ArrayList; |
55 |
import java.util.ArrayList; |
54 |
import java.util.Arrays; |
56 |
import java.util.Arrays; |
55 |
import java.util.Collection; |
57 |
import java.util.Collection; |
Lines 57-70
Link Here
|
57 |
import java.util.HashSet; |
59 |
import java.util.HashSet; |
58 |
import java.util.Iterator; |
60 |
import java.util.Iterator; |
59 |
import java.util.List; |
61 |
import java.util.List; |
60 |
import java.util.NoSuchElementException; |
|
|
61 |
import java.util.Set; |
62 |
import java.util.Set; |
62 |
import java.util.logging.Level; |
63 |
import java.util.logging.Level; |
63 |
import java.util.logging.Logger; |
64 |
import java.util.logging.Logger; |
64 |
import javax.swing.AbstractAction; |
65 |
import javax.swing.AbstractAction; |
|
|
66 |
import javax.swing.Action; |
65 |
import javax.swing.ActionMap; |
67 |
import javax.swing.ActionMap; |
|
|
68 |
import javax.swing.JButton; |
66 |
import javax.swing.JTextField; |
69 |
import javax.swing.JTextField; |
|
|
70 |
import javax.swing.event.ChangeEvent; |
71 |
import javax.swing.event.ChangeListener; |
67 |
import org.netbeans.junit.NbTestCase; |
72 |
import org.netbeans.junit.NbTestCase; |
|
|
73 |
import org.openide.awt.Actions; |
68 |
import org.openide.cookies.CloseCookie; |
74 |
import org.openide.cookies.CloseCookie; |
69 |
import org.openide.cookies.EditCookie; |
75 |
import org.openide.cookies.EditCookie; |
70 |
import org.openide.cookies.OpenCookie; |
76 |
import org.openide.cookies.OpenCookie; |
Lines 74-79
Link Here
|
74 |
import org.openide.nodes.Children; |
80 |
import org.openide.nodes.Children; |
75 |
import org.openide.nodes.FilterNode; |
81 |
import org.openide.nodes.FilterNode; |
76 |
import org.openide.nodes.Node; |
82 |
import org.openide.nodes.Node; |
|
|
83 |
import org.openide.util.ContextAwareAction; |
77 |
import org.openide.util.Lookup; |
84 |
import org.openide.util.Lookup; |
78 |
import org.openide.util.Lookup.Result; |
85 |
import org.openide.util.Lookup.Result; |
79 |
import org.openide.util.LookupEvent; |
86 |
import org.openide.util.LookupEvent; |
Lines 106-121
Link Here
|
106 |
|
113 |
|
107 |
/** Setup component with lookup. |
114 |
/** Setup component with lookup. |
108 |
*/ |
115 |
*/ |
|
|
116 |
@Override |
109 |
protected void setUp() { |
117 |
protected void setUp() { |
110 |
top = new TopComponent(); |
118 |
top = new TopComponent(); |
111 |
get = top; |
119 |
get = top; |
112 |
lookup = top.getLookup(); |
120 |
lookup = top.getLookup(); |
|
|
121 |
defaultFocusManager.setC(null); |
113 |
} |
122 |
} |
114 |
|
123 |
|
|
|
124 |
@Override |
115 |
protected boolean runInEQ() { |
125 |
protected boolean runInEQ() { |
116 |
return true; |
126 |
return true; |
117 |
} |
127 |
} |
118 |
|
128 |
|
|
|
129 |
@Override |
119 |
protected Level logLevel() { |
130 |
protected Level logLevel() { |
120 |
return Level.FINER; |
131 |
return Level.FINER; |
121 |
} |
132 |
} |
Lines 223-229
Link Here
|
223 |
assertEquals("Empty now", res.allItems().size(), 0); |
234 |
assertEquals("Empty now", res.allItems().size(), 0); |
224 |
|
235 |
|
225 |
LOG.fine("Changing state to 0x01"); |
236 |
LOG.fine("Changing state to 0x01"); |
226 |
arr[0].state(0x01); // enabled open cookie |
237 |
arr[0].state(0x01); // check open cookie |
227 |
LOG.fine("Changing state to 0x01 done"); |
238 |
LOG.fine("Changing state to 0x01 done"); |
228 |
|
239 |
|
229 |
assertEquals("One item", res.allItems().size(), 1); |
240 |
assertEquals("One item", res.allItems().size(), 1); |
Lines 507-512
Link Here
|
507 |
assertTrue("closeWindow was there: " + listener.keys2, listener.keys2.contains("closeWindow")); |
518 |
assertTrue("closeWindow was there: " + listener.keys2, listener.keys2.contains("closeWindow")); |
508 |
} |
519 |
} |
509 |
|
520 |
|
|
|
521 |
public void testActionMapFromFocusedOneButNotOwnButton() { |
522 |
ContextAwareAction a = Actions.callback("find", null, false, "Find", null, false); |
523 |
|
524 |
class Act extends AbstractAction { |
525 |
int cnt; |
526 |
Action check; |
527 |
|
528 |
@Override |
529 |
public void actionPerformed(ActionEvent ev) { |
530 |
cnt++; |
531 |
} |
532 |
} |
533 |
Act act1 = new Act(); |
534 |
Act act3 = new Act(); |
535 |
|
536 |
Action action = a; |
537 |
act1.check = action; |
538 |
act3.check = action; |
539 |
final JButton disabled = new JButton(); |
540 |
top.add(BorderLayout.CENTER, disabled); |
541 |
final JButton f = new JButton(action); |
542 |
class L implements PropertyChangeListener { |
543 |
private int cnt; |
544 |
@Override |
545 |
public void propertyChange(PropertyChangeEvent evt) { |
546 |
assertEquals("enabled", evt.getPropertyName()); |
547 |
cnt++; |
548 |
} |
549 |
} |
550 |
L listener = new L(); |
551 |
action.addPropertyChangeListener(listener); |
552 |
top.add(BorderLayout.SOUTH, f); |
553 |
defaultFocusManager.setC(top); |
554 |
|
555 |
disabled.getActionMap().put("find", act3); |
556 |
top.open(); |
557 |
top.requestActive(); |
558 |
assertFalse("Disabled by default", action.isEnabled()); |
559 |
assertFalse("Button disabled too", f.isEnabled()); |
560 |
assertEquals("no change yet", 0, listener.cnt); |
561 |
|
562 |
defaultFocusManager.setC(disabled); |
563 |
|
564 |
assertEquals("One change", 1, listener.cnt); |
565 |
assertTrue("Still enabled", action.isEnabled()); |
566 |
assertTrue("Button enabled too", f.isEnabled()); |
567 |
|
568 |
f.getModel().addChangeListener(new ChangeListener() { |
569 |
|
570 |
@Override |
571 |
public void stateChanged(ChangeEvent e) { |
572 |
if (f.getModel().isPressed()) { |
573 |
defaultFocusManager.setC(f); |
574 |
} else { |
575 |
defaultFocusManager.setC(disabled); |
576 |
} |
577 |
} |
578 |
}); |
579 |
f.doClick(); |
580 |
|
581 |
assertEquals("Not Delegated to act1", 0, act1.cnt); |
582 |
assertEquals("Delegated to act3", 1, act3.cnt); |
583 |
} |
584 |
|
510 |
|
585 |
|
511 |
public void testChangingNodesDoesNotChangeActionMap() { |
586 |
public void testChangingNodesDoesNotChangeActionMap() { |
512 |
N node = new N("testChangingNodesDoesNotChangeActionMap"); |
587 |
N node = new N("testChangingNodesDoesNotChangeActionMap"); |