completed conditional actions
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.7.11</version>
|
<version>0.7.12</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>
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ public class ControlUnit extends Thread implements Constants{
|
|||||||
restart();
|
restart();
|
||||||
return t("Control unit (re)started.");
|
return t("Control unit (re)started.");
|
||||||
case ACTION_EMERGENCY:
|
case ACTION_EMERGENCY:
|
||||||
power = true;
|
return emergency();
|
||||||
case ACTION_POWER:
|
case ACTION_POWER:
|
||||||
return togglePower();
|
return togglePower();
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
@@ -134,6 +134,11 @@ public class ControlUnit extends Thread implements Constants{
|
|||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object emergency() {
|
||||||
|
power = true;
|
||||||
|
return togglePower();
|
||||||
|
}
|
||||||
|
|
||||||
public Object properties() {
|
public Object properties() {
|
||||||
Window win = new Window("cu-props", t("Properties of the control unit"));
|
Window win = new Window("cu-props", t("Properties of the control unit"));
|
||||||
Form form = new Form();
|
Form form = new Form();
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public abstract class Action implements Constants {
|
|||||||
public Route route = null;
|
public Route route = null;
|
||||||
public Train train = null;
|
public Train train = null;
|
||||||
|
|
||||||
public Context(Contact c) {
|
public Context(Contact c) {
|
||||||
contact = c;
|
contact = c;
|
||||||
route = contact.route();
|
route = contact.route();
|
||||||
if (route == null) return;
|
if (route == null) return;
|
||||||
@@ -56,7 +56,7 @@ public abstract class Action implements Constants {
|
|||||||
protected Tag link(int actionId, String context) {
|
protected Tag link(int actionId, String context) {
|
||||||
Map<String, String> props = Map.of(REALM,REALM_ACTIONS,ID,actionId+"/"+id,ACTION,ACTION_PROPS,CONTEXT,context);
|
Map<String, String> props = Map.of(REALM,REALM_ACTIONS,ID,actionId+"/"+id,ACTION,ACTION_PROPS,CONTEXT,context);
|
||||||
String action = "request("+(new JSONObject(props).toString().replace("\"", "'"))+")";
|
String action = "request("+(new JSONObject(props).toString().replace("\"", "'"))+")";
|
||||||
return new Tag("span").content(toString()).attr("onclick", action);
|
return new Tag("span").content(toString()+NBSP).attr("onclick", action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Action load(JSONObject json) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
|
public static Action load(JSONObject json) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||||
|
|||||||
@@ -56,11 +56,14 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
new Input(CONTEXT,context).hideIn(typeForm);
|
new Input(CONTEXT,context).hideIn(typeForm);
|
||||||
Select select = new Select(TYPE);
|
Select select = new Select(TYPE);
|
||||||
List<Class<? extends Action>> classes = List.of(
|
List<Class<? extends Action>> classes = List.of(
|
||||||
|
ConditionalAction.class,
|
||||||
SpeedReduction.class,
|
SpeedReduction.class,
|
||||||
SetSignalsToStop.class,
|
SetSignalsToStop.class,
|
||||||
FinishRoute.class,
|
FinishRoute.class,
|
||||||
TurnTrain.class,
|
TurnTrain.class,
|
||||||
ConditionalAction.class);
|
StopAuto.class,
|
||||||
|
PowerOff.class
|
||||||
|
);
|
||||||
for (Class<? extends Action> clazz : classes) select.addOption(clazz.getSimpleName());
|
for (Class<? extends Action> clazz : classes) select.addOption(clazz.getSimpleName());
|
||||||
select.addTo(new Label("Action type:")).addTo(typeForm);
|
select.addTo(new Label("Action type:")).addTo(typeForm);
|
||||||
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm).addTo(win);
|
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm).addTo(win);
|
||||||
@@ -87,7 +90,13 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
break;
|
break;
|
||||||
case "TurnTrain":
|
case "TurnTrain":
|
||||||
add(new TurnTrain());
|
add(new TurnTrain());
|
||||||
break;
|
break;
|
||||||
|
case "StopAuto":
|
||||||
|
add(new StopAuto());
|
||||||
|
break;
|
||||||
|
case "PowerOff":
|
||||||
|
add(new PowerOff());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
actionTypeForm(win,context);
|
actionTypeForm(win,context);
|
||||||
new Tag("span").content(t("Unknown action type: {}",type)).addTo(win);
|
new Tag("span").content(t("Unknown action type: {}",type)).addTo(win);
|
||||||
@@ -117,6 +126,10 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
}
|
}
|
||||||
props.put(ACTION, ACTION_DROP);
|
props.put(ACTION, ACTION_DROP);
|
||||||
new Button("-",props).addTo(act);
|
new Button("-",props).addTo(act);
|
||||||
|
if (action instanceof ConditionalAction) {
|
||||||
|
ConditionalAction ca = (ConditionalAction) action;
|
||||||
|
ca.children().addTo(act, context);
|
||||||
|
}
|
||||||
act.addTo(ul);
|
act.addTo(ul);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,15 @@ public class ConditionalAction extends Action {
|
|||||||
|
|
||||||
private Vector<Condition> conditions = new Vector<Condition>();
|
private Vector<Condition> conditions = new Vector<Condition>();
|
||||||
private ActionList actions = new ActionList();
|
private ActionList actions = new ActionList();
|
||||||
|
|
||||||
|
private Tag actionsForm(HashMap<String, String> params) {
|
||||||
|
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||||
|
actions.addTo(fieldset, params.get(CONTEXT));
|
||||||
|
return fieldset;
|
||||||
|
}
|
||||||
|
|
||||||
private Tag conditionForm(HashMap<String, String> params) {
|
private Tag conditionForm(HashMap<String, String> params) {
|
||||||
Fieldset fieldset = new Fieldset("Conditions");
|
Fieldset fieldset = new Fieldset(t("Conditions"));
|
||||||
|
|
||||||
if (!conditions.isEmpty()) {
|
if (!conditions.isEmpty()) {
|
||||||
Tag list = new Tag("ul");
|
Tag list = new Tag("ul");
|
||||||
@@ -63,6 +69,7 @@ public class ConditionalAction extends Action {
|
|||||||
public Window properties(HashMap<String, String> params) {
|
public Window properties(HashMap<String, String> params) {
|
||||||
Window win = super.properties(params);
|
Window win = super.properties(params);
|
||||||
conditionForm(params).addTo(win);
|
conditionForm(params).addTo(win);
|
||||||
|
actionsForm(params).addTo(win);
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,4 +99,8 @@ public class ConditionalAction extends Action {
|
|||||||
}
|
}
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionList children() {
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main/java/de/srsoftware/web4rail/actions/PowerOff.java
Normal file
10
src/main/java/de/srsoftware/web4rail/actions/PowerOff.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
public class PowerOff extends Action{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
context.contact.plan().controlUnit().emergency();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/main/java/de/srsoftware/web4rail/actions/StopAuto.java
Normal file
16
src/main/java/de/srsoftware/web4rail/actions/StopAuto.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class StopAuto extends Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) throws IOException {
|
||||||
|
if (context.train != null) {
|
||||||
|
context.train.quitAutopilot();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,8 +17,7 @@ public class TrainSelect extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fulfilledBy(Context context) {
|
public boolean fulfilledBy(Context context) {
|
||||||
// TODO Auto-generated method stub
|
return context.train == train;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ public class Train implements Constants {
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object quitAutopilot() {
|
public Object quitAutopilot() {
|
||||||
if (autopilot != null) {
|
if (autopilot != null) {
|
||||||
autopilot.stop = true;
|
autopilot.stop = true;
|
||||||
autopilot = null;
|
autopilot = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user