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

(-)a/spi.quicksearch/nbproject/project.xml (+8 lines)
Lines 76-81 Link Here
76
                <test-type>
76
                <test-type>
77
                    <name>unit</name>
77
                    <name>unit</name>
78
                    <test-dependency>
78
                    <test-dependency>
79
                        <code-name-base>org.netbeans.bootstrap</code-name-base>
80
                        <compile-dependency/>
81
                    </test-dependency>
82
                    <test-dependency>
79
                        <code-name-base>org.netbeans.core.startup</code-name-base>
83
                        <code-name-base>org.netbeans.core.startup</code-name-base>
80
                    </test-dependency>
84
                    </test-dependency>
81
                    <test-dependency>
85
                    <test-dependency>
Lines 87-92 Link Here
87
                        <recursive/>
91
                        <recursive/>
88
                        <compile-dependency/>
92
                        <compile-dependency/>
89
                    </test-dependency>
93
                    </test-dependency>
94
                    <test-dependency>
95
                        <code-name-base>org.openide.modules</code-name-base>
96
                        <compile-dependency/>
97
                    </test-dependency>
90
                </test-type>
98
                </test-type>
91
            </test-dependencies>
99
            </test-dependencies>
92
            <public-packages>
100
            <public-packages>
(-)a/spi.quicksearch/src/org/netbeans/modules/quicksearch/AbstractQuickSearchComboBar.java (-22 / +191 lines)
Lines 43-48 Link Here
43
package org.netbeans.modules.quicksearch;
43
package org.netbeans.modules.quicksearch;
44
44
45
import java.awt.Color;
45
import java.awt.Color;
46
import java.awt.Component;
47
import java.awt.Container;
46
import java.awt.FontMetrics;
48
import java.awt.FontMetrics;
47
import java.awt.KeyboardFocusManager;
49
import java.awt.KeyboardFocusManager;
48
import java.awt.event.ActionEvent;
50
import java.awt.event.ActionEvent;
Lines 51-63 Link Here
51
import java.awt.event.MouseAdapter;
53
import java.awt.event.MouseAdapter;
52
import java.awt.event.MouseEvent;
54
import java.awt.event.MouseEvent;
53
import java.lang.ref.WeakReference;
55
import java.lang.ref.WeakReference;
56
import java.util.Collections;
57
import java.util.HashSet;
58
import java.util.Iterator;
59
import java.util.Set;
60
import javax.swing.JCheckBoxMenuItem;
54
import javax.swing.JComponent;
61
import javax.swing.JComponent;
55
import javax.swing.JList;
62
import javax.swing.JList;
63
import javax.swing.JMenuItem;
56
import javax.swing.JPopupMenu;
64
import javax.swing.JPopupMenu;
57
import javax.swing.JRadioButtonMenuItem;
58
import javax.swing.KeyStroke;
65
import javax.swing.KeyStroke;
66
import javax.swing.MenuElement;
67
import javax.swing.MenuSelectionManager;
59
import javax.swing.SwingUtilities;
68
import javax.swing.SwingUtilities;
60
import javax.swing.UIManager;
69
import javax.swing.UIManager;
70
import javax.swing.event.ChangeEvent;
71
import javax.swing.event.ChangeListener;
61
import javax.swing.event.DocumentEvent;
72
import javax.swing.event.DocumentEvent;
62
import javax.swing.event.DocumentListener;
73
import javax.swing.event.DocumentListener;
63
import javax.swing.text.AbstractDocument;
74
import javax.swing.text.AbstractDocument;
Lines 78-86 Link Here
78
 * Quick search toolbar component
89
 * Quick search toolbar component
79
 * @author  Jan Becicka
90
 * @author  Jan Becicka
80
 */
91
 */
81
public abstract class AbstractQuickSearchComboBar extends javax.swing.JPanel implements ActionListener {
92
public abstract class AbstractQuickSearchComboBar extends javax.swing.JPanel {
82
83
    private static final String CATEGORY = "cat";
84
93
85
    QuickSearchPopup displayer = new QuickSearchPopup(this);
94
    QuickSearchPopup displayer = new QuickSearchPopup(this);
86
    WeakReference<TopComponent> caller;
95
    WeakReference<TopComponent> caller;
Lines 253-259 Link Here
253
        setShowHint(false);
262
        setShowHint(false);
254
        if (CommandEvaluator.isCatTemporary()) {
263
        if (CommandEvaluator.isCatTemporary()) {
255
            CommandEvaluator.setCatTemporary(false);
264
            CommandEvaluator.setCatTemporary(false);
256
            CommandEvaluator.setEvalCat(null);
265
            CommandEvaluator.setEvalCats(null);
257
        }
266
        }
258
    }
267
    }
