This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 106989
Collapse All | Expand All

(-)test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java (-4 / +53 lines)
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
            }
(-)test/unit/src/org/netbeans/api/options/RegisteredCategory.java (-6 / +58 lines)
Lines 20-30 Link Here
20
package org.netbeans.api.options;
20
package org.netbeans.api.options;
21
21
22
import java.awt.Image;
22
import java.awt.Image;
23
import java.beans.PropertyChangeEvent;
23
import java.beans.PropertyChangeListener;
24
import java.beans.PropertyChangeListener;
25
import java.util.Arrays;
26
import java.util.Collection;
27
import java.util.HashSet;
24
import javax.swing.Icon;
28
import javax.swing.Icon;
25
import javax.swing.ImageIcon;
29
import javax.swing.ImageIcon;
26
import javax.swing.JComponent;
30
import javax.swing.JComponent;
27
import javax.swing.JLabel;
31
import javax.swing.JLabel;
32
import javax.swing.SwingUtilities;
33
import junit.framework.TestCase;
28
import org.netbeans.spi.options.OptionsCategory;
34
import org.netbeans.spi.options.OptionsCategory;
29
import org.netbeans.spi.options.OptionsPanelController;
35
import org.netbeans.spi.options.OptionsPanelController;
30
import org.openide.util.HelpCtx;
36
import org.openide.util.HelpCtx;
Lines 36-42 Link Here
36
 */
42
 */
37
public final class RegisteredCategory extends OptionsCategory {
43
public final class RegisteredCategory extends OptionsCategory {
38
    private static Icon icon;
44
    private static Icon icon;
45
    private static PropertyChangeListener propertyChangeListener;
46
    private Collection<String> calls = new HashSet<String>();
39
    
47
    
48
    public void setInvalid() {
49
        propertyChangeListener.propertyChange(new PropertyChangeEvent(this, OptionsPanelController.PROP_VALID, null, null));
50
    }
51
    
52
    public void helpChanged() {
53
        propertyChangeListener.propertyChange(new PropertyChangeEvent(this, OptionsPanelController.PROP_HELP_CTX, null, null));
54
    }
55
    
56
40
    public Icon getIcon() {
57
    public Icon getIcon() {
41
        if (icon == null) {
58
        if (icon == null) {
42
            Image image = Utilities.loadImage("org/netbeans/modules/options/resources/generalOptions.png");
59
            Image image = Utilities.loadImage("org/netbeans/modules/options/resources/generalOptions.png");
Lines 46-52 Link Here
46
    }
63
    }
47
    
64
    
48
    public String getCategoryName() {
65
    public String getCategoryName() {
49
        return  "CTL_General_Options";
66
        return "CTL_General_Options";
50
    }
67
    }
51
    
68
    
52
    public String getTitle() {
69
    public String getTitle() {
Lines 57-71 Link Here
57
        return "CTL_General_Options_Description";
74
        return "CTL_General_Options_Description";
58
    }
75
    }
59
    
76
    
77
    public void assertThreadingForAllCallsWereTested() {
78
        TestCase.assertTrue(calls.contains("update()"));
79
        TestCase.assertTrue(calls.contains("cancel()"));        
80
        TestCase.assertTrue(calls.contains("isValid()"));
81
        TestCase.assertTrue(calls.contains("getLookup()"));
82
        TestCase.assertTrue(calls.contains("getComponent()"));        
83
        TestCase.assertTrue(calls.contains("applyChanges()"));
84
        
85
    }
86
60
    public OptionsPanelController create() {
87
    public OptionsPanelController create() {
61
        return new OptionsPanelController() {
88
        return new OptionsPanelController() {
62
            public void update() {}
63
            
89
            
64
            public void applyChanges() {}
90
            public void update() {
91
                TestCase.assertTrue(SwingUtilities.isEventDispatchThread());
92
                calls.add("update()");
93
            }
65
            
94
            
66
            public void cancel() {}
95
            public void applyChanges() {
96
                TestCase.assertTrue(SwingUtilities.isEventDispatchThread());
97
                calls.add("applyChanges()");
98
            }
67
            
99
            
100
            public void cancel() {
101
                TestCase.assertTrue(SwingUtilities.isEventDispatchThread());
102
                calls.add("cancel()");
103
            }
104
68
            public boolean isValid() {
105
            public boolean isValid() {
106
                TestCase.assertTrue(SwingUtilities.isEventDispatchThread());
107
                calls.add("isValid()");
69
                return true;
108
                return true;
70
            }
109
            }
71
            
110
            
Lines 77-89 Link Here
77
                return null;
116
                return null;
78
            }
117
            }
79
            
118
            
119
            public Lookup getLookup() {
120
                TestCase.assertFalse(SwingUtilities.isEventDispatchThread());
121
                calls.add("getLookup()");                
122
                return super.getLookup();
123
            }
124
            
125
80
            public JComponent getComponent(Lookup masterLookup) {
126
            public JComponent getComponent(Lookup masterLookup) {
127
                TestCase.assertTrue(SwingUtilities.isEventDispatchThread());
128
                calls.add("getComponent()");
81
                return new JLabel();
129
                return new JLabel();
82
            }
130
            }
83
            
131
            
84
            public void addPropertyChangeListener(PropertyChangeListener l) {}
132
            public void addPropertyChangeListener(PropertyChangeListener l) {
133
                propertyChangeListener = l;
134
            }
85
            
135
            
86
            public void removePropertyChangeListener(PropertyChangeListener l) {}
136
            public void removePropertyChangeListener(PropertyChangeListener l) {
137
                propertyChangeListener = null;
138
            }
87
        };
139
        };
88
    }
140
    }
89
}
141
}
(-)src/org/netbeans/modules/options/OptionsDisplayerImpl.java (-28 / +4 lines)
Lines 165-176 Link Here
165
                log.fine("Options Dialog - Ok pressed."); //NOI18N
