# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /space/work/all2/core/options # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java --- /space/work/all2/core/options/test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java Base (1.1) +++ /space/work/all2/core/options/test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java Locally Modified (Based On 1.1) @@ -29,6 +29,7 @@ import java.awt.Dialog; import java.awt.event.ActionEvent; import java.lang.reflect.InvocationTargetException; +import java.util.Collection; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; @@ -38,6 +39,8 @@ import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; /** * @@ -46,6 +49,7 @@ public class OptionsDisplayerOpenTest extends NbTestCase { private static TestDisplayer displayer = new TestDisplayer(); private static final int REPEATER = 10; + private Collection all; Logger log; static { String[] layers = new String[] {"org/netbeans/api/options/mf-layer.xml"};//NOI18N @@ -59,6 +63,10 @@ protected void setUp() throws Exception { log = Logger.getLogger("[Test - " + getName() + "]"); + Lookup lookup = Lookups.forPath("OptionsDialog"); // NOI18N + Lookup.Result result = lookup.lookup(new Lookup.Template(RegisteredCategory.class)); + all = result.allInstances(); + assertTrue(all.size() > 0); } protected void tearDown() throws Exception { @@ -70,6 +78,39 @@ assertNotNull(OptionsDisplayer.getDefault()); } + public void testSimulatesAllNecessaryCallAndCheckThreading() throws Exception { + RegisteredCategory rcTemp = null; + for (RegisteredCategory rc : all) { + rcTemp = rc; + break; + } + final RegisteredCategory registeredCategory = rcTemp; + assertNotNull(registeredCategory); + //cals getComponent,update, getLookup + open("Registered", true); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + //calls isValid + registeredCategory.setInvalid(); + //calls getHelpCtx + registeredCategory.helpChanged(); + } + }); + } finally { + //calls cancel + close(false); + + try { + open("Registered", true); + } finally { + //calls applyChanges + close(); + } + registeredCategory.assertThreadingForAllCallsWereTested(); + } + } + public void testOpenFromWorkerThread() { openOpen(null); openOpen("Registered"); @@ -159,6 +200,11 @@ } public void close() { + close(true); + } + + public void close(boolean okButtonForClose) { + displayer.okButtonForClose = okButtonForClose; modality(displayer.descriptor); displayer.close(); } @@ -167,9 +213,10 @@ return Level.FINE; } - private static class TestDisplayer extends DialogDisplayer implements Runnable { + public static class TestDisplayer extends DialogDisplayer implements Runnable { DialogDescriptor descriptor; private JDialog dialog; + boolean okButtonForClose = true; public Object notify(NotifyDescriptor descriptor) { throw new UnsupportedOperationException("Not supported yet."); } @@ -195,10 +242,12 @@ if (descriptor != null) { Object[] oo = descriptor.getClosingOptions(); for (int i = 0; i < oo.length; i++) { - String command = ((JButton)oo[i]).getActionCommand(); - if (oo[i] instanceof JButton && "OK".equals(command)) { - descriptor.getButtonListener().actionPerformed(new ActionEvent(oo[i], 0, command)); + if (okButtonForClose && oo[i] instanceof JButton && ((JButton)oo[i]).getActionCommand().equals("OK")) { + descriptor.getButtonListener().actionPerformed(new ActionEvent(oo[i], 0, ((JButton)oo[i]).getActionCommand())); return; + } else if (!okButtonForClose && !(oo[i] instanceof JButton)) { + descriptor.getButtonListener().actionPerformed(new ActionEvent(DialogDescriptor.CANCEL_OPTION, 0, "")); + return; \ No newline at end of file } } } Index: test/unit/src/org/netbeans/api/options/RegisteredCategory.java --- /space/work/all2/core/options/test/unit/src/org/netbeans/api/options/RegisteredCategory.java Base (1.1) +++ /space/work/all2/core/options/test/unit/src/org/netbeans/api/options/RegisteredCategory.java Locally Modified (Based On 1.1) @@ -20,11 +20,17 @@ package org.netbeans.api.options; import java.awt.Image; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel; +import javax.swing.SwingUtilities; +import junit.framework.TestCase; import org.netbeans.spi.options.OptionsCategory; import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.HelpCtx; @@ -36,7 +42,18 @@ */ public final class RegisteredCategory extends OptionsCategory { private static Icon icon; + private static PropertyChangeListener propertyChangeListener; + private Collection calls = new HashSet(); + public void setInvalid() { + propertyChangeListener.propertyChange(new PropertyChangeEvent(this, OptionsPanelController.PROP_VALID, null, null)); + } + + public void helpChanged() { + propertyChangeListener.propertyChange(new PropertyChangeEvent(this, OptionsPanelController.PROP_HELP_CTX, null, null)); + } + + public Icon getIcon() { if (icon == null) { Image image = Utilities.loadImage("org/netbeans/modules/options/resources/generalOptions.png"); @@ -46,7 +63,7 @@ } public String getCategoryName() { - return "CTL_General_Options"; + return "CTL_General_Options"; } public String getTitle() { @@ -57,15 +74,37 @@ return "CTL_General_Options_Description"; } + public void assertThreadingForAllCallsWereTested() { + TestCase.assertTrue(calls.contains("update()")); + TestCase.assertTrue(calls.contains("cancel()")); + TestCase.assertTrue(calls.contains("isValid()")); + TestCase.assertTrue(calls.contains("getLookup()")); + TestCase.assertTrue(calls.contains("getComponent()")); + TestCase.assertTrue(calls.contains("applyChanges()")); + + } + public OptionsPanelController create() { return new OptionsPanelController() { - public void update() {} - public void applyChanges() {} + public void update() { + TestCase.assertTrue(SwingUtilities.isEventDispatchThread()); + calls.add("update()"); + } - public void cancel() {} + public void applyChanges() { + TestCase.assertTrue(SwingUtilities.isEventDispatchThread()); + calls.add("applyChanges()"); + } + public void cancel() { + TestCase.assertTrue(SwingUtilities.isEventDispatchThread()); + calls.add("cancel()"); + } + public boolean isValid() { + TestCase.assertTrue(SwingUtilities.isEventDispatchThread()); + calls.add("isValid()"); return true; } @@ -77,13 +116,26 @@ return null; } + public Lookup getLookup() { + TestCase.assertFalse(SwingUtilities.isEventDispatchThread()); + calls.add("getLookup()"); + return super.getLookup(); + } + + public JComponent getComponent(Lookup masterLookup) { + TestCase.assertTrue(SwingUtilities.isEventDispatchThread()); + calls.add("getComponent()"); return new JLabel(); } - public void addPropertyChangeListener(PropertyChangeListener l) {} + public void addPropertyChangeListener(PropertyChangeListener l) { + propertyChangeListener = l; + } - public void removePropertyChangeListener(PropertyChangeListener l) {} + public void removePropertyChangeListener(PropertyChangeListener l) { + propertyChangeListener = null; + } }; } } Index: src/org/netbeans/modules/options/OptionsDisplayerImpl.java --- /space/work/all2/core/options/src/org/netbeans/modules/options/OptionsDisplayerImpl.java Base (1.2) +++ /space/work/all2/core/options/src/org/netbeans/modules/options/OptionsDisplayerImpl.java Locally Modified (Based On 1.2) @@ -165,12 +165,8 @@ log.fine("Options Dialog - Ok pressed."); //NOI18N Dialog d = dialog; dialog = null; - d.dispose (); - RequestProcessor.getDefault ().post (new Runnable () { - public void run () { optionsPanel.save (); - } - }); + d.dispose (); } else if (e.getSource () == DialogDescriptor.CANCEL_OPTION || e.getSource () == DialogDescriptor.CLOSED_OPTION @@ -178,12 +174,8 @@ log.fine("Options Dialog - Cancel pressed."); //NOI18N Dialog d = dialog; dialog = null; - d.dispose (); - RequestProcessor.getDefault ().post (new Runnable () { - public void run () { optionsPanel.cancel (); - } - }); + d.dispose (); } else if (e.getSource () == bClassic) { log.fine("Options Dialog - Classic pressed."); //NOI18N @@ -198,32 +190,20 @@ Object result = DialogDisplayer.getDefault (). notify (descriptor); if (result == NotifyDescriptor.YES_OPTION) { - d.dispose (); - RequestProcessor.getDefault ().post (new Runnable () { - public void run () { optionsPanel.save (); - } - }); + d.dispose (); } else if (result == NotifyDescriptor.NO_OPTION) { - d.dispose (); - RequestProcessor.getDefault ().post (new Runnable () { - public void run () { optionsPanel.cancel (); - } - }); + d.dispose (); } else { dialog = d; return; } } else { d.dispose (); - RequestProcessor.getDefault ().post (new Runnable () { - public void run () { optionsPanel.cancel (); } - }); - } try { ClassLoader cl = (ClassLoader) Lookup.getDefault ().lookup (ClassLoader.class); Class clz = (Class)cl.loadClass("org.netbeans.core.actions.OptionsAction"); @@ -253,11 +233,7 @@ public void windowClosing (WindowEvent e) { if (dialog == null) return; log.fine("Options Dialog - windowClosing "); //NOI18N - RequestProcessor.getDefault ().post (new Runnable () { - public void run () { optionsPanel.cancel (); - } - }); if (this.originalDialog == dialog) { dialog = null; }