Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Renaud Lancelot committed Oct 5, 2016
1 parent 4cac9c5 commit 267d282
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 48 deletions.
18 changes: 7 additions & 11 deletions gs-common/src/main/java/org/genericsystem/common/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ protected Class<?> adaptClass(Class<?> clazz, Generic meta) {
return metaAnnotation == null ? getTClass() : metaAnnotation.value();

DirectClass directClass = clazz.getAnnotation(DirectClass.class);
if (directClass != null)
if (metaAnnotation == null)
return clazz;
else if (metaAnnotation.value().isAssignableFrom(clazz))
if (directClass != null){
if (metaAnnotation == null||metaAnnotation.value().isAssignableFrom(clazz))
return clazz;
else
getCurrentCache().discardWithException(new IllegalStateException(clazz + " must extend " + metaAnnotation.value()));
getCurrentCache().discardWithException(new IllegalStateException(clazz + " must extend " + metaAnnotation.value()));}
if (metaAnnotation == null)
return getTClass().isAssignableFrom(clazz) ? clazz : getTClass();

Expand Down Expand Up @@ -164,8 +162,7 @@ protected Generic init(Generic generic, DefaultHandler handler) {

private Generic newInstance(Class<?> clazz) {
PROXY_FACTORY.setSuperclass(clazz.isInterface() ? Object.class : clazz);
PROXY_FACTORY.setInterfaces(clazz.isInterface() ? getTClass().isAssignableFrom(clazz) ? new Class[] { clazz } : new Class[] { clazz, getTClass() }
: getTClass().isAssignableFrom(clazz) ? new Class[] {} : new Class[] { getTClass() });
PROXY_FACTORY.setInterfaces(clazz.isInterface() ? (getTClass().isAssignableFrom(clazz) ? new Class[] { clazz } : new Class[] { clazz, getTClass() }) : getTClass().isAssignableFrom(clazz) ? new Class[] {} : new Class[] { getTClass() });
try {
return (Generic) PROXY_FACTORY.createClass(METHOD_FILTER).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
Expand Down Expand Up @@ -214,8 +211,8 @@ public Object invoke(Object self, Method m, Method proceed, Object[] args) throw
abstract protected Root getRoot();

public Vertex getVertex() {
return new Vertex(getClazz(), getTs(), getMeta() != null ? getMeta().getTs() : getTs(), getSupers().stream().map(Generic::getTs)
.collect(Collectors.toList()), getValue(), getComponents().stream().map(Generic::getTs).collect(Collectors.toList()), getBirthTs());
return new Vertex(getClazz(), getTs(), getMeta() != null ? getMeta().getTs() : getTs(), getSupers().stream().map(Generic::getTs).collect(Collectors.toList()), getValue(),
getComponents().stream().map(Generic::getTs).collect(Collectors.toList()), getBirthTs());
}

public Class<?> getClazz() {
Expand Down Expand Up @@ -253,8 +250,7 @@ public long getTs() {
public AbstractCache getCurrentCache() {
AbstractCache context = cacheLocal.get();
if (context == null)
throw new IllegalStateException(
"Unable to find the current cache, thread context is not defined. Did you miss to call start() method on your cache ? or perhaps have you accidentaly closed your engine ?");
throw new IllegalStateException("Unable to find the current cache, thread context is not defined. Did you miss to call start() method on your cache ? or perhaps have you accidentaly closed your engine ?");
return context;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.ListBinding;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.genericsystem.api.core.ApiStatics;
import org.genericsystem.api.core.IGeneric;
import org.genericsystem.api.core.Snapshot;
Expand All @@ -24,6 +18,12 @@

import com.sun.javafx.collections.ObservableListWrapper;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.ListBinding;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

/**
* @author Nicolas Feybesse
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public EngineServer(EnginesDeploymentConfig options) {
for (String path : options.getEnginePaths()) {
AbstractServer root = buildRoot(options.getPersistentDirectoryPath(path), options.getClasses(path));
roots.put(path, root);
System.out.println("Starts engine with path : " + path + " and persistence repository path : "
+ options.getPersistentDirectoryPath(path));
System.out.println("Starts engine with path : " + path + " and persistence repository path : " + options.getPersistentDirectoryPath(path));
}
}

Expand All @@ -57,8 +56,7 @@ protected Buffer getReplyBuffer(int methodId, int op, AbstractServer root, GSBuf
case Protocol.PICK_NEW_TS:
return replyBuffer.appendLongThrowException(() -> root.pickNewTs());
case Protocol.GET_DEPENDENCIES:
return replyBuffer.appendGSVertexArrayThrowException(() -> root.getDependencies(gsBuffer.getLong(),
gsBuffer.getLong()));
return replyBuffer.appendGSVertexArrayThrowException(() -> root.getDependencies(gsBuffer.getLong(), gsBuffer.getLong()));
case Protocol.GET_VERTEX:
return replyBuffer.appendGSVertexThrowException(() -> root.getVertex(gsBuffer.getLong()));
case Protocol.APPLY:
Expand Down
29 changes: 16 additions & 13 deletions gs-reactor/src/main/java/org/genericsystem/reactor/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@ default <T extends Tag> void processAnnotations(Tag result) {
});

processAnnotation(Style.class, result, annotation -> result.addStyle(((Style) annotation).name(), ((Style) annotation).value()));

processAnnotation(StyleClass.class, result, annotation -> {
for (String sc : ((StyleClass) annotation).value())
result.addStyleClass(sc);
});
processAnnotation(FlexDirectionStyle.class, result, annotation -> {
if (GSDiv.class.isAssignableFrom(result.getClass()))
((GSDiv) result).setDirection(((FlexDirectionStyle) annotation).value());
Expand Down Expand Up @@ -529,43 +532,43 @@ default boolean isAssignableFrom(List<Class<?>> list1, List<Class<?>> list2) {
default <T extends Tag> void processAnnotation(Class<? extends Annotation> annotationClass, Tag result, Consumer<Annotation> consumer) {
List<Class<?>> classesToResult = new ArrayList<>();
Tag current = result;
Annotation applyingAnnotation = null;
List<Annotation> applyingAnnotations = new ArrayList<>();
while (current != null) {
Annotation[] annotations = current.getClass().getAnnotationsByType(annotationClass);
Annotation annotationFound = selectAnnotation(annotations, annotationClass, classesToResult);
List<Annotation> annotationsFound = selectAnnotations(annotations, annotationClass, classesToResult);

if (!DirectSelect.class.equals(annotationClass)) {
Class<?> superClass = current.getClass().getSuperclass();
while (annotationFound == null && superClass != null) {
while (annotationsFound.isEmpty() && superClass != null) {
annotations = superClass.getAnnotationsByType(annotationClass);
annotationFound = selectAnnotation(annotations, annotationClass, classesToResult);
annotationsFound = selectAnnotations(annotations, annotationClass, classesToResult);
superClass = superClass.getSuperclass();
}
}
if (annotationFound != null)
applyingAnnotation = annotationFound;
if (!annotationsFound.isEmpty())
applyingAnnotations = annotationsFound;
classesToResult.add(0, current.getClass());
current = current.getParent();
}
if (applyingAnnotation != null)
for (Annotation applyingAnnotation : applyingAnnotations)
consumer.accept(applyingAnnotation);
}

default Annotation selectAnnotation(Annotation[] annotations, Class<? extends Annotation> annotationClass, List<Class<?>> classesToResult) {
Annotation annotationFound = null;
default List<Annotation> selectAnnotations(Annotation[] annotations, Class<? extends Annotation> annotationClass, List<Class<?>> classesToResult) {
List<Annotation> annotationsFound = new ArrayList<>();
for (Annotation annotation : annotations)
try {
Class<?>[] path = (Class<?>[]) annotation.annotationType().getDeclaredMethod("path").invoke(annotation);
if (isAssignableFrom(Arrays.asList(path), classesToResult)) {
if (annotationFound != null)
if (!annotationsFound.isEmpty() && !Style.class.equals(annotationClass))
throw new IllegalStateException("Multiple annotations applicable to same tag defined at same level. Annotation: " + annotationClass.getSimpleName() + ", path to tag: "
+ Arrays.asList(path).stream().map(c -> c.getSimpleName()).collect(Collectors.toList()));
annotationFound = annotation;
annotationsFound.add(annotation);
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new IllegalStateException(e);
}
return annotationFound;
return annotationsFound;
}

default <T extends Tag> void processStyleAnnotation(Class<? extends Annotation> annotationClass, Tag result, String propertyName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
public class HtmlH1 extends GSTagImpl {

public HtmlH1() {

}

public HtmlH1(Tag parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
public class HtmlHeader extends GSTagImpl {

public HtmlHeader() {

}

public HtmlHeader(Tag parent) {
Expand Down
30 changes: 20 additions & 10 deletions gs-todomvc/src/main/java/org/genericsystem/todomvc/TodoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
import java.util.Map;
import java.util.function.Predicate;

import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableObjectValue;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;

import org.genericsystem.common.Generic;
import org.genericsystem.defaults.tools.BidirectionalBinding;
import org.genericsystem.defaults.tools.ObservableListWrapperExtended;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.ReactorStatics;
Expand All @@ -36,6 +29,16 @@
import org.genericsystem.reactor.gstag.HtmlUl;
import org.genericsystem.todomvc.Todos.Completed;

import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableObjectValue;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;

/**
* @author Nicolas Feybesse
*
Expand Down Expand Up @@ -145,7 +148,7 @@ public Observable[] get(Object key) {
new HtmlLi(this) {
{
storeProperty(COMPLETED, model -> {
Generic completed = model.getGeneric().getHolder(model.getGeneric().getRoot().find(Completed.class));
Generic completed = model.getGeneric().getHolder(model.find(Completed.class));
return new SimpleBooleanProperty(completed != null && Boolean.TRUE.equals(completed.getValue()) ? true : false);
});
forEach2(model -> getFilteredTodos(model));
Expand All @@ -155,14 +158,21 @@ public Observable[] get(Object key) {
addStyleClass("view");
new HtmlCheckBox(this) {
{
addPrefixBinding(todo -> {
Property<Boolean> completedProperty = getProperty(COMPLETED, todo);
ObservableValue<Generic> completed = (ObservableValue<Generic>) getExtractors(todo.getParent()).get(todo.getGeneric())[0];
Property<Generic> completedGenericProperty = new SimpleObjectProperty(completed.getValue());
BidirectionalBinding.bind(completedGenericProperty, completedProperty, g -> g == null ? false : (Boolean) g.getValue(),
b -> todo.getGeneric().isAlive() ? todo.getGeneric().setHolder(todo.find(Completed.class), b) : null);
completed.addListener((ov, v, nv) -> completedGenericProperty.setValue(nv));
});
addStyleClass("toggle");
addPrefixBinding(todo -> {
if (Boolean.TRUE.equals(getObservableValue(COMPLETED, todo).getValue())) {
getDomNodeAttributes(todo).put(ReactorStatics.CHECKED, ReactorStatics.CHECKED);
}
});
bindOptionalBiDirectionalAttribute(COMPLETED, ReactorStatics.CHECKED, ReactorStatics.CHECKED);
addPropertyChangeListener(COMPLETED, (model, nva) -> model.getGeneric().setHolder(model.find(Completed.class), nva));
}
};
new HtmlLabel(this) {
Expand Down
5 changes: 3 additions & 2 deletions gs-todomvc/src/main/java/org/genericsystem/todomvc/Todos.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.SystemGeneric;
import org.genericsystem.api.core.annotations.constraints.InstanceValueClassConstraint;
import org.genericsystem.api.core.annotations.constraints.PropertyConstraint;
import org.genericsystem.api.core.annotations.constraints.SingularConstraint;
import org.genericsystem.api.core.annotations.constraints.UniqueValueConstraint;

@UniqueValueConstraint
@SystemGeneric
public class Todos {
@SystemGeneric
@InstanceValueClassConstraint(Boolean.class)
@PropertyConstraint
// @PropertyConstraint
@SingularConstraint
@Components(Todos.class)
public static class Completed {

Expand Down

0 comments on commit 267d282

Please sign in to comment.