Skip to content

Commit

Permalink
Add @HideValue to hide a type’s and its instances’ values in the reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fducroquet committed Feb 8, 2017
1 parent 35f2f4a commit 57660fd
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 77 deletions.
21 changes: 21 additions & 0 deletions gs-api/src/main/java/org/genericsystem/api/core/IGeneric.java
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,27 @@ public static interface SystemProperty {

boolean isHidden();

/**
* Hide this vertex’s and its instances’ values in the reactor.
*
* @return <code>this</code>.
*/
T hideValue();

/**
* Show this vertex’s and its instances’ values in the reactor.
*
* @return <code>this</code>.
*/
T unhideValue();

/**
* Indicates whether this vertex’s and its instances’ values should be shown by the reactor.
*
* @return <code>true</code> if this vertex’s and its instances’ values should be shown, <code>false</code> otherwise.
*/
boolean isValueHidden();

/**
* Removes this vertex.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.genericsystem.api.core.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Indicates that the value of this generic should not be displayed by the reactor.
*
* @author Fabienne Ducroquet
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface HideValue {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.genericsystem.carcolor.model;

import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.SystemGeneric;
import org.genericsystem.api.core.annotations.constraints.SingularConstraint;

@SystemGeneric
@Components({ Car.class, Color.class })
@SingularConstraint
@HideValue
public class CarColor {

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.genericsystem.carcolor.model;

import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.SystemGeneric;

@SystemGeneric
@Components({ Car.class, Color.class })
@HideValue
public class CarColor2 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.Dependencies;
import org.genericsystem.api.core.annotations.Hidden;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.Meta;
import org.genericsystem.api.core.annotations.constraints.InstanceValueClassConstraint;
import org.genericsystem.api.core.annotations.constraints.InstanceValueGenerator;
Expand Down Expand Up @@ -147,6 +148,9 @@ void mountConstraints(Class<?> clazz, Generic result) {

if (clazz.getAnnotation(Hidden.class) != null)
result.hide();

if (clazz.getAnnotation(HideValue.class) != null)
result.hideValue();
}

private void triggersDependencies(Class<?> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public static class HiddenProperty implements SystemProperty {

}

@SystemGeneric
@Meta(MetaAttribute.class)
@Supers(SystemMap.class)
@Components(MetaAttribute.class)
@PropertyConstraint
public static class HiddenValueProperty implements SystemProperty {

}

@SystemGeneric
@Meta(MetaAttribute.class)
@Supers(SystemMap.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.genericsystem.api.core.exceptions.NotFoundException;
import org.genericsystem.defaults.DefaultConfig.CascadeRemoveProperty;
import org.genericsystem.defaults.DefaultConfig.HiddenProperty;
import org.genericsystem.defaults.DefaultConfig.HiddenValueProperty;
import org.genericsystem.defaults.DefaultConfig.InstanceValueGeneratorProperty;
import org.genericsystem.defaults.DefaultConfig.NoReferentialIntegrityProperty;
import org.genericsystem.defaults.DefaultConfig.NonHeritableProperty;
Expand Down Expand Up @@ -217,6 +218,23 @@ default boolean isHidden() {
return isSystemPropertyEnabled(HiddenProperty.class, ApiStatics.NO_POSITION);
}

@SuppressWarnings("unchecked")
@Override
default T hideValue() {
return enableSystemProperty(HiddenValueProperty.class, ApiStatics.NO_POSITION);
}

@SuppressWarnings("unchecked")
@Override
default T unhideValue() {
return disableSystemProperty(HiddenValueProperty.class, ApiStatics.NO_POSITION);
}

@Override
default boolean isValueHidden() {
return isSystemPropertyEnabled(HiddenValueProperty.class, ApiStatics.NO_POSITION);
}

@SuppressWarnings("unchecked")
@Override
default Class<? extends Serializable> getInstanceValueClassConstraint() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.genericsystem.reactor.example;

import org.genericsystem.reactor.example.App.ExampleReactorScript;

import org.genericsystem.api.core.ApiStatics;
import org.genericsystem.carcolor.model.Car;
import org.genericsystem.carcolor.model.CarColor;
Expand All @@ -20,6 +18,7 @@
import org.genericsystem.reactor.appserver.ApplicationServer;
import org.genericsystem.reactor.appserver.Script;
import org.genericsystem.reactor.context.ObservableContextSelector;
import org.genericsystem.reactor.example.App.ExampleReactorScript;
import org.genericsystem.reactor.gscomponents.DivWithTitle.TitledHorizontalInstanceEditor;
import org.genericsystem.reactor.gscomponents.DivWithTitle.TitledHorizontalInstanceStepEditor;
import org.genericsystem.reactor.gscomponents.DivWithTitle.TitledHorizontalInstancesTable;
Expand Down Expand Up @@ -62,6 +61,7 @@ public void run(Root engine) {
Generic carColor = engine.find(CarColor.class);
Generic color = engine.find(Color.class);
Generic carPerson = car.setRelation("CarDriverOwner", category, person);
carPerson.hideValue();
carPerson.enablePropertyConstraint();
Generic red = color.setInstance("Red");
Generic black = color.setInstance("Black");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.genericsystem.extendedcarcolor.model;

import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.SystemGeneric;
import org.genericsystem.api.core.annotations.constraints.SingularConstraint;

@SystemGeneric
@Components({ Car.class, Color.class })
@SingularConstraint
@HideValue
public class CarColor {

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.genericsystem.extendedcarcolor.model;

import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.SystemGeneric;

@SystemGeneric
@Components({ Car.class, Color.class })
@HideValue
public class CarColor2 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.Dependencies;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.SystemGeneric;
import org.genericsystem.api.core.annotations.constraints.SingularConstraint;

@SystemGeneric
@Components({ Vehicle.class, Color.class })
@SingularConstraint
@Dependencies({ Vehicle.class, Color.class })
@HideValue
public class VehicleColor {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.Dependencies;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.SystemGeneric;
import org.genericsystem.api.core.annotations.constraints.SingularConstraint;

@SystemGeneric
@Components({ Vehicle.class, Energy.class })
@SingularConstraint
@Dependencies({ Vehicle.class, Energy.class })
@HideValue
public class VehicleEnergy {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.Dependencies;
import org.genericsystem.api.core.annotations.HideValue;
import org.genericsystem.api.core.annotations.SystemGeneric;
import org.genericsystem.api.core.annotations.constraints.SingularConstraint;

@SystemGeneric
@Components({ Vehicle.class, VehicleEngine.class })
@SingularConstraint
@Dependencies({ Vehicle.class, VehicleEngine.class })
@HideValue
public class VehicleVehicleEngine {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,52 @@ public Generic apply(Generic[] gs) {
}
}

public static class RELATION_SELECTOR implements ObservableValueSelector {
public static class GENERIC_INSTANCE_VALUE_DISPLAYER implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return gs[0].getComponents().size() >= 2 ? gs[0] : null;
return !gs[1].isValueHidden() ? gs[0] : null;
}
}

public static class STRICT_ATTRIBUTE_SELECTOR_OR_CHECK_BOX_DISPLAYER implements ObservableValueSelector {
public static class GENERIC_VALUE_DISPLAYER implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return gs[0];
// return gs[1].getComponents().size() < 2 || Boolean.class.equals(gs[1].getInstanceValueClassConstraint())
// ? gs[0] : null;
return !gs[0].isValueHidden() ? gs[0] : null;
}
}

public static class STRICT_ATTRIBUTE_SELECTOR_OR_CHECK_BOX_DISPLAYER_ATTRIBUTE implements ObservableValueSelector {
public static class INSTANCE_CHECK_BOX_DISPLAYER implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return gs[0];
// return gs[0].getComponents().size() < 2 || Boolean.class.equals(gs[0].getInstanceValueClassConstraint())
// ? gs[0] : null;
return !gs[1].isValueHidden() && Boolean.class.equals(gs[1].getInstanceValueClassConstraint()) ? gs[0] : null;
}
}

public static class CHECK_BOX_DISPLAYER implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return Boolean.class.equals(gs[1].getInstanceValueClassConstraint()) ? gs[0] : null;
return !gs[0].isValueHidden() && Boolean.class.equals(gs[0].getInstanceValueClassConstraint()) ? gs[0] : null;
}
}

public static class CHECK_BOX_DISPLAYER_ATTRIBUTE implements ObservableValueSelector {
public static class INSTANCE_LABEL_DISPLAYER implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return Boolean.class.equals(gs[0].getInstanceValueClassConstraint()) ? gs[0] : null;
return !gs[1].isValueHidden() && !Boolean.class.equals(gs[1].getInstanceValueClassConstraint()) ? gs[0] : null;
}
}

public static class LABEL_DISPLAYER implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return /* gs[1].getComponents().size() < 2 && */!Boolean.class
.equals(gs[1].getInstanceValueClassConstraint()) ? gs[0] : null;
return !gs[0].isValueHidden() && !Boolean.class.equals(gs[0].getInstanceValueClassConstraint()) ? gs[0] : null;
}
}

