From f91d50369c71ca17c653920aa13fcf918007a754 Mon Sep 17 00:00:00 2001 From: Nicolas Feybesse Date: Tue, 13 Dec 2016 16:55:41 +0100 Subject: [PATCH] merge --- .../genericsystem/api/core/TagAnnotation.java | 4 ++ .../reactor/context/ContextAction.java | 2 +- .../reactor/gscomponents/ExtendedRootTag.java | 65 +++++++++---------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/gs-api/src/main/java/org/genericsystem/api/core/TagAnnotation.java b/gs-api/src/main/java/org/genericsystem/api/core/TagAnnotation.java index 3894e1d5d..35dd9f27e 100644 --- a/gs-api/src/main/java/org/genericsystem/api/core/TagAnnotation.java +++ b/gs-api/src/main/java/org/genericsystem/api/core/TagAnnotation.java @@ -42,6 +42,10 @@ public String getName() { return name; } + public boolean equivs(TagAnnotation otherAnnotation) { + return Objects.equals(annotationClass, otherAnnotation.annotationClass) && Objects.equals(name, otherAnnotation.name); + } + @Override public int hashCode() { return annotationClass.hashCode(); diff --git a/gs-reactor/src/main/java/org/genericsystem/reactor/context/ContextAction.java b/gs-reactor/src/main/java/org/genericsystem/reactor/context/ContextAction.java index e30d13526..0b16dc3ad 100644 --- a/gs-reactor/src/main/java/org/genericsystem/reactor/context/ContextAction.java +++ b/gs-reactor/src/main/java/org/genericsystem/reactor/context/ContextAction.java @@ -14,10 +14,10 @@ import org.genericsystem.reactor.Tag; import org.genericsystem.reactor.contextproperties.ConvertedValueDefaults; import org.genericsystem.reactor.contextproperties.GSBuilderDefaults; +import org.genericsystem.reactor.contextproperties.GSBuilderDefaults.GenericValueComponents; import org.genericsystem.reactor.contextproperties.PasswordDefaults; import org.genericsystem.reactor.contextproperties.SelectionDefaults; import org.genericsystem.reactor.contextproperties.StepperDefaults; -import org.genericsystem.reactor.contextproperties.GSBuilderDefaults.GenericValueComponents; import org.genericsystem.reactor.gscomponents.Composite.Header; import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlInputText; import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlSpan; diff --git a/gs-reactor/src/main/java/org/genericsystem/reactor/gscomponents/ExtendedRootTag.java b/gs-reactor/src/main/java/org/genericsystem/reactor/gscomponents/ExtendedRootTag.java index 234cdfd32..60d2dc24d 100644 --- a/gs-reactor/src/main/java/org/genericsystem/reactor/gscomponents/ExtendedRootTag.java +++ b/gs-reactor/src/main/java/org/genericsystem/reactor/gscomponents/ExtendedRootTag.java @@ -1,8 +1,5 @@ package org.genericsystem.reactor.gscomponents; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; - import java.lang.annotation.Annotation; import java.util.ArrayDeque; import java.util.ArrayList; @@ -11,21 +8,12 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; import java.util.stream.Stream; -import javafx.beans.binding.MapBinding; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import javafx.collections.ObservableMap; -import javafx.collections.ObservableSet; -import javafx.collections.WeakListChangeListener; - import org.genericsystem.api.core.Snapshot; import org.genericsystem.api.core.TagAnnotation; import org.genericsystem.api.core.annotations.Components; @@ -39,6 +27,7 @@ import org.genericsystem.api.core.annotations.value.ClassGenericValue; import org.genericsystem.common.Generic; import org.genericsystem.common.Root; +import org.genericsystem.defaults.tools.AbstractMinimalChangesObservableList.MinimalChangesObservableList; import org.genericsystem.reactor.AnnotationsManager; import org.genericsystem.reactor.Context; import org.genericsystem.reactor.ExtendedAnnotationsManager; @@ -51,6 +40,15 @@ import org.genericsystem.reactor.gscomponents.ExtendedRootTag.TagType.TagAnnotationAttribute; import org.genericsystem.reactor.gscomponents.ExtendedRootTag.TagType.TagAnnotationContentAttribute; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import javafx.beans.binding.MapBinding; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.collections.ObservableMap; +import javafx.collections.WeakListChangeListener; + public class ExtendedRootTag extends RootTagImpl { private final Root engine; @@ -67,23 +65,15 @@ public class ExtendedRootTag extends RootTagImpl { } }; - private static BiConsumer, GTagAnnotation> ON_ADD = (styles, gTagAnnotation) -> { - GTagAnnotation applyingAnnotation = gTagAnnotation; - TagAnnotation newAnnotation = gTagAnnotation.getValue(); - for (GTagAnnotation styleAnnotationGeneric : styles) { - TagAnnotation annotation = styleAnnotationGeneric.getValue(); - if (Style.class.equals(annotation.getAnnotationClass()) && annotation.getName().equals(newAnnotation.getName()) && annotation.getPath().length > newAnnotation.getPath().length) - applyingAnnotation = styleAnnotationGeneric; - } - if (gTagAnnotation.equals(applyingAnnotation)) - styles.add(gTagAnnotation); + private static BiConsumer, GTagAnnotation> ON_ADD = (styles, gTagAnnotation) -> { + styles.add(gTagAnnotation); }; - private static BiConsumer, GTagAnnotation> ON_REMOVE = (styles, gTagAnnotation) -> { + private static BiConsumer, GTagAnnotation> ON_REMOVE = (styles, gTagAnnotation) -> { styles.remove(gTagAnnotation); }; - private void doStyle(Stream streamToConsum, BiConsumer, GTagAnnotation> action) { + private void doStyle(Stream streamToConsum, BiConsumer, GTagAnnotation> action) { streamToConsum.forEach(valueGeneric -> { GTagAnnotation gTagAnnotation = valueGeneric.getBaseComponent(); TagAnnotation tagAnnotation = gTagAnnotation.getValue(); @@ -184,22 +174,25 @@ public void processStyle(Tag tag, String name, String value) { public class GenericTagNode extends SimpleTagNode { - private ObservableSet tagAnnotations = FXCollections.observableSet(new HashSet() { - - private static final long serialVersionUID = 1887068618788935803L; + private ObservableList tagAnnotations = new MinimalChangesObservableList(FXCollections.observableArrayList()) { @Override public boolean add(GTagAnnotation annotation) { - Optional overriddenElement = this.stream().filter(gta -> { - TagAnnotation ta = gta.getValue(); - TagAnnotation newAnnotation = annotation.getValue(); - return Objects.equals(ta.getAnnotationClass(), newAnnotation.getAnnotationClass()) && Objects.equals(ta.getName(), newAnnotation.getName()); - }).findAny(); - if (overriddenElement.isPresent()) - remove(overriddenElement.get()); + Optional equivAnnotation = this.stream().filter(gta -> gta.getValue().equivs(annotation.getValue())).findAny(); + // Allow addition of an already present annotation because the flush() causes the same generic + // to be added twice before being remove once. + if (equivAnnotation.isPresent() && !equivAnnotation.get().equals(annotation)) { + GTagAnnotation overriddenAnnotation = equivAnnotation.get(); + if (overriddenAnnotation.getValue().getPath().length <= annotation.getValue().getPath().length) { + remove(overriddenAnnotation); + } else + // Found an annotation applying to this tag that’s more precise than the new annotation, + // so the new annotation is not added to the Set. + return false; + } return super.add(annotation); } - }); + }; public GenericTagNode(Tag tag) { Deque> classesToResult = new ArrayDeque<>(); @@ -301,7 +294,7 @@ default GTagAnnotation setAnnotation(Class annotationClass } default void setStyleAnnotation(Style annotation) { - setAnnotation(annotation.getClass(), annotation.name(), annotation.value(), annotation.path(), annotation.pos()); + setAnnotation(Style.class, annotation.name(), annotation.value(), annotation.path(), annotation.pos()); } default void setChildrenAnnotation(Children annotation) {