aboutsummaryrefslogtreecommitdiffstats
path: root/rule_api/src/com/android/ide/common/api/RuleAction.java
blob: f6c7e8c3073e43194f8aa0a136d3456f19768195 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.ide.common.api;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.util.Pair;
import com.google.common.annotations.Beta;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * A {@link RuleAction} represents an action provided by an {@link IViewRule}, typically
 * shown in a context menu or in the layout actions bar.
 * <p/>
 * Each action should have a reasonably unique ID. This is used when multiple nodes
 * are selected to filter the actions down to just those actions that are supported
 * across all selected nodes. If an action does not support multiple nodes, it can
 * return false from {@link #supportsMultipleNodes()}.
 * <p/>
 * Actions can be grouped into a hierarchy of sub-menus using the {@link NestedAction} class,
 * or into a flat submenu using the {@link Choices} class.
 * <p/>
 * Actions (including separators) all have a "sort priority", and this is used to
 * sort the menu items or toolbar buttons into a specific order.
 * <p>
 * <b>NOTE: This is not a public or final API; if you rely on this be prepared
 * to adjust your code for the next tools release.</b>
 * </p>
 */
@Beta
public class RuleAction implements Comparable<RuleAction> {
    /**
     * Character used to split multiple checked choices.
     * The pipe character "|" is used, to natively match Android resource flag separators.
     */
    public final static String CHOICE_SEP = "|"; //$NON-NLS-1$

    /**
     * Same as {@link #CHOICE_SEP} but safe for use in regular expressions.
     */
    public final static String CHOICE_SEP_PATTERN = Pattern.quote(CHOICE_SEP);

    /**
     * The unique id of the action.
     * @see #getId()
     */
    private final String mId;
    /**
     * The UI-visible title of the action.
     */
    private final String mTitle;

    /** A URL pointing to an icon, or null */
    private URL mIconUrl;

    /**
     * A callback executed when the action is selected in the context menu.
     */
    private final IMenuCallback mCallback;

    /**
     * The sorting priority of this item; actions can be sorted according to these
     */
    protected final int mSortPriority;

    /**
     * Whether this action supports multiple nodes, see
     * {@link #supportsMultipleNodes()} for details.
     */
    private final boolean mSupportsMultipleNodes;

    /**
     * Special value which will insert a separator in the choices' submenu.
     */
    public final static String SEPARATOR = "----";

    // Factories

    /**
     * Constructs a new separator which will be shown in places where separators
     * are supported such as context menus
     *
     * @param sortPriority a priority used for sorting this action
     * @return a new separator
     */
    @NonNull
    public static Separator createSeparator(int sortPriority) {
        return new Separator(sortPriority, true /* supportsMultipleNodes*/);
    }

    /**
     * Constructs a new base {@link RuleAction} with its ID, title and action callback.
     *
     * @param id The unique ID of the action. Must not be null.
     * @param title The title of the action. Must not be null.
     * @param callback The callback executed when the action is selected.
     *            Must not be null.
     * @param iconUrl a URL pointing to an icon to use for this action, or null
     * @param sortPriority a priority used for sorting this action
     * @param supportsMultipleNodes whether this action supports multiple nodes,
     *            see {@link #supportsMultipleNodes()} for details
     * @return the new {@link RuleAction}
     */
    @NonNull
    public static RuleAction createAction(
            @NonNull String id,
            @NonNull String title,
            @NonNull IMenuCallback callback,
            @Nullable URL iconUrl,
            int sortPriority,
            boolean supportsMultipleNodes) {
        RuleAction action = new RuleAction(id, title, callback, sortPriority,
                supportsMultipleNodes);
        action.setIconUrl(iconUrl);

        return action;
    }

    /**
     * Creates a new immutable toggle action.
     *
     * @param id The unique id of the action. Cannot be null.
     * @param title The UI-visible title of the context menu item. Cannot be null.
     * @param isChecked Whether the context menu item has a check mark.
     * @param callback A callback to execute when the context menu item is
     *            selected.
     * @param iconUrl a URL pointing to an icon to use for this action, or null
     * @param sortPriority a priority used for sorting this action
     * @param supportsMultipleNodes whether this action supports multiple nodes,
     *            see {@link #supportsMultipleNodes()} for details
     * @return the new {@link Toggle}
     */
    @NonNull
    public static Toggle createToggle(
            @NonNull String id,
            @NonNull String title,
            boolean isChecked,
            @NonNull IMenuCallback callback,
            @Nullable URL iconUrl,
            int sortPriority,
            boolean supportsMultipleNodes) {
        Toggle toggle = new Toggle(id, title, isChecked, callback, sortPriority,
                supportsMultipleNodes);
        toggle.setIconUrl(iconUrl);
        return toggle;
    }

    /**
     * Creates a new immutable multiple-choice action with a defined ordered set
     * of action children.
     *
     * @param id The unique id of the action. Cannot be null.
     * @param title The title of the action to be displayed to the user
     * @param provider Provides the actions to be shown as children of this
     *            action
     * @param callback A callback to execute when the context menu item is
     *            selected.
     * @param iconUrl the icon to use for the multiple choice action itself
     * @param sortPriority the sorting priority to use for the multiple choice
     *            action itself
     * @param supportsMultipleNodes whether this action supports multiple nodes,
     *            see {@link #supportsMultipleNodes()} for details
     * @return the new {@link NestedAction}
     */
    @NonNull
    public static NestedAction createChoices(
            @NonNull String id,
            @NonNull String title,
            @NonNull IMenuCallback callback,
            @Nullable URL iconUrl,
            int sortPriority,
            boolean supportsMultipleNodes,
            @NonNull ActionProvider provider) {
        NestedAction choices = new NestedAction(id, title, provider, callback,
                sortPriority, supportsMultipleNodes);
        choices.setIconUrl(iconUrl);
        return choices;
    }

    /**
     * Creates a new immutable multiple-choice action with a defined ordered set
     * of children.
     *
     * @param id The unique id of the action. Cannot be null.
     * @param title The title of the action to be displayed to the user
     * @param iconUrls The icon urls for the children items (may be null)
     * @param ids The internal ids for the children
     * @param current The id(s) of the current choice(s) that will be check
     *            marked. Can be null. Can be an id not present in the choices
     *            map. There can be more than one id separated by
     *            {@link #CHOICE_SEP}.
     * @param callback A callback to execute when the context menu item is
     *            selected.
     * @param titles The UI-visible titles of the children
     * @param iconUrl the icon to use for the multiple choice action itself
     * @param sortPriority the sorting priority to use for the multiple choice
     *            action itself
     * @param supportsMultipleNodes whether this action supports multiple nodes,
     *            see {@link #supportsMultipleNodes()} for details
     * @return the new {@link Choices}
     */
    @NonNull
    public static Choices createChoices(
            @NonNull String id,
            @NonNull String title,
            @NonNull IMenuCallback callback,
            @NonNull List<String> titles,
            @Nullable List<URL> iconUrls,
            @NonNull List<String> ids,
            @Nullable String current,
            @Nullable URL iconUrl,
            int sortPriority,
            boolean supportsMultipleNodes) {
        Choices choices = new Choices(id, title, callback, titles, iconUrls,
                ids, current, sortPriority, supportsMultipleNodes);
        choices.setIconUrl(iconUrl);

        return choices;
    }

    /**
     * Creates a new immutable multiple-choice action with a defined ordered set
     * of children.
     *
     * @param id The unique id of the action. Cannot be null.
     * @param title The title of the action to be displayed to the user
     * @param iconUrls The icon urls for the children items (may be null)
     * @param current The id(s) of the current choice(s) that will be check
     *            marked. Can be null. Can be an id not present in the choices
     *            map. There can be more than one id separated by
     *            {@link #CHOICE_SEP}.
     * @param callback A callback to execute when the context menu item is
     *            selected.
     * @param iconUrl the icon to use for the multiple choice action itself
     * @param sortPriority the sorting priority to use for the multiple choice
     *            action itself
     * @param supportsMultipleNodes whether this action supports multiple nodes,
     *            see {@link #supportsMultipleNodes()} for details
     * @param idsAndTitles a list of pairs (of ids and titles) to use for the
     *            menu items
     * @return the new {@link Choices}
     */
    @NonNull
    public static Choices createChoices(
            @NonNull String id,
            @NonNull String title,
            @NonNull IMenuCallback callback,
            @Nullable List<URL> iconUrls,
            @Nullable String current,
            @Nullable URL iconUrl,
            int sortPriority,
            boolean supportsMultipleNodes,
            @NonNull List<Pair<String, String>> idsAndTitles) {
        int itemCount = idsAndTitles.size();
        List<String> titles = new ArrayList<String>(itemCount);
        List<String> ids = new ArrayList<String>(itemCount);
        for (Pair<String, String> pair : idsAndTitles) {
            ids.add(pair.getFirst());
            titles.add(pair.getSecond());
        }
        Choices choices = new Choices(id, title, callback, titles, iconUrls,
                ids, current, sortPriority, supportsMultipleNodes);
        choices.setIconUrl(iconUrl);
        return choices;
    }

    /**
     * Creates a new immutable multiple-choice action with lazily computed children.
     *
     * @param id The unique id of the action. Cannot be null.
     * @param title The title of the multiple-choice itself
     * @param callback A callback to execute when the context menu item is
     *            selected.
     * @param provider the provider which provides choices lazily
     * @param current The id(s) of the current choice(s) that will be check
     *            marked. Can be null. Can be an id not present in the choice
     *            alternatives. There can be more than one id separated by
     *            {@link #CHOICE_SEP}.
     * @param iconUrl the icon to use for the multiple choice action itself
     * @param sortPriority the sorting priority to use for the multiple choice
     *            action itself
     * @param supportsMultipleNodes whether this action supports multiple nodes,
     *            see {@link #supportsMultipleNodes()} for details
     * @return the new {@link Choices}
     */
    @NonNull
    public static Choices createChoices(
            @NonNull String id,
            @NonNull String title,
            IMenuCallback callback,
            @NonNull ChoiceProvider provider,
            @Nullable String current,
            @Nullable URL iconUrl,
            int sortPriority,
            boolean supportsMultipleNodes) {
        Choices choices = new DelayedChoices(id, title, callback,
                current, provider, sortPriority, supportsMultipleNodes);
        choices.setIconUrl(iconUrl);
        return choices;
    }

    /**
     * Creates a new {@link RuleAction} with the given id and the given title.
     * Actions which have the same id and the same title are deemed equivalent.
     *
     * @param id The unique id of the action, which must be similar for all actions that
     *           perform the same task. Cannot be null.
     * @param title The UI-visible title of the action.
     * @param callback A callback to execute when the context menu item is
     *            selected.
     * @param sortPriority a priority used for sorting this action
     * @param supportsMultipleNodes the new return value for
     *            {@link #supportsMultipleNodes()}
     */
    private RuleAction(
            @NonNull String id,
            @NonNull String title,
            @NonNull IMenuCallback callback,
            int sortPriority,
            boolean supportsMultipleNodes) {
        mId = id;
        mTitle = title;
        mSortPriority = sortPriority;
        mSupportsMultipleNodes = supportsMultipleNodes;
        mCallback = callback;
    }

    /**
     * Returns the unique id of the action. In the context of a multiple selection,
     * actions which have the same id are collapsed together and must represent the same
     * action. Cannot be null.
     *
     * @return the unique id of the action, never null
     */
    @NonNull
    public String getId() {
        return mId;
    }

    /**
     * Returns the UI-visible title of the action, shown in the context menu.
     * Cannot be null.
     *
     * @return the user name of the action, never null
     */
    @NonNull
    public String getTitle() {
        return mTitle;
    }

    /**
     * Actions which have the same id and the same title are deemed equivalent.
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof RuleAction) {
            RuleAction rhs = (RuleAction) obj;

            if (mId != rhs.mId && !(mId != null && mId.equals(rhs.mId))) return false;
            if (mTitle != rhs.mTitle &&
                    !(mTitle != null && mTitle.equals(rhs.mTitle))) return false;
            return true;
        }
        return false;
    }

    /**
     * Whether this action supports multiple nodes. An action which supports
     * multiple nodes can be applied to different nodes by passing in different
     * nodes to its callback. Some actions are hardcoded for a specific node (typically
     * one that isn't selected, such as an action which affects the parent of a selected
     * node), and these actions will not be added to the context menu when more than
     * one node is selected.
     *
     * @return true if this node supports multiple nodes
     */
    public boolean supportsMultipleNodes() {
        return mSupportsMultipleNodes;
    }

    /**
     * Actions which have the same id and the same title have the same hash code.
     */
    @Override
    public int hashCode() {
        int h = mId == null ? 0 : mId.hashCode();
        h = h ^ (mTitle == null ? 0 : mTitle.hashCode());
        return h;
    }

    /**
     * Gets a URL pointing to an icon to use for this action, if any.
     *
     * @return a URL pointing to an icon to use for this action, or null
     */
    public URL getIconUrl() {
        return mIconUrl;
    }

    /**
     * Sets a URL pointing to an icon to use for this action, if any.
     *
     * @param iconUrl a URL pointing to an icon to use for this action, or null
     * @return this action, to allow setter chaining
     */
    @NonNull
    public RuleAction setIconUrl(URL iconUrl) {
        mIconUrl = iconUrl;

        return this;
    }

    /**
     * Return a priority used for sorting this action
     *
     * @return a priority used for sorting this action
     */
    public int getSortPriority() {
        return mSortPriority;
    }

    /**
     * Returns the callback executed when the action is selected in the
     * context menu. Cannot be null.
     *
     * @return the callback, never null
     */
    @NonNull
    public IMenuCallback getCallback() {
        return mCallback;
    }

    // Implements Comparable<MenuAciton>
    @Override
    public int compareTo(@NonNull RuleAction other) {
        if (mSortPriority != other.mSortPriority) {
            return mSortPriority - other.mSortPriority;
        }

        return mTitle.compareTo(other.mTitle);
    }

    @NonNull
    @Override
    public String toString() {
        return "RuleAction [id=" + mId + ", title=" + mTitle + ", priority=" + mSortPriority + "]";
    }

    /** A separator to display between actions */
    public static class Separator extends RuleAction {
        /** Construct using the factory {@link #createSeparator(int)} */
        private Separator(int sortPriority, boolean supportsMultipleNodes) {
            super("_separator", "", null, sortPriority,  //$NON-NLS-1$ //$NON-NLS-2$
                    supportsMultipleNodes);
        }
    }

    /**
     * A toggle is a simple on/off action, displayed as an item in a context menu
     * with a check mark if the item is checked.
     * <p/>
     * Two toggles are equal if they have the same id, title and group-id.
     * It is expected for the checked state and action callback to be different.
     */
    public static class Toggle extends RuleAction {
        /**
         * True if the item is displayed with a check mark.
         */
        private final boolean mIsChecked;

        /**
         * Creates a new immutable toggle action.
         *
         * @param id The unique id of the action. Cannot be null.
         * @param title The UI-visible title of the context menu item. Cannot be null.
         * @param isChecked Whether the context menu item has a check mark.
         * @param callback A callback to execute when the context menu item is
         *            selected.
         */
        private Toggle(
                @NonNull String id,
                @NonNull String title,
                boolean isChecked,
                @NonNull IMenuCallback callback,
                int sortPriority,
                boolean supportsMultipleNodes) {
            super(id, title, callback, sortPriority, supportsMultipleNodes);
            mIsChecked = isChecked;
        }

        /**
         * Returns true if the item is displayed with a check mark.
         *
         * @return true if the item is displayed with a check mark.
         */
        public boolean isChecked() {
            return mIsChecked;
        }

        /**
         * Two toggles are equal if they have the same id and title.
         * It is acceptable for the checked state and action callback to be different.
         */
        @Override
        public boolean equals(Object obj) {
            return super.equals(obj);
        }

        /**
         * Two toggles have the same hash code if they have the same id and title.
         */
        @Override
        public int hashCode() {
            return super.hashCode();
        }
    }

    /**
     * An ordered list of choices the user can choose between. For choosing between
     * actions, there is a {@link NestedAction} class.
     */
    public static class Choices extends RuleAction {
        protected List<String> mTitles;
        protected List<URL> mIconUrls;
        protected List<String> mIds;
        private boolean mRadio;

        /**
         * One or more id for the checked choice(s) that will be check marked.
         * Can be null. Can be an id not present in the choices map.
         */
        protected final String mCurrent;

        private Choices(
                @NonNull String id,
                @NonNull String title,
                @NonNull IMenuCallback callback,
                @NonNull List<String> titles,
                @Nullable List<URL> iconUrls,
                @NonNull List<String> ids,
                @Nullable String current,
                int sortPriority,
                boolean supportsMultipleNodes) {
            super(id, title, callback, sortPriority, supportsMultipleNodes);
            mTitles = titles;
            mIconUrls = iconUrls;
            mIds = ids;
            mCurrent = current;
        }

        /**
         * Returns the list of urls to icons to display for each choice, or null
         *
         * @return the list of urls to icons to display for each choice, or null
         */
        @Nullable
        public List<URL> getIconUrls() {
            return mIconUrls;
        }

        /**
         * Returns the list of ids for the menu choices, never null
         *
         * @return the list of ids for the menu choices, never null
         */
        @NonNull
        public List<String> getIds() {
            return mIds;
        }

        /**
         * Returns the titles to be displayed for the menu choices, never null
         *
         * @return the titles to be displayed for the menu choices, never null
         */
        @NonNull
        public List<String> getTitles() {
            return mTitles;
        }

        /**
         * Returns the current value of the choice
         *
         * @return the current value of the choice, possibly null
         */
        @Nullable
        public String getCurrent() {
            return mCurrent;
        }

        /**
         * Set whether this choice list is best visualized as a radio group (instead of a
         * dropdown)
         *
         * @param radio true if this choice list should be visualized as a radio group
         */
        public void setRadio(boolean radio) {
            mRadio = radio;
        }

        /**
         * Returns true if this choice list is best visualized as a radio group (instead
         * of a dropdown)
         *
         * @return true if this choice list should be visualized as a radio group
         */
        public boolean isRadio() {
            return mRadio;
        }
    }

    /**
     * An ordered list of actions the user can choose between. Similar to
     * {@link Choices} but for actions instead.
     */
    public static class NestedAction extends RuleAction {
        /** The provider to produce the list of nested actions when needed */
        private final ActionProvider mProvider;

        private NestedAction(
                @NonNull String id,
                @NonNull String title,
                @NonNull ActionProvider provider,
                @NonNull IMenuCallback callback,
                int sortPriority,
                boolean supportsMultipleNodes) {
            super(id, title, callback, sortPriority, supportsMultipleNodes);
            mProvider = provider;
        }

        /**
         * Returns the nested actions available for the given node
         *
         * @param node the node to look up nested actions for
         * @return a list of nested actions
         */
        @NonNull
        public List<RuleAction> getNestedActions(@NonNull INode node) {
            return mProvider.getNestedActions(node);
        }
    }

    /** Like {@link Choices}, but the set of choices is computed lazily */
    private static class DelayedChoices extends Choices {
        private final ChoiceProvider mProvider;
        private boolean mInitialized;

        private DelayedChoices(
                @NonNull String id,
                @NonNull String title,
                @NonNull IMenuCallback callback,
                @Nullable String current,
                @NonNull ChoiceProvider provider,
                int sortPriority, boolean supportsMultipleNodes) {
            super(id, title, callback, new ArrayList<String>(), new ArrayList<URL>(),
                    new ArrayList<String>(), current, sortPriority, supportsMultipleNodes);
            mProvider = provider;
        }

        private void ensureInitialized() {
            if (!mInitialized) {
                mInitialized = true;
                mProvider.addChoices(mTitles, mIconUrls, mIds);
            }
        }

        @Override
        public List<URL> getIconUrls() {
            ensureInitialized();
            return mIconUrls;
        }

        @Override
        public List<String> getIds() {
            ensureInitialized();
            return mIds;
        }

        @Override
        public List<String> getTitles() {
            ensureInitialized();
            return mTitles;
        }
    }

    /**
     * Provides the set of nested action choices associated with a {@link NestedAction}
     * object when they are needed. Useful for lazy initialization of context
     * menus and popup menus until they are actually needed.
     */
    public interface ActionProvider {
        /**
         * Returns the nested actions available for the given node
         *
         * @param node the node to look up nested actions for
         * @return a list of nested actions
         */
        @NonNull
        public List<RuleAction> getNestedActions(@NonNull INode node);
    }

    /**
     * Provides the set of choices associated with an {@link Choices}
     * object when they are needed. Useful for lazy initialization of context
     * menus and popup menus until they are actually needed.
     */
    public interface ChoiceProvider {
        /**
         * Adds in the needed titles, iconUrls (if any) and ids.
         * Use {@link RuleAction#SEPARATOR} to create separators.
         *
         * @param titles a list of titles that the provider should append to
         * @param iconUrls a list of icon URLs that the provider should append to
         * @param ids a list of ids that the provider should append to
         */
        public void addChoices(
                @NonNull List<String> titles,
                @NonNull List<URL> iconUrls,
                @NonNull List<String> ids);
    }
}