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/OptionsPanelControllerProcessor.java (+56 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 108-113 Link Here
108
            keywords(e, r.keywords(), r.keywordsCategory(), r, file);
115
            keywords(e, r.keywords(), r.keywordsCategory(), r, file);
109
            file.write();
116
            file.write();
110
        }
117
        }
118
        
119
        ArrayList<KeywordPanel> advanced = new ArrayList<KeywordPanel>();
120
        for (Element e : roundEnv.getElementsAnnotatedWith(KeywordPanel.class)) {
121
            KeywordPanel annotation = e.getAnnotation(KeywordPanel.class);
122
            if (annotation != null) {
123
                String location = annotation.location();
124
                if(location.equals(OptionsDisplayer.ADVANCED)) {
125
                    advanced.add(annotation);
126
                }
127
            }
128
        }
129
        Collections.sort(advanced, new AdvancedComparable());
130
        
131
        for (Element e : roundEnv.getElementsAnnotatedWith(KeywordPanel.class)) {
132
            handleElement(e, e.getAnnotation(KeywordPanel.class), advanced, null);
133
        }
134
        for (Element e : roundEnv.getElementsAnnotatedWith(KeywordPanels.class)) {
135
            KeywordPanels r = e.getAnnotation(KeywordPanels.class);
136
            KeywordPanel[] panels = r.value();
137
            for (int i = 0; i < panels.length; i++) {
138
                handleElement(e, panels[i], advanced, e.asType().toString());
139
            }
140
        }
111
        for (Element e : roundEnv.getElementsAnnotatedWith(ContainerRegistration.class)) {
141
        for (Element e : roundEnv.getElementsAnnotatedWith(ContainerRegistration.class)) {
112
            ContainerRegistration r = e.getAnnotation(ContainerRegistration.class);
142
            ContainerRegistration r = e.getAnnotation(ContainerRegistration.class);
113
            LayerBuilder builder = layer(e);
143
            LayerBuilder builder = layer(e);
Lines 123-128 Link Here
123
        }
153
        }
124
        return true;
154
        return true;
125
    }
155
    }
156
    
157
    private void handleElement(Element e, KeywordPanel annotation, ArrayList<KeywordPanel> advanced, String name) throws LayerGenerationException {
158
        int index = annotation.index();
159
        if (annotation.location().equals(OptionsDisplayer.ADVANCED)) {
160
            index = advanced.indexOf(annotation);
161
        }
162
        File file = layer(e).
163
                instanceFile("OptionsDialog/PanelKeywords", name, annotation, null).
164
                stringvalue("instanceOf", JPanel.class.getName()).
165
                bundlevalue("location", annotation.location(), annotation, "location").
166
                bundlevalue("id", annotation.id()).
167
                intvalue("index", index);
168
        int i = 1;
169
        for (String keyword : annotation.keywords()) {
170
            file.bundlevalue("keyword-".concat(Integer.toString(i++)), keyword, annotation, "keywords");
171
        }
172
        file.write();
173
    }
174
    
175
    private class AdvancedComparable implements Comparator<KeywordPanel> {
176
177
        @Override
178
        public int compare(KeywordPanel r1, KeywordPanel r2) {
179
            return r1.id().compareTo(r2.id());
180
        }
181
    }
126
182
127
    private void iconBase(Element e, String iconBase, Annotation r, File file, LayerBuilder builder) throws LayerGenerationException {
183
    private void iconBase(Element e, String iconBase, Annotation r, File file, LayerBuilder builder) throws LayerGenerationException {
128
        builder.validateResource(iconBase, e, r, "iconBase", true);
184
        builder.validateResource(iconBase, e, r, "iconBase", true);
(-)a/options.api/src/org/netbeans/spi/options/OptionsPanelController.java (+59 lines)
Lines 285-290 Link Here
285
         */
285
         */
286
        int position() default Integer.MAX_VALUE;
286
        int position() default Integer.MAX_VALUE;
287
    }
287
    }
288
    
289
    /**
290
     * Similar to {@link KeywordPanel} but permits multiple registrations of
291
     * one class.
292
     *
293
     * @since org.netbeans.modules.options.api/1 1.28
294
     */
295
    @Target({ElementType.TYPE})
296
    @Retention(RetentionPolicy.RUNTIME)
297
    public @interface KeywordPanels {
298
299
        /**
300
         * List of KeywordPanel registrations.
301
         */
302
        KeywordPanel[] value();
303
    }
304
    
305
    /**
306
     * Registers keywords for some panel in the Options dialog. Should be placed
307
     * on a {@link JPanel} instance with a no-argument constructor.
308
     *
309
     * @since org.netbeans.modules.options.api/1 1.28
310
     */
311
    @Target({ElementType.TYPE})
312
    @Retention(RetentionPolicy.RUNTIME)
313
    public @interface KeywordPanel {
314
315
        /**
316
         * Keywords for use with search inside the Options dialog. You may use
317
         * {@code #key} syntax.
318
         */
319
        String[] keywords();
320
321
        /**
322
         * Keyword category for use with search inside the Options dialog.
323
         */
324
        /**
325
         * Location of this panel inside some top-level panel matching
326
         * {@link ContainerRegistration#id} or {@link SubRegistration#location}.
327
         * Typically this should be a reference to a compile-time constant also
328
         * used for the container's ID.
329
         */
330
        String location();
331
332
        /**
333
         * Path that can be used (with {@link #location}) in
334
         * {@link OptionsDisplayer#open(String)} matching
335
         * {@link SubRegistration#id}. Typically this should be a reference to a
336
         * compile-time constant to which other code can refer. You may use
337
         * {@code #key} syntax.
338
         */
339
        String id();
340
341
        /**
342
         * Position relative to sibling subpanels. Miscellaneous panel's tabs
343
         * are always sorted alphabetically.
344
         */
345
        int index();
346
    }
288
347
289
    /**
348
    /**
290
     * Registers a panel with child panels at the top level of the Options dialog.
349
     * Registers a panel with child panels at the top level of the Options dialog.

Return to bug 218312