overhauled registry
This commit is contained in:
@@ -13,6 +13,7 @@ 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;
|
||||
|
||||
@@ -103,6 +104,10 @@ public abstract class Action extends BaseClass {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties() { // goes up to first ancestor, which is not an Action
|
||||
return parent().properties();
|
||||
}
|
||||
|
||||
public static Tag selector() {
|
||||
Select select = new Select(TYPE);
|
||||
@@ -129,13 +134,6 @@ public abstract class Action extends BaseClass {
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
super.update(params);
|
||||
BaseClass parent = parent();
|
||||
if (isNull(parent)) return properties();
|
||||
if (parent instanceof ActionList) {
|
||||
ActionList al = (ActionList) parent;
|
||||
return al.parent().properties();
|
||||
}
|
||||
return parent.properties();
|
||||
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -18,10 +19,10 @@ import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class ActionList extends Action{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActionList.class);
|
||||
public class ActionList extends Action implements Iterable<Action>{
|
||||
static final Logger LOG = LoggerFactory.getLogger(ActionList.class);
|
||||
|
||||
private Vector<Action> actions;
|
||||
protected Vector<Action> actions;
|
||||
|
||||
public ActionList(BaseClass parent) {
|
||||
super(parent);
|
||||
@@ -51,7 +52,7 @@ public class ActionList extends Action{
|
||||
Action action = Action.create(type,this);
|
||||
if (action instanceof Action) {
|
||||
add(action);
|
||||
return plan.showContext(params);
|
||||
return parent().properties();
|
||||
}
|
||||
actionTypeForm(win,context);
|
||||
new Tag("span").content(t("Unknown action type: {}",type)).addTo(win);
|
||||
@@ -80,15 +81,11 @@ public class ActionList extends Action{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return actions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean drop(Action action) {
|
||||
return actions.remove(action);
|
||||
}
|
||||
|
||||
|
||||
public boolean fire(Context context) {
|
||||
if (!isEmpty()) LOG.debug(t("Firing {}"),this);
|
||||
for (Action action : actions) {
|
||||
@@ -97,6 +94,22 @@ public class ActionList extends Action{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Action> iterator() {
|
||||
return actions.iterator();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return actions.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
String cls = getClass().getSimpleName();
|
||||
throw new UnsupportedOperationException(cls+".json() not supported, use "+cls+".jsonArray instead!");
|
||||
}
|
||||
|
||||
public JSONArray jsonArray() {
|
||||
JSONArray result = new JSONArray();
|
||||
for (Action action : actions) result.put(action.json());
|
||||
@@ -104,7 +117,7 @@ public class ActionList extends Action{
|
||||
}
|
||||
|
||||
public Tag list() {
|
||||
Button button = button(t("Add action"), contextAction(ACTION_ADD_ACTION));
|
||||
Button button = button(t("add action"), contextAction(ACTION_ADD_ACTION));
|
||||
Tag span = new Tag("span");
|
||||
button.addTo(span);
|
||||
|
||||
@@ -116,6 +129,7 @@ public class ActionList extends Action{
|
||||
if (first) {
|
||||
first = false;
|
||||
} else action.button("↑", contextAction(ACTION_MOVE)).addTo(item.content(NBSP));
|
||||
if (action instanceof ActionList) ((ActionList) action).list().addTo(item);
|
||||
item.addTo(list);
|
||||
}
|
||||
list.addTo(span);
|
||||
@@ -160,9 +174,9 @@ public class ActionList extends Action{
|
||||
if (isNull(actionList)) return t("Id ({}) does not belong to ActionList!",actionId);
|
||||
return actionList.addActionForm(params,plan);
|
||||
case ACTION_DROP:
|
||||
return action.drop() ? action.parent().properties() : t("No action with id {} found!",actionId);
|
||||
return action.drop() ? action.properties() : t("No action with id {} found!",actionId);
|
||||
case ACTION_MOVE:
|
||||
return action.moveUp() ? action.parent().properties() : t("No action with id {} found!",actionId);
|
||||
return action.moveUp() ? action.properties() : t("No action with id {} found!",actionId);
|
||||
case ACTION_PROPS:
|
||||
return action.properties();
|
||||
case ACTION_UPDATE:
|
||||
@@ -178,4 +192,9 @@ public class ActionList extends Action{
|
||||
preForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChild(BaseClass child) {
|
||||
actions.remove(child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ public class BrakeCancel extends Action {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,5 +15,9 @@ public class BrakeStart extends Action {
|
||||
LOG.debug("Started brake process...");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ public class BrakeStop extends Action {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,22 +17,16 @@ import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class ConditionalAction extends Action {
|
||||
public class ConditionalAction extends ActionList {
|
||||
|
||||
private static final String CONDITIONS = "conditions";
|
||||
private static final String ACTIONS = "actions";
|
||||
private Vector<Condition> conditions = new Vector<Condition>();
|
||||
private ActionList actions;
|
||||
|
||||
public ConditionalAction(BaseClass parent) {
|
||||
super(parent);
|
||||
actions = new ActionList(this);
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
private StringBuffer conditions() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i<conditions.size(); i++) {
|
||||
@@ -77,7 +71,7 @@ public class ConditionalAction extends Action {
|
||||
for (Condition condition : conditions) {
|
||||
if (!condition.fulfilledBy(context)) return true;
|
||||
}
|
||||
return actions.fire(context.clone()); // actions, that happen within the conditional action list must not modify the global context.
|
||||
return super.fire(context.clone()); // actions, that happen within the conditional action list must not modify the global context.
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +80,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.jsonArray());
|
||||
json.put(ACTIONS, super.jsonArray());
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -103,7 +97,7 @@ public class ConditionalAction extends Action {
|
||||
}
|
||||
}
|
||||
}
|
||||
actions.load(json.getJSONArray(ACTIONS));
|
||||
super.load(json.getJSONArray(ACTIONS));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -111,15 +105,15 @@ public class ConditionalAction extends Action {
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
preForm.add(conditionForm());
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
actions.list().addTo(fieldset);
|
||||
list().addTo(fieldset);
|
||||
postForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
|
||||
}
|
||||
|
||||
public ConditionalAction remove(Condition condition) {
|
||||
conditions.remove(condition);
|
||||
return this;
|
||||
@Override
|
||||
public void removeChild(BaseClass child) {
|
||||
conditions.remove(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,22 +11,16 @@ import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class DelayedAction extends Action {
|
||||
public class DelayedAction extends ActionList {
|
||||
|
||||
|
||||
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;
|
||||
|
||||
public DelayedAction(BaseClass parent) {
|
||||
super(parent);
|
||||
actions = new ActionList(this);
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public boolean equals(DelayedAction other) {
|
||||
@@ -43,7 +37,7 @@ public class DelayedAction extends Action {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warn("Interrupted Exception thrown while waiting:",e);
|
||||
}
|
||||
actions.fire(context);
|
||||
DelayedAction.super.fire(context);
|
||||
};
|
||||
}.start();
|
||||
return true;
|
||||
@@ -53,14 +47,14 @@ public class DelayedAction extends Action {
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
json.put(DELAY, delay);
|
||||
json.put(ACTIONS, actions.jsonArray());
|
||||
json.put(ACTIONS, jsonArray());
|
||||
return json;
|
||||
}
|
||||
|
||||
public DelayedAction load(JSONObject json) {
|
||||
super.load(json);
|
||||
delay = json.getInt(DELAY);
|
||||
if (json.has(ACTIONS)) actions.load(json.getJSONArray(ACTIONS));
|
||||
if (json.has(ACTIONS)) super.load(json.getJSONArray(ACTIONS));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -68,7 +62,7 @@ public class DelayedAction extends Action {
|
||||
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"));
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
actions.list().addTo(fieldset);
|
||||
list().addTo(fieldset);
|
||||
postForm.add(fieldset);
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ public class DetermineTrainInBlock extends Action {
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
if (child == block) block = null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return isSet(block) ? t("Determine, which train is in {}",block) : t("[Click here to select block!]");
|
||||
};
|
||||
|
||||
@@ -15,4 +15,9 @@ public class FinishRoute extends Action {
|
||||
if (isSet(route)) route.finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,5 +29,9 @@ public class PreserveRoute extends Action {
|
||||
train.reserveNext();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,11 @@ public class SendCommand extends Action{
|
||||
formInputs.add(t("Command to send to control unit"),new Input(COMMAND, command));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -12,11 +12,11 @@ import de.srsoftware.web4rail.tags.Fieldset;
|
||||
|
||||
public class SetContextTrain extends Action {
|
||||
|
||||
private Train train = null;
|
||||
|
||||
public SetContextTrain(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private Train train = null;
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
@@ -55,6 +55,11 @@ public class SetContextTrain extends Action {
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
if (child == train) train = null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return isSet(train) ? t("Set {} as context",train) : "["+t("Click here to select train!")+"]";
|
||||
};
|
||||
|
||||
@@ -13,12 +13,12 @@ import de.srsoftware.web4rail.tiles.TextDisplay;
|
||||
|
||||
public class SetDisplayText extends TextAction{
|
||||
|
||||
private TextDisplay display;
|
||||
private static final String DISPLAY = "display";
|
||||
|
||||
public SetDisplayText(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private TextDisplay display;
|
||||
private static final String DISPLAY = "display";
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
@@ -51,6 +51,11 @@ public class SetDisplayText extends TextAction{
|
||||
return super.load(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
if (child == display) display = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(t("Select display"),TextDisplay.selector(display, null));
|
||||
|
||||
@@ -68,6 +68,11 @@ public class SetPower extends Action{
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (pc) {
|
||||
|
||||
@@ -61,6 +61,11 @@ public class SetRelay extends Action {
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
if (child == relay) relay = null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (isNull(relay)) return "["+t("click here to setup relay")+"]";
|
||||
return t("Set {} to {}",relay,state?relay.stateLabelA:relay.stateLabelB);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SetSignal extends Action {
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
Select select = new Select(SIGNAL);
|
||||
for (Signal signal : plan.signals()) {
|
||||
for (Signal signal : BaseClass.listElements(Signal.class)) {
|
||||
Tag option = select.addOption(signal.id(),signal.title());
|
||||
if (signal == this.signal) option.attr("selected", "selected");
|
||||
}
|
||||
@@ -66,6 +66,11 @@ public class SetSignal extends Action {
|
||||
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
if (child == signal) signal = null;
|
||||
}
|
||||
|
||||
public SetSignal set(Signal sig) {
|
||||
signal = sig;
|
||||
|
||||
@@ -46,6 +46,11 @@ public class SetSpeed extends Action{
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return t("Set speed to {} {}",speed,speedUnit);
|
||||
|
||||
@@ -21,6 +21,11 @@ public class ShowText extends TextAction{
|
||||
return new Label(t("Text to display on clients:")+NBSP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return t("Display \"{}\" on clients.",text);
|
||||
|
||||
@@ -14,4 +14,9 @@ public class StopAllTrains extends Action {
|
||||
Train.list().forEach(train -> train.stopNow());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ public class StopAuto extends Action {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ public class TriggerContact extends Action {
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
if (child == contact) contact = null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return isSet(contact) ? t("Trigger {}",contact) : "["+t("click here to setup contact")+"]";
|
||||
};
|
||||
|
||||
@@ -16,4 +16,9 @@ public class TurnTrain extends Action{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeChild(BaseClass child) {
|
||||
// this class has no child elements
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user