implemented inversion of conditions
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>0.8.1</version>
|
<version>0.8.2</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class ConditionalAction extends Action {
|
|||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) throws IOException {
|
||||||
for (Condition condition : conditions) {
|
for (Condition condition : conditions) {
|
||||||
if (condition.fulfilledBy(context)) return fireActions(context);
|
if (condition.fulfilledBy(context) != condition.inverted) return fireActions(context);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ public class ConditionalAction extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (conditions.isEmpty()) return t("Invalid condition");
|
if (conditions.isEmpty()) return t("[Click here to add condition]");
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (int i = 0; i<conditions.size(); i++) {
|
for (int i = 0; i<conditions.size(); i++) {
|
||||||
if (i>0) sb.append(t(" or "));
|
if (i>0) sb.append(t(" or "));
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import de.keawe.tools.translations.Translation;
|
import de.keawe.tools.translations.Translation;
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
@@ -12,12 +14,17 @@ import de.srsoftware.web4rail.Constants;
|
|||||||
import de.srsoftware.web4rail.Plan;
|
import de.srsoftware.web4rail.Plan;
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.actions.Action.Context;
|
import de.srsoftware.web4rail.actions.Action.Context;
|
||||||
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
|
import de.srsoftware.web4rail.tags.Checkbox;
|
||||||
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
|
||||||
public abstract class Condition implements Constants {
|
public abstract class Condition implements Constants {
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(Condition.class);
|
||||||
|
private static final String INVERTED = "inverted";
|
||||||
private static HashMap<Integer, Condition> conditions = new HashMap<Integer, Condition>();
|
private static HashMap<Integer, Condition> conditions = new HashMap<Integer, Condition>();
|
||||||
|
|
||||||
public abstract boolean fulfilledBy(Context context);
|
public abstract boolean fulfilledBy(Context context);
|
||||||
|
public boolean inverted = false;
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
public Condition() {
|
public Condition() {
|
||||||
@@ -66,7 +73,22 @@ public abstract class Condition implements Constants {
|
|||||||
return new Tag(tagClass).clazz("link").attr("onclick","request("+json+")").content(toString());
|
return new Tag(tagClass).clazz("link").attr("onclick","request("+json+")").content(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Window properties(HashMap<String, String> params);
|
public Tag propForm(HashMap<String, String> params) {
|
||||||
|
Form form = new Form("condition-props-"+id);
|
||||||
|
new Input(REALM,REALM_CONDITION).hideIn(form);
|
||||||
|
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||||
|
new Input(ID,id).hideIn(form);
|
||||||
|
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Window properties(HashMap<String, String> params) {
|
||||||
|
Window win = new Window("condition-props", t("Properties of {}",getClass().getSimpleName()));
|
||||||
|
Tag form = propForm(params);
|
||||||
|
new Checkbox(INVERTED, t("inverted"), inverted).addTo(form);
|
||||||
|
new Button(t("Apply"),"return submitForm('condition-props-"+id+"');").addTo(form).addTo(win);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
public static String t(String text, Object...fills) {
|
public static String t(String text, Object...fills) {
|
||||||
return Translation.get(Application.class, text, fills);
|
return Translation.get(Application.class, text, fills);
|
||||||
@@ -77,5 +99,8 @@ public abstract class Condition implements Constants {
|
|||||||
return t("invalid condition");
|
return t("invalid condition");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Object update(HashMap<String, String> params);
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
inverted = "on".equals(params.get(INVERTED));
|
||||||
|
return t("updated {}.",this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.actions.Action.Context;
|
import de.srsoftware.web4rail.actions.Action.Context;
|
||||||
import de.srsoftware.web4rail.moving.Train;
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
|
||||||
public class TrainSelect extends Condition {
|
public class TrainSelect extends Condition {
|
||||||
@@ -33,23 +30,16 @@ public class TrainSelect extends Condition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(HashMap<String, String> params) {
|
public Tag propForm(HashMap<String, String> params) {
|
||||||
Window win = new Window("condition-props", t("Properties of {}",getClass().getSimpleName()));
|
Tag form = super.propForm(params);
|
||||||
String formId = "conditional-props-"+id;
|
|
||||||
Form form = new Form(formId);
|
|
||||||
new Input(REALM,REALM_CONDITION).hideIn(form);
|
|
||||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
|
||||||
new Input(ID,id).hideIn(form);
|
|
||||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
|
||||||
Train.selector(train, null).addTo(new Label(t("Select train:")+NBSP)).addTo(form);
|
Train.selector(train, null).addTo(new Label(t("Select train:")+NBSP)).addTo(form);
|
||||||
new Button(t("Apply"),"return submitForm('"+formId+"');").addTo(form).addTo(win);
|
return form;
|
||||||
return win;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (train == null) return super.toString();
|
if (train == null) return t("[Click here to select train!]");
|
||||||
return t("Train = {}",train);
|
return t(inverted?"Train ≠ {}":"Train = {}",train);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TrainSelect train(Train train) {
|
private TrainSelect train(Train train) {
|
||||||
@@ -65,6 +55,6 @@ public class TrainSelect extends Condition {
|
|||||||
Train train = Train.get(tid);
|
Train train = Train.get(tid);
|
||||||
if (train == null) return t("No train with id {} found!",tid);
|
if (train == null) return t("No train with id {} found!",tid);
|
||||||
this.train = train;
|
this.train = train;
|
||||||
return t("Updated condition");
|
return super.update(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user