Lines 29-34
Link Here
|
29 |
import java.awt.Dialog; |
29 |
import java.awt.Dialog; |
30 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionEvent; |
31 |
import java.lang.reflect.InvocationTargetException; |
31 |
import java.lang.reflect.InvocationTargetException; |
|
|
32 |
import java.util.Collection; |
32 |
import java.util.logging.Level; |
33 |
import java.util.logging.Level; |
33 |
import java.util.logging.Logger; |
34 |
import java.util.logging.Logger; |
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JButton; |
Lines 38-43
Link Here
|
38 |
import org.openide.DialogDescriptor; |
39 |
import org.openide.DialogDescriptor; |
39 |
import org.openide.DialogDisplayer; |
40 |
import org.openide.DialogDisplayer; |
40 |
import org.openide.NotifyDescriptor; |
41 |
import org.openide.NotifyDescriptor; |
|
|
42 |
import org.openide.util.Lookup; |
43 |
import org.openide.util.lookup.Lookups; |
41 |
|
44 |
|
42 |
/** |
45 |
/** |
43 |
* |
46 |
* |
Lines 46-51
Link Here
|
46 |
public class OptionsDisplayerOpenTest extends NbTestCase { |
49 |
public class OptionsDisplayerOpenTest extends NbTestCase { |
47 |
private static TestDisplayer displayer = new TestDisplayer(); |
50 |
private static TestDisplayer displayer = new TestDisplayer(); |
48 |
private static final int REPEATER = 10; |
51 |
private static final int REPEATER = 10; |
|
|
52 |
private Collection<? extends RegisteredCategory> all; |
49 |
Logger log; |
53 |
Logger log; |
50 |
static { |
54 |
static { |
51 |
String[] layers = new String[] {"org/netbeans/api/options/mf-layer.xml"};//NOI18N |
55 |
String[] layers = new String[] {"org/netbeans/api/options/mf-layer.xml"};//NOI18N |
Lines 59-64
Link Here
|
59 |
|
63 |
|
60 |
protected void setUp() throws Exception { |
64 |
protected void setUp() throws Exception { |
61 |
log = Logger.getLogger("[Test - " + getName() + "]"); |
65 |
log = Logger.getLogger("[Test - " + getName() + "]"); |
|
|
66 |
Lookup lookup = Lookups.forPath("OptionsDialog"); // NOI18N |
67 |
Lookup.Result<RegisteredCategory> result = lookup.lookup(new Lookup.Template<RegisteredCategory>(RegisteredCategory.class)); |
68 |
all = result.allInstances(); |
69 |
assertTrue(all.size() > 0); |
62 |
} |
70 |
} |
63 |
|
71 |
|
64 |
protected void tearDown() throws Exception { |
72 |
protected void tearDown() throws Exception { |
Lines 70-75
Link Here
|
70 |
assertNotNull(OptionsDisplayer.getDefault()); |
78 |
assertNotNull(OptionsDisplayer.getDefault()); |
71 |
} |
79 |
} |
72 |
|
80 |
|
|
|
81 |
public void testSimulatesAllNecessaryCallAndCheckThreading() throws Exception { |
82 |
RegisteredCategory rcTemp = null; |
83 |
for (RegisteredCategory rc : all) { |
84 |
rcTemp = rc; |
85 |
break; |
86 |
} |
87 |
final RegisteredCategory registeredCategory = rcTemp; |
88 |
assertNotNull(registeredCategory); |
89 |
//cals getComponent,update, getLookup |
90 |
open("Registered", true); |
91 |
try { |
92 |
SwingUtilities.invokeAndWait(new Runnable() { |
93 |
public void run() { |
94 |
//calls isValid |
95 |
registeredCategory.setInvalid(); |
96 |
//calls getHelpCtx |
97 |
registeredCategory.helpChanged(); |
98 |
} |
99 |
}); |
100 |
} finally { |
101 |
//calls cancel |
102 |
close(false); |
103 |
|
104 |
try { |
105 |
open("Registered", true); |
106 |
} finally { |
107 |
//calls applyChanges |
108 |
close(); |
109 |
} |
110 |
registeredCategory.assertThreadingForAllCallsWereTested(); |
111 |
} |
112 |
} |
113 |
|
73 |
public void testOpenFromWorkerThread() { |
114 |
public void testOpenFromWorkerThread() { |
74 |
openOpen(null); |
115 |
openOpen(null); |
75 |
openOpen("Registered"); |
116 |
openOpen("Registered"); |
Lines 159-164
Link Here
|
159 |
} |
200 |
} |
160 |
|
201 |
|
161 |
public void close() { |
202 |
public void close() { |
|
|
203 |
close(true); |
204 |
} |
205 |
|
206 |
public void close(boolean okButtonForClose) { |
207 |
displayer.okButtonForClose = okButtonForClose; |
162 |
modality(displayer.descriptor); |
208 |
modality(displayer.descriptor); |
163 |
displayer.close(); |
209 |
displayer.close(); |
164 |
} |
210 |
} |
Lines 167-175
Link Here
|
167 |
return Level.FINE; |
213 |
return Level.FINE; |
168 |
} |
214 |
} |
169 |
|
215 |
|
170 |
private static class TestDisplayer extends DialogDisplayer implements Runnable { |
216 |
public static class TestDisplayer extends DialogDisplayer implements Runnable { |
171 |
DialogDescriptor descriptor; |
217 |
DialogDescriptor descriptor; |
172 |
private JDialog dialog; |
218 |
private JDialog dialog; |
|
|
219 |
boolean okButtonForClose = true; |
173 |
public Object notify(NotifyDescriptor descriptor) { |
220 |
public Object notify(NotifyDescriptor descriptor) { |
174 |
throw new UnsupportedOperationException("Not supported yet."); |
221 |
throw new UnsupportedOperationException("Not supported yet."); |
175 |
} |
222 |
} |
Lines 195-204
Link Here
|
195 |
if (descriptor != null) { |
242 |
if (descriptor != null) { |
196 |
Object[] oo = descriptor.getClosingOptions(); |
243 |
Object[] oo = descriptor.getClosingOptions(); |
197 |
for (int i = 0; i < oo.length; i++) { |
244 |
for (int i = 0; i < oo.length; i++) { |
198 |
String command = ((JButton)oo[i]).getActionCommand(); |
245 |
if (okButtonForClose && oo[i] instanceof JButton && ((JButton)oo[i]).getActionCommand().equals("OK")) { |
199 |
if (oo[i] instanceof JButton && "OK".equals(command)) { |
246 |
descriptor.getButtonListener().actionPerformed(new ActionEvent(oo[i], 0, ((JButton)oo[i]).getActionCommand())); |
200 |
descriptor.getButtonListener().actionPerformed(new ActionEvent(oo[i], 0, command)); |
|
|
201 |
return; |
247 |
return; |
|
|
248 |
} else if (!okButtonForClose && !(oo[i] instanceof JButton)) { |
249 |
descriptor.getButtonListener().actionPerformed(new ActionEvent(DialogDescriptor.CANCEL_OPTION, 0, "")); |
250 |
return; |
202 |
} |
251 |
} |
203 |
} |
252 |
} |
204 |
} |
253 |
} |