259
268
Lines 263-283 Link Here
263
        }
272
        }
264
273
265
        JPopupMenu pm = new JPopupMenu();
274
        JPopupMenu pm = new JPopupMenu();
266
        ProviderModel.Category evalCat = null;
275
        final Set<ProviderModel.Category> evalCats =
276
                new HashSet<ProviderModel.Category>();
267
        if (!CommandEvaluator.isCatTemporary()) {
277
        if (!CommandEvaluator.isCatTemporary()) {
268
            evalCat = CommandEvaluator.getEvalCat();
278
            evalCats.addAll(CommandEvaluator.getEvalCats());
269
        }
279
        }
270
280
        JMenuItem allCats = new AllMenuItem(evalCats);
271
        JRadioButtonMenuItem allCats = new JRadioButtonMenuItem(
272
                NbBundle.getMessage(getClass(), "LBL_AllCategories"), evalCat == null);
273
        allCats.addActionListener(this);
274
        pm.add(allCats);
281
        pm.add(allCats);
275
282
276
        for (ProviderModel.Category cat : ProviderModel.getInstance().getCategories()) {
283
        for (ProviderModel.Category cat : ProviderModel.getInstance().getCategories()) {
277
            if (!CommandEvaluator.RECENT.equals(cat.getName())) {
284
            if (!CommandEvaluator.RECENT.equals(cat.getName())) {
278
                JRadioButtonMenuItem item = new JRadioButtonMenuItem(cat.getDisplayName(), cat == evalCat);
285
                JCheckBoxMenuItem item = new CategoryCheckBoxMenuItem(cat,
279
                item.putClientProperty(CATEGORY, cat);
286
                        evalCats);
280
                item.addActionListener(this);
281
                pm.add(item);
287
                pm.add(item);
282
            }
288
            }
283
        }
289
        }
Lines 285-304 Link Here
285
        pm.show(getInnerComponent(), 0, getInnerComponent().getHeight() - 1);
291
        pm.show(getInnerComponent(), 0, getInnerComponent().getHeight() - 1);
286
    }
292
    }
287
293
288
    /** ActionListener implementation, reaction to popup menu item invocation */
294
    private void updateCats(Set<Category> evalCats) {
289
    public void actionPerformed(ActionEvent e) {
295
        CommandEvaluator.setEvalCats(evalCats);
290
        JRadioButtonMenuItem item = (JRadioButtonMenuItem)e.getSource();
291
        CommandEvaluator.setEvalCat((Category) item.getClientProperty(CATEGORY));
292
        CommandEvaluator.setCatTemporary(false);
296
        CommandEvaluator.setCatTemporary(false);
293
        // refresh hint
297
        // refresh hint
294
        setShowHint(!command.isFocusOwner());
298
        setShowHint(!command.isFocusOwner());
295
    }
299
    }
296
300
301
    private void updateCheckBoxes(Container container, Set<Category> evalCats) {
302
        Container parent = container.getParent();
303
        for (Component c : parent.getComponents()) {
304
            if (c instanceof CategoryCheckBoxMenuItem) {
305
                CategoryCheckBoxMenuItem ci = (CategoryCheckBoxMenuItem) c;
306
                ci.setSelected(evalCats.contains(ci.category));
307
            }
308
        }
309
    }
310
297
    /** Runs evaluation narrowed to specified category
311
    /** Runs evaluation narrowed to specified category
298
     *
312
     *
299
     */
313
     */
300
    public void evaluateCategory (Category cat, boolean temporary) {
314
    public void evaluateCategory (Category cat, boolean temporary) {
301
        CommandEvaluator.setEvalCat(cat);
315
        CommandEvaluator.setEvalCats(
316
                cat == null ? null : Collections.singleton(cat));
302
        CommandEvaluator.setCatTemporary(temporary);
317
        CommandEvaluator.setCatTemporary(temporary);
303
        displayer.maybeEvaluate(command.getText());
318
        displayer.maybeEvaluate(command.getText());
304
    }
319
    }
Lines 322-330 Link Here
322
        }
337
        }
