A box is either included in a Variant, excluded in a Variant or it doesn't matter (it can stay if it's here, or stay away if it isn't). Here we keep enough information to disconnect boxes (completely) from the hierarchy and reconnect them again when we want to This will require the cooperation of IO
| 29 | * We have to add copy history and merge to this (from Diff, in the personal tree). |
| 30 | */ |
| 31 | public class Variant extends Box implements IO.Loaded { |
| 32 | |
| 33 | static public Dict.Prop<Set<String>> includes = new Dict.Prop<Set<String>>("includes").type() |
| 34 | .toCanon() |
| 35 | .autoConstructs(() -> new LinkedHashSet<String>()); // todo: doc |
| 36 | |
| 37 | |
| 38 | static public Dict.Prop<Set<String>> excludes = new Dict.Prop<Set<String>>("excludes").type() |
| 39 | .toCanon() |
| 40 | .autoConstructs(() -> new LinkedHashSet<String>()); // todo: doc |
| 41 | |
| 42 | // this is set per box, because we need it to be loaded and saved with the boxes |
| 43 | static public Dict.Prop<String> theVariant = new Dict.Prop<>("_theVariant").type(); |
| 44 | |
| 45 | static public Dict.Prop<FunctionOfBoxValued<CurrentVariant>> variant = new Dict.Prop<FunctionOfBoxValued<CurrentVariant>>("variant").type() |
| 46 | .toCanon(); |
| 47 | |
| 48 | static { |
| 49 | IO.persist(theVariant); |
| 50 | IO.persist(includes); |
| 51 | IO.persist(excludes); |
| 52 | |
| 53 | |
| 54 | variant.set(BoxBrowser.toMarkdown, (box, val) -> { |
| 55 | |
| 56 | String s = ""; |
| 57 | |
| 58 | s += "*Current Variant* : " + val + "\n"; |
| 59 | |
| 60 | Set<String> o = box.properties.get(includes); |
| 61 | s += "*Included in* : " + o + "\n"; |
| 62 | o = box.properties.get(excludes); |
| 63 | s += "*Excluded in* : " + o + "\n"; |
| 64 | |
| 65 | return s; |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | static public class CurrentVariant implements fieldlinker.AsMap { |
| 70 | |
| 71 | private final Box from; |
| 72 | private final String variant; |
| 73 | |
| 74 | public CurrentVariant(Box from, String variant) { |
| 75 | this.from = from; |
| 76 | this.variant = variant; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public boolean asMap_isProperty(String p) { |
| 81 | return from.asMap_isProperty(p) || from.asMap_isProperty(prefix(p)); |
| 82 | } |
| 83 | |
| 84 | private String prefix(String p) { |
| 85 | return "__variant:" + variant + ":" + p; |
| 86 | } |
| 87 | |
| 88 | @Override |