extended SendCommand action, added SavePlan action
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.2.28</version>
|
<version>1.2.29</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
|||||||
click here to setup relay : Hier klicken, um Relais einzurichten
|
click here to setup relay : Hier klicken, um Relais einzurichten
|
||||||
click here to setup turnout : Hier klicken, um Weiche einzurichten
|
click here to setup turnout : Hier klicken, um Weiche einzurichten
|
||||||
Click on a name to edit the entry. : Klicke auf einen Namen, um einen Eintrag zu bearbeiten.
|
Click on a name to edit the entry. : Klicke auf einen Namen, um einen Eintrag zu bearbeiten.
|
||||||
Command to send to control unit\: : Kommando, welches zur Zentrale gesendet werden soll:
|
Command to send : Kommando, welches gesendet werden soll
|
||||||
ConditionalAction : bedingte Aktion
|
ConditionalAction : bedingte Aktion
|
||||||
Conditions : Bedingungen
|
Conditions : Bedingungen
|
||||||
Condition type\: : Bedingungs-Typ:
|
Condition type\: : Bedingungs-Typ:
|
||||||
@@ -134,6 +134,7 @@ On : An
|
|||||||
One of : eine von
|
One of : eine von
|
||||||
One way : Richtung
|
One way : Richtung
|
||||||
Online Documentation : Online-Dokumentation
|
Online Documentation : Online-Dokumentation
|
||||||
|
Operating System : Betriebssystem
|
||||||
or : oder
|
or : oder
|
||||||
OrCondition : Oder-Bedingung
|
OrCondition : Oder-Bedingung
|
||||||
other train properties : andere Zug-Eigenschaften
|
other train properties : andere Zug-Eigenschaften
|
||||||
@@ -155,6 +156,7 @@ Right port\: : Port für rechts
|
|||||||
Routes using this tile : Fahrstraßen, die diesen Abschnitt verwenden
|
Routes using this tile : Fahrstraßen, die diesen Abschnitt verwenden
|
||||||
Route will only be available, if all conditions are fulfilled. : Route ist nur verfügbar, wenn alle Bedingungen erfüllt sind.
|
Route will only be available, if all conditions are fulfilled. : Route ist nur verfügbar, wenn alle Bedingungen erfüllt sind.
|
||||||
Save : speichern
|
Save : speichern
|
||||||
|
SavePlan : Plan speichern
|
||||||
Select block : Block auswählen
|
Select block : Block auswählen
|
||||||
Select contact\: : Kotakt auswählen:
|
Select contact\: : Kotakt auswählen:
|
||||||
Select display : Anzeige auswählen
|
Select display : Anzeige auswählen
|
||||||
@@ -163,7 +165,8 @@ Select relay\: : Relais auswählen:
|
|||||||
Select train : Zug auswählen
|
Select train : Zug auswählen
|
||||||
Select turnout : Weiche wählen
|
Select turnout : Weiche wählen
|
||||||
SendCommand : Kommando senden
|
SendCommand : Kommando senden
|
||||||
Send command "{}" to control unit : Kommando „{}“ an Zentrale senden
|
Send command "{}" to {} : Kommando „{}“ an {} senden
|
||||||
|
Send command to : Kommando senden an
|
||||||
Set {} as context : {} als Kontext setzen
|
Set {} as context : {} als Kontext setzen
|
||||||
SetContextTrain : Zug für Folgeaktionen festlegen
|
SetContextTrain : Zug für Folgeaktionen festlegen
|
||||||
SetDisplayText : Anzeige-Text setzen
|
SetDisplayText : Anzeige-Text setzen
|
||||||
@@ -184,6 +187,8 @@ Simulating movement of {}... : Simuliere Fahrt von {}...
|
|||||||
Slower (10 {}) : 10 {} langsamer
|
Slower (10 {}) : 10 {} langsamer
|
||||||
SOUTH : Süden
|
SOUTH : Süden
|
||||||
Speed unit : Geschwindigkeits-Einheit
|
Speed unit : Geschwindigkeits-Einheit
|
||||||
|
SRCP : SRCP-Dienst
|
||||||
|
SRCP daemon : SRCP-Dienst
|
||||||
Start actions : Start-Aktionen
|
Start actions : Start-Aktionen
|
||||||
Stock ID : Inventarnummer
|
Stock ID : Inventarnummer
|
||||||
Stop settings : Halte-Einstellungen
|
Stop settings : Halte-Einstellungen
|
||||||
@@ -199,6 +204,7 @@ Straight port\: : Port für gerade
|
|||||||
STRAIGHT : gerade
|
STRAIGHT : gerade
|
||||||
Switch power off : Strom ausschalten
|
Switch power off : Strom ausschalten
|
||||||
Switch power on : Strom anschalten
|
Switch power on : Strom anschalten
|
||||||
|
SYSTEM : Betriebssystem
|
||||||
Tag : Markierung
|
Tag : Markierung
|
||||||
Tags : Markierungen
|
Tags : Markierungen
|
||||||
Text to display on clients\: : Text, welcher auf den Clients angezeigt werden soll:
|
Text to display on clients\: : Text, welcher auf den Clients angezeigt werden soll:
|
||||||
|
|||||||
@@ -639,6 +639,10 @@ public class Plan extends BaseClass{
|
|||||||
super.removeChild(child);
|
super.removeChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void save() throws IOException {
|
||||||
|
plan.stream(plan.saveTo("default"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saves the plan to a set of files, along with its cars, tiles, trains, routes and control unit settings
|
* saves the plan to a set of files, along with its cars, tiles, trains, routes and control unit settings
|
||||||
* @param name
|
* @param name
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public abstract class Action extends BaseClass {
|
|||||||
DetermineTrainInBlock.class,
|
DetermineTrainInBlock.class,
|
||||||
FinishRoute.class,
|
FinishRoute.class,
|
||||||
PreserveRoute.class,
|
PreserveRoute.class,
|
||||||
|
SavePlan.class,
|
||||||
SendCommand.class,
|
SendCommand.class,
|
||||||
SetContextTrain.class,
|
SetContextTrain.class,
|
||||||
SetDisplayText.class,
|
SetDisplayText.class,
|
||||||
|
|||||||
22
src/main/java/de/srsoftware/web4rail/actions/SavePlan.java
Normal file
22
src/main/java/de/srsoftware/web4rail/actions/SavePlan.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
|
||||||
|
public class SavePlan extends Action{
|
||||||
|
|
||||||
|
public SavePlan(BaseClass parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
try {
|
||||||
|
plan.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,68 +1,96 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
import de.srsoftware.web4rail.Command;
|
import de.srsoftware.web4rail.Command;
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tags.Radio;
|
||||||
|
|
||||||
public class SendCommand extends Action{
|
public class SendCommand extends Action{
|
||||||
|
|
||||||
|
enum Target{
|
||||||
|
SYSTEM, SRCP
|
||||||
|
}
|
||||||
|
|
||||||
public SendCommand(BaseClass parent) {
|
public SendCommand(BaseClass parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String COMMAND = "command";
|
public static final String COMMAND = "command";
|
||||||
|
private static final String TARGET = "target";
|
||||||
private String command = "SET 1 POWER OFF";
|
private String command = "SET 1 POWER OFF";
|
||||||
|
private Target target = Target.SRCP;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) {
|
public boolean fire(Context context) {
|
||||||
plan.queue(new Command(command) {
|
switch (target) {
|
||||||
|
case SRCP:
|
||||||
|
plan.queue(new Command(command) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Reply reply) {
|
public void onResponse(Reply reply) {
|
||||||
super.onResponse(reply);
|
super.onResponse(reply);
|
||||||
plan.stream(reply.message());
|
plan.stream(reply.message());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
case SYSTEM:
|
||||||
|
try {
|
||||||
|
Runtime.getRuntime().exec(command);
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
json.put(COMMAND, command);
|
json.put(COMMAND, command);
|
||||||
|
json.put(TARGET, target.toString());
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action load(JSONObject json) {
|
public Action load(JSONObject json) {
|
||||||
super.load(json);
|
super.load(json);
|
||||||
command = json.getString(COMMAND);
|
if (json.has(COMMAND)) command = json.getString(COMMAND);
|
||||||
|
if (json.has(TARGET)) target = Target.valueOf(json.getString(TARGET));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
formInputs.add(t("Command to send to control unit"),new Input(COMMAND, command));
|
formInputs.add(t("Command to send"),new Input(COMMAND, command));
|
||||||
|
Tag div = new Tag("div");
|
||||||
|
new Radio(TARGET, Target.SYSTEM, t("Operating System"), target == Target.SYSTEM).addTo(div);
|
||||||
|
new Radio(TARGET, Target.SRCP, t("SRCP daemon"), target == Target.SRCP).addTo(div);
|
||||||
|
formInputs.add(t("Send command to"),div);
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return t("Send command \"{}\" to control unit",command);
|
return t("Send command \"{}\" to {}",command,t(target.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
LOG.debug("update: {}",params);
|
LOG.debug("update: {}",params);
|
||||||
command = params.get(COMMAND);
|
command = params.get(COMMAND);
|
||||||
|
String t = params.get(TARGET);
|
||||||
|
if (isSet(t)) target = Target.valueOf(t);
|
||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user