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

(-)a/options.api/apichanges.xml (+14 lines)
Lines 75-80 Link Here
75
<!-- ACTUAL CHANGES BEGIN HERE: -->
75
<!-- ACTUAL CHANGES BEGIN HERE: -->
76
76
77
<changes>
77
<changes>
78
    <change id="optionsSearchAnnotation">
79
      <api name="OptionsAPI"/>
80
      <summary>Annotation to register keywords for some panel in the Options dialog</summary>
81
      <version major="1" minor="28"/>
82
      <date day="1" month="10" year="2012"/>
83
      <author login="theofanis"/>
84
      <compatibility addition="yes" binary="compatible" source="compatible" deprecation="no" semantic="compatible" modification="no" deletion="no"/>
85
      <description>
86
          Introduced an annotation inside <code>OptionsPanelController</code>
87
          to register keywords for some panel in the Options dialog declaratively.
88
      </description>
89
      <class package="org.netbeans.spi.options" name="OptionsPanelController"/>
90
      <issue number="218312"/>
91
    </change>
78
    <change id="annotations">
92
    <change id="annotations">
79
        <api name="OptionsAPI"/>
93
        <api name="OptionsAPI"/>
80
        <summary>Annotations to register dialog panels</summary>
94
        <summary>Annotations to register dialog panels</summary>
(-)a/options.api/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.netbeans.modules.options.api/1
2
OpenIDE-Module: org.netbeans.modules.options.api/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/options/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/options/Bundle.properties
4
OpenIDE-Module-Layer: org/netbeans/modules/options/resources/mf-layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/options/resources/mf-layer.xml
5
OpenIDE-Module-Specification-Version: 1.27
5
OpenIDE-Module-Specification-Version: 1.28
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
7
AutoUpdate-Essential-Module: true
7
AutoUpdate-Essential-Module: true
(-)a/options.api/nbproject/project.xml (+20 lines)
Lines 200-205 Link Here
200
                        <test/>
200
                        <test/>
201
                    </test-dependency>
201
                    </test-dependency>
202
                </test-type>
202
                </test-type>
203
                <test-type>
204
                    <name>qa-functional</name>
205
                    <test-dependency>
206
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
207
                        <compile-dependency/>
208
                    </test-dependency>
209
                    <test-dependency>
210
                        <code-name-base>org.netbeans.modules.jellytools.platform</code-name-base>
211
                        <compile-dependency/>
212
                    </test-dependency>
213
                    <test-dependency>
214
                        <code-name-base>org.netbeans.modules.jemmy</code-name-base>
215
                        <compile-dependency/>
216
                    </test-dependency>
217
                    <test-dependency>
218
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
219
                        <recursive/>
220
                        <compile-dependency/>
221
                    </test-dependency>
222
                </test-type>
203
            </test-dependencies>
223
            </test-dependencies>
204
            <public-packages>
224
            <public-packages>
205
                <package>org.netbeans.api.options</package>
225
                <package>org.netbeans.api.options</package>
(-)a/options.api/src/org/netbeans/api/options/OptionsDisplayer.java (+16 lines)
Lines 74-79 Link Here
74
     * @since 1.8
74
     * @since 1.8
75
     */
75
     */
76
    public static final String ADVANCED = "Advanced"; // NOI18N
76
    public static final String ADVANCED = "Advanced"; // NOI18N
77
    /** Registration name of Keymaps category (aka Keymap). 
78
     * @since 1.28
79
     */
80
    public static final String KEYMAPS = "Keymaps"; // NOI18N
81
    /** Registration name of FontsAndColors category (aka Fonts & Colors).
82
     * @since 1.28
83
     */
84
    public static final String FONTSANDCOLORS = "FontsAndColors"; // NOI18N
85
    /** Registration name of Editor category.
86
     * @since 1.28
87
     */
88
    public static final String EDITOR = "Editor"; // NOI18N
89
    /** Registration name of General category.
90
     * @since 1.28
91
     */
92
    public static final String GENERAL = "General"; // NOI18N
77
    private String currentCategoryID = null;
93
    private String currentCategoryID = null;
78
    private AtomicBoolean operationCancelled;
94
    private AtomicBoolean operationCancelled;