public static class LABEL_DISPLAYER_ATTRIBUTE implements ObservableValueSelector {
public static class VALUE_BUILDER_DISPLAYER_SELECTOR implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return /* gs[0].getComponents().size() < 2 && */!Boolean.class
.equals(gs[0].getInstanceValueClassConstraint()) ? gs[0] : null;
}
}

public static class LABEL_DISPLAYER_SELECTOR implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return (!Boolean.class.equals(gs[0].getInstanceValueClassConstraint())
&& gs[0].getInstanceValueGenerator() == null) ? gs[0] : null;
return !gs[0].isValueHidden() && !Boolean.class.equals(gs[0].getInstanceValueClassConstraint()) && gs[0].getInstanceValueGenerator() == null ? gs[0] : null;
}
}

Expand Down Expand Up @@ -114,44 +100,39 @@ public Generic apply(Generic[] gs) {
public static class REVERSED_RELATION_SELECTOR implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
return !gs[1].isReferentialIntegrityEnabled(gs[1].getComponents().indexOf(gs[0]))
&& !gs[0].getLinks(gs[2]).isEmpty() ? gs[0] : null;
return !gs[1].isReferentialIntegrityEnabled(gs[1].getComponents().indexOf(gs[0])) && !gs[0].getLinks(gs[2]).isEmpty() ? gs[0] : null;
}
}

