Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nfeybesse committed Dec 13, 2016
1 parent 9c7b218 commit f91d503
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -67,23 +65,15 @@ public class ExtendedRootTag extends RootTagImpl {
}
};

private static BiConsumer<ObservableSet<GTagAnnotation>, 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<ObservableList<GTagAnnotation>, GTagAnnotation> ON_ADD = (styles, gTagAnnotation) -> {
styles.add(gTagAnnotation);
};

private static BiConsumer<ObservableSet<GTagAnnotation>, GTagAnnotation> ON_REMOVE = (styles, gTagAnnotation) -> {
private static BiConsumer<ObservableList<GTagAnnotation>, GTagAnnotation> ON_REMOVE = (styles, gTagAnnotation) -> {
styles.remove(gTagAnnotation);
};

private void doStyle(Stream<? extends GTagAnnotationContent> streamToConsum, BiConsumer<ObservableSet<GTagAnnotation>, GTagAnnotation> action) {
private void doStyle(Stream<? extends GTagAnnotationContent> streamToConsum, BiConsumer<ObservableList<GTagAnnotation>, GTagAnnotation> action) {
streamToConsum.forEach(valueGeneric -> {
GTagAnnotation gTagAnnotation = valueGeneric.getBaseComponent();
TagAnnotation tagAnnotation = gTagAnnotation.getValue();
Expand Down Expand Up @@ -184,22 +174,25 @@ public void processStyle(Tag tag, String name, String value) {

public class GenericTagNode extends SimpleTagNode {

private ObservableSet<GTagAnnotation> tagAnnotations = FXCollections.observableSet(new HashSet<GTagAnnotation>() {

private static final long serialVersionUID = 1887068618788935803L;
private ObservableList<GTagAnnotation> tagAnnotations = new MinimalChangesObservableList<GTagAnnotation>(FXCollections.observableArrayList()) {

@Override
public boolean add(GTagAnnotation annotation) {
Optional<GTagAnnotation> 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<GTagAnnotation> 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<Class<?>> classesToResult = new ArrayDeque<>();
Expand Down Expand Up @@ -301,7 +294,7 @@ default GTagAnnotation setAnnotation(Class<? extends Annotation> 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) {
Expand Down

0 comments on commit f91d503

Please sign in to comment.