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="20" month="9" 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/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_KEYWORDPANELS_FOLDER_NAME = "OptionsDialog/KeywordPanels"; // 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 / +59 lines)
Lines 43-49 Link Here
43
package org.netbeans.modules.options;
43
package org.netbeans.modules.options;
44
44
45
import java.lang.annotation.Annotation;
45
import java.lang.annotation.Annotation;
46
import java.util.ArrayList;
46
import java.util.Arrays;
47
import java.util.Arrays;
48
import java.util.Collections;
49
import java.util.Comparator;
47
import java.util.HashSet;
50
import java.util.HashSet;
48
import java.util.Set;
51
import java.util.Set;
49
import javax.annotation.processing.Processor;
52
import javax.annotation.processing.Processor;
Lines 52-61 Link Here
52
import javax.lang.model.SourceVersion;
55
import javax.lang.model.SourceVersion;
53
import javax.lang.model.element.Element;
56
import javax.lang.model.element.Element;
54
import javax.lang.model.element.TypeElement;
57
import javax.lang.model.element.TypeElement;
58
import javax.swing.JPanel;
59
import org.netbeans.api.options.OptionsDisplayer;
55
import org.netbeans.spi.options.AdvancedOption;
60
import org.netbeans.spi.options.AdvancedOption;
56
import org.netbeans.spi.options.OptionsCategory;
61
import org.netbeans.spi.options.OptionsCategory;
57
import org.netbeans.spi.options.OptionsPanelController;
62
import org.netbeans.spi.options.OptionsPanelController;
58
import org.netbeans.spi.options.OptionsPanelController.ContainerRegistration;
63
import org.netbeans.spi.options.OptionsPanelController.ContainerRegistration;
64
import org.netbeans.spi.options.OptionsPanelController.KeywordPanel;
65
import org.netbeans.spi.options.OptionsPanelController.KeywordPanels;
59
import org.netbeans.spi.options.OptionsPanelController.SubRegistration;
66
import org.netbeans.spi.options.OptionsPanelController.SubRegistration;
60
import org.netbeans.spi.options.OptionsPanelController.TopLevelRegistration;
67
import org.netbeans.spi.options.OptionsPanelController.TopLevelRegistration;
61
import org.openide.filesystems.annotations.LayerBuilder;
68
import org.openide.filesystems.annotations.LayerBuilder;
Lines 72-78 Link Here
72
        return new HashSet<String>(Arrays.asList(
79
        return new HashSet<String>(Arrays.asList(
73
            TopLevelRegistration.class.getCanonicalName(),
80
            TopLevelRegistration.class.getCanonicalName(),
74
            ContainerRegistration.class.getCanonicalName(),
81
            ContainerRegistration.class.getCanonicalName(),
75
            SubRegistration.class.getCanonicalName()
82
            SubRegistration.class.getCanonicalName(),
83
            KeywordPanels.class.getCanonicalName(),
84
            KeywordPanel.class.getCanonicalName()
76
        ));
85
        ));
77
    }
86
    }
78
87
Lines 108-113 Link Here
108
            keywords(e, r.keywords(), r.keywordsCategory(), r, file);
117
            keywords(e, r.keywords(), r.keywordsCategory(), r, file);
109
            file.write();
118
            file.write();
110
        }
119
        }
120
        
121
        ArrayList<KeywordPanel> advanced = new ArrayList<KeywordPanel>();
122
        for (Element e : roundEnv.getElementsAnnotatedWith(KeywordPanel.class)) {
123
            KeywordPanel annotation = e.getAnnotation(KeywordPanel.class);
124
            if (annotation != null) {
125
                String location = annotation.location();
126
                if(location.equals(OptionsDisplayer.ADVANCED)) {
127
                    advanced.add(annotation);
128
                }
129
            }
130
        }
131
        Collections.sort(advanced, new AdvancedComparable());
132
133
        for (Element e : roundEnv.getElementsAnnotatedWith(KeywordPanel.class)) {
134
            handleElement(e, e.getAnnotation(KeywordPanel.class), advanced, "");
135
        }
136
        for (Element e : roundEnv.getElementsAnnotatedWith(KeywordPanels.class)) {
137
            KeywordPanels r = e.getAnnotation(KeywordPanels.class);
138
            KeywordPanel[] panels = r.value();
139
            for (int i = 0; i < panels.length; i++) {
140
                handleElement(e, panels[i], advanced, Integer.toString(-(i + 1)));
141
            }
142
        }
111
        for (Element e : roundEnv.getElementsAnnotatedWith(ContainerRegistration.class)) {
143
        for (Element e : roundEnv.getElementsAnnotatedWith(ContainerRegistration.class)) {
112
            ContainerRegistration r = e.getAnnotation(ContainerRegistration.class);
144
            ContainerRegistration r = e.getAnnotation(ContainerRegistration.class);
113
            LayerBuilder builder = layer(e);
145
            LayerBuilder builder = layer(e);
Lines 123-128 Link Here
123
        }
155
        }
124
        return true;
156
        return true;
125
    }
157
    }
158
    
159
    private void handleElement(Element e, KeywordPanel annotation, ArrayList<KeywordPanel> advanced, String name) throws LayerGenerationException {
160
        int index = annotation.index();
161
        if (annotation.location().equals(OptionsDisplayer.ADVANCED)) {
162
            index = advanced.indexOf(annotation);
163
        }
164
        File file = layer(e).
165
                file("OptionsDialog/KeywordPanels/".concat(e.asType().toString()).concat(name)).
166
                stringvalue("instanceOf", JPanel.class.getName()).
167
                bundlevalue("location", annotation.location(), annotation, "location").
168
                bundlevalue("id", annotation.id()).
169
                intvalue("index", index);
170
        int i = 1;
171
        for (String keyword : annotation.keywords()) {
172
            file.bundlevalue("keyword-".concat(Integer.toString(i++)), keyword, annotation, "keywords");
173
        }
174
        file.write();
175
    }
176
    
177
    private class AdvancedComparable implements Comparator<KeywordPanel> {
178
179
        @Override
180
        public int compare(KeywordPanel r1, KeywordPanel r2) {
181
            return r1.id().compareTo(r2.id());
182
        }
183
    }
126
184
127
    private void iconBase(Element e, String iconBase, Annotation r, File file, LayerBuilder builder) throws LayerGenerationException {
185
    private void iconBase(Element e, String iconBase, Annotation r, File file, LayerBuilder builder) throws LayerGenerationException {
128
        builder.validateResource(iconBase, e, r, "iconBase", true);
186
        builder.validateResource(iconBase, e, r, "iconBase", true);
(-)a/options.api/src/org/netbeans/spi/options/OptionsPanelController.java (+58 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 KeywordPanel} 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 KeywordPanels {
328
329
        /**
330
         * List of KeywordPanel registrations.
331
         */
332
        KeywordPanel[] 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 KeywordPanel {
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
        String location();
360
361
        /**
362
         * Path that can be used (with {@link #location}) in
363
         * {@link OptionsDisplayer#open(String)} matching
364
         * {@link SubRegistration#id}. Typically this should be a reference to a
365
         * compile-time constant to which other code can refer. You may use
366
         * {@code #key} syntax.
367
         */
368
        String id();
369
370
        /**
371
         * Position relative to sibling subpanels matching the tab index in a tabbed pane.
372
         * Miscellaneous panel's tabs are always sorted alphabetically.
373
         */
374
        int index();
375
    }
376
319
}
377
}

Return to bug 218312