Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
plagarrigue committed Sep 5, 2016
2 parents 28e6567 + fe3ab42 commit a238fca
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.genericsystem.example.reactor;

import org.genericsystem.api.core.ApiStatics;
import org.genericsystem.carcolor.model.Car;
import org.genericsystem.carcolor.model.CarColor;
import org.genericsystem.carcolor.model.CarColor2;
import org.genericsystem.carcolor.model.Color;
import org.genericsystem.carcolor.model.Power;
import org.genericsystem.carcolor.model.UsedCar;
import org.genericsystem.common.Generic;
import org.genericsystem.common.Root;
import org.genericsystem.example.reactor.AppHtml.ExampleReactorScript;
import org.genericsystem.reactor.annotations.DependsOnModel;
import org.genericsystem.reactor.annotations.RunScript;
import org.genericsystem.reactor.appserver.ApplicationServer;
import org.genericsystem.reactor.appserver.Script;
import org.genericsystem.reactor.gs.GSApp;
import org.genericsystem.reactor.gs2.GSTable.GSSubSubCellTable;
import org.genericsystem.reactor.modelproperties.SelectionDefaults;

@DependsOnModel({ Car.class, Power.class, UsedCar.class, Color.class, CarColor.class, CarColor2.class })
@RunScript(ExampleReactorScript.class)
public class AppHtml2 extends GSApp implements SelectionDefaults {

public static void main(String[] mainArgs) {
ApplicationServer.startSimpleGenericApp(mainArgs, AppHtml2.class, "/example-reactor");
}

public AppHtml2() {
addStyle("justify-content", "center");
new GSSubSubCellTable(this).select(Color.class);
new GSSubSubCellTable(this).select(Car.class);
}

public static class ExampleReactorScript implements Script {

@Override
public void run(Root engine) {
Generic car = engine.find(Car.class);
Generic power = engine.find(Power.class);
Generic diesel = engine.find(UsedCar.class);
car.setAttribute("Description");
Generic person = engine.setInstance("Person");
Generic category = engine.setInstance("Category");
Generic carColor = engine.find(CarColor.class);
Generic color = engine.find(Color.class);
Generic carPerson = car.setRelation("CarDriverOwner", category, person);
carPerson.enablePropertyConstraint();
Generic red = color.setInstance("Red");
Generic black = color.setInstance("Black");
Generic green = color.setInstance("Green");
color.setInstance("Blue");
color.setInstance("Orange");
color.setInstance("White");
color.setInstance("Yellow");
Generic jdoe = person.setInstance("John Doe");
Generic hoover = person.setInstance("Edgar Hoover");
Generic jsnow = person.setInstance("Jon Snow");
Generic driver = category.setInstance("Driver");
Generic owner = category.setInstance("Owner");
category.setInstance("Passenger");
person.setInstance("Chuck Norris");
person.setInstance("Barack Obama");
person.setInstance("Donald Trump");
Generic audiS4 = car.setInstance("Audi S4");
audiS4.setHolder(power, 333);
audiS4.setHolder(diesel, false);
audiS4.setLink(carColor, "Audi S4 Green", green);
audiS4.setLink(carPerson, "Audi S4 owner", owner, jsnow);
audiS4.setLink(carPerson, "Audi S4 driver", driver, hoover);
Generic bmwM3 = car.setInstance("BMW M3");
bmwM3.setHolder(power, 450);
bmwM3.setHolder(diesel, false);
bmwM3.setLink(carColor, "BMW M3 Red", red);
bmwM3.setLink(carPerson, "BMW M3 owner", owner, jdoe);
bmwM3.setLink(carPerson, "BMW M3 owner", driver, jdoe);
Generic ferrariF40 = car.setInstance("Ferrari F40");
ferrariF40.setHolder(power, 478);
ferrariF40.setHolder(diesel, false);
ferrariF40.setLink(carColor, "Ferrari F40 red", red);
Generic miniCooper = car.setInstance("Mini Cooper");
miniCooper.setHolder(power, 175);
miniCooper.setHolder(diesel, true);
miniCooper.setLink(carColor, "Mini Cooper", black);
car.setInstance("Audi A4 3.0 TDI").setHolder(power, 233);
car.setInstance("Peugeot 106 GTI").setHolder(power, 120);
car.setInstance("Peugeot 206 S16").setHolder(power, 136);
power.enableRequiredConstraint(ApiStatics.BASE_POSITION);
engine.getCurrentCache().flush();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public TagConstructor getBooleanHolderDisplayerConstructor() {
}

public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSLabelDisplayer(tag) {
return tag -> new GSDiv(tag, ((GSDiv) tag).getDirection()) {
{
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[2])));
new GSLabelDisplayer(this);
}
};
}
Expand Down Expand Up @@ -277,9 +278,10 @@ public LinkTitleDisplayer(Tag parent) {

@Override
public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSLabelDisplayer(tag) {
return tag -> new GSDiv(tag, ((GSDiv) tag).getDirection()) {
{
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[1])));
new GSLabelDisplayer(this);
}
};
}
Expand All @@ -300,9 +302,10 @@ public InstanceLinkTitleDisplayer(Tag parent) {

@Override
public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSLabelDisplayer(tag) {
return tag -> new GSDiv(tag, ((GSDiv) tag).getDirection()) {
{
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[2])));
new GSLabelDisplayer(this);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package org.genericsystem.reactor.gs2;

import org.genericsystem.reactor.Tag;

public class GSCell extends GSComposite {

public GSCell(GSRow parent, MetaTag metaTag) {
super(parent, metaTag);
public GSCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag, ((GSComposite) parent).getReverseDirection());
}

public static class GSFirstCell extends GSCell {

public GSFirstCell(GSRow parent, MetaTag metaTag) {
public GSFirstCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
}
}

public static class GSFirstRowFirstCell extends GSCell {

public GSFirstRowFirstCell(GSRow parent, MetaTag metaTag) {
public GSFirstRowFirstCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
}
}

public static class GSFirstRowCell extends GSCell {

public GSFirstRowCell(GSRow parent, MetaTag metaTag) {
public GSFirstRowCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.genericsystem.reactor.gs2;

import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.gstag.HtmlLabel;

public class GSComponentSubCell extends GSComposite {

public GSComponentSubCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
new HtmlLabel(this).bindText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@

public abstract class GSComposite extends GSDiv {

public GSComposite(GSComposite parent, MetaTag metaTag) {
super(parent, FlexDirection.COLUMN);
public GSComposite(Tag parent, MetaTag metaTag) {
this(parent, metaTag, FlexDirection.COLUMN);
}

public GSComposite(Tag parent, MetaTag metaTag, FlexDirection flexDirection) {
super(parent, flexDirection);
for (MetaTag subMetaTag : metaTag.getSubNodes())
createChild(subMetaTag);
}

protected <TAG extends GSComposite> void createChild(MetaTag subMetaTag) {
try {
subMetaTag.<TAG> getBuilder().getConstructor(GSComposite.class, MetaTag.class).newInstance(this, subMetaTag);
subMetaTag.<TAG> getBuilder().getConstructor(Tag.class, MetaTag.class).newInstance(this, subMetaTag);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new IllegalStateException(e);
}
Expand All @@ -31,7 +35,7 @@ public Stream<Tag> tags(Class<? extends GSComposite>... classes) {

private Stream<Tag> tags(List<Class<? extends GSComposite>> classes) {
if (classes.isEmpty())
return Stream.empty();
return getObservableChildren().stream().filter(tag -> classes.get(0) == null || classes.get(0).equals(tag.getClass())).flatMap(tag -> ((GSComposite) tag).tags(classes.subList(1, classes.size())));
return Stream.of(new Tag[] { this });
return getObservableChildren().stream().filter(tag -> classes.get(0).equals(tag.getClass())).flatMap(tag -> ((GSComposite) tag).tags(classes.subList(1, classes.size())));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.genericsystem.reactor.gs2;

import org.genericsystem.reactor.Tag;

public class GSRow extends GSComposite {

public GSRow(GSTable parent, MetaTag metaTag) {
super(parent, metaTag);
public GSRow(Tag parent, MetaTag metaTag) {
super(parent, metaTag, ((GSComposite) parent).getReverseDirection());
}

public static class GSFirstRow extends GSRow {

public GSFirstRow(GSTable parent, MetaTag metaTag) {
public GSFirstRow(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package org.genericsystem.reactor.gs2;

import org.genericsystem.reactor.Tag;

public class GSSubCell extends GSComposite {

public GSSubCell(GSCell parent, MetaTag metaTag) {
super(parent, metaTag);
public GSSubCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag, ((GSComposite) parent).getReverseDirection());
}

public static class GSFirstSubCell extends GSSubCell {

public GSFirstSubCell(GSCell parent, MetaTag metaTag) {
public GSFirstSubCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
}
}

public static class GSFirstCellFirstSubCell extends GSSubCell {

public GSFirstCellFirstSubCell(GSCell parent, MetaTag metaTag) {
public GSFirstCellFirstSubCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
}
}

public static class GSFirstCellSubCell extends GSSubCell {

public GSFirstCellSubCell(GSCell parent, MetaTag metaTag) {
public GSFirstCellSubCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
}
}
Expand Down
62 changes: 46 additions & 16 deletions gs-reactor/src/main/java/org/genericsystem/reactor/gs2/GSTable.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.genericsystem.reactor.gs2;

import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.gs.GSDiv;
import org.genericsystem.reactor.gs2.GSCell.GSFirstCell;
import org.genericsystem.reactor.gs2.GSCell.GSFirstRowCell;
import org.genericsystem.reactor.gs2.GSCell.GSFirstRowFirstCell;
import org.genericsystem.reactor.gs2.GSRow.GSFirstRow;
import org.genericsystem.reactor.gs2.GSSubCell.GSFirstSubCell;
import org.genericsystem.reactor.model.ObservableListExtractor;

public class GSTable extends GSComposite {
Expand All @@ -15,14 +16,23 @@ public TableMetaTag() {
}
}

public GSTable(GSComposite parent) {
public GSTable(Tag parent) {
this(parent, new TableMetaTag());
}

public GSTable(GSComposite parent, MetaTag metaTag) {
public GSTable(Tag parent, MetaTag metaTag) {
super(parent, metaTag);
tags(GSRow.class).forEach(gsrow -> gsrow.forEach(ObservableListExtractor.SUBINSTANCES));
tags(GSRow.class, GSCell.class).forEach(gsrow -> gsrow.forEach(ObservableListExtractor.ATTRIBUTES_OF_INSTANCES));
tags(GSRow.class).forEach(gsrow -> {
gsrow.forEach(ObservableListExtractor.SUBINSTANCES);
gsrow.addStyle("flex", "1");
});
tags(GSRow.class, GSCell.class).forEach(gscell -> {
gscell.forEach(ObservableListExtractor.ATTRIBUTES_OF_INSTANCES);
gscell.addStyle("flex", "1");
gscell.addStyle("flex-direction", ((GSDiv) gscell.getParent()).getReverseDirection().toString());
gscell.addStyle("margin-bottom", "1px");
gscell.addStyle("margin-right", "1px");
});
}

public static class GSFirstRowTableMetaTag extends MetaTag {
Expand All @@ -33,7 +43,7 @@ public GSFirstRowTableMetaTag() {

public class GSFirstRowTable extends GSTable {

public GSFirstRowTable(GSComposite parent) {
public GSFirstRowTable(Tag parent) {
super(parent, new GSFirstRowTableMetaTag());
}
}
Expand All @@ -46,7 +56,7 @@ public GSFirstColumnTableMetaTag() {

public class GSFirstColumnTable extends GSTable {

public GSFirstColumnTable(GSComposite parent) {
public GSFirstColumnTable(Tag parent) {
super(parent, new GSFirstColumnTableMetaTag());
}
}
Expand All @@ -59,22 +69,42 @@ public GSFirstRowFirstColumnTableMetaTag() {

public static class GSFirstRowFirstColumnTable extends GSTable {

public GSFirstRowFirstColumnTable(GSComposite parent) {
public GSFirstRowFirstColumnTable(Tag parent) {
super(parent, new GSFirstRowFirstColumnTableMetaTag());
}
}

public static class GSSubCellTableMetaTag extends MetaTag {
public GSSubCellTableMetaTag() {
super(null, new MetaTag(GSRow.class, new MetaTag(GSCell.class, new MetaTag(GSFirstSubCell.class), new MetaTag(GSSubCell.class))));
public static class GSSubSubCellTableMetaTag extends MetaTag {

public GSSubSubCellTableMetaTag() {
super(null, new MetaTag(GSRow.class, new MetaTag(GSCell.class, new MetaTag(GSSubCell.class, new MetaTag(GSValueSubCell.class), new MetaTag(GSComponentSubCell.class)))));
}
}

public static class GSSubCellTable extends GSTable {

public GSSubCellTable(GSComposite parent) {
super(parent, new GSSubCellTableMetaTag());
tags(GSRow.class, GSCell.class, GSSubCell.class).forEach(gsrow -> gsrow.forEach(ObservableListExtractor.HOLDERS));
public static class GSSubSubCellTable extends GSTable {

public GSSubSubCellTable(Tag parent) {
super(parent, new GSSubSubCellTableMetaTag());
tags(GSRow.class, GSCell.class, GSSubCell.class).forEach(gssubcell -> {
gssubcell.forEach(ObservableListExtractor.HOLDERS);
gssubcell.addStyle("flex", "1");
});
tags(GSRow.class, GSCell.class, GSSubCell.class, GSComponentSubCell.class).forEach(t -> {
t.forEach(gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[2])));
t.addStyle("flex", "1");
t.addStyle("justify-content", "center");
t.addStyle("align-items", "center");
t.addStyle("margin-bottom", "1px");
t.addStyle("margin-right", "1px");
t.addStyle("background-color", "#e5e400");
});
tags(GSRow.class, GSCell.class, GSSubCell.class, GSValueSubCell.class).forEach(t -> {
t.select(gs -> gs[1].getComponents().size() == 1 ? gs[0] : null);
t.addStyle("justify-content", "center");
t.addStyle("align-items", "center");
t.addStyle("flex", "1");
t.addStyle("background-color", "#e5e400");
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.genericsystem.reactor.gs2;

import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.gstag.HtmlLabel;

public class GSValueSubCell extends GSComposite {

public GSValueSubCell(Tag parent, MetaTag metaTag) {
super(parent, metaTag, ((GSComposite) parent).getDirection());
new HtmlLabel(this).bindText();
}
}

0 comments on commit a238fca

Please sign in to comment.