public static class MULTICHECKBOX_SELECTOR implements ObservableValueSelector {
public static class MULTICHECKBOX_INSTANCE_SELECTOR implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
Generic component = gs[0].getComponents().stream().filter(c -> gs[2].inheritsFrom(c)).findFirst().get();
return !gs[0].isHidden() && gs[0].getComponents().size() == 2
&& !gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component)) ? gs[0] : null;
return !gs[0].isHidden() && gs[0].isValueHidden() && gs[0].getComponents().size() == 2 && !gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component)) ? gs[0] : null;
}
}

public static class NON_MULTICHECKBOX_SELECTOR implements ObservableValueSelector {
public static class NON_MULTICHECKBOX_INSTANCE_SELECTOR implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
Generic component = gs[0].getComponents().stream().filter(c -> gs[2].inheritsFrom(c)).findFirst().get();
return !gs[0].isHidden() && (gs[0].getComponents().size() != 2
|| gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component))) ? gs[0] : null;
return !gs[0].isHidden() && (!gs[0].isValueHidden() || (gs[0].getComponents().size() != 2 || gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component)))) ? gs[0] : null;
}
}

public static class MULTICHECKBOX_SELECTOR_RELATION implements ObservableValueSelector {
public static class MULTICHECKBOX_SELECTOR implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
Generic component = gs[0].getComponents().stream().filter(c -> gs[1].inheritsFrom(c)).findFirst().get();
return !gs[0].isHidden() && gs[0].getComponents().size() == 2
&& !gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component)) ? gs[0] : null;
return !gs[0].isHidden() && gs[0].isValueHidden() && gs[0].getComponents().size() == 2 && !gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component)) ? gs[0] : null;
}
}

public static class NON_MULTICHECKBOX_SELECTOR_RELATION implements ObservableValueSelector {
public static class NON_MULTICHECKBOX_SELECTOR implements ObservableValueSelector {
@Override
public Generic apply(Generic[] gs) {
Generic component = gs[0].getComponents().stream().filter(c -> gs[1].inheritsFrom(c)).findFirst().get();
return !gs[0].isHidden() && (gs[0].getComponents().size() != 2
|| gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component))) ? gs[0] : null;
return !gs[0].isHidden() && (!gs[0].isValueHidden() || (gs[0].getComponents().size() != 2 || gs[0].isSingularConstraintEnabled(gs[0].getComponents().indexOf(component)))) ? gs[0] : null;
}
}

Expand Down
Loading

0 comments on commit 57660fd

Please sign in to comment.