working on action management
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>0.7.9</version>
|
<version>0.7.10</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>
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
case "SetSignalsToStop":
|
case "SetSignalsToStop":
|
||||||
add(new SetSignalsToStop());
|
add(new SetSignalsToStop());
|
||||||
break;
|
break;
|
||||||
|
case "SpeedReduction":
|
||||||
|
return SpeedReduction.propForm(this,params);
|
||||||
case "TurnTrain":
|
case "TurnTrain":
|
||||||
add(new TurnTrain());
|
add(new TurnTrain());
|
||||||
break;
|
break;
|
||||||
@@ -163,4 +165,8 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
select.addTo(new Label("Action type:")).addTo(typeForm);
|
select.addTo(new Label("Action type:")).addTo(typeForm);
|
||||||
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm).addTo(win);
|
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm).addTo(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,16 @@ import java.util.HashMap;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Route;
|
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
import de.srsoftware.web4rail.tiles.Contact;
|
|
||||||
|
|
||||||
public class SpeedReduction extends Action{
|
public class SpeedReduction extends Action{
|
||||||
|
|
||||||
public static final String MAX_SPEED = "max_speed";
|
public static final String MAX_SPEED = "max_speed";
|
||||||
private int maxSpeed;
|
private int maxSpeed = -1;
|
||||||
|
|
||||||
public SpeedReduction(int kmh) {
|
public SpeedReduction(int kmh) {
|
||||||
super();
|
super();
|
||||||
@@ -39,7 +37,7 @@ public class SpeedReduction extends Action{
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Window propForm(HashMap<String, String> params, Route route, Contact contact) {
|
public static Object propForm(ActionList actionList, HashMap<String, String> params) {
|
||||||
String error = null;
|
String error = null;
|
||||||
String ms = params.get(MAX_SPEED);
|
String ms = params.get(MAX_SPEED);
|
||||||
if (ms == null) {
|
if (ms == null) {
|
||||||
@@ -49,25 +47,22 @@ public class SpeedReduction extends Action{
|
|||||||
int s = Integer.parseInt(ms);
|
int s = Integer.parseInt(ms);
|
||||||
if (s<0) error = t("Speed must not be less than zero!");
|
if (s<0) error = t("Speed must not be less than zero!");
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
route.addAction(contact.trigger(),new SpeedReduction(s));
|
actionList.add(new SpeedReduction(s));
|
||||||
contact.plan().stream("Action added!");
|
return t("Action added!");
|
||||||
return route.properties();
|
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
error = t("Not a valid number!");
|
error = t("Not a valid number!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Window win = Action.propForm(params);
|
Window win = Action.propForm(params);
|
||||||
String formId = "add-action-to-contact-"+contact.id();
|
String formId = "edit-speedreduction";
|
||||||
Tag form = new Form(formId);
|
Tag form = new Form(formId);
|
||||||
new Tag("div").content(t("Add Action {} to contact {} on route {}:",SpeedReduction.class.getSimpleName(),contact,route)).addTo(win);
|
new Input(REALM, REALM_ACTIONS).hideIn(form);
|
||||||
new Input(REALM, REALM_ROUTE).hideIn(form);
|
new Input(ID,actionList.id()).hideIn(form);
|
||||||
new Input(ID,route.id()).hideIn(form);
|
new Input(ACTION,ACTION_ADD).hideIn(form);
|
||||||
new Input(ACTION,ACTION_ADD_ACTION).hideIn(form);
|
|
||||||
new Input(CONTACT,contact.id()).hideIn(form);
|
|
||||||
new Input(TYPE,SpeedReduction.class.getSimpleName()).hideIn(form);
|
new Input(TYPE,SpeedReduction.class.getSimpleName()).hideIn(form);
|
||||||
new Input(MAX_SPEED, ms).addTo(new Label("new speed")).addTo(form);
|
new Input(MAX_SPEED, ms).addTo(new Label("new speed")).addTo(form);
|
||||||
if (error != null) new Tag("div").content(error).addTo(form);
|
//if (error != null) new Tag("div").content(error).addTo(form);
|
||||||
new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(form).addTo(win);
|
new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(form).addTo(win);
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user