323
        if (showHint) {
338
        if (showHint) {
324
            command.setForeground(command.getDisabledTextColor());
339
            command.setForeground(command.getDisabledTextColor());
325
            Category evalCat = CommandEvaluator.getEvalCat();
340
            Set<Category> evalCats = CommandEvaluator.getEvalCats();
326
            if (evalCat != null && !CommandEvaluator.isCatTemporary()) {
341
            if (evalCats.size() < 3 && !CommandEvaluator.isCatTemporary()) {
327
                command.setText(getHintText(evalCat));
342
                Category bestFound = null;
343
                for (Category c : evalCats) {
344
                    if (bestFound == null || CommandEvaluator.RECENT.equals(
345
                            bestFound.getName())) {
346
                        bestFound = c;
347
                    }
348
                }
349
                command.setText(getHintText(bestFound));
328
            } else {
350
            } else {
329
                command.setText(getHintText(null));
351
                command.setText(getHintText(null));
330
            }
352
            }
Lines 493-496 Link Here
493
            DialogDisplayer.getDefault().notifyLater(nd);
515
            DialogDisplayer.getDefault().notifyLater(nd);
494
        }
516
        }
495
    }
517
    }
518
519
    /**
520
     * Show and select menu at a given path. Used to restore a menu after click.
521
     */
522
    private void showMenuPath(MenuElement[] selectedPath) {
523
        if (selectedPath != null && selectedPath.length > 1) {
524
            if (selectedPath[0] instanceof JPopupMenu) {
525
                ((JPopupMenu) selectedPath[0]).setVisible(true);
526
                MenuSelectionManager.defaultManager().setSelectedPath(
527
                        selectedPath);
528
            }
529
        }
530
    }
531
532
    /**
533
     * Menu item representing a single category.
534
     */
535
    private class CategoryCheckBoxMenuItem extends JCheckBoxMenuItem
536
            implements ActionListener {
537
538
        private MenuElement[] selectedPath = null;
539
        private Category category;
540
        private final Set<Category> evalCats;
541
542
        public CategoryCheckBoxMenuItem(final Category category,
543
                final Set<Category> evalCats) {
544
            super(category.getDisplayName(), evalCats.contains(category));
545
            this.category = category;
546
            this.evalCats = evalCats;
547
            setOpaque(false);
548
            getModel().addChangeListener(new ChangeListener() {
549
                @Override
550
                public void stateChanged(ChangeEvent e) {
551
                    if (isShowing() && model.isArmed()) {
552
                        selectedPath = MenuSelectionManager.defaultManager()
553
                                .getSelectedPath();
554
                    }
555
                }
556
            });
557
            addActionListener(this);
558
            addMouseListener(new MouseAdapter() {
559
560
                @Override
561
                public void mouseClicked(MouseEvent e) {
562
                    mouseClickedOnItem(e);
563
                }
564
            });
565
        }
566
567
        @Override
568
        public void doClick(int pressTime) {
569
            super.doClick(pressTime);
570
            showMenuPath(selectedPath);
571
        }
572
573
        private void mouseClickedOnItem(MouseEvent e) {
574
            if (SwingUtilities.isRightMouseButton(e)) {
575
                e.consume();
576
                if (isSelected()) {
577
                    Iterator<Category> iterator = evalCats.iterator();
578
                    while (iterator.hasNext()) {
579
                        Category c = iterator.next();
580
                        if (!CommandEvaluator.RECENT.equals(c.getName())) {
581
                            iterator.remove();
582
                        }
583
                    }
584
                    evalCats.add(category);
585
                } else {
586
                    evalCats.addAll(
587
                            ProviderModel.getInstance().getCategories());
588
                    evalCats.remove(category);
589
                }
590
                updateCheckBoxes(CategoryCheckBoxMenuItem.this, evalCats);
591
                updateCats(evalCats);
592
            }
593
        }
594
595
        @Override
596
        public void actionPerformed(ActionEvent e) {
597
            if (this.isSelected()) {
598
                evalCats.add(category);
599
            } else {
600
                evalCats.remove(category);
601
            }
602
            updateCats(evalCats);
603
        }
604
    }
605
606
    /**
607
     * Menu item for enabling or disabling all categories.
608
     */