165
                log.fine("Options Dialog - Ok pressed."); //NOI18N
166
                Dialog d = dialog;
166
                Dialog d = dialog;
167
                dialog = null;
167
                dialog = null;
168
                d.dispose ();
169
                RequestProcessor.getDefault ().post (new Runnable () {
170
                   public void run () {
171
                        optionsPanel.save ();
168
                        optionsPanel.save ();
172
                   } 
169
                d.dispose ();
173
                });
174
            } else
170
            } else
175
            if (e.getSource () == DialogDescriptor.CANCEL_OPTION ||
171
            if (e.getSource () == DialogDescriptor.CANCEL_OPTION ||
176
                e.getSource () == DialogDescriptor.CLOSED_OPTION
172
                e.getSource () == DialogDescriptor.CLOSED_OPTION
Lines 178-189 Link Here
178
                log.fine("Options Dialog - Cancel pressed."); //NOI18N
174
                log.fine("Options Dialog - Cancel pressed."); //NOI18N
179
                Dialog d = dialog;
175
                Dialog d = dialog;
180
                dialog = null;
176
                dialog = null;
181
                d.dispose ();
182
                RequestProcessor.getDefault ().post (new Runnable () {
183
                   public void run () {
184
                        optionsPanel.cancel ();
177
                        optionsPanel.cancel ();
185
                   } 
178
                d.dispose ();                
186
                });
187
            } else
179
            } else
188
            if (e.getSource () == bClassic) {
180
            if (e.getSource () == bClassic) {
189
                log.fine("Options Dialog - Classic pressed."); //NOI18N
181
                log.fine("Options Dialog - Classic pressed."); //NOI18N
Lines 198-229 Link Here
198
                    Object result = DialogDisplayer.getDefault ().
190
                    Object result = DialogDisplayer.getDefault ().
199
                        notify (descriptor);
191
                        notify (descriptor);
200
                    if (result == NotifyDescriptor.YES_OPTION) {
192
                    if (result == NotifyDescriptor.YES_OPTION) {
201
                        d.dispose ();
202
                        RequestProcessor.getDefault ().post (new Runnable () {
203
                           public void run () {
204
                                optionsPanel.save ();
193
                                optionsPanel.save ();
205
                           } 
194
                        d.dispose ();                        
206
                        });
207
                    } else
195
                    } else
208
                    if (result == NotifyDescriptor.NO_OPTION) {
196
                    if (result == NotifyDescriptor.NO_OPTION) {
209
                        d.dispose ();
210
                        RequestProcessor.getDefault ().post (new Runnable () {
211
                           public void run () {
212
                                optionsPanel.cancel ();
197
                                optionsPanel.cancel ();
213
                           } 
198
                        d.dispose ();                        
214
                        });
215
                    } else {
199
                    } else {
216
                        dialog = d;
200
                        dialog = d;
217
                        return;
201
                        return;
218
                    }
202
                    }
219
                } else {
203
                } else {
220
                    d.dispose ();
204
                    d.dispose ();
221
                    RequestProcessor.getDefault ().post (new Runnable () {
222
                       public void run () {
223
                            optionsPanel.cancel ();
205
                            optionsPanel.cancel ();
224
                       } 
206
                       } 
225
                    });
226
                }
227
                try {
207
                try {
228
                    ClassLoader cl = (ClassLoader) Lookup.getDefault ().lookup (ClassLoader.class);
208
                    ClassLoader cl = (ClassLoader) Lookup.getDefault ().lookup (ClassLoader.class);
229
                    Class<CallableSystemAction> clz = (Class<CallableSystemAction>)cl.loadClass("org.netbeans.core.actions.OptionsAction");
209
                    Class<CallableSystemAction> clz = (Class<CallableSystemAction>)cl.loadClass("org.netbeans.core.actions.OptionsAction");
Lines 253-263 Link Here
253
        public void windowClosing (WindowEvent e) {
233
        public void windowClosing (WindowEvent e) {
254
            if (dialog == null) return;
234
            if (dialog == null) return;
255
            log.fine("Options Dialog - windowClosing "); //NOI18N
235
            log.fine("Options Dialog - windowClosing "); //NOI18N
256
            RequestProcessor.getDefault ().post (new Runnable () {
257
               public void run () {
258
                    optionsPanel.cancel ();
236
                    optionsPanel.cancel ();
259
               } 
260
            });
261
            if (this.originalDialog == dialog) {
237
            if (this.originalDialog == dialog) {
262
                dialog = null;            
238
                dialog = null;            
263
            }
239
            }

Return to bug 106989