A handy box for grouping (and naming) a collection of boxes
| 16 | * A handy box for grouping (and naming) a collection of boxes |
| 17 | */ |
| 18 | public class Group extends Box { |
| 19 | |
| 20 | private final Box root; |
| 21 | |
| 22 | public Group(Box root) { |
| 23 | |
| 24 | this.root = root; |
| 25 | |
| 26 | properties.put(Commands.commands, () -> { |
| 27 | |
| 28 | Map<Pair<String, String>, Runnable> m = new LinkedHashMap<>(); |
| 29 | |
| 30 | long s = selection().count(); |
| 31 | if (s > 1) { |
| 32 | m.put(new Pair<>("Make group from selection", "Turns the " + s + " selected boxes into a group — a handy, named, unit"), new RemoteEditor.ExtendedCommand() { |
| 33 | public RemoteEditor.SupportsPrompt prompt; |
| 34 | |
| 35 | @Override |
| 36 | public void begin(RemoteEditor.SupportsPrompt prompt, String alternativeChosen) { |
| 37 | this.prompt = prompt; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void run() { |
| 42 | prompt.prompt("Name for group...", new LinkedHashMap<>(), new RemoteEditor.ExtendedCommand() { |
| 43 | public String a; |
| 44 | |
| 45 | @Override |
| 46 | public void begin(RemoteEditor.SupportsPrompt prompt, String alternativeChosen) { |
| 47 | this.a = alternativeChosen; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public void run() { |
| 52 | makeSelectionIntoGroup(a); |
| 53 | } |
| 54 | }); |
| 55 | } |
| 56 | }); |
| 57 | } |
| 58 | return m; |
| 59 | |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | private void makeSelectionIntoGroup(String a) { |
| 64 | newGroup(root, a, selection().collect(Collectors.toList())); |
| 65 | } |
| 66 | |
| 67 | static public Box newGroup(Box root, String a, List<Box> collect) { |
| 68 | |
| 69 | if (collect.size() < 1) return null; |
| 70 | |
| 71 | BoxGroup g = new BoxGroup(); |
| 72 | |
| 73 | for (Box bb : collect) { |
| 74 | g.connect(bb); |
| 75 | } |
nothing calls this directly
no outgoing calls
no test coverage detected