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 171284
Collapse All | Expand All

(-)a/options.api/nbproject/project.xml (+5 lines)
Lines 170-175 Link Here
170
                        <code-name-base>org.netbeans.modules.settings</code-name-base>
170
                        <code-name-base>org.netbeans.modules.settings</code-name-base>
171
                        <recursive/>
171
                        <recursive/>
172
                    </test-dependency>
172
                    </test-dependency>
173
                    <test-dependency>
174
                        <code-name-base>org.openide.util</code-name-base>
175
                        <compile-dependency/>
176
                        <test/>
177
                    </test-dependency>
173
                </test-type>
178
                </test-type>
174
            </test-dependencies>
179
            </test-dependencies>
175
            <public-packages>
180
            <public-packages>
(-)a/options.api/test/unit/src/org/netbeans/api/options/IDEInitializer.java (-158 lines)
Lines 1-158 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.api.options;
43
44
import java.beans.PropertyVetoException;
45
import java.io.File;
46
import java.io.IOException;
47
import java.net.URL;
48
import java.net.URLStreamHandler;
49
import java.net.URLStreamHandlerFactory;
50
import java.util.Enumeration;
51
import junit.framework.Assert;
52
import org.netbeans.junit.Manager;
53
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileSystem;
55
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.LocalFileSystem;
57
import org.openide.filesystems.MultiFileSystem;
58
import org.openide.filesystems.Repository;
59
import org.openide.filesystems.XMLFileSystem;
60
import org.openide.util.Lookup;
61
import org.openide.util.lookup.Lookups;
62
import org.openide.util.lookup.ProxyLookup;
63
64
65
/**
66
 * Inspired by org.netbeans.api.project.TestUtil.
67
 *
68
 * @author Miloslav Metelka, Jan Lahoda
69
 */