609
    private class AllMenuItem extends JMenuItem implements ActionListener {
610
611
        private Set<Category> evalCats;
612
        private int totalCount;
613
        private MenuElement[] selectedPath = null;
614
615
        public AllMenuItem(Set<Category> evalCats) {
616
            this.evalCats = evalCats;
617
            this.totalCount = ProviderModel.getInstance()
618
                    .getCategories().size();
619
            getModel().addChangeListener(new ChangeListener() {
620
                @Override
621
                public void stateChanged(ChangeEvent e) {
622
                    if (isShowing() && model.isArmed()) {
623
                        selectedPath = MenuSelectionManager.defaultManager()
624
                                .getSelectedPath();
625
                    }
626
                }
627
            });
628
            addActionListener(this);
629
        }
630
631
        @Override
632
        public void actionPerformed(ActionEvent e) {
633
            if (evalCats.size() == totalCount) {
634
                Iterator<Category> iterator = evalCats.iterator();
635
                while (iterator.hasNext()) {
636
                    Category c = iterator.next();
637
                    if (!CommandEvaluator.RECENT.equals(c.getName())) {
638
                        iterator.remove();
639
                    }
640
                }
641
            } else {
642
                evalCats.addAll(ProviderModel.getInstance().getCategories());
643
            }
644
            updateCats(evalCats);
645
            updateCheckBoxes(this, evalCats);
646
        }
647
648
        @Override
649
        public void doClick(int pressTime) {
650
            super.doClick(pressTime);
651
            showMenuPath(selectedPath);
652
        }
653
654
        @Override
655
        public String getText() {
656
            if (evalCats == null || evalCats.size() != totalCount) {
657
                return NbBundle.getMessage(getClass(),
658
                        "LBL_AllCategories");                           //NOI18N
659
            } else {
660
                return NbBundle.getMessage(getClass(),
661
                        "LBL_NoCategory");                              //NOI18N
662
            }
663
        }
664
    }
