updating 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.3</version>
|
||||
<version>1.2.4</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;
|
||||
|
||||
public static class Context {
|
||||
|
||||
@@ -331,20 +331,8 @@ public abstract class BaseClass implements Constants{
|
||||
return win;
|
||||
}
|
||||
|
||||
public Map<String,String> props(Map<String,String> additionalProps){
|
||||
String realm = null;
|
||||
if (this instanceof Tile) realm = REALM_PLAN;
|
||||
if (this instanceof Contact) realm = REALM_CONTACT;
|
||||
|
||||
if (this instanceof Car) realm = REALM_CAR;
|
||||
if (this instanceof Locomotive) realm = REALM_LOCO;
|
||||
|
||||
if (this instanceof Train) realm = REALM_TRAIN;
|
||||
if (this instanceof Route) realm = REALM_ROUTE;
|
||||
if (this instanceof Action) realm = REALM_ACTIONS;
|
||||
if (this instanceof Condition) realm = REALM_CONDITION;
|
||||
|
||||
HashMap<String,String> props = new HashMap<String, String>(Map.of(REALM, realm, ACTION, ACTION_PROPS, ID, id().toString()));
|
||||
private Map<String,String> props(Map<String,String> additionalProps){
|
||||
HashMap<String,String> props = new HashMap<String, String>(Map.of(REALM, realm(), ACTION, ACTION_PROPS, ID, id().toString()));
|
||||
if (isSet(additionalProps)) props.putAll(additionalProps);
|
||||
return props;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public interface Constants {
|
||||
public static final String NBSP = " ";
|
||||
public static final String NOTES = "notes";
|
||||
public static final String PORT = "port";
|
||||
public static final String RELAY = "relay";
|
||||
public static final String TYPE = "type";
|
||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
}
|
||||
|
||||
@@ -807,7 +807,7 @@ public class Plan extends BaseClass{
|
||||
return isNull(tile) ? null : tile.properties();
|
||||
case REALM_ACTIONS:
|
||||
Action action = Action.get(id);
|
||||
return (isSet(action)) ? action.properties(params) : null;
|
||||
return (isSet(action)) ? action.properties() : null;
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -258,11 +258,11 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
Tag list = new Tag("ol");
|
||||
|
||||
Tag setup = new Tag("li").content(t("Setup actions")+NBSP);
|
||||
setupActions.addTo(setup, context());
|
||||
setupActions.list().addTo(setup);
|
||||
setup.addTo(list);
|
||||
|
||||
Tag start = new Tag("li").content(t("Start actions")+NBSP);
|
||||
startActions.addTo(start, context());
|
||||
startActions.list().addTo(setup);
|
||||
start.addTo(list);
|
||||
|
||||
for (Contact c : contacts) {
|
||||
@@ -272,7 +272,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
actions = new ActionList();
|
||||
triggers.put(c.trigger(), actions);
|
||||
}
|
||||
actions.addTo(link,context());
|
||||
actions.list().addTo(link);
|
||||
}
|
||||
list.addTo(win);
|
||||
return win;
|
||||
@@ -371,20 +371,21 @@ 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());
|
||||
add(trigger,new PreserveRoute());
|
||||
for (Signal signal : signals) add(trigger,new SetSignal().set(signal).to(Signal.STOP));
|
||||
add(trigger,new BrakeStart(parent));
|
||||
add(trigger,new PreserveRoute(parent));
|
||||
for (Signal signal : signals) add(trigger,new SetSignal(parent).set(signal).to(Signal.STOP));
|
||||
}
|
||||
if (!contacts.isEmpty()) {
|
||||
Contact lastContact = contacts.lastElement();
|
||||
add(lastContact.trigger(), new BrakeStop());
|
||||
add(lastContact.trigger(), new FinishRoute());
|
||||
add(lastContact.trigger(), new BrakeStop(parent));
|
||||
add(lastContact.trigger(), new FinishRoute(parent));
|
||||
}
|
||||
for (Signal signal : signals) setupActions.add(new SetSignal().set(signal).to(Signal.GO));
|
||||
startActions.add(new SetSpeed().to(999));
|
||||
for (Signal signal : signals) setupActions.add(new SetSignal(parent).set(signal).to(Signal.GO));
|
||||
startActions.add(new SetSpeed(parent).to(999));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -512,7 +513,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
||||
JSONObject trigger = new JSONObject();
|
||||
trigger.put(TRIGGER, entry.getKey());
|
||||
ActionList actionList = entry.getValue();
|
||||
trigger.put(ACTIONS, actionList.json());
|
||||
trigger.put(ACTIONS, actionList.jsonArray());
|
||||
|
||||
jTriggers.put(trigger);
|
||||
|
||||
@@ -565,8 +566,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 = ActionList.load(json.getJSONArray(SETUP_ACTIONS));
|
||||
if (json.has(START_ACTIONS)) startActions = ActionList.load(json.getJSONArray(START_ACTIONS));
|
||||
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(DISABLED)) disabled = json.getBoolean(DISABLED);
|
||||
if (json.has(BRAKE_TIMES)) {
|
||||
JSONObject dummy = json.getJSONObject(BRAKE_TIMES);
|
||||
@@ -579,7 +580,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 = ActionList.load(json.getJSONArray(ACTIONS));
|
||||
ActionList actionList = new ActionList().load(json.getJSONArray(ACTIONS));
|
||||
triggers.put(trigger, actionList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Application;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
|
||||
@@ -27,13 +26,14 @@ 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() {
|
||||
public Action(Context parent) {
|
||||
actions.put(id(), this);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public static Action create(String type) {
|
||||
public static Action create(String type,Context parent) {
|
||||
try {
|
||||
return (Action) Class.forName(PREFIX+"."+type).getDeclaredConstructor().newInstance();
|
||||
return (Action) Class.forName(PREFIX+"."+type).getDeclaredConstructor(Context.class).newInstance(parent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -96,10 +96,6 @@ public abstract class Action extends BaseClass {
|
||||
return select.addTo(new Label(t("Action type:")+NBSP));
|
||||
}
|
||||
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
return new Window("action-props-"+id, t("Properties of {}",this.getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
protected static String t(String tex,Object...fills) {
|
||||
return Translation.get(Application.class, tex, fills);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,8 @@ import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Application;
|
||||
import de.srsoftware.web4rail.BaseClass.Context;
|
||||
import de.srsoftware.web4rail.BaseClass.Id;
|
||||
import de.srsoftware.web4rail.Constants;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
@@ -23,16 +19,18 @@ import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class ActionList extends Vector<Action> implements Constants{
|
||||
public class ActionList extends BaseClass{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActionList.class);
|
||||
|
||||
private static final long serialVersionUID = 4862000041987682112L;
|
||||
private static final HashMap<Id, ActionList> actionLists = new HashMap<Id, ActionList>();
|
||||
private Vector<Action> actions;
|
||||
private Id id;
|
||||
|
||||
public ActionList() {
|
||||
id = new Id();
|
||||
actions = new Vector<Action>();
|
||||
actionLists.put(id,this);
|
||||
|
||||
}
|
||||
|
||||
private static Id actionId(HashMap<String, String> params) {
|
||||
@@ -58,13 +56,18 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
return new Button(t("Create action"),typeForm).addTo(typeForm).addTo(win);
|
||||
}
|
||||
|
||||
public ActionList add(Action action) {
|
||||
actions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
private Object addActionForm(HashMap<String, String> params, Plan plan) {
|
||||
Window win = new Window("add-action-form", t("Add action to action list"));
|
||||
String type = params.get(TYPE);
|
||||
String context = params.get(CONTEXT);
|
||||
if (type == null) return actionTypeForm(win,context);
|
||||
|
||||
Action action = Action.create(type);
|
||||
Context parent = new Context(this);
|
||||
Action action = Action.create(type,parent);
|
||||
if (action instanceof Action) {
|
||||
add(action);
|
||||
return plan.showContext(params);
|
||||
@@ -75,12 +78,12 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
}
|
||||
|
||||
public void addActionsFrom(ActionList other) {
|
||||
for (Action otherAction : other) {
|
||||
for (Action otherAction : other.actions) {
|
||||
//LOG.debug("old action ({}): {}",otherAction.getClass().getSimpleName(),otherAction);
|
||||
boolean exists = false;
|
||||
int len = this.size();
|
||||
int len = actions.size();
|
||||
for (int i=0; i<len; i++) {
|
||||
Action thisAction = this.get(i);
|
||||
Action thisAction = actions.get(i);
|
||||
LOG.debug("→ {} ?",thisAction);
|
||||
if (thisAction.equals(otherAction)) {
|
||||
LOG.debug("Action already existing!");
|
||||
@@ -97,52 +100,14 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
}
|
||||
}
|
||||
|
||||
public void addTo(Tag link, String context) {
|
||||
Map<String, Object> props = new HashMap<String, Object>(Map.of(
|
||||
REALM,REALM_ACTIONS,
|
||||
ID,id,
|
||||
ACTION,ACTION_ADD,
|
||||
CONTEXT,context));
|
||||
new Button(t("add action"),props).addTo(link);
|
||||
|
||||
props.put(ACTION,ACTION_PROPS);
|
||||
if (!isEmpty()) {
|
||||
Tag ul = new Tag("ol");
|
||||
boolean first = true;
|
||||
for (Action action : this) {
|
||||
props.put(ID, id+"/"+action.id());
|
||||
Tag act = action.link("span", action+NBSP, Map.of(CONTEXT,context,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);
|
||||
if (action instanceof ConditionalAction) {
|
||||
ConditionalAction ca = (ConditionalAction) action;
|
||||
ca.children().addTo(act, context);
|
||||
}
|
||||
if (action instanceof DelayedAction) {
|
||||
DelayedAction da = (DelayedAction) action;
|
||||
da.children().addTo(act, context);
|
||||
}
|
||||
act.addTo(ul);
|
||||
first = false;
|
||||
}
|
||||
ul.addTo(link);
|
||||
}
|
||||
}
|
||||
|
||||
public Fieldset properties() {
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
new Tag("p").content("replace ActionList.addTo(...) by ActionsList.properties()!").addTo(fieldset);
|
||||
return fieldset;
|
||||
public boolean isEmpty() {
|
||||
return actions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean drop(Id actionId) {
|
||||
for (Action action : this) {
|
||||
for (Action action : actions) {
|
||||
if (action.id().equals(actionId)) {
|
||||
this.remove(action);
|
||||
actions.remove(action);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -151,7 +116,7 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
|
||||
public boolean fire(Context context) {
|
||||
if (!isEmpty()) LOG.debug(t("Firing {}"),this);
|
||||
for (Action action : this) {
|
||||
for (Action action : actions) {
|
||||
if (!action.fire(context)) return false;
|
||||
}
|
||||
return true;
|
||||
@@ -161,29 +126,59 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
return id;
|
||||
}
|
||||
|
||||
public JSONArray json() {
|
||||
public JSONArray jsonArray() {
|
||||
JSONArray result = new JSONArray();
|
||||
for (Action action : this) result.put(action.json());
|
||||
for (Action action : actions) result.put(action.json());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ActionList load(JSONArray list) {
|
||||
ActionList actionList = new ActionList();
|
||||
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));
|
||||
|
||||
if (!isEmpty()) {
|
||||
Tag ul = 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;
|
||||
}
|
||||
ul.addTo(fieldset);
|
||||
}
|
||||
|
||||
return fieldset;
|
||||
}
|
||||
|
||||
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));
|
||||
if (action != null) actionList.add(action.load(json));
|
||||
Action action = Action.create(json.getString(TYPE),parent);
|
||||
if (action != null) add(action.load(json));
|
||||
}
|
||||
}
|
||||
return actionList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean moveUp(Id actionId) {
|
||||
for (int i=1; i<size(); i++) {
|
||||
if (actionId.equals(elementAt(i).id())) {
|
||||
Action action = remove(i);
|
||||
insertElementAt(action, i-1);
|
||||
for (int i=1; i<actions.size(); i++) {
|
||||
if (actionId.equals(actions.elementAt(i).id())) {
|
||||
Action action = actions.remove(i);
|
||||
actions.insertElementAt(action, i-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -207,24 +202,20 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
return actionList.drop(actionId) ? plan.showContext(params) : t("No action with id {} found!",actionId);
|
||||
case ACTION_MOVE:
|
||||
return actionList.moveUp(actionId) ? plan.showContext(params) : t("No action with id {} found!",actionId);
|
||||
case ACTION_PROPS:
|
||||
return propsOf(params);
|
||||
case ACTION_UPDATE:
|
||||
return update(actionId,params,plan);
|
||||
}
|
||||
return t("Unknown action: {}",action);
|
||||
}
|
||||
|
||||
private static Object propsOf(HashMap<String, String> params) {
|
||||
Id actionId = actionId(params);
|
||||
Action action = Action.get(actionId);
|
||||
if (action != null) return action.properties(params);
|
||||
return t("No action with id {} found!",actionId);
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
list().addTo(fieldset);
|
||||
preForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
private static String t(String text,Object...fills) {
|
||||
return Translation.get(Application.class, text, fills);
|
||||
}
|
||||
|
||||
private static Object update(Id actionId, HashMap<String, String> params, Plan plan) {
|
||||
Action action = Action.get(actionId);
|
||||
|
||||
@@ -2,6 +2,10 @@ package de.srsoftware.web4rail.actions;
|
||||
|
||||
public class BrakeCancel extends Action {
|
||||
|
||||
public BrakeCancel(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
if (isNull(context.route())) return false;
|
||||
|
||||
@@ -2,6 +2,10 @@ package de.srsoftware.web4rail.actions;
|
||||
|
||||
public class BrakeStart extends Action {
|
||||
|
||||
public BrakeStart(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
if (isNull(context.route())) return false;
|
||||
|
||||
@@ -2,6 +2,10 @@ package de.srsoftware.web4rail.actions;
|
||||
|
||||
public class BrakeStop extends Action {
|
||||
|
||||
public BrakeStop(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
if (isNull(context.route())) return false;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -17,17 +18,15 @@ 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 Tag actionsForm(HashMap<String, String> params) {
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
actions.addTo(fieldset, params.get(CONTEXT));
|
||||
return fieldset;
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
@@ -41,15 +40,14 @@ public class ConditionalAction extends Action {
|
||||
return sb;
|
||||
}
|
||||
|
||||
private Tag conditionForm(HashMap<String, String> params) {
|
||||
private Fieldset conditionForm() {
|
||||
Fieldset fieldset = new Fieldset(t("Conditions"));
|
||||
String context = params.get(CONTEXT);
|
||||
|
||||
new Tag("p").content(t("Actions will only fire, if all conditions are fullfilled.")).addTo(fieldset);
|
||||
if (!conditions.isEmpty()) {
|
||||
Tag list = new Tag("ul");
|
||||
for (Condition condition : conditions) {
|
||||
Tag li = link("span", condition+NBSP,Map.of(CONTEXT,context)).addTo(new Tag("li"));
|
||||
Tag li = link("span", condition+NBSP,Map.of()).addTo(new Tag("li"));
|
||||
HashMap<String,Object> props = new HashMap<String, Object>(Map.of(REALM,REALM_CONDITION,ID,condition.id(),ACTION,ACTION_DROP,CONTEXT, REALM_ACTIONS+":"+id()));
|
||||
new Button(t("delete"), props).addTo(li).addTo(list);
|
||||
}
|
||||
@@ -58,14 +56,14 @@ public class ConditionalAction extends Action {
|
||||
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ID,id()).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,context).hideIn(form);
|
||||
|
||||
Condition.selector().addTo(form);
|
||||
|
||||
new Button(t("Add condition"),form).addTo(form);
|
||||
return button(t("Back")).addTo(form).addTo(fieldset);
|
||||
button(t("Back")).addTo(form).addTo(fieldset);
|
||||
return fieldset;
|
||||
}
|
||||
|
||||
public boolean equals(ConditionalAction other) {
|
||||
@@ -86,7 +84,7 @@ public class ConditionalAction extends Action {
|
||||
JSONArray conditions = new JSONArray();
|
||||
for (Condition condition : this.conditions) conditions.put(condition.json());
|
||||
json.put(CONDITIONS, conditions);
|
||||
json.put(ACTIONS, actions.json());
|
||||
json.put(ACTIONS, actions.jsonArray());
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -100,16 +98,16 @@ public class ConditionalAction extends Action {
|
||||
if (isSet(condition)) conditions.add(condition.parent(this).load(j));
|
||||
}
|
||||
}
|
||||
actions = ActionList.load(json.getJSONArray(ACTIONS));
|
||||
actions = new ActionList().load(json.getJSONArray(ACTIONS));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
conditionForm(params).addTo(win);
|
||||
actionsForm(params).addTo(win);
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
preForm.add(conditionForm());
|
||||
preForm.add(actions.list());
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
|
||||
}
|
||||
|
||||
public ConditionalAction remove(Condition condition) {
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
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;
|
||||
@@ -21,29 +23,10 @@ public class DelayedAction extends Action {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
private Tag delayForm(HashMap<String, String> params) {
|
||||
Fieldset fieldset = new Fieldset(t("Delay"));
|
||||
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
|
||||
new Input(DELAY,delay).numeric().addTo(new Label(t("Delay")+NBSP)).content(NBSP+"ms").addTo(form);
|
||||
return new Button(t("Apply"),form).addTo(form).addTo(fieldset);
|
||||
}
|
||||
|
||||
public boolean equals(DelayedAction other) {
|
||||
return (delay+":"+actions).equals(other.delay+":"+other.actions);
|
||||
}
|
||||
@@ -68,23 +51,23 @@ public class DelayedAction extends Action {
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
json.put(DELAY, delay);
|
||||
json.put(ACTIONS, actions.json());
|
||||
json.put(ACTIONS, actions.jsonArray());
|
||||
return json;
|
||||
}
|
||||
|
||||
public DelayedAction load(JSONObject json) {
|
||||
super.load(json);
|
||||
delay = json.getInt(DELAY);
|
||||
if (json.has(ACTIONS)) actions = ActionList.load(json.getJSONArray(ACTIONS));
|
||||
if (json.has(ACTIONS)) actions = new ActionList().load(json.getJSONArray(ACTIONS));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
delayForm(params).addTo(win);
|
||||
actionsForm(params).addTo(win);
|
||||
return win;
|
||||
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());
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,7 +83,7 @@ public class DelayedAction extends Action {
|
||||
if (ms < 0) throw new NumberFormatException(t("Delay must not be less than zero!"));
|
||||
delay = ms;
|
||||
} catch (NumberFormatException nfe) {
|
||||
Window props = properties(params);
|
||||
Window props = properties();
|
||||
props.children().insertElementAt(new Tag("div").content(nfe.getMessage()), 2);
|
||||
return props;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.Window;
|
||||
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.Select;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
|
||||
public class DetermineTrainInBlock extends Action {
|
||||
|
||||
public DetermineTrainInBlock(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private Block block = null;
|
||||
|
||||
@Override
|
||||
@@ -39,19 +40,9 @@ public class DetermineTrainInBlock extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
|
||||
Select select = Block.selector(block, null);
|
||||
select.addTo(new Label(t("Select block:")+NBSP)).addTo(form);
|
||||
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Select block"),Block.selector(block, null));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -63,6 +54,6 @@ public class DetermineTrainInBlock extends Action {
|
||||
LOG.debug("update: {}",params);
|
||||
Id blockId = Id.from(params,Block.class.getSimpleName());
|
||||
if (isSet(blockId)) block = Block.get(blockId);
|
||||
return properties(params);
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import de.srsoftware.web4rail.Route;
|
||||
|
||||
public class FinishRoute extends Action {
|
||||
|
||||
public FinishRoute(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
Route route = context.route();
|
||||
|
||||
@@ -6,6 +6,10 @@ import de.srsoftware.web4rail.moving.Train;
|
||||
|
||||
public class PreserveRoute extends Action {
|
||||
|
||||
public PreserveRoute(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
Train train = context.train();
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Command;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public class SendCommand extends Action{
|
||||
|
||||
public SendCommand(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public static final String COMMAND = "command";
|
||||
private String command = "SET 1 POWER OFF";
|
||||
|
||||
@@ -46,17 +48,9 @@ public class SendCommand extends Action{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
Label label = new Label(t("Command to send to control unit:")+NBSP);
|
||||
new Input(COMMAND, command).addTo(label).addTo(form);
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Command to send to control unit"),new Input(COMMAND, command));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,9 +61,7 @@ public class SendCommand extends Action{
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
LOG.debug("update: {}",params);
|
||||
String error = null;
|
||||
command = params.get(COMMAND);
|
||||
Window win = properties(params);
|
||||
return new Tag("span").content(error).addTo(win);
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.Window;
|
||||
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.Select;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
|
||||
public class SetContextTrain extends Action {
|
||||
|
||||
public SetContextTrain(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private Train train = null;
|
||||
|
||||
@Override
|
||||
@@ -46,20 +47,11 @@ public class SetContextTrain extends Action {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
|
||||
Select select = Train.selector(train, null);
|
||||
select.addTo(new Label(t("Select train:")+NBSP)).addTo(form);
|
||||
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Select train"),Train.selector(train, null));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -71,7 +63,7 @@ public class SetContextTrain extends Action {
|
||||
LOG.debug("update: {}",params);
|
||||
Id trainId = Id.from(params,Train.class.getSimpleName());
|
||||
if (isSet(trainId)) train = Train.get(trainId);
|
||||
return properties(params);
|
||||
return properties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
import de.srsoftware.web4rail.tiles.TextDisplay;
|
||||
|
||||
public class SetDisplayText extends TextAction{
|
||||
|
||||
public SetDisplayText(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private TextDisplay display;
|
||||
private static final String DISPLAY = "display";
|
||||
|
||||
@@ -48,19 +51,9 @@ public class SetDisplayText extends TextAction{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
|
||||
Select select = TextDisplay.selector(display, null);
|
||||
Tag label = select.addTo(new Label(t("Select display:")+NBSP));
|
||||
|
||||
for (Tag tag : win.children()) {
|
||||
if (tag instanceof Form) {
|
||||
tag.children().insertElementAt(label, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Select display"),TextDisplay.selector(display, null));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,6 +66,6 @@ public class SetDisplayText extends TextAction{
|
||||
super.update(params);
|
||||
String displayId = params.get(TextDisplay.class.getSimpleName());
|
||||
if (isSet(displayId)) display = (TextDisplay) plan.get(new Id(displayId), false);
|
||||
return properties(params);
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.ControlUnit;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Radio;
|
||||
|
||||
public class SetPower extends Action{
|
||||
|
||||
public SetPower(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private static final String STATE = "state";
|
||||
private POWERCHANGE pc = POWERCHANGE.OFF;
|
||||
|
||||
@@ -54,20 +57,14 @@ public class SetPower extends Action{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
Tag div = new Tag("div");
|
||||
new Radio(STATE, POWERCHANGE.ON, t("On"), pc == POWERCHANGE.ON).addTo(div);
|
||||
new Radio(STATE, POWERCHANGE.OFF, t("Off"), pc == POWERCHANGE.OFF).addTo(div);
|
||||
new Radio(STATE, POWERCHANGE.TOGGLE, t("Toggle"), pc == POWERCHANGE.TOGGLE).addTo(div);
|
||||
formInputs.add(t("Set state to"),div);
|
||||
|
||||
new Radio(STATE, POWERCHANGE.ON, t("On"), pc == POWERCHANGE.ON).addTo(form);
|
||||
new Radio(STATE, POWERCHANGE.OFF, t("Off"), pc == POWERCHANGE.OFF).addTo(form);
|
||||
new Radio(STATE, POWERCHANGE.TOGGLE, t("Toggle"), pc == POWERCHANGE.TOGGLE).addTo(form);
|
||||
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,12 +80,10 @@ public class SetPower extends Action{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
protected Window update(HashMap<String, String> params) {
|
||||
LOG.debug("update: {}",params);
|
||||
String error = null;
|
||||
String newState = params.get(STATE);
|
||||
if (isSet(newState)) pc = POWERCHANGE.valueOf(newState);
|
||||
Window win = properties(params);
|
||||
return new Tag("span").content(error).addTo(win);
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
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.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
import de.srsoftware.web4rail.tiles.Relay;
|
||||
|
||||
public class SetRelay extends Action {
|
||||
|
||||
private static final String RELAY = "relay";
|
||||
public SetRelay(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private Relay relay = null;
|
||||
private boolean state = false;
|
||||
|
||||
@@ -48,29 +48,16 @@ public class SetRelay extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
|
||||
Select select = new Select(RELAY);
|
||||
for (Relay relay : Relay.list()) {
|
||||
Tag option = select.addOption(relay.id(),relay.title());
|
||||
if (relay == this.relay) option.attr("selected", "selected");
|
||||
}
|
||||
select.addTo(new Label(t("Select relay:")+NBSP)).addTo(form);
|
||||
formInputs.add(t("Select relay"),Relay.selector(relay,null));
|
||||
|
||||
Select state = new Select(Relay.STATE);
|
||||
state.addOption(true,isNull(relay)?Relay.DEFAULT_LABEL_A:relay.stateLabelA);
|
||||
state.addOption(false,isNull(relay)?Relay.DEFAULT_LABEL_B:relay.stateLabelB);
|
||||
state.addTo(new Label(t("Select state:")+NBSP)).addTo(form);
|
||||
formInputs.add(t("Select state"),state);
|
||||
|
||||
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -85,6 +72,6 @@ public class SetRelay extends Action {
|
||||
relay = Relay.get(relayId);
|
||||
String st = params.get(Relay.STATE);
|
||||
if (isSet(st)) state = st.equals("true");
|
||||
return properties(params);
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
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.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
import de.srsoftware.web4rail.tiles.Signal;
|
||||
import de.srsoftware.web4rail.tiles.Tile;
|
||||
|
||||
public class SetSignal extends Action {
|
||||
|
||||
public SetSignal(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private static final String SIGNAL = "signal";
|
||||
private Signal signal = null;
|
||||
private String state = Signal.STOP;
|
||||
@@ -46,31 +48,22 @@ public class SetSignal extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
Select select = new Select(SIGNAL);
|
||||
for (Signal signal : plan.signals()) {
|
||||
Tag option = select.addOption(signal.id(),signal.title());
|
||||
if (signal == this.signal) option.attr("selected", "selected");
|
||||
}
|
||||
select.addTo(new Label(t("Select signal:")+NBSP)).addTo(form);
|
||||
formInputs.add(t("Select signal"),select);
|
||||
|
||||
Select state = new Select(Signal.STATE);
|
||||
for (String st:Signal.knownStates) {
|
||||
Tag option = state.addOption(st);
|
||||
if (st.equals(this.state)) option.attr("selected", "selected");
|
||||
}
|
||||
state.addTo(new Label(t("Select state:")+NBSP)).addTo(form);
|
||||
formInputs.add(t("Select state"),state);
|
||||
|
||||
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
public SetSignal set(Signal sig) {
|
||||
@@ -95,7 +88,7 @@ public class SetSignal extends Action {
|
||||
if (tile instanceof Signal) signal = (Signal) tile;
|
||||
String st = params.get(Signal.STATE);
|
||||
if (isSet(st)) state = st;
|
||||
return properties(params);
|
||||
return properties();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public class SetSpeed extends Action{
|
||||
|
||||
public SetSpeed(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public static final String MAX_SPEED = "max_speed";
|
||||
private int speed = 0;
|
||||
|
||||
@@ -38,18 +41,9 @@ public class SetSpeed extends Action{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
Label label = new Label(t("Set speed to")+NBSP);
|
||||
new Input(MAX_SPEED, speed).numeric().addTo(label).content(NBSP+speedUnit);
|
||||
label.addTo(form);
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Set speed to"),new Input(MAX_SPEED, speed).numeric());
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,7 +75,7 @@ public class SetSpeed extends Action{
|
||||
error = t("Not a valid number!");
|
||||
}
|
||||
}
|
||||
Window win = properties(params);
|
||||
Window win = properties();
|
||||
return new Tag("span").content(error).addTo(win);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ import de.srsoftware.web4rail.tags.Label;
|
||||
public class ShowText extends TextAction{
|
||||
|
||||
|
||||
public ShowText(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
plan.stream(fill(text,context));
|
||||
|
||||
@@ -4,6 +4,10 @@ import de.srsoftware.web4rail.moving.Train;
|
||||
|
||||
public class StopAllTrains extends Action {
|
||||
|
||||
public StopAllTrains(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
Train.list().forEach(train -> train.stopNow());
|
||||
|
||||
@@ -2,6 +2,10 @@ package de.srsoftware.web4rail.actions;
|
||||
|
||||
public class StopAuto extends Action {
|
||||
|
||||
public StopAuto(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
if (isNull(context.train())) return false;
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public abstract class TextAction extends Action {
|
||||
|
||||
public TextAction(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public static final String TEXT = "text";
|
||||
protected String text = "Hello, world!";
|
||||
|
||||
@@ -42,24 +45,15 @@ public abstract class TextAction extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
new Input(TEXT, text).addTo(label()).addTo(form);
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Text"),new Input(TEXT, text));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
LOG.debug("update: {}",params);
|
||||
String error = null;
|
||||
text = params.get(TEXT);
|
||||
Window win = properties(params);
|
||||
return new Tag("span").content(error).addTo(win);
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.Window;
|
||||
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.Select;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tiles.Contact;
|
||||
|
||||
public class TriggerContact extends Action {
|
||||
|
||||
public TriggerContact(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private Contact contact = null;
|
||||
|
||||
@Override
|
||||
@@ -38,19 +39,9 @@ public class TriggerContact extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
Window win = super.properties(params);
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,params.get(ID)).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||
|
||||
Select select = Contact.selector(contact);
|
||||
select.addTo(new Label(t("Select contact:")+NBSP)).addTo(form);
|
||||
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Select contact"),Contact.selector(contact));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -62,7 +53,7 @@ public class TriggerContact extends Action {
|
||||
LOG.debug("update: {}",params);
|
||||
Id contactId = Id.from(params,CONTACT);
|
||||
if (isSet(contactId)) contact = Contact.get(contactId);
|
||||
return properties(params);
|
||||
return properties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package de.srsoftware.web4rail.actions;
|
||||
|
||||
public class TurnTrain extends Action{
|
||||
|
||||
public TurnTrain(Context parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
if (context.train() != null) {
|
||||
|
||||
@@ -119,7 +119,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 = ActionList.load(json.getJSONArray(REALM_ACTIONS));
|
||||
if (json.has(REALM_ACTIONS)) actions = new ActionList().load(json.getJSONArray(REALM_ACTIONS));
|
||||
return super.load(json);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class Contact extends Tile{
|
||||
button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(span);
|
||||
formInputs.add(t("Address"),span);
|
||||
|
||||
postForm.add(actions.properties());
|
||||
postForm.add(actions.list());
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@@ -18,6 +19,7 @@ import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Radio;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
|
||||
public class Relay extends Tile implements Device{
|
||||
public static final String STATE = "state";
|
||||
@@ -240,4 +242,16 @@ public class Relay extends Tile implements Device{
|
||||
public static Relay get(Id relayId) {
|
||||
return relays.get(relayId);
|
||||
}
|
||||
|
||||
public static Select selector(Relay preselected, Collection<Relay> exclude) {
|
||||
if (isNull(exclude)) exclude = new Vector<Relay>();
|
||||
Select select = new Select(Relay.class.getSimpleName());
|
||||
new Tag("option").attr("value","0").content(t("unset")).addTo(select);
|
||||
for (Relay relay : Relay.list()) {
|
||||
if (exclude.contains(relay)) continue;
|
||||
Tag opt = select.addOption(relay.id, relay);
|
||||
if (relay == preselected) opt.attr("selected", "selected");
|
||||
}
|
||||
return select;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user