70
public class IDEInitializer extends ProxyLookup {
71
    
72
    public static IDEInitializer DEFAULT_LOOKUP = null;
73
    private static FileSystem lfs;
74
    
75
    static {
76
        IDEInitializer.class.getClassLoader ().setDefaultAssertionStatus (true);
77
        System.setProperty ("org.openide.util.Lookup", IDEInitializer.class.getName ());
78
        Assert.assertEquals (IDEInitializer.class, Lookup.getDefault ().getClass ());
79
    }
80
    
81
    public IDEInitializer () {
82
        Assert.assertNull (DEFAULT_LOOKUP);
83
        DEFAULT_LOOKUP = this;
84
        URL.setURLStreamHandlerFactory (new MyURLHandlerFactory ());
85
    }
86
    
87
    /**
88
     * Set the global default lookup with the specified content.
89
     *
90
     * @param layers xml-layer URLs to be present in the system filesystem.
91
     * @param instances object instances to be present in the default lookup.
92
     */
93
    public static void setup (
94
        String[] layers, 
95
        Object[] instances
96
    ) {
97
        ClassLoader classLoader = IDEInitializer.class.getClassLoader ();
98
        File workDir = new File (Manager.getWorkDirPath ());
99
        URL[] urls = new URL [layers.length];
100
        int i, k = urls.length;
101
        for (i = 0; i < k; i++)
102
            urls [i] = classLoader.getResource (layers [i]);
103
104
        // 1) create repository
105
        XMLFileSystem systemFS = new XMLFileSystem ();
106
        lfs = FileUtil.createMemoryFileSystem();
107
        try {
108
            systemFS.setXmlUrls (urls);
109
        } catch (Exception ex) {
110
            ex.printStackTrace ();
111
        }
112
        MyFileSystem myFileSystem = new MyFileSystem (
113
            new FileSystem [] {lfs, systemFS}
114
        );
115
        Repository repository = new Repository (myFileSystem);
116
117
        Object[] lookupContent = new Object [instances.length + 1];
118
        lookupContent [0] = repository;
119
        System.arraycopy (instances, 0, lookupContent, 1, instances.length);
120
        
121
        DEFAULT_LOOKUP.setLookups (new Lookup[] {
122
            Lookups.fixed (lookupContent),
123
            Lookups.metaInfServices (classLoader),
124
            Lookups.singleton (classLoader),
125
        });
126
        Assert.assertTrue (myFileSystem.isDefault());
127
    }
128
    
129
    public static void cleanWorkDir () {
130
        try {
131
            Enumeration en = lfs.getRoot ().getChildren (false);
132
            while (en.hasMoreElements ()) 
133
                ((FileObject) en.nextElement ()).delete ();
134
        } catch (IOException ex) {
135
            ex.printStackTrace ();
136
        }
137
    }
138
    
139
    private static class MyFileSystem extends MultiFileSystem {
140
        public MyFileSystem (FileSystem[] fileSystems) {
141
            super (fileSystems);
142
            try {
143
                setSystemName ("TestFS");
144
            } catch (PropertyVetoException ex) {
145
                ex.printStackTrace();
146
            }
147
        }
148
    }
149
    
150
    private static class MyURLHandlerFactory implements URLStreamHandlerFactory {
151
        public URLStreamHandler createURLStreamHandler(String protocol) {
152
            if (protocol.equals ("nbfs")) {
153
                return FileUtil.nbfsURLStreamHandler ();
154
            }
155
            return null;
156
        }
157
    }
158
}
(-)a/options.api/test/unit/src/org/netbeans/api/options/MyAdvancedCategory.java (-70 lines)
Lines 1-70 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.api.options;
40
41
import javax.swing.Icon;
42
import org.netbeans.spi.options.OptionsCategory;
43
import org.netbeans.spi.options.OptionsPanelController;
44
import org.openide.util.ImageUtilities;
45
46
public final class MyAdvancedCategory extends OptionsCategory {
47
48
    private OptionsPanelController controller;
49
    
50
    @Override
51
    public Icon getIcon() {
52
        return ImageUtilities.loadImageIcon("org/netbeans/modules/options/resources/advanced.png", false);
53
    }
54
55
    public String getCategoryName() {
56
        return "MyAdvancedCategory";
57
    }
58
59
    public String getTitle() {
60
        return "My Advanced Category";
61
    }
62
63
    @SuppressWarnings("deprecation")
64
    public OptionsPanelController create() {
65
        if(controller == null) {
66
            controller = OptionsPanelController.createAdvanced("MyAdvancedCategory");
67
        }
68
        return controller;
69
    }
70
}
(-)a/options.api/test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java (-28 / +78 lines)
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
}
(-)a/options.api/test/unit/src/org/netbeans/api/options/RegisteredCategory.java (-45 / +12 lines)
Lines 41-103 Link Here
41
41
42
package org.netbeans.api.options;
42
package org.netbeans.api.options;
43
43
44
import java.awt.Image;
45
import java.beans.PropertyChangeEvent;
44
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
45
import java.beans.PropertyChangeListener;
47
import java.util.Collection;
46
import java.util.Collection;
48
import java.util.HashSet;
47
import java.util.HashSet;
49
import javax.swing.Icon;
50
import javax.swing.ImageIcon;
51
import javax.swing.JComponent;
48
import javax.swing.JComponent;
52
import javax.swing.JLabel;
49
import javax.swing.JLabel;
53
import javax.swing.SwingUtilities;
50
import javax.swing.SwingUtilities;
54
import junit.framework.TestCase;
51
import junit.framework.TestCase;
55
import org.netbeans.spi.options.OptionsCategory;
56
import org.netbeans.spi.options.OptionsPanelController;
52
import org.netbeans.spi.options.OptionsPanelController;
57
import org.openide.util.HelpCtx;
53
import org.openide.util.HelpCtx;
58
import org.openide.util.ImageUtilities;
59
import org.openide.util.Lookup;
54
import org.openide.util.Lookup;
60
import org.openide.util.Utilities;
61
55
56
@OptionsPanelController.TopLevelRegistration(
57
    categoryName="CTL_General_Options",
58
    iconBase="org/netbeans/modules/options/resources/generalOptions.png"
59
)
60
public final class RegisteredCategory extends OptionsPanelController {
61
    private static PropertyChangeListener propertyChangeListener;
62
    private static Collection<String> calls = new HashSet<String>();
62
63
63
/**
64
    public static void setInvalid() {
64
 */
65
        propertyChangeListener.propertyChange(new PropertyChangeEvent(null, OptionsPanelController.PROP_VALID, null, null));
65
public final class RegisteredCategory extends OptionsCategory {
66
    private static Icon icon;
67
    private static PropertyChangeListener propertyChangeListener;
68
    private Collection<String> calls = new HashSet<String>();
69
70
    public void setInvalid() {
71
        propertyChangeListener.propertyChange(new PropertyChangeEvent(this, OptionsPanelController.PROP_VALID, null, null));
72
    }
66
    }
73
    
67
    
74
    public void helpChanged() {
68
    public static void helpChanged() {
75
        propertyChangeListener.propertyChange(new PropertyChangeEvent(this, OptionsPanelController.PROP_HELP_CTX, null, null));
69
        propertyChangeListener.propertyChange(new PropertyChangeEvent(null, OptionsPanelController.PROP_HELP_CTX, null, null));
76
    }
70
    }
77
    
71
    
78
72
    public static void assertThreadingForAllCallsWereTested() {
79
    @Override
80
    public Icon getIcon() {
81
        if (icon == null) {
82
            Image image = ImageUtilities.loadImage("org/netbeans/modules/options/resources/generalOptions.png");
83
            icon = new ImageIcon(image);
84
        }
85
        return icon;
86
    }
87
88
    public String getCategoryName() {
89
        return "CTL_General_Options";
90
    }
91
92
    public String getTitle() {
93
        return "CTL_General_Options_Title";
94
    }
95
96
    public String getDescription() {
97
        return "CTL_General_Options_Description";
98
    }
99
    
100
    public void assertThreadingForAllCallsWereTested() {
101
        TestCase.assertTrue(calls.contains("update()"));
73
        TestCase.assertTrue(calls.contains("update()"));
102
        TestCase.assertTrue(calls.contains("cancel()"));        
74
        TestCase.assertTrue(calls.contains("cancel()"));        
103
        TestCase.assertTrue(calls.contains("isValid()"));
75
        TestCase.assertTrue(calls.contains("isValid()"));
Lines 109-117 Link Here
109
81
110
    public static String subcategoryID;
82
    public static String subcategoryID;
111
83
112
    public OptionsPanelController create() {
113
        return new OptionsPanelController() {
114
115
            public void update() {
84
            public void update() {
116
                TestCase.assertTrue(SwingUtilities.isEventDispatchThread());
85
                TestCase.assertTrue(SwingUtilities.isEventDispatchThread());
117
                calls.add("update()");
86
                calls.add("update()");
Lines 169-174 Link Here
169
            public void removePropertyChangeListener(PropertyChangeListener l) {
138
            public void removePropertyChangeListener(PropertyChangeListener l) {
170
                propertyChangeListener = null;
139
                propertyChangeListener = null;
171
            }
140
            }
172
        };        
173
    }
174
}
141
}
(-)a/options.api/test/unit/src/org/netbeans/api/options/Subcategory1.java (-115 lines)
Lines 1-115 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.api.options;
41
42
import java.beans.PropertyChangeListener;
43
import javax.swing.JComponent;
44
import javax.swing.JLabel;
45
import org.netbeans.spi.options.AdvancedOption;
46
import org.netbeans.spi.options.OptionsPanelController;
47
import org.openide.util.HelpCtx;
48
import org.openide.util.Lookup;
49
50
/**
51
 */
52
public class Subcategory1 extends AdvancedOption {
53
54
    public static final String DISPLAY_NAME = "Subcategory1 display name";
55
56
    @SuppressWarnings("deprecation")
57
    public Subcategory1() {}
58
    
59
    @Override
60
    public String getDisplayName() {
61
        return DISPLAY_NAME;
62
    }
63
64
    @Override
65
    public String getTooltip() {
66
        return "Subcategory1 tooltip";
67
    }
68
69
    @Override
70
    public OptionsPanelController create() {
71
        return new OptionsPanelController() {
72
73
            @Override
74
            public void update() {
75
            }
76
77
            @Override
78
            public void applyChanges() {
79
            }
80
81
            @Override
82
            public void cancel() {
83
            }
84
85
            @Override
86
            public boolean isValid() {
87
                return true;
88
            }
89
90
            @Override
91
            public boolean isChanged() {
92
                return false;
93
            }
94
95
            @Override
96
            public JComponent getComponent(Lookup masterLookup) {
97
                return new JLabel();
98
            }
99
100
            @Override
101
            public HelpCtx getHelpCtx() {
102
                return null;
103
            }
104
105
            @Override
106
            public void addPropertyChangeListener(PropertyChangeListener l) {
107
            }
108
109
            @Override
110
            public void removePropertyChangeListener(PropertyChangeListener l) {
111
            }
112
        };
113
    }
114
115
}
(-)a/options.api/test/unit/src/org/netbeans/api/options/Subcategory2.java (-126 lines)
Lines 1-126 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.api.options;
41
42
import java.beans.PropertyChangeListener;
43
import javax.swing.JComponent;
44
import javax.swing.JLabel;
45
import org.netbeans.spi.options.AdvancedOption;
46
import org.netbeans.spi.options.OptionsPanelController;
47
import org.openide.util.HelpCtx;
48
import org.openide.util.Lookup;
49
50
/**
51
 */
52
public class Subcategory2 extends AdvancedOption {
53
    
54
    public static final String DISPLAY_NAME = "Subcategory2 display name";
55
    public static String currentSubpath;
56
57
    @SuppressWarnings("deprecation")
58
    public Subcategory2() {}
59
60
    @Override
61
    public String getDisplayName() {
62
        return DISPLAY_NAME;
63
    }
64
65
    @Override
66
    public String getTooltip() {
67
        return "Subcategory2 tooltip";
68
    }
69
    
70
    /** Needed just for tests. */
71
    public static String getSubpath() {
72
        return currentSubpath;
73
    }
74
75
    @Override
76
    public OptionsPanelController create() {
77
        return new OptionsPanelController() {
78
79
            @Override
80
            public void update() {
81
            }
82
83
            @Override
84
            public void applyChanges() {
85
            }
86
87
            @Override
88
            public void cancel() {
89
            }
90
91
            @Override
92
            public boolean isValid() {
93
                return true;
94
            }
95
96
            @Override
97
            public boolean isChanged() {
98
                return false;
99
            }
100
101
            @Override
102
            public JComponent getComponent(Lookup masterLookup) {
103
                return new JLabel();
104
            }
105
106
            @Override
107
            public void setCurrentSubcategory(String subpath) {
108
                currentSubpath = subpath;
109
            }
110
            
111
            @Override
112
            public HelpCtx getHelpCtx() {
113
                return null;
114
            }
115
116
            @Override
117
            public void addPropertyChangeListener(PropertyChangeListener l) {
118
            }
119
120
            @Override
121
            public void removePropertyChangeListener(PropertyChangeListener l) {
122
            }
123
        };
124
    }
125
126
}
(-)a/options.api/test/unit/src/org/netbeans/api/options/mf-layer.xml (-76 lines)
Lines 1-76 Link Here
1
<?xml version="1.0"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
7
8
The contents of this file are subject to the terms of either the GNU
9
General Public License Version 2 only ("GPL") or the Common
10
Development and Distribution License("CDDL") (collectively, the
11
"License"). You may not use this file except in compliance with the
12
License. You can obtain a copy of the License at
13
http://www.netbeans.org/cddl-gplv2.html
14
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
specific language governing permissions and limitations under the
16
License.  When distributing the software, include this License Header
17
Notice in each file and include the License file at
18
nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
19
particular file as subject to the "Classpath" exception as provided
20
by Sun in the GPL Version 2 section of the License file that
21
accompanied this code. If applicable, add the following below the
22
License Header, with the fields enclosed by brackets [] replaced by
23
your own identifying information:
24
"Portions Copyrighted [year] [name of copyright owner]"
25
26
Contributor(s):
27
28
The Original Software is NetBeans. The Initial Developer of the Original
29
Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
30
Microsystems, Inc. All Rights Reserved.
31
32
If you wish your version of this file to be governed by only the CDDL
33
or only the GPL Version 2, indicate your decision by adding
34
"[Contributor] elects to include this software in this distribution
35
under the [CDDL or GPL Version 2] license." If you do not indicate a
36
single choice of license, a recipient has the option to distribute
37
your version of this file under either the CDDL, the GPL Version 2 or
38
to extend the choice of license to its licensees as provided above.
39
However, if you add GPL Version 2 code and therefore, elected the GPL
40
Version 2 license, then the option applies only if the new code is
41
made subject to such option by the copyright holder.
42
-->
43
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.0//EN" "http://www.netbeans.org/dtds/filesystem-1_0.dtd">
44
45
<filesystem>
46
    <folder name="OptionsDialog">
47
        <file name="Registered.instance">
48
            <attr name="instanceClass" stringvalue="org.netbeans.api.options.RegisteredCategory"/>
49
        </file>
50
        <file name="Advanced.instance">
51
            <attr name="instanceClass" stringvalue="org.netbeans.modules.options.advanced.Advanced"/>
52
        </file>
53
        <folder name="Advanced">
54
            <file name="Subcategory2.instance">
55
                <attr name="instanceClass" stringvalue="org.netbeans.api.options.Subcategory2"/>
56
            </file>
57
            <file name="Subcategory1.instance">
58
                <attr name="instanceClass" stringvalue="org.netbeans.api.options.Subcategory1"/>
59
            </file>
60
        </folder>
61
        <file name="MyAdvancedCategory.instance">
62
            <attr name="instanceClass" stringvalue="org.netbeans.api.options.MyAdvancedCategory"/>
63
            <attr name="position" intvalue="900"/>
64
        </file>
65
        <folder name="MyAdvancedCategory">
66
            <file name="Subcategory1.instance">
67
                <attr name="instanceClass" stringvalue="org.netbeans.api.options.Subcategory1"/>
68
                <attr name="position" intvalue="102"/>
69
            </file>
70
            <file name="Subcategory2.instance">
71
                <attr name="instanceClass" stringvalue="org.netbeans.api.options.Subcategory2"/>
72
                <attr name="position" intvalue="101"/>
73
            </file>
74
        </folder>
75
    </folder>
76
</filesystem>
(-)a/options.api/test/unit/src/org/netbeans/api/options/package-info.java (+49 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
@ContainerRegistration(
41
    id="MyAdvancedCategory",
42
    categoryName="MyAdvancedCategory",
43
    iconBase="org/netbeans/modules/options/resources/advanced.png",
44
    position=900
45
)
46
package org.netbeans.api.options;
47
48
import org.netbeans.spi.options.OptionsPanelController.ContainerRegistration;
49

Return to bug 171284