79
        
95
        
(-)a/options.api/src/org/netbeans/modules/options/CategoryModel.java (+1 lines)
Lines 81-86 Link Here
81
            Collections.synchronizedMap(new LinkedHashMap<String, CategoryModel.Category>());
81
            Collections.synchronizedMap(new LinkedHashMap<String, CategoryModel.Category>());
82
    private MasterLookup masterLookup;
82
    private MasterLookup masterLookup;
83
    static final String OD_LAYER_FOLDER_NAME = "OptionsDialog"; // NOI18N
83
    static final String OD_LAYER_FOLDER_NAME = "OptionsDialog"; // NOI18N
84
    static final String OD_LAYER_KEYWORDS_FOLDER_NAME = OD_LAYER_FOLDER_NAME.concat("/Keywords"); // NOI18N
84
    private Result<OptionsCategory> result;
85
    private Result<OptionsCategory> result;
85
    
86
    
86
    Set<Map.Entry<String, CategoryModel.Category>> getCategories() {
87
    Set<Map.Entry<String, CategoryModel.Category>> getCategories() {
(-)a/options.api/src/org/netbeans/modules/options/OptionsPanelControllerProcessor.java (-1 / +138 lines)
Lines 42-78 Link Here
42
42
43
package org.netbeans.modules.options;
43
package org.netbeans.modules.options;
44
44
45
import java.io.IOException;
46
import java.io.InputStream;
45
import java.lang.annotation.Annotation;
47
import java.lang.annotation.Annotation;
48
import java.util.ArrayList;
46
import java.util.Arrays;
49
import java.util.Arrays;
50
import java.util.Collections;
51
import java.util.Comparator;
47
import java.util.HashSet;
52
import java.util.HashSet;
53
import java.util.Properties;
48
import java.util.Set;
54
import java.util.Set;
55
import java.util.regex.Matcher;
56
import java.util.regex.Pattern;
49
import javax.annotation.processing.Processor;
57
import javax.annotation.processing.Processor;
50
import javax.annotation.processing.RoundEnvironment;
58
import javax.annotation.processing.RoundEnvironment;
51
import javax.annotation.processing.SupportedSourceVersion;
59
import javax.annotation.processing.SupportedSourceVersion;
52
import javax.lang.model.SourceVersion;
60
import javax.lang.model.SourceVersion;
53
import javax.lang.model.element.Element;
61
import javax.lang.model.element.Element;
62
import javax.lang.model.element.ElementKind;
63
import javax.lang.model.element.PackageElement;
54
import javax.lang.model.element.TypeElement;
64
import javax.lang.model.element.TypeElement;
65
import javax.swing.JPanel;
66
import org.netbeans.api.options.OptionsDisplayer;
55
import org.netbeans.spi.options.AdvancedOption;
67
import org.netbeans.spi.options.AdvancedOption;
56
import org.netbeans.spi.options.OptionsCategory;
68
import org.netbeans.spi.options.OptionsCategory;
57
import org.netbeans.spi.options.OptionsPanelController;
69
import org.netbeans.spi.options.OptionsPanelController;
58
import org.netbeans.spi.options.OptionsPanelController.ContainerRegistration;
70
import org.netbeans.spi.options.OptionsPanelController.ContainerRegistration;
71
import org.netbeans.spi.options.OptionsPanelController.Keywords;
72
import org.netbeans.spi.options.OptionsPanelController.KeywordsRegistration;
59
import org.netbeans.spi.options.OptionsPanelController.SubRegistration;
73
import org.netbeans.spi.options.OptionsPanelController.SubRegistration;
60
import org.netbeans.spi.options.OptionsPanelController.TopLevelRegistration;
74
import org.netbeans.spi.options.OptionsPanelController.TopLevelRegistration;
61
import org.openide.filesystems.annotations.LayerBuilder;
75
import org.openide.filesystems.annotations.LayerBuilder;
62
import org.openide.filesystems.annotations.LayerBuilder.File;
76
import org.openide.filesystems.annotations.LayerBuilder.File;
63
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
77
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
64
import org.openide.filesystems.annotations.LayerGenerationException;
78
import org.openide.filesystems.annotations.LayerGenerationException;
79
import org.openide.util.NbBundle;
65
import org.openide.util.lookup.ServiceProvider;
80
import org.openide.util.lookup.ServiceProvider;
66
81
67
@ServiceProvider(service=Processor.class)
82
@ServiceProvider(service=Processor.class)
68
@SupportedSourceVersion(SourceVersion.RELEASE_6)
83
@SupportedSourceVersion(SourceVersion.RELEASE_6)
69
public class OptionsPanelControllerProcessor extends LayerGeneratingProcessor {
84
public class OptionsPanelControllerProcessor extends LayerGeneratingProcessor {
70
85
86
    private Element originatingElement;
87
71
    public @Override Set<String> getSupportedAnnotationTypes() {
88
    public @Override Set<String> getSupportedAnnotationTypes() {
72
        return new HashSet<String>(Arrays.asList(
89
        return new HashSet<String>(Arrays.asList(
73
            TopLevelRegistration.class.getCanonicalName(),
90
            TopLevelRegistration.class.getCanonicalName(),
74
            ContainerRegistration.class.getCanonicalName(),
91
            ContainerRegistration.class.getCanonicalName(),
75
            SubRegistration.class.getCanonicalName()
92
            SubRegistration.class.getCanonicalName(),
93
            KeywordsRegistration.class.getCanonicalName(),
94
            Keywords.class.getCanonicalName()
76
        ));
95
        ));
77
    }
96
    }
78
97
Lines 108-113 Link Here
108
            keywords(e, r.keywords(), r.keywordsCategory(), r, file);
127
            keywords(e, r.keywords(), r.keywordsCategory(), r, file);
109
            file.write();
128
            file.write();
110
        }
129
        }
130
        
131
        ArrayList<Keywords> advanced = new ArrayList<Keywords>();
132
        for (Element e : roundEnv.getElementsAnnotatedWith(Keywords.class)) {
133
            Keywords annotation = e.getAnnotation(Keywords.class);
134
            if (annotation != null) {
135
                originatingElement = e;
136
                String location = annotation.location();
137
                if(location.equals(OptionsDisplayer.ADVANCED)) {
138
                    if(getBundleValue(annotation.tabTitle(), annotation, "tabTitle").trim().isEmpty()) {
139
                        throw new LayerGenerationException("Must specify both location and tabTitle", e, processingEnv, annotation, "tabTitle");
140
                    }
141
                    if(annotation.index() != -1) {
142
                        throw new LayerGenerationException("No need to specify index, panels in Miscellaneous category are sorted alphabetically", e, processingEnv, annotation, "index");
143
                    }
144
                    advanced.add(annotation);
145
                } else if(!location.equals(OptionsDisplayer.GENERAL) && !location.equals(OptionsDisplayer.KEYMAPS)) {
146
                    if(annotation.index() < 0) {
147
                        throw new LayerGenerationException("You need to specify a non-negative value for index", e, processingEnv, annotation, "index");
148
                    }
149
                }
150
            }
151
        }
152
        Collections.sort(advanced, new AdvancedComparable());
153
154
        for (Element e : roundEnv.getElementsAnnotatedWith(Keywords.class)) {
155
            handleElement(e, e.getAnnotation(Keywords.class), advanced, "");
156
        }
157
        for (Element e : roundEnv.getElementsAnnotatedWith(KeywordsRegistration.class)) {
158
            KeywordsRegistration r = e.getAnnotation(KeywordsRegistration.class);
159
            Keywords[] panels = r.value();
160
            for (int i = 0; i < panels.length; i++) {
161
                handleElement(e, panels[i], advanced, Integer.toString(-(i + 1)));
162
            }
163
        }
111
        for (Element e : roundEnv.getElementsAnnotatedWith(ContainerRegistration.class)) {
164
        for (Element e : roundEnv.getElementsAnnotatedWith(ContainerRegistration.class)) {
112
            ContainerRegistration r = e.getAnnotation(ContainerRegistration.class);
165
            ContainerRegistration r = e.getAnnotation(ContainerRegistration.class);
113
            LayerBuilder builder = layer(e);
166
            LayerBuilder builder = layer(e);
Lines 124-129 Link Here
124
        return true;
177
        return true;
125
    }
178
    }
126
179
180
    private void handleElement(Element e, Keywords annotation, ArrayList<Keywords> advanced, String name) throws LayerGenerationException {
181
        originatingElement = e;
182
        int index = annotation.index();
183
        if (annotation.location().equals(OptionsDisplayer.ADVANCED)) {
184
            index = advanced.indexOf(annotation);
185
        }
186
        File file = layer(e).
187
                file("OptionsDialog/Keywords/".concat(e.asType().toString()).concat(name)).
188
                stringvalue("instanceOf", JPanel.class.getName()).
189
                stringvalue("location", annotation.location()).
190
                stringvalue("tabTitle", getBundleValue(annotation.tabTitle(), annotation, "tabTitle")).
191
                intvalue("index", index);
192
        StringBuilder keywordsSB = new StringBuilder();
193
        String[] keywords = annotation.keywords();
194
        keywordsSB.append(getBundleValue(keywords[0], annotation, "keywords").toUpperCase());
195
        for (int j = 1; j < keywords.length; j++) {
196
            keywordsSB.append(",").append(getBundleValue(keywords[j], annotation, "keywords").toUpperCase());
197
        }
198
        file.stringvalue("keywords", keywordsSB.toString());
199
        file.write();
200
    }
201
    
202
    private class AdvancedComparable implements Comparator<Keywords> {
203
204
        @Override
205
        public int compare(Keywords r1, Keywords r2) {
206
            return r1.tabTitle().compareTo(r2.tabTitle());
207
        }
208
    }
209
210
    private String getBundleValue(String label, Annotation annotation, String annotationMethod) throws LayerGenerationException {
211
        String javaIdentifier = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)";
212
        Matcher m = Pattern.compile("((?:" + javaIdentifier + "\\.)+[^\\s.#]+)?#(\\S*)").matcher(label);
213
        if (m.matches()) {
214
            String bundle = m.group(1);
215
            String key = m.group(2);
216
            if (bundle == null) {
217
                Element referenceElement = originatingElement;
218
                while (referenceElement != null && referenceElement.getKind() != ElementKind.PACKAGE) {
219
                    referenceElement = referenceElement.getEnclosingElement();
220
                }
221
                if (referenceElement == null) {
222
                    throw new LayerGenerationException("No reference element to determine package in '" + label + "'", originatingElement);
223
                }
224
                bundle = ((PackageElement) referenceElement).getQualifiedName() + ".Bundle";
225
            }
226
            return verifyBundleValue(bundle, key, m.group(1) == null, annotation, annotationMethod);
227
        }
228
        return label;
229
    }
230
231
    private String verifyBundleValue(String bundle, String key, boolean samePackage, Annotation annotation, String annotationMethod) throws LayerGenerationException {
232
        if (processingEnv == null) {
233
            return "";
234
        }
235
        if (samePackage) {
236
            for (Element e = originatingElement; e != null; e = e.getEnclosingElement()) {
237
                NbBundle.Messages m = e.getAnnotation(NbBundle.Messages.class);
238
                if (m != null) {
239
                    for (String kv : m.value()) {
240
                        if (kv.startsWith(key + "=")) {
241
                            return kv.substring(kv.indexOf("=") + 1);
242
                        }
243
                    }
244
                }
245
            }
246
        }
247
        try {
248
            InputStream is = layer(originatingElement).validateResource(bundle.replace('.', '/') + ".properties", originatingElement, null, null, false).openInputStream();
249
            try {
250
                Properties p = new Properties();
251
                p.load(is);
252
                if (p.getProperty(key) == null) {
253
                    throw new LayerGenerationException("No key '" + key + "' found in " + bundle, originatingElement, processingEnv, annotation, annotationMethod);
254
                }
255
                return p.getProperty(key);
256
            } finally {
257
                is.close();
258
            }
259
        } catch (IOException x) {
260
            throw new LayerGenerationException("Could not open " + bundle + ": " + x, originatingElement, processingEnv, annotation, annotationMethod);
261
        }
262
    }
263
127
    private void iconBase(Element e, String iconBase, Annotation r, File file, LayerBuilder builder) throws LayerGenerationException {
264
    private void iconBase(Element e, String iconBase, Annotation r, File file, LayerBuilder builder) throws LayerGenerationException {
128
        builder.validateResource(iconBase, e, r, "iconBase", true);
265
        builder.validateResource(iconBase, e, r, "iconBase", true);
129
        file.stringvalue("iconBase", iconBase);
266
        file.stringvalue("iconBase", iconBase);
(-)a/options.api/src/org/netbeans/spi/options/OptionsPanelController.java (+59 lines)
Lines 316-319 Link Here
316
        int position() default Integer.MAX_VALUE;
316
        int position() default Integer.MAX_VALUE;
317
    }
317
    }
318
318
319
    /**
320
     * Similar to {@link Keywords} but permits multiple registrations of
321
     * one class.
322
     *
323
     * @since org.netbeans.modules.options.api/1 1.28
324
     */
325
    @Target({ElementType.TYPE})
326
    @Retention(RetentionPolicy.SOURCE)
327
    public @interface KeywordsRegistration {
328
329
        /**
330
         * List of Keywords registrations.
331
         */
332
        Keywords[] value();
333
    }
334
335
    /**
336
     * Registers keywords for some panel in the Options dialog. Should be placed
337
     * on a {@link JPanel} instance.
338
     *
339
     * @since org.netbeans.modules.options.api/1 1.28
340
     */
341
    @Target({ElementType.TYPE})
342
    @Retention(RetentionPolicy.SOURCE)
343
    public @interface Keywords {
344
345
        /**
346
         * Keywords for use with search inside the Options dialog. You may use
347
         * {@code #key} syntax.
348
         */
349
        String[] keywords();
350
351
        /**
352
         * Keyword category for use with search inside the Options dialog.
353
         *
354
         * Location of this panel inside some top-level panel matching
355
         * {@link ContainerRegistration#id} or {@link SubRegistration#location}.
356
         * Typically this should be a reference to a compile-time constant also
357
         * used for the container's ID.
358
         *
359
         * If the panel is in the Miscellaneous category you must also specify {@link #tabTitle}).
360
         */
361
        String location();
362
363
        /**
364
         * Optional title that must be used if the panel is in the Miscellaneous category.
365
         * 
366
         * You may use {@code #key} syntax.
367
         */
368
        String tabTitle() default "";
369
370
        /**
371
         * Position relative to sibling subpanels matching the tab index in a tabbed pane.
372
         * If the panel is in the Miscellaneous panel there is no need to specify the index 
373
         * as tabs in Miscellaneous category are always sorted alphabetically.
374
         */
375
        int index() default -1;
376
    }
377
319
}
378
}
(-)a/options.api/test/qa-functional/src/org/netbeans/modules/options/SearchInOptionsTest.java (+261 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.options;
43
44
import java.awt.Component;
45
import java.awt.event.KeyEvent;
46
import java.util.ArrayList;
47
import java.util.Arrays;
48
import javax.swing.JLabel;
49
import junit.framework.Test;
50
import org.netbeans.jellytools.JellyTestCase;
51
import org.netbeans.jellytools.OptionsOperator;
52
import org.netbeans.jemmy.ComponentChooser;
53
import org.netbeans.jemmy.EventTool;
54
import org.netbeans.jemmy.operators.JLabelOperator;
55
import org.netbeans.jemmy.operators.JTabbedPaneOperator;
56
import org.netbeans.jemmy.operators.JTextFieldOperator;
57
import org.netbeans.jemmy.operators.Operator;
58
import org.netbeans.jemmy.operators.Operator.StringComparator;
59
import org.netbeans.junit.NbModuleSuite;
60
61
/**
62
 *
63
 * @author theofanis
64
 */
65
public class SearchInOptionsTest extends JellyTestCase {
66
67
    private StringComparator stringComparator;
68
    private OptionsOperator optionsOperator;
69
    private JTextFieldOperator jTextFieldOperator;
70
    private JTabbedPaneOperator jTabbedPaneOperator;
71
    private String[] categoryIDs;
72
73
    /**
74
     * Constructor required by JUnit
75
     */
76
    public SearchInOptionsTest(String testName) {
77
        super(testName);
78
    }
79
80
    /**
81
     * Creates suite from particular test cases.
82
     */
83
    public static Test suite() {
84
        return NbModuleSuite.createConfiguration(SearchInOptionsTest.class).addTest(
85
                "testSearchInOptionsWindow").clusters(".*").enableModules(".*").gui(true).suite();
86
    }
87
88
    public void testSearchInOptionsWindow() {
89
        OptionsOperator.invoke();
90
        new EventTool().waitNoEvent(1000);
91
        log("Option dialog was opened");
92
93
        optionsOperator = new OptionsOperator();
94
        new EventTool().waitNoEvent(1000);
95
96
        jTextFieldOperator = new JTextFieldOperator(optionsOperator);
97
        stringComparator = Operator.getDefaultStringComparator();
98
        categoryIDs = CategoryModel.getInstance().getCategoryIDs();
99
100
        int[] tabIndexes = {0};
101
        String[] selectedCategories = {"Editor"};
102
        ArrayList<String> enabledCategories = new ArrayList<String>();
103
        enabledCategories.add("Editor");
104
        searchFor("general editor", tabIndexes, selectedCategories, enabledCategories);
105
106
        tabIndexes[0] = 6;
107
        searchFor("macros", tabIndexes, selectedCategories, enabledCategories);
108
109
        tabIndexes[0] = 2;
110
        searchFor("completion", tabIndexes, selectedCategories, enabledCategories);
111
112
        tabIndexes[0] = 3;
113
        searchFor("templates", tabIndexes, selectedCategories, enabledCategories);
114
115
        tabIndexes[0] = 8;
116
        searchFor("dictionary", tabIndexes, selectedCategories, enabledCategories);
117
118
        tabIndexes[0] = 7;
119
        searchFor("on save", tabIndexes, selectedCategories, enabledCategories);
120
121
        enabledCategories.clear();
122
        enabledCategories.add("General");
123
        tabIndexes[0] = -1;
124
        selectedCategories[0] = "General";
125
        searchFor("proxy", tabIndexes, selectedCategories, enabledCategories);
126
127
        enabledCategories.clear();
128
        enabledCategories.add("Fonts & Colors");
129
        tabIndexes[0] = 0;
130
        selectedCategories[0] = "FontsAndColors";
131
        searchFor("syntax", tabIndexes, selectedCategories, enabledCategories);
132
133
        tabIndexes[0] = 1;
134
        searchFor("highlighting", tabIndexes, selectedCategories, enabledCategories);
135
136
        tabIndexes[0] = 4;
137
        searchFor("versioning", tabIndexes, selectedCategories, enabledCategories);
138
139
        enabledCategories.clear();
140
        enabledCategories.add("Keymap");
141
        tabIndexes[0] = -1;
142
        selectedCategories[0] = "Keymaps";
143
        searchFor("keymap", tabIndexes, selectedCategories, enabledCategories);
144
145
        enabledCategories.clear();
146
        enabledCategories.add("Java");
147
        tabIndexes[0] = 5;
148
        selectedCategories[0] = "Java";
149
        searchFor("maven", tabIndexes, selectedCategories, enabledCategories);
150
151
        tabIndexes[0] = 0;
152
        selectedCategories[0] = "Java";
153
        searchFor("ant", tabIndexes, selectedCategories, enabledCategories);
154
155
        enabledCategories.add("Miscellaneous");
156
        tabIndexes = new int[2];
157
        selectedCategories = new String[2];
158
        tabIndexes[0] = 4;
159
        tabIndexes[1] = 2;
160
        selectedCategories[0] = "Java";
161
        selectedCategories[1] = "Miscellaneous";
162
        searchFor("me", tabIndexes, selectedCategories, enabledCategories);
163
164
        enabledCategories.clear();
165
        enabledCategories.add("Java");
166
        tabIndexes = new int[1];
167
        selectedCategories = new String[1];
168
        tabIndexes[0] = 7;
169
        selectedCategories[0] = "Java";
170
        searchFor("fx", tabIndexes, selectedCategories, enabledCategories);
171
172
        enabledCategories.clear();
173
        enabledCategories.add("Miscellaneous");
174
        tabIndexes[0] = 3;
175
        selectedCategories[0] = "Miscellaneous";
176
        searchFor("groovy", tabIndexes, selectedCategories, enabledCategories);
177
178
        tabIndexes[0] = 5;
179
        selectedCategories[0] = "Miscellaneous";
180
        searchFor("javascript", tabIndexes, selectedCategories, enabledCategories);
181
182
        tabIndexes[0] = 7;
183
        selectedCategories[0] = "Miscellaneous";
184
        searchFor("svg", tabIndexes, selectedCategories, enabledCategories);
185
186
        tabIndexes[0] = 8;
187
        selectedCategories[0] = "Miscellaneous";
188
        searchFor("terminal", tabIndexes, selectedCategories, enabledCategories);
189
190
        enabledCategories.add("Fonts & Colors");
191
        tabIndexes = new int[2];
192
        selectedCategories = new String[2];
193
        tabIndexes[0] = 3;
194
        tabIndexes[1] = 1;
195
        selectedCategories[0] = "FontsAndColors";
196
        selectedCategories[1] = "Miscellaneous";
197
        searchFor("diff", tabIndexes, selectedCategories, enabledCategories);
198
199
        enabledCategories.clear();
200
        enabledCategories.addAll(Arrays.asList("General", "Editor", "Fonts & Colors", "Keymap", "Java", "PHP", "C/C++", "Miscellaneous"));
201
        tabIndexes = new int[1];
202
        selectedCategories = new String[1];
203
        tabIndexes[0] = 1;
204
        selectedCategories[0] = "Miscellaneous";
205
        searchFor("", tabIndexes, selectedCategories, enabledCategories);
206
    }
207
208
    private void searchFor(String searchTxt, int[] selectedTabIndexes, String[] selectedCategories, ArrayList<String> enabledCategories) {
209
        jTextFieldOperator.setText(searchTxt);
210
        new EventTool().waitNoEvent(500);
211
        jTextFieldOperator.pushKey(KeyEvent.VK_ENTER);
212
        new EventTool().waitNoEvent(1000);
213
        for (int i = 0; i < selectedCategories.length; i++) {
214
            String selectedCategory = selectedCategories[i];
215
            if (selectedCategory.equals("General")) {
216
                optionsOperator.selectGeneral();
217
            } else if (selectedCategory.equals("Editor")) {
218
                optionsOperator.selectEditor();
219
            } else if (selectedCategory.equals("FontsAndColors")) {
220
                optionsOperator.selectFontAndColors();
221
            } else if (selectedCategory.equals("Keymaps")) {
222
                optionsOperator.selectKeymap();
223
            } else if (selectedCategory.equals("Java")) {
224
                optionsOperator.selectJava();
225
            } else if (selectedCategory.equals("Miscellaneous")) {
226
                optionsOperator.selectMiscellaneous();
227
            }
228
            new EventTool().waitNoEvent(1000);
229
            int selectedTabIndex = selectedTabIndexes[i];
230
            if (selectedTabIndex != -1) {
231
                jTabbedPaneOperator = new JTabbedPaneOperator(optionsOperator);
232
                assertEquals(selectedTabIndex, jTabbedPaneOperator.getSelectedIndex());
233
            }
234
        }
235
        for(String category : categoryIDs) {
236
            if(enabledCategories.contains(category)) {
237
                assertTrue(getJLabelOperator(category).isEnabled());
238
            }
239
        }
240
    }
241
242
    private JLabelOperator getJLabelOperator(final String category) {
243
        return new JLabelOperator(optionsOperator, new ComponentChooser() {
244
            @Override
245
            public boolean checkComponent(Component comp) {
246
                if (comp.getClass().getName().equals("org.netbeans.modules.options.OptionsPanel$CategoryButton") ||// NOI18N
247
                        comp.getClass().getName().equals("org.netbeans.modules.options.OptionsPanel$NimbusCategoryButton")) { // NOI18N
248
                    if (((JLabel) comp).getText() != null) {
249
                        return stringComparator.equals(((JLabel) comp).getText(), category);
250
                    }
251
                }
252
                return false;
253
            }
254
255
            @Override
256
            public String getDescription() {
257
                return "OptionsPanel$CategoryButton with text " + category; // NOI18N
258
            }
259
        });
260
    }
261
}

Return to bug 218312