496
}
665
}
(-)a/spi.quicksearch/src/org/netbeans/modules/quicksearch/Bundle.properties (+1 lines)
Lines 48-53 Link Here
48
MSG_DiscoverabilityHint2=Search in {0}
48
MSG_DiscoverabilityHint2=Search in {0}
49
LBL_MoreResults=...
49
LBL_MoreResults=...
50
LBL_AllCategories=All Categories
50
LBL_AllCategories=All Categories
51
LBL_NoCategory=Deselect All
51
QuickSearchPopup.searchingLabel.text=Searching ...
52
QuickSearchPopup.searchingLabel.text=Searching ...
52
QuickSearchPopup.noResultsLabel.text=( No Results )
53
QuickSearchPopup.noResultsLabel.text=( No Results )
53
QuickSearchPopup.hintLabel.text={0}; Press {1} for All Categories
54
QuickSearchPopup.hintLabel.text={0}; Press {1} for All Categories
(-)a/spi.quicksearch/src/org/netbeans/modules/quicksearch/CommandEvaluator.java (-18 / +65 lines)
Lines 43-55 Link Here
43
package org.netbeans.modules.quicksearch;
43
package org.netbeans.modules.quicksearch;
44
44
45
import java.util.ArrayList;
45
import java.util.ArrayList;
46
import java.util.Arrays;
47
import java.util.HashSet;
48
import java.util.Iterator;
46
import java.util.List;
49
import java.util.List;
50
import java.util.Set;
47
import java.util.regex.Matcher;
51
import java.util.regex.Matcher;
48
import java.util.regex.Pattern;
52
import java.util.regex.Pattern;
49
import org.netbeans.modules.quicksearch.ProviderModel.Category;
53
import org.netbeans.modules.quicksearch.ProviderModel.Category;
50
import org.netbeans.spi.quicksearch.SearchProvider;
54
import org.netbeans.spi.quicksearch.SearchProvider;
51
import org.netbeans.spi.quicksearch.SearchRequest;
55
import org.netbeans.spi.quicksearch.SearchRequest;
52
import org.netbeans.spi.quicksearch.SearchResponse;
56
import org.netbeans.spi.quicksearch.SearchResponse;
57
import org.openide.util.NbPreferences;
53
import org.openide.util.RequestProcessor;
58
import org.openide.util.RequestProcessor;
54
import org.openide.util.RequestProcessor.Task;
59
import org.openide.util.RequestProcessor.Task;
55
60
Lines 61-66 Link Here
61
public class CommandEvaluator {
66
public class CommandEvaluator {
62
    
67
    
63
    final static String RECENT = "Recent";
68
    final static String RECENT = "Recent";
69
    private static final String PROP_ENABLED_CATEGORIES =
70
            "enabledCategories";                                        //NOI18N
64
    
71
    
65
    /**
72
    /**
66
     * command pattern is:
73
     * command pattern is:
Lines 68-82 Link Here
68
     */
75
     */
69
    private static Pattern COMMAND_PATTERN = Pattern.compile("(\\w+)(\\s+)(.+)");
76
    private static Pattern COMMAND_PATTERN = Pattern.compile("(\\w+)(\\s+)(.+)");
70
77
71
    /** Narrow evaluation only to specified category if non null.
72
     * Evaluate all categories otherwise
73
     */
74
    private static ProviderModel.Category evalCat;
75
76
    /** Temporary narrow evaluation to only specified category **/
78
    /** Temporary narrow evaluation to only specified category **/
77
    private static boolean isCatTemporary;
79
    private static boolean isCatTemporary;
78
80
79
    private static final RequestProcessor RP = new RequestProcessor("QuickSearch Command Evaluator", 10); // NOI18N
81
    private static final RequestProcessor RP = new RequestProcessor("QuickSearch Command Evaluator", 10); // NOI18N
82
    /**
83
     * Narrow evaluation to specified set of categories.
84
     */
85
    private static Set<ProviderModel.Category> evalCats = loadEvalCats();
80
    
86
    
81
    /**
87
    /**
82
     * Runs evaluation.
88
     * Runs evaluation.
Lines 113-124 Link Here
113
        return new Wait4AllTask(tasks);
119
        return new Wait4AllTask(tasks);
114
    }
120
    }
115
121
116
    public static Category getEvalCat () {
122
    private static Set<Category> loadEvalCats() {
117
        return evalCat;
123
        final Set<Category> cats = new HashSet<Category>(
124
                ProviderModel.getInstance().getCategories());
125
        RP.post(new Runnable() {
126
            @Override
127
            public void run() {
128
                String ec = NbPreferences.forModule(CommandEvaluator.class).get(
129
                        PROP_ENABLED_CATEGORIES, null);
130
                if (ec != null) {
131
                    Set<String> categoryNames = new HashSet<String>();
132
                    categoryNames.addAll(Arrays.asList(ec.split(":"))); //NOI18N
133
                    Iterator<Category> iterator = cats.iterator();
134
                    while (iterator.hasNext()) {
135
                        Category category = iterator.next();
136
                        if (!categoryNames.contains(category.getName())
137
                                && !RECENT.equals(category.getName())) {
138
                            iterator.remove();
139
                        }
140
                    }
141
                }
142
            }
143
        });
144
        return cats;
118
    }
145
    }
119
146
120
    public static void setEvalCat (Category cat) {
147
    private static void storeEvalCats() {
121
        CommandEvaluator.evalCat = cat;
148
        RP.post(new Runnable() {
149
            @Override
150
            public void run() {
151
                StringBuilder sb = new StringBuilder();
152
                for (Category category : evalCats) {
153
                    if (!RECENT.equals(category.getName())) {
154
                        sb.append(category.getName());
155
                        sb.append(':');
156
                    }
157
                }
158
                NbPreferences.forModule(CommandEvaluator.class).put(
159
                        PROP_ENABLED_CATEGORIES, sb.toString());
160
            }
161
        });
162
    }
163
164
    public static Set<Category> getEvalCats () {
165
        return evalCats;
166
    }
167
168
    public static void setEvalCats(Set<Category> cat) {
169
        CommandEvaluator.evalCats = (cat == null)
170
                ? new HashSet<Category>(ProviderModel.getInstance()
171
                .getCategories())
172
                : cat;
122
    }
173
    }
123
174
124
    public static boolean isCatTemporary () {
175
    public static boolean isCatTemporary () {
Lines 127-132 Link Here
127
178
128
    public static void setCatTemporary (boolean isCatTemporary) {
179
    public static void setCatTemporary (boolean isCatTemporary) {
129
        CommandEvaluator.isCatTemporary = isCatTemporary;
180
        CommandEvaluator.isCatTemporary = isCatTemporary;
181
        if (!isCatTemporary) {
182
            storeEvalCats();
183
        }
130
    }
184
    }
131
185
132
    private static String[] parseCommand (String command) {
186
    private static String[] parseCommand (String command) {
Lines 180-194 Link Here
180
            }
234
            }
181
        }
235
        }
182
236
183
        // evaluation narrowed to category perhaps?
237
        //no narrowing
184
        if (evalCat != null) {
238
        result.addAll(evalCats);
185
            result.add(evalCat);
186
            return true;
187
        }
188
189
        // no narrowing
190
        result.clear();
191
        result.addAll(cats);
192
239
193
        return false;
240
        return false;
194
    }
241
    }
(-)a/spi.quicksearch/src/org/netbeans/modules/quicksearch/QuickSearchPopup.java (-4 / +5 lines)
Lines 55-60 Link Here
55
import java.awt.event.MouseAdapter;
55
import java.awt.event.MouseAdapter;
56
import java.awt.event.MouseEvent;
56
import java.awt.event.MouseEvent;
57
import java.awt.event.MouseMotionAdapter;
57
import java.awt.event.MouseMotionAdapter;
58
import java.util.Set;
58
import java.util.logging.Level;
59
import java.util.logging.Level;
59
import java.util.logging.Logger;
60
import java.util.logging.Logger;
60
import java.util.prefs.Preferences;
61
import java.util.prefs.Preferences;
Lines 541-547 Link Here
541
        shouldBeVisible = shouldBeVisible || areNoResults;
542
        shouldBeVisible = shouldBeVisible || areNoResults;
542
543
543
        hintLabel.setText(getHintText());
544
        hintLabel.setText(getHintText());
544
        boolean isNarrowed = CommandEvaluator.getEvalCat() != null && searchedNotEmpty;
545
        boolean isNarrowed = CommandEvaluator.getEvalCats().size() == 1 && searchedNotEmpty;
545
        hintSep.setVisible(isNarrowed);
546
        hintSep.setVisible(isNarrowed);
546
        hintLabel.setVisible(isNarrowed);
547
        hintLabel.setVisible(isNarrowed);
547
        shouldBeVisible = shouldBeVisible || isNarrowed;
548
        shouldBeVisible = shouldBeVisible || isNarrowed;
Lines 550-561 Link Here
550
    }
551
    }
551
552
552
    private String getHintText () {
553
    private String getHintText () {
553
        ProviderModel.Category evalCat = CommandEvaluator.getEvalCat();
554
        Set<ProviderModel.Category> evalCats = CommandEvaluator.getEvalCats();
554
        if (evalCat == null) {
555
        if (evalCats.size() != 1) {
555
            return null;
556
            return null;
556
        }
557
        }
557
        return NbBundle.getMessage(QuickSearchPopup.class, "QuickSearchPopup.hintLabel.text",
558
        return NbBundle.getMessage(QuickSearchPopup.class, "QuickSearchPopup.hintLabel.text",
558
                evalCat.getDisplayName(), SearchResultRender.getKeyStrokeAsText(
559
                evalCats.iterator().next().getDisplayName(), SearchResultRender.getKeyStrokeAsText(
559
                comboBar.getKeyStroke()));
560
                comboBar.getKeyStroke()));
560
    }
561
    }
561
562
(-)a/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/CommandEvaluatorTest.java (+75 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.quicksearch;
43
44
import java.util.HashSet;
45
import java.util.Set;
46
import static org.junit.Assert.*;
47
import org.junit.Test;
48
import org.netbeans.modules.quicksearch.ProviderModel.Category;
49
50
/**
51
 *
52
 * @author jhavlin
53
 */
54
public class CommandEvaluatorTest {
55
56
    @Test
57
    public void testGetSetEvalCats() {
58
        Set<ProviderModel.Category> evalCats = CommandEvaluator.getEvalCats();
59
        Category recent = null;
60
        for (Category c : evalCats) {
61
            if (CommandEvaluator.RECENT.equals(c.getName())) {
62
                recent = c;
63
            }
64
        }
65
        assertNotNull("Recent category should be enabled", recent);
66
        CommandEvaluator.setEvalCats(new HashSet<Category>());
67
        assertEquals(0, CommandEvaluator.getEvalCats().size());
68
        CommandEvaluator.setEvalCats(null);
69
        assertNotNull(ProviderModel.getInstance().getCategories());
70
        assertNotNull(CommandEvaluator.getEvalCats());
71
        assertEquals(ProviderModel.getInstance().getCategories().size(),
72
                CommandEvaluator.getEvalCats().size());
73
        CommandEvaluator.setEvalCats(evalCats);
74
    }
75
}

Return to bug 143367