From 6c6be7087abee5e51ce4c87b07ebc7800ed7f54c Mon Sep 17 00:00:00 2001 From: Nicolas Feybesse Date: Fri, 23 Sep 2016 11:33:23 +0200 Subject: [PATCH] Change ChildForEach --- .../example/reactor/AppHtml5.java | 16 +++++++------- .../reactor/annotations/ForEach.java | 6 ++++-- .../reactor/gs3/CompositeTagImpl.java | 21 ++++++++----------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/gs-example-reactor/src/main/java/org/genericsystem/example/reactor/AppHtml5.java b/gs-example-reactor/src/main/java/org/genericsystem/example/reactor/AppHtml5.java index 93f7874cb..8353b20d8 100644 --- a/gs-example-reactor/src/main/java/org/genericsystem/example/reactor/AppHtml5.java +++ b/gs-example-reactor/src/main/java/org/genericsystem/example/reactor/AppHtml5.java @@ -70,7 +70,7 @@ public static void main(String[] mainArgs) { @org.genericsystem.reactor.annotations.Style.BackgroundColor("Green") @org.genericsystem.reactor.annotations.DirectSelect(Car.class) - @org.genericsystem.reactor.annotations.ForEach.ChildForEach(ObservableListExtractor.SUBINSTANCES.class) + @org.genericsystem.reactor.annotations.ForEach.ChildForEach(decorate = GSContentComponent.class, forEach = ObservableListExtractor.SUBINSTANCES.class) public static class GSInstancesComposite extends org.genericsystem.reactor.gs3.GSComposite { } @@ -78,14 +78,14 @@ public static class GSInstancesComposite extends org.genericsystem.reactor.gs3.G @BackgroundColor("Blue") @FlexDirection("row") @DirectSelect(Car.class) - @ChildForEach(ObservableListExtractor.SUBINSTANCES.class) + @ChildForEach(decorate = GSContentComponent.class, forEach = ObservableListExtractor.SUBINSTANCES.class) public static class GSRowInstancesComposite extends GSComposite { } @BackgroundColor("Red") @DirectSelect(Car.class) - @ChildForEach(ObservableListExtractor.ATTRIBUTES_OF_TYPE.class) + @ChildForEach(decorate = GSContentComponent.class, forEach = ObservableListExtractor.ATTRIBUTES_OF_TYPE.class) @ReactorDependencies({ GSHeaderComponent.class, GSContentComponent.class }) public static class GSTypeAttributes extends GSComposite { @@ -95,7 +95,7 @@ public static class GSTypeAttributes extends GSComposite { @Style.Color("White") @DirectSelect(Car.class) @FlexDirection("row") - @ChildForEach(ObservableListExtractor.ATTRIBUTES_OF_TYPE.class) + @ChildForEach(decorate = GSContentComponent.class, forEach = ObservableListExtractor.ATTRIBUTES_OF_TYPE.class) @ChildFlexDirection("row") @ReactorDependencies({ GSHeaderComponent.class, GSContentComponent.class }) public static class GSTypeAttributesRow extends GSComposite { @@ -105,14 +105,14 @@ public static class GSTypeAttributesRow extends GSComposite { @org.genericsystem.reactor.annotations.Style.BackgroundColor("Orange") @org.genericsystem.reactor.annotations.Style.FlexDirection("row") @org.genericsystem.reactor.annotations.Style.ChildFlexDirection("row") - @org.genericsystem.reactor.annotations.ForEach.ChildForEach(ObservableListExtractor.ATTRIBUTES_OF_INSTANCES.class) + @org.genericsystem.reactor.annotations.ForEach.ChildForEach(decorate = GSContentComponent.class, forEach = ObservableListExtractor.ATTRIBUTES_OF_INSTANCES.class) @org.genericsystem.reactor.annotations.ReactorDependencies({ GSHeaderComponent.class, GSContentComponent.class }) public static class GSInstanceAttributesRow extends org.genericsystem.reactor.gs3.GSComposite { } @org.genericsystem.reactor.annotations.Style.BackgroundColor("Brown") - @org.genericsystem.reactor.annotations.ForEach.ChildForEach(ObservableListExtractor.HOLDERS.class) + @org.genericsystem.reactor.annotations.ForEach.ChildForEach(decorate = GSContentComponent.class, forEach = ObservableListExtractor.HOLDERS.class) @org.genericsystem.reactor.annotations.ReactorDependencies({ GSContentComponent.class }) public static class GSHolders extends org.genericsystem.reactor.gs3.GSComposite { @@ -120,7 +120,7 @@ public static class GSHolders extends org.genericsystem.reactor.gs3.GSComposite @BackgroundColor("Pink") @FlexDirection("row") - @ChildForEach(ObservableListExtractor.COMPONENTS.class) + @ChildForEach(decorate = GSContentComponent.class, forEach = ObservableListExtractor.COMPONENTS.class) @ReactorDependencies({ GSHeaderComponent.class, GSContentComponent.class }) public static class GSValueComponents extends GSComposite { @@ -196,7 +196,7 @@ public static class GSInstanceAttributesRow_ extends GSInstanceAttributesRow { public static class Unit { } - @org.genericsystem.reactor.annotations.DirectSelect(Power.class) + @org.genericsystem.reactor.annotations.DirectSelect(Car.class) @org.genericsystem.reactor.annotations.ReactorDependencies({ GSHeaderComponent_.class, GSInstanceContentComponent__.class }) public static class GSTypeTableInstancesComposite extends GSTypeLabeledInstancesComposite { @org.genericsystem.reactor.annotations.ReactorDependencies({ GSInstanceAttributesRow__.class }) diff --git a/gs-reactor/src/main/java/org/genericsystem/reactor/annotations/ForEach.java b/gs-reactor/src/main/java/org/genericsystem/reactor/annotations/ForEach.java index 81459c32d..fe74cbe26 100644 --- a/gs-reactor/src/main/java/org/genericsystem/reactor/annotations/ForEach.java +++ b/gs-reactor/src/main/java/org/genericsystem/reactor/annotations/ForEach.java @@ -23,13 +23,15 @@ @Target({ ElementType.TYPE }) @Inherited public @interface ParentForEach { - int pos() default 0; + } @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE }) @Inherited public @interface ChildForEach { - Class>[] value(); + Class decorate(); + + Class> forEach(); } } \ No newline at end of file diff --git a/gs-reactor/src/main/java/org/genericsystem/reactor/gs3/CompositeTagImpl.java b/gs-reactor/src/main/java/org/genericsystem/reactor/gs3/CompositeTagImpl.java index a3d71952e..e6fd3ab35 100644 --- a/gs-reactor/src/main/java/org/genericsystem/reactor/gs3/CompositeTagImpl.java +++ b/gs-reactor/src/main/java/org/genericsystem/reactor/gs3/CompositeTagImpl.java @@ -52,22 +52,18 @@ public GSTagImpl get(Object key) { public CompositeTagImpl() { super(); - nodes.put(getClass(), this); - ReactorDependencies deps = getClass().getAnnotation(ReactorDependencies.class); - if (deps != null) { - System.out.println("Declaring classes : " + Arrays.toString(getClass().getDeclaredClasses())); - System.out.println("ReactorDependencies : " + Arrays.toString(deps.value())); - for (Class clazz : deps.value()) - find(clazz); - } - for (Tag tag : nodes.values()) - tag.postfix(); + initComposite(); } public CompositeTagImpl(Tag parent) { super(parent); init(); style(); + initComposite(); + processAnnotations(getClass(), this); + } + + private void initComposite() { nodes.put(getClass(), this); ReactorDependencies deps = getClass().getAnnotation(ReactorDependencies.class); if (deps != null) { @@ -121,16 +117,17 @@ private static void processAnnotations(Class tagClass, Tag } } } else { - ChildForEach childForEach = result.getParent().getClass().getAnnotation(ChildForEach.class); if (childForEach != null) { try { - result.forEach(childForEach.value()[parentForEach.pos()].newInstance().get()); + if (childForEach.decorate().isAssignableFrom(result.getClass())) + result.forEach(childForEach.forEach().newInstance().get()); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } } else System.out.println("Warning : unable to find childForEach on : " + result.getParent().getClass().getSimpleName() + " for : " + tagClass.getSimpleName()); + } Select select = tagClass.getAnnotation(Select.class);