Lines 40-48
Link Here
|
40 |
*/ |
40 |
*/ |
41 |
package org.netbeans.core; |
41 |
package org.netbeans.core; |
42 |
|
42 |
|
|
|
43 |
import java.awt.EventQueue; |
43 |
import java.awt.Toolkit; |
44 |
import java.awt.Toolkit; |
44 |
import java.awt.event.ActionEvent; |
45 |
import java.awt.event.ActionEvent; |
45 |
import java.awt.event.KeyEvent; |
46 |
import java.awt.event.KeyEvent; |
|
|
47 |
import java.beans.PropertyChangeEvent; |
48 |
import java.beans.PropertyChangeListener; |
46 |
import java.io.IOException; |
49 |
import java.io.IOException; |
47 |
import java.lang.ref.Reference; |
50 |
import java.lang.ref.Reference; |
48 |
import java.lang.ref.WeakReference; |
51 |
import java.lang.ref.WeakReference; |
Lines 95-103
Link Here
|
95 |
public void testApplyChangeToFactoryActionIssue49597 () throws Exception { |
98 |
public void testApplyChangeToFactoryActionIssue49597 () throws Exception { |
96 |
final FileSystem fs = Repository.getDefault ().getDefaultFileSystem (); |
99 |
final FileSystem fs = Repository.getDefault ().getDefaultFileSystem (); |
97 |
final FileObject shortcuts = fs.getRoot ().getFileObject ("Shortcuts"); |
100 |
final FileObject shortcuts = fs.getRoot ().getFileObject ("Shortcuts"); |
98 |
FileObject inst = FileUtil.createData (fs.getRoot (), "/Actions/Tools/TestAction.instance"); |
101 |
FileObject inst = FileUtil.createData (fs.getRoot (), "/Actions/Tools/org-netbeans-core-ShortcutsFolderTest$TestAction.instance"); |
99 |
TestAction action = new TestAction (); |
|
|
100 |
inst.setAttribute ("instanceCreate", action); |
101 |
|
102 |
|
102 |
Reference<?> ref = new WeakReference<Object>(inst); |
103 |
Reference<?> ref = new WeakReference<Object>(inst); |
103 |
inst = null; |
104 |
inst = null; |
Lines 114-120
Link Here
|
114 |
|
115 |
|
115 |
public void run() throws IOException { |
116 |
public void run() throws IOException { |
116 |
inst2 = FileUtil.createData (fs.getRoot (), "/Shortcuts/CA-F9.shadow"); |
117 |
inst2 = FileUtil.createData (fs.getRoot (), "/Shortcuts/CA-F9.shadow"); |
117 |
inst2.setAttribute ("originalFile", "/Actions/Tools/TestAction.instance"); |
118 |
inst2.setAttribute ("originalFile", "/Actions/Tools/org-netbeans-core-ShortcutsFolderTest$TestAction.instance"); |
118 |
} |
119 |
} |
119 |
} |
120 |
} |
120 |
R run = new R(); |
121 |
R run = new R(); |
Lines 125-140
Link Here
|
125 |
|
126 |
|
126 |
FileObject[] arr = shortcuts.getChildren (); |
127 |
FileObject[] arr = shortcuts.getChildren (); |
127 |
err.log("children are here"); |
128 |
err.log("children are here"); |
|
|
129 |
assertEquals("No test action created yet", 0, TestAction.cnt); |
128 |
|
130 |
|
129 |
assertEquals ("One element is there", 1, arr.length); |
131 |
assertEquals ("One element is there", 1, arr.length); |
130 |
org.openide.loaders.DataObject obj = org.openide.loaders.DataObject.find (arr[0]); |
132 |
org.openide.loaders.DataObject obj = org.openide.loaders.DataObject.find (arr[0]); |
131 |
err.log("Object is here" + obj); |
133 |
err.log("Object is here" + obj); |
|
|
134 |
assertEquals("No test action created yet", 0, TestAction.cnt); |
132 |
|
135 |
|
133 |
assertEquals ("It is DataShadow", org.openide.loaders.DataShadow.class, obj.getClass ()); |
136 |
assertEquals ("It is DataShadow", org.openide.loaders.DataShadow.class, obj.getClass ()); |
|
|
137 |
assertEquals("No test action created yet", 0, TestAction.cnt); |
134 |
|
138 |
|
135 |
Object a = keymap.getAction (stroke); |
139 |
final Object a = keymap.getAction (stroke); |
136 |
assertNotNull ("There is an action", a); |
140 |
assertNotNull ("There is an action", a); |
137 |
assertEquals ("It is test action", TestAction.class, a.getClass ()); |
141 |
assertEquals("No test action created yet", 0, TestAction.cnt); |
|
|
142 |
assertTrue("It is action", a instanceof Action); |
143 |
|
144 |
class RR implements Runnable, PropertyChangeListener { |
145 |
int change; |
146 |
|
147 |
public void run() { |
148 |
assertTrue("Enabled", ((Action)a).isEnabled()); |
149 |
((Action)a).actionPerformed(new ActionEvent(this, 0, "")); |
150 |
assertFalse("Disabled", ((Action)a).isEnabled()); |
151 |
assertEquals("One change", 1, change); |
152 |
} |
153 |
|
154 |
public void propertyChange(PropertyChangeEvent ev) { |
155 |
change++; |
156 |
} |
157 |
} |
158 |
RR call = new RR(); |
159 |
((Action)a).addPropertyChangeListener(call); |
160 |
EventQueue.invokeAndWait(call); |
161 |
|
162 |
assertEquals("Now the action is created", 1, TestAction.cnt); |
163 |
assertEquals("Now the action is called", 1, TestAction.invoke); |
138 |
} |
164 |
} |
139 |
|
165 |
|
140 |
@RandomlyFails |
166 |
@RandomlyFails |
Lines 174-180
Link Here
|
174 |
} |
200 |
} |
175 |
|
201 |
|
176 |
public static class TestAction extends AbstractAction { |
202 |
public static class TestAction extends AbstractAction { |
177 |
public void actionPerformed (ActionEvent ae) {} |
203 |
static int cnt; |
|
|
204 |
static int invoke; |
205 |
|
206 |
public TestAction() { |
207 |
cnt++; |
208 |
} |
209 |
|
210 |
public void actionPerformed (ActionEvent ae) { |
211 |
invoke++; |
212 |
setEnabled(!isEnabled()); |
213 |
} |
178 |
} |
214 |
} |
179 |
|
215 |
|
180 |
public static class ENV extends Object implements org.openide.loaders.Environment.Provider { |
216 |
public static class ENV extends Object implements org.openide.loaders.Environment.Provider { |