Lines 50-74
Link Here
|
50 |
import java.awt.Frame; |
50 |
import java.awt.Frame; |
51 |
import java.awt.Dialog; |
51 |
import java.awt.Dialog; |
52 |
import java.awt.event.ActionEvent; |
52 |
import java.awt.event.ActionEvent; |
|
|
53 |
import java.beans.PropertyChangeListener; |
53 |
import java.lang.reflect.InvocationTargetException; |
54 |
import java.lang.reflect.InvocationTargetException; |
54 |
import java.lang.reflect.Method; |
55 |
import java.lang.reflect.Method; |
55 |
import java.util.Collection; |
56 |
import java.util.Collection; |
56 |
import java.util.logging.Level; |
57 |
import java.util.logging.Level; |
57 |
import java.util.logging.Logger; |
58 |
import java.util.logging.Logger; |
58 |
import javax.swing.JButton; |
59 |
import javax.swing.JButton; |
|
|
60 |
import javax.swing.JComponent; |
59 |
import javax.swing.JDialog; |
61 |
import javax.swing.JDialog; |
|
|
62 |
import javax.swing.JLabel; |
60 |
import javax.swing.SwingUtilities; |
63 |
import javax.swing.SwingUtilities; |
61 |
import org.netbeans.junit.NbTestCase; |
64 |
import org.netbeans.junit.NbTestCase; |
62 |
import org.netbeans.junit.RandomlyFails; |
65 |
import org.netbeans.junit.RandomlyFails; |
63 |
import org.netbeans.modules.options.advanced.Advanced; |
|
|
64 |
import org.netbeans.modules.options.advanced.AdvancedPanel; |
66 |
import org.netbeans.modules.options.advanced.AdvancedPanel; |
65 |
import org.netbeans.modules.options.advanced.AdvancedPanelController; |
67 |
import org.netbeans.modules.options.advanced.AdvancedPanelController; |
66 |
import org.netbeans.spi.options.OptionsCategory; |
68 |
import org.netbeans.spi.options.OptionsCategory; |
|
|
69 |
import org.netbeans.spi.options.OptionsPanelController; |
67 |
import org.openide.DialogDescriptor; |
70 |
import org.openide.DialogDescriptor; |
68 |
import org.openide.DialogDisplayer; |
71 |
import org.openide.DialogDisplayer; |
69 |
import org.openide.NotifyDescriptor; |
72 |
import org.openide.NotifyDescriptor; |
|
|
73 |
import org.openide.util.HelpCtx; |
70 |
import org.openide.util.Lookup; |
74 |
import org.openide.util.Lookup; |
71 |
import org.openide.util.lookup.Lookups; |
75 |
import org.openide.util.lookup.Lookups; |
|
|
76 |
import org.openide.util.test.MockLookup; |
72 |
|
77 |
|
73 |
/** |
78 |
/** |
74 |
* |
79 |
* |
Lines 79-89
Link Here
|
79 |
private static final int REPEATER = 10; |
84 |
private static final int REPEATER = 10; |
80 |
private Collection<? extends RegisteredCategory> all; |
85 |
private Collection<? extends RegisteredCategory> all; |
81 |
Logger log; |
86 |
Logger log; |
82 |
static { |
|
|
83 |
String[] layers = new String[] {"org/netbeans/api/options/mf-layer.xml"};//NOI18N |
84 |
Object[] instances = new Object[] {displayer}; |
85 |
IDEInitializer.setup(layers,instances); |
86 |
} |
87 |
|
87 |
|
88 |
public OptionsDisplayerOpenTest(String testName) { |
88 |
public OptionsDisplayerOpenTest(String testName) { |
89 |
super(testName); |
89 |
super(testName); |
Lines 93-103
Link Here
|
93 |
|
93 |
|
94 |
@Override |
94 |
@Override |
95 |
protected void setUp() throws Exception { |
95 |
protected void setUp() throws Exception { |
|
|
96 |
MockLookup.setInstances(displayer); |
96 |
log = Logger.getLogger("[Test - " + getName() + "]"); |
97 |
log = Logger.getLogger("[Test - " + getName() + "]"); |
97 |
lookup = Lookups.forPath("OptionsDialog"); // NOI18N |
98 |
lookup = Lookups.forPath("OptionsDialog"); // NOI18N |
98 |
Lookup.Result<RegisteredCategory> result = lookup.lookup(new Lookup.Template<RegisteredCategory>(RegisteredCategory.class)); |
99 |
all = lookup.lookupAll(RegisteredCategory.class); |
99 |
all = result.allInstances(); |
|
|
100 |
assertTrue(all.size() > 0); |
101 |
} |
100 |
} |
102 |
|
101 |
|
103 |
/** |
102 |
/** |
Lines 122-130
Link Here
|
122 |
SwingUtilities.invokeAndWait(new Runnable() { |
121 |
SwingUtilities.invokeAndWait(new Runnable() { |
123 |
public void run() { |
122 |
public void run() { |
124 |
//calls isValid |
123 |
//calls isValid |
125 |
registeredCategory.setInvalid(); |
124 |
RegisteredCategory.setInvalid(); |
126 |
//calls getHelpCtx |
125 |
//calls getHelpCtx |
127 |
registeredCategory.helpChanged(); |
126 |
RegisteredCategory.helpChanged(); |
128 |
} |
127 |
} |
129 |
}); |
128 |
}); |
130 |
} finally { |
129 |
} finally { |
Lines 137-143
Link Here
|
137 |
//calls applyChanges |
136 |
//calls applyChanges |
138 |
close(); |
137 |
close(); |
139 |
} |
138 |
} |
140 |
registeredCategory.assertThreadingForAllCallsWereTested(); |
139 |
RegisteredCategory.assertThreadingForAllCallsWereTested(); |
141 |
} |
140 |
} |
142 |
} |
141 |
} |
143 |
|
142 |
|
Lines 183-198
Link Here
|
183 |
*/ |
182 |
*/ |
184 |
public void testAdvancedSubcategorySelection() throws Exception { |
183 |
public void testAdvancedSubcategorySelection() throws Exception { |
185 |
open(OptionsDisplayer.ADVANCED, true); |
184 |
open(OptionsDisplayer.ADVANCED, true); |
186 |
assertEquals("First subcategory should be selected by default.", Subcategory1.DISPLAY_NAME, getSelectedSubcategory(Advanced.class)); |
185 |
assertEquals("First subcategory should be selected by default.", "Subcategory1 display name", getSelectedSubcategory("Advanced")); |
187 |
close(); |
186 |
close(); |
188 |
open(OptionsDisplayer.ADVANCED+"/Subcategory2", true); |
187 |
open(OptionsDisplayer.ADVANCED+"/Subcategory2", true); |
189 |
assertEquals("Wrong subcategory selected.", Subcategory2.DISPLAY_NAME, getSelectedSubcategory(Advanced.class)); |
188 |
assertEquals("Wrong subcategory selected.", "Subcategory2 display name", getSelectedSubcategory("Advanced")); |
190 |
close(); |
189 |
close(); |
191 |
open(OptionsDisplayer.ADVANCED+"/UnknownID", true); |
190 |
open(OptionsDisplayer.ADVANCED+"/UnknownID", true); |
192 |
assertEquals("Wrong subcategory selected.", Subcategory2.DISPLAY_NAME, getSelectedSubcategory(Advanced.class)); |
191 |
assertEquals("Wrong subcategory selected.", "Subcategory2 display name", getSelectedSubcategory("Advanced")); |
193 |
close(); |
192 |
close(); |
194 |
open(OptionsDisplayer.ADVANCED+"/Subcategory1", true); |
193 |
open(OptionsDisplayer.ADVANCED+"/Subcategory1", true); |
195 |
assertEquals("Wrong subcategory selected.", Subcategory1.DISPLAY_NAME, getSelectedSubcategory(Advanced.class)); |
194 |
assertEquals("Wrong subcategory selected.", "Subcategory1 display name", getSelectedSubcategory("Advanced")); |
196 |
close(); |
195 |
close(); |
197 |
} |
196 |
} |
198 |
|
197 |
|
Lines 201-225
Link Here
|
201 |
*/ |
200 |
*/ |
202 |
public void testSubcategorySelection() throws Exception { |
201 |
public void testSubcategorySelection() throws Exception { |
203 |
open("MyAdvancedCategory", true); |
202 |
open("MyAdvancedCategory", true); |
204 |
assertEquals("Subcategory2 should be first and selected by default.", Subcategory2.DISPLAY_NAME, getSelectedSubcategory(MyAdvancedCategory.class)); |
203 |
assertEquals("Subcategory2 should be first and selected by default.", "Subcategory2 display name", getSelectedSubcategory("MyAdvancedCategory")); |
205 |
close(); |
204 |
close(); |
206 |
open("MyAdvancedCategory/Subcategory1", true); |
205 |
open("MyAdvancedCategory/Subcategory1", true); |
207 |
assertEquals("Wrong subcategory selected.", Subcategory1.DISPLAY_NAME, getSelectedSubcategory(MyAdvancedCategory.class)); |
206 |
assertEquals("Wrong subcategory selected.", "Subcategory1 display name", getSelectedSubcategory("MyAdvancedCategory")); |
208 |
close(); |
207 |
close(); |
209 |
open("MyAdvancedCategory/UnknownID", true); |
208 |
open("MyAdvancedCategory/UnknownID", true); |
210 |
assertEquals("Wrong subcategory selected.", Subcategory1.DISPLAY_NAME, getSelectedSubcategory(MyAdvancedCategory.class)); |
209 |
assertEquals("Wrong subcategory selected.", "Subcategory1 display name", getSelectedSubcategory("MyAdvancedCategory")); |
211 |
close(); |
210 |
close(); |
212 |
open("MyAdvancedCategory/Subcategory2", true); |
211 |
open("MyAdvancedCategory/Subcategory2", true); |
213 |
assertEquals("Wrong subcategory selected.", Subcategory2.DISPLAY_NAME, getSelectedSubcategory(MyAdvancedCategory.class)); |
212 |
assertEquals("Wrong subcategory selected.", "Subcategory2 display name", getSelectedSubcategory("MyAdvancedCategory")); |
214 |
close(); |
213 |
close(); |
215 |
open("MyAdvancedCategory/Subcategory2/Subcategory22", true); |
214 |
open("MyAdvancedCategory/Subcategory2/Subcategory22", true); |
216 |
assertEquals("setCurrentSubcategory not called in Subcategory2 controller.", "Subcategory22", Subcategory2.getSubpath()); |
215 |
assertEquals("setCurrentSubcategory not called in Subcategory2 controller.", "Subcategory22", Subcategory.currentSubpath); |
217 |
close(); |
216 |
close(); |
218 |
} |
217 |
} |
219 |
|
218 |
|
220 |
/** Returns display name of subcategory selected in AdvancedPanel. */ |
219 |
/** Returns display name of subcategory selected in AdvancedPanel. */ |
221 |
private String getSelectedSubcategory(Class<? extends OptionsCategory> categoryClass) throws Exception { |
220 |
private String getSelectedSubcategory(String id) throws Exception { |
222 |
OptionsCategory category = lookup.lookup(categoryClass); |
221 |
Collection<? extends OptionsCategory> instances = lookup.lookup(new Lookup.Template<OptionsCategory>(OptionsCategory.class, id, null)).allInstances(); |
|
|
222 |
assertEquals("got wrong instances for " + id, 1, instances.size()); |
223 |
OptionsCategory category = instances.iterator().next(); |
223 |
Method getAdvancedPanelMethod = AdvancedPanelController.class.getDeclaredMethod("getAdvancedPanel", (Class[])null); |
224 |
Method getAdvancedPanelMethod = AdvancedPanelController.class.getDeclaredMethod("getAdvancedPanel", (Class[])null); |
224 |
getAdvancedPanelMethod.setAccessible(true); |
225 |
getAdvancedPanelMethod.setAccessible(true); |
225 |
AdvancedPanel advancedPanel = (AdvancedPanel)getAdvancedPanelMethod.invoke(category.create(), (Object[])null); |
226 |
AdvancedPanel advancedPanel = (AdvancedPanel)getAdvancedPanelMethod.invoke(category.create(), (Object[])null); |
Lines 302-311
Link Here
|
302 |
displayer.close(); |
303 |
displayer.close(); |
303 |
} |
304 |
} |
304 |
|
305 |
|
305 |
@Override |
306 |
// @Override |
306 |
protected Level logLevel() { |
307 |
// protected Level logLevel() { |
307 |
return Level.FINE; |
308 |
// return Level.FINE; |
308 |
} |
309 |
// } |
309 |
|
310 |
|
310 |
public static class TestDisplayer extends DialogDisplayer implements Runnable { |
311 |
public static class TestDisplayer extends DialogDisplayer implements Runnable { |
311 |
DialogDescriptor descriptor; |
312 |
DialogDescriptor descriptor; |
Lines 360-363
Link Here
|
360 |
} |
361 |
} |
361 |
} |
362 |
} |
362 |
} |
363 |
} |
363 |
} |
364 |
|
|
|
365 |
private static abstract class Subcategory extends OptionsPanelController { |
366 |
public void update() {} |
367 |
public void applyChanges() {} |
368 |
public void cancel() {} |
369 |
public boolean isValid() { |
370 |
return true; |
371 |
} |
372 |
public boolean isChanged() { |
373 |
return false; |
374 |
} |
375 |
public JComponent getComponent(Lookup masterLookup) { |
376 |
return new JLabel(); |
377 |
} |
378 |
public HelpCtx getHelpCtx() { |
379 |
return null; |
380 |
} |
381 |
public void addPropertyChangeListener(PropertyChangeListener l) {} |
382 |
public void removePropertyChangeListener(PropertyChangeListener l) {} |
383 |
static String currentSubpath; |
384 |
public @Override void setCurrentSubcategory(String subpath) { |
385 |
currentSubpath = subpath; |
386 |
} |
387 |
} |
388 |
|
389 |
@OptionsPanelController.SubRegistration( |
390 |
displayName="Subcategory1 display name" |
391 |
) |
392 |
public static class Subcategory1a extends Subcategory {} |
393 |
|
394 |
@OptionsPanelController.SubRegistration( |
395 |
displayName="Subcategory2 display name" |
396 |
) |
397 |
public static class Subcategory2a extends Subcategory {} |
398 |
|
399 |
@OptionsPanelController.SubRegistration( |
400 |
displayName="Subcategory1 display name", |
401 |
location="MyAdvancedCategory", |
402 |
position=102 |
403 |
) |
404 |
public static class Subcategory1b extends Subcategory {} |
405 |
|
406 |
@OptionsPanelController.SubRegistration( |
407 |
displayName="Subcategory2 display name", |
408 |
location="MyAdvancedCategory", |
409 |
position=101 |
410 |
) |
411 |
public static class Subcategory2b extends Subcategory {} |
412 |
|
413 |
} |