source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionGroup.java @ 14027

Last change on this file since 14027 was 14027, checked in by michael2402, 5 weeks ago

See #16388: New mechanism for plugins to register relation editor actions.

File size: 1.4 KB
Line 
1package org.openstreetmap.josm.gui.dialogs.relation.actions;
2
3import java.util.Comparator;
4import java.util.List;
5
6import javax.swing.JButton;
7import javax.swing.JToolBar;
8
9import org.openstreetmap.josm.actions.ExpertToggleAction;
10
11/**
12 * An action group for the relation editor, to be used in one of the tool bars.
13 *
14 * @author Michael Zangl
15 * @since 14027
16 */
17public interface IRelationEditorActionGroup {
18
19        /**
20         * Get the position at which the action group should be added.
21         *
22         * @return The order index, default is to add at the end.
23         */
24        default int order() {
25                return 100;
26        }
27
28        /**
29         * Get the actions in this action group.
30         *
31         * @param editorAccess
32         *            Methods to access the relation editor.
33         * @return The actions
34         */
35        List<AbstractRelationEditorAction> getActions(IRelationEditorActionAccess editorAccess);
36
37        static void fillToolbar(JToolBar toolbar, List<IRelationEditorActionGroup> groups,
38                        IRelationEditorActionAccess editorAccess) {
39                groups.stream().sorted(Comparator.comparingInt(IRelationEditorActionGroup::order)).forEach(group -> {
40                        if (toolbar.getComponentCount() > 0) {
41                                toolbar.addSeparator();
42                        }
43
44                        for (AbstractRelationEditorAction action : group.getActions(editorAccess)) {
45                                JButton button = toolbar.add(action);
46                                if (action.isExpertOnly()) {
47                                        ExpertToggleAction.addVisibilitySwitcher(button);
48                                }
49                        }
50                });
51        }
52}
Note: See TracBrowser for help on using the repository browser.