refactoring actions
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.2.4</version>
|
||||
<version>1.2.5</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class BaseClass implements Constants{
|
||||
private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
|
||||
protected Id id = null;
|
||||
protected String notes;
|
||||
protected Context parent;
|
||||
private BaseClass parent;
|
||||
|
||||
public static class Context {
|
||||
|
||||
@@ -306,6 +306,15 @@ public abstract class BaseClass implements Constants{
|
||||
return merged;
|
||||
}
|
||||
|
||||
public BaseClass parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public BaseClass parent(BaseClass parent) {
|
||||
this.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Window properties() {
|
||||
return properties(new ArrayList<>(), new FormInput(), new ArrayList<>());
|
||||
}
|
||||
|
||||
@@ -147,11 +147,16 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
public Train train;
|
||||
private HashMap<String,ActionList> triggers = new HashMap<String, ActionList>();
|
||||
private HashMap<Turnout,Turnout.State> turnouts;
|
||||
private ActionList setupActions = new ActionList();
|
||||
private ActionList startActions = new ActionList();
|
||||
private ActionList setupActions;
|
||||
private ActionList startActions;
|
||||
private Block startBlock = null;
|
||||
public Direction startDirection;
|
||||
private HashSet<Contact> triggeredContacts = new HashSet<>();
|
||||
private HashSet<Contact> triggeredContacts = new HashSet<>();
|
||||
|
||||
public Route() {
|
||||
setupActions = new ActionList(this);
|
||||
startActions = new ActionList(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* process commands from the client
|
||||
@@ -211,7 +216,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
public void add(String trigger, Action action) {
|
||||
ActionList actions = triggers.get(trigger);
|
||||
if (isNull(actions)) {
|
||||
actions = new ActionList();
|
||||
actions = new ActionList(this);
|
||||
triggers.put(trigger, actions);
|
||||
}
|
||||
actions.add(action);
|
||||
@@ -258,21 +263,19 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
Tag list = new Tag("ol");
|
||||
|
||||
Tag setup = new Tag("li").content(t("Setup actions")+NBSP);
|
||||
setupActions.list().addTo(setup);
|
||||
setup.addTo(list);
|
||||
setupActions.list().addTo(setup).addTo(list);
|
||||
|
||||
Tag start = new Tag("li").content(t("Start actions")+NBSP);
|
||||
startActions.list().addTo(setup);
|
||||
start.addTo(list);
|
||||
startActions.list().addTo(start).addTo(list);
|
||||
|
||||
for (Contact c : contacts) {
|
||||
Tag link = Plan.addLink(c,c+NBSP,list);
|
||||
Tag item = c.link("span", c).addTo(new Tag("li")).content(NBSP);
|
||||
ActionList actions = triggers.get(c.trigger());
|
||||
if (isNull(actions)) {
|
||||
actions = new ActionList();
|
||||
actions = new ActionList(this);
|
||||
triggers.put(c.trigger(), actions);
|
||||
}
|
||||
actions.list().addTo(link);
|
||||
actions.list().addTo(item).addTo(list);
|
||||
}
|
||||
list.addTo(win);
|
||||
return win;
|
||||
@@ -371,21 +374,20 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
}
|
||||
|
||||
public Route complete() {
|
||||
Context parent = new Context(this);
|
||||
if (contacts.size()>1) { // mindestens 2 Kontakte: erster Kontakt aktiviert Block, vorletzter Kontakt leitet Bremsung ein
|
||||
Contact nextToLastContact = contacts.get(contacts.size()-2);
|
||||
String trigger = nextToLastContact.trigger();
|
||||
add(trigger,new BrakeStart(parent));
|
||||
add(trigger,new PreserveRoute(parent));
|
||||
for (Signal signal : signals) add(trigger,new SetSignal(parent).set(signal).to(Signal.STOP));
|
||||
add(trigger,new BrakeStart(this));
|
||||
add(trigger,new PreserveRoute(this));
|
||||
for (Signal signal : signals) add(trigger,new SetSignal(this).set(signal).to(Signal.STOP));
|
||||
}
|
||||
if (!contacts.isEmpty()) {
|
||||
Contact lastContact = contacts.lastElement();
|
||||
add(lastContact.trigger(), new BrakeStop(parent));
|
||||
add(lastContact.trigger(), new FinishRoute(parent));
|
||||
add(lastContact.trigger(), new BrakeStop(this));
|
||||
add(lastContact.trigger(), new FinishRoute(this));
|
||||
}
|
||||
for (Signal signal : signals) setupActions.add(new SetSignal(parent).set(signal).to(Signal.GO));
|
||||
startActions.add(new SetSpeed(parent).to(999));
|
||||
for (Signal signal : signals) setupActions.add(new SetSignal(this).set(signal).to(Signal.GO));
|
||||
startActions.add(new SetSpeed(this).to(999));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -566,8 +568,8 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
}
|
||||
if (json.has(ACTION_LISTS)) loadActions(json.getJSONArray(ACTION_LISTS));
|
||||
if (json.has(CONDITIONS)) conditions.load(json.getJSONArray(CONDITIONS));
|
||||
if (json.has(SETUP_ACTIONS)) setupActions = new ActionList().load(json.getJSONArray(SETUP_ACTIONS));
|
||||
if (json.has(START_ACTIONS)) startActions = new ActionList().load(json.getJSONArray(START_ACTIONS));
|
||||
if (json.has(SETUP_ACTIONS)) setupActions.load(json.getJSONArray(SETUP_ACTIONS));
|
||||
if (json.has(START_ACTIONS)) startActions.load(json.getJSONArray(START_ACTIONS));
|
||||
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
|
||||
if (json.has(BRAKE_TIMES)) {
|
||||
JSONObject dummy = json.getJSONObject(BRAKE_TIMES);
|
||||
@@ -580,7 +582,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
for (int i=0; i<arr.length(); i++) {
|
||||
JSONObject json = arr.getJSONObject(i);
|
||||
String trigger = json.getString(TRIGGER);
|
||||
ActionList actionList = new ActionList().load(json.getJSONArray(ACTIONS));
|
||||
ActionList actionList = new ActionList(this).load(json.getJSONArray(ACTIONS));
|
||||
triggers.put(trigger, actionList);
|
||||
}
|
||||
}
|
||||
@@ -651,7 +653,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
|
||||
formInputs.add(t("Name"),new Input(NAME, name()));
|
||||
formInputs.add(t("disabled"),new Checkbox(DISABLED, t("disabled"), disabled));
|
||||
formInputs.add(t("State"),new Checkbox(DISABLED, t("disabled"), disabled));
|
||||
|
||||
postForm.add(basicProperties());
|
||||
if (!turnouts.isEmpty()) postForm.add(turnouts());
|
||||
@@ -773,7 +775,8 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
|
||||
Condition condition = Condition.create(params.get(REALM_CONDITION));
|
||||
if (isSet(condition)) {
|
||||
conditions.add(condition.parent(this));
|
||||
condition.parent(this);
|
||||
conditions.add(condition);
|
||||
return properties();
|
||||
}
|
||||
String message = t("{} updated.",this);
|
||||
|
||||
@@ -26,20 +26,30 @@ public abstract class Action extends BaseClass {
|
||||
public static final Logger LOG = LoggerFactory.getLogger(Action.class);
|
||||
private static final String PREFIX = Action.class.getPackageName();
|
||||
|
||||
public Action(Context parent) {
|
||||
public Action(BaseClass parent) {
|
||||
actions.put(id(), this);
|
||||
this.parent = parent;
|
||||
parent(parent);
|
||||
}
|
||||
|
||||
public static Action create(String type,Context parent) {
|
||||
public static Action create(String type,BaseClass parent) {
|
||||
try {
|
||||
return (Action) Class.forName(PREFIX+"."+type).getDeclaredConstructor(Context.class).newInstance(parent);
|
||||
return (Action) Class.forName(PREFIX+"."+type).getDeclaredConstructor(BaseClass.class).newInstance(parent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean drop() {
|
||||
BaseClass parent = parent();
|
||||
if (parent instanceof ActionList) {
|
||||
ActionList actionList = (ActionList) parent;
|
||||
return actionList.drop(this);
|
||||
}
|
||||
LOG.error("Action.drop() called on Action ({}) whose parent ({}) is not an ActionList!",this,parent);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Action other) {
|
||||
return this.toString().equals(other.toString());
|
||||
}
|
||||
@@ -54,7 +64,7 @@ public abstract class Action extends BaseClass {
|
||||
return new JSONObject().put(TYPE, getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public static List<Class<? extends Action>> list() {
|
||||
public static List<Class<? extends Action>> classes() {
|
||||
return List.of(
|
||||
BrakeStart.class,
|
||||
BrakeStop.class,
|
||||
@@ -83,11 +93,22 @@ public abstract class Action extends BaseClass {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean moveUp() {
|
||||
BaseClass parent = parent();
|
||||
if (parent instanceof ActionList) {
|
||||
ActionList actionList = (ActionList) parent;
|
||||
return actionList.moveUp(this);
|
||||
}
|
||||
LOG.error("Action.drop() called on Action ({}) whose parent ({}) is not an ActionList!",this,parent);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static Tag selector() {
|
||||
Select select = new Select(TYPE);
|
||||
TreeMap<String, String> names = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (Class<? extends Action> clazz : Action.list()) {
|
||||
for (Class<? extends Action> clazz : Action.classes()) {
|
||||
String s = t(clazz.getSimpleName());
|
||||
names.put(s, clazz.getSimpleName());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -19,33 +18,16 @@ import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class ActionList extends BaseClass{
|
||||
public class ActionList extends Action{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActionList.class);
|
||||
|
||||
private static final HashMap<Id, ActionList> actionLists = new HashMap<Id, ActionList>();
|
||||
private Vector<Action> actions;
|
||||
private Id id;
|
||||
|
||||
public ActionList() {
|
||||
id = new Id();
|
||||
public ActionList(BaseClass parent) {
|
||||
super(parent);
|
||||
actions = new Vector<Action>();
|
||||
actionLists.put(id,this);
|
||||
|
||||
}
|
||||
|
||||
private static Id actionId(HashMap<String, String> params) {
|
||||
if (!params.containsKey(ID)) return null;
|
||||
String[] parts = params.get(ID).split("/");
|
||||
if (parts.length<2) return null;
|
||||
return new Id(parts[1]);
|
||||
}
|
||||
|
||||
private static Id actionListId(HashMap<String, String> params) {
|
||||
if (!params.containsKey(ID)) return null;
|
||||
String[] parts = params.get(ID).split("/");
|
||||
return new Id(parts[0]);
|
||||
}
|
||||
|
||||
private Object actionTypeForm(Window win, String context) {
|
||||
Form typeForm = new Form("add-action-to-"+id);
|
||||
new Input(REALM, REALM_ACTIONS).hideIn(typeForm);
|
||||
@@ -66,8 +48,7 @@ public class ActionList extends BaseClass{
|
||||
String type = params.get(TYPE);
|
||||
String context = params.get(CONTEXT);
|
||||
if (type == null) return actionTypeForm(win,context);
|
||||
Context parent = new Context(this);
|
||||
Action action = Action.create(type,parent);
|
||||
Action action = Action.create(type,this);
|
||||
if (action instanceof Action) {
|
||||
add(action);
|
||||
return plan.showContext(params);
|
||||
@@ -104,14 +85,8 @@ public class ActionList extends BaseClass{
|
||||
return actions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean drop(Id actionId) {
|
||||
for (Action action : actions) {
|
||||
if (action.id().equals(actionId)) {
|
||||
actions.remove(action);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean drop(Action action) {
|
||||
return actions.remove(action);
|
||||
}
|
||||
|
||||
public boolean fire(Context context) {
|
||||
@@ -121,10 +96,6 @@ public class ActionList extends BaseClass{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Id id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public JSONArray jsonArray() {
|
||||
JSONArray result = new JSONArray();
|
||||
@@ -132,52 +103,42 @@ public class ActionList extends BaseClass{
|
||||
return result;
|
||||
}
|
||||
|
||||
public Fieldset list() {
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
|
||||
Map<String, Object> props = new HashMap<String, Object>(Map.of(
|
||||
REALM,REALM_ACTIONS,
|
||||
ID,id,
|
||||
ACTION,ACTION_PROPS));
|
||||
public Tag list() {
|
||||
Button button = button(t("Add action"), contextAction(ACTION_ADD_ACTION));
|
||||
Tag span = new Tag("span");
|
||||
button.addTo(span);
|
||||
|
||||
if (!isEmpty()) {
|
||||
Tag ul = new Tag("ol");
|
||||
Tag list = new Tag("ol");
|
||||
boolean first = true;
|
||||
for (Action action : actions) {
|
||||
props.put(ID, id+"/"+action.id());
|
||||
Tag act = action.link("span", action+NBSP, Map.of(ID,id+"/"+action.id())).addTo(new Tag("li"));
|
||||
if (!first) {
|
||||
props.put(ACTION, ACTION_MOVE);
|
||||
new Button("↑",props).addTo(act);
|
||||
}
|
||||
props.put(ACTION, ACTION_DROP);
|
||||
new Button("-",props).addTo(act);
|
||||
// TODO: add children for conditionalActions and delayedActions
|
||||
act.addTo(ul);
|
||||
first = false;
|
||||
Tag item = action.link("span",action).addTo(new Tag("li"));
|
||||
if (first) {
|
||||
first = false;
|
||||
} else action.button("↑", contextAction(ACTION_MOVE)).addTo(item.content(NBSP));
|
||||
item.addTo(list);
|
||||
}
|
||||
ul.addTo(fieldset);
|
||||
}
|
||||
|
||||
return fieldset;
|
||||
list.addTo(span);
|
||||
}
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
public ActionList load(JSONArray list) {
|
||||
Context parent = new Context(this);
|
||||
for (Object o : list) {
|
||||
if (o instanceof JSONObject) {
|
||||
JSONObject json = (JSONObject) o;
|
||||
Action action = Action.create(json.getString(TYPE),parent);
|
||||
Action action = Action.create(json.getString(TYPE),this);
|
||||
if (action != null) add(action.load(json));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean moveUp(Id actionId) {
|
||||
public boolean moveUp(Action action) {
|
||||
for (int i=1; i<actions.size(); i++) {
|
||||
if (actionId.equals(actions.elementAt(i).id())) {
|
||||
Action action = actions.remove(i);
|
||||
if (actions.elementAt(i) == action) {
|
||||
actions.remove(i);
|
||||
actions.insertElementAt(action, i-1);
|
||||
return true;
|
||||
}
|
||||
@@ -186,26 +147,28 @@ public class ActionList extends BaseClass{
|
||||
}
|
||||
|
||||
public static Object process(HashMap<String, String> params, Plan plan) {
|
||||
Id listId = actionListId(params);
|
||||
if (listId == null) return t("No action list id passed to ActionList.process()!");
|
||||
ActionList actionList = actionLists.get(listId);
|
||||
|
||||
Id actionId = actionId(params);
|
||||
String action = params.get(ACTION);
|
||||
if (action == null) return t("No action passed to ActionList.process()!");
|
||||
if (actionList == null && !List.of(ACTION_UPDATE,ACTION_PROPS).contains(action)) return t("No action list with id {} found!",listId);
|
||||
String command = params.get(ACTION);
|
||||
if (command == null) return t("No action passed to ActionList.process()!");
|
||||
|
||||
switch (action) {
|
||||
case ACTION_ADD:
|
||||
Id actionId = Id.from(params);
|
||||
Action action = Action.get(actionId);
|
||||
if (isNull(action)) return t("Id ({}) does not belong to Action!",actionId);
|
||||
ActionList actionList = action instanceof ActionList ? (ActionList) action : null;
|
||||
|
||||
switch (command) {
|
||||
case ACTION_ADD:
|
||||
if (isNull(actionList)) return t("Id ({}) does not belong to ActionList!",actionId);
|
||||
return actionList.addActionForm(params,plan);
|
||||
case ACTION_DROP:
|
||||
return actionList.drop(actionId) ? plan.showContext(params) : t("No action with id {} found!",actionId);
|
||||
return action.drop() ? action.parent().properties() : t("No action with id {} found!",actionId);
|
||||
case ACTION_MOVE:
|
||||
return actionList.moveUp(actionId) ? plan.showContext(params) : t("No action with id {} found!",actionId);
|
||||
return action.moveUp() ? action.parent().properties() : t("No action with id {} found!",actionId);
|
||||
case ACTION_PROPS:
|
||||
return action.properties();
|
||||
case ACTION_UPDATE:
|
||||
return update(actionId,params,plan);
|
||||
return action.update(params);
|
||||
}
|
||||
return t("Unknown action: {}",action);
|
||||
return t("Unknown action: {}",command);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -215,14 +178,4 @@ public class ActionList extends BaseClass{
|
||||
preForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
|
||||
private static Object update(Id actionId, HashMap<String, String> params, Plan plan) {
|
||||
Action action = Action.get(actionId);
|
||||
if (action != null) {
|
||||
plan.stream(action.update(params).toString());
|
||||
return plan.showContext(params);
|
||||
}
|
||||
return t("No action with id {} found.",actionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
|
||||
public class BrakeCancel extends Action {
|
||||
|
||||
public BrakeCancel(Context parent) {
|
||||
public BrakeCancel(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
|
||||
public class BrakeStart extends Action {
|
||||
|
||||
public BrakeStart(Context parent) {
|
||||
public BrakeStart(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
|
||||
public class BrakeStop extends Action {
|
||||
|
||||
public BrakeStop(Context parent) {
|
||||
public BrakeStop(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.conditions.Condition;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
@@ -18,15 +19,16 @@ import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class ConditionalAction extends Action {
|
||||
|
||||
public ConditionalAction(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private static final String CONDITIONS = "conditions";
|
||||
private static final String ACTIONS = "actions";
|
||||
private Vector<Condition> conditions = new Vector<Condition>();
|
||||
private ActionList actions = new ActionList();
|
||||
|
||||
private ActionList actions;
|
||||
|
||||
public ConditionalAction(BaseClass parent) {
|
||||
super(parent);
|
||||
actions = new ActionList(this);
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
@@ -94,18 +96,23 @@ public class ConditionalAction extends Action {
|
||||
for (Object o : json.getJSONArray(CONDITIONS)) {
|
||||
if (o instanceof JSONObject) {
|
||||
JSONObject j = (JSONObject) o;
|
||||
Condition condition = Condition.create(j.getString(TYPE));
|
||||
if (isSet(condition)) conditions.add(condition.parent(this).load(j));
|
||||
Condition condition = Condition.create(j.getString(TYPE));
|
||||
if (isSet(condition)) {
|
||||
condition.parent(this);
|
||||
conditions.add(condition.load(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
actions = new ActionList().load(json.getJSONArray(ACTIONS));
|
||||
actions.load(json.getJSONArray(ACTIONS));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
preForm.add(conditionForm());
|
||||
preForm.add(actions.list());
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
actions.list().addTo(fieldset);
|
||||
postForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
|
||||
}
|
||||
@@ -126,7 +133,8 @@ public class ConditionalAction extends Action {
|
||||
String conditionClass = params.get(REALM_CONDITION);
|
||||
Condition condition = Condition.create(conditionClass);
|
||||
if (isNull(condition)) return t("Unknown type of condition: {}",conditionClass);
|
||||
conditions.add(condition.parent(this));
|
||||
condition.parent(this);
|
||||
conditions.add(condition);
|
||||
return super.update(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,23 +6,25 @@ import java.util.List;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class DelayedAction extends Action {
|
||||
|
||||
public DelayedAction(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private static final String ACTIONS = "actions";
|
||||
public static final String DELAY = "delay";
|
||||
private static final int DEFAULT_DELAY = 1000;
|
||||
private int delay = DEFAULT_DELAY;
|
||||
|
||||
private ActionList actions = new ActionList();
|
||||
private ActionList actions;
|
||||
|
||||
public DelayedAction(BaseClass parent) {
|
||||
super(parent);
|
||||
actions = new ActionList(this);
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
@@ -58,15 +60,16 @@ public class DelayedAction extends Action {
|
||||
public DelayedAction load(JSONObject json) {
|
||||
super.load(json);
|
||||
delay = json.getInt(DELAY);
|
||||
if (json.has(ACTIONS)) actions = new ActionList().load(json.getJSONArray(ACTIONS));
|
||||
if (json.has(ACTIONS)) actions.load(json.getJSONArray(ACTIONS));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
|
||||
formInputs.add(t("Delay"),new Input(DELAY,delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
|
||||
postForm.add(actions.list());
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
actions.list().addTo(fieldset);
|
||||
postForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
|
||||
public class DetermineTrainInBlock extends Action {
|
||||
|
||||
public DetermineTrainInBlock(Context parent) {
|
||||
public DetermineTrainInBlock(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
|
||||
public class FinishRoute extends Action {
|
||||
|
||||
public FinishRoute(Context parent) {
|
||||
public FinishRoute(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Range;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
|
||||
public class PreserveRoute extends Action {
|
||||
|
||||
public PreserveRoute(Context parent) {
|
||||
public PreserveRoute(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Command;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
@@ -12,7 +13,7 @@ import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class SendCommand extends Action{
|
||||
|
||||
public SendCommand(Context parent) {
|
||||
public SendCommand(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
|
||||
public class SetContextTrain extends Action {
|
||||
|
||||
public SetContextTrain(Context parent) {
|
||||
public SetContextTrain(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
@@ -12,7 +13,7 @@ import de.srsoftware.web4rail.tiles.TextDisplay;
|
||||
|
||||
public class SetDisplayText extends TextAction{
|
||||
|
||||
public SetDisplayText(Context parent) {
|
||||
public SetDisplayText(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.ControlUnit;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
@@ -13,7 +14,7 @@ import de.srsoftware.web4rail.tags.Radio;
|
||||
|
||||
public class SetPower extends Action{
|
||||
|
||||
public SetPower(Context parent) {
|
||||
public SetPower(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
@@ -12,7 +13,7 @@ import de.srsoftware.web4rail.tiles.Relay;
|
||||
|
||||
public class SetRelay extends Action {
|
||||
|
||||
public SetRelay(Context parent) {
|
||||
public SetRelay(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
@@ -14,7 +15,7 @@ import de.srsoftware.web4rail.tiles.Tile;
|
||||
|
||||
public class SetSignal extends Action {
|
||||
|
||||
public SetSignal(Context parent) {
|
||||
public SetSignal(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,14 @@ import java.util.List;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class SetSpeed extends Action{
|
||||
|
||||
public SetSpeed(Context parent) {
|
||||
public SetSpeed(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public class ShowText extends TextAction{
|
||||
|
||||
|
||||
public ShowText(Context parent) {
|
||||
public ShowText(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
|
||||
public class StopAllTrains extends Action {
|
||||
|
||||
public StopAllTrains(Context parent) {
|
||||
public StopAllTrains(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
|
||||
public class StopAuto extends Action {
|
||||
|
||||
public StopAuto(Context parent) {
|
||||
public StopAuto(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
@@ -12,7 +13,7 @@ import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public abstract class TextAction extends Action {
|
||||
|
||||
public TextAction(Context parent) {
|
||||
public TextAction(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tiles.Contact;
|
||||
|
||||
public class TriggerContact extends Action {
|
||||
|
||||
public TriggerContact(Context parent) {
|
||||
public TriggerContact(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
|
||||
public class TurnTrain extends Action{
|
||||
|
||||
public TurnTrain(Context parent) {
|
||||
public TurnTrain(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,13 @@ public class Contact extends Tile{
|
||||
private boolean state = false;
|
||||
private String trigger = null;
|
||||
private int addr = 0;
|
||||
private ActionList actions = new ActionList();
|
||||
private ActionList actions;
|
||||
private OffTimer timer = null;
|
||||
|
||||
public Contact() {
|
||||
actions = new ActionList(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dieser Timer dient dazu, Merhfachauslösungen eines Kontakes innerhalb einer Sekunde zu unterbinden
|
||||
*
|
||||
@@ -119,7 +123,7 @@ public class Contact extends Tile{
|
||||
@Override
|
||||
public Tile load(JSONObject json) {
|
||||
if (json.has(ADDRESS)) addr(json.getInt(ADDRESS));
|
||||
if (json.has(REALM_ACTIONS)) actions = new ActionList().load(json.getJSONArray(REALM_ACTIONS));
|
||||
if (json.has(REALM_ACTIONS)) actions.load(json.getJSONArray(REALM_ACTIONS));
|
||||
return super.load(json);
|
||||
}
|
||||
|
||||
@@ -155,7 +159,9 @@ public class Contact extends Tile{
|
||||
button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(span);
|
||||
formInputs.add(t("Address"),span);
|
||||
|
||||
postForm.add(actions.list());
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
actions.list().addTo(fieldset);
|
||||
postForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user