Browse Source

working on action management

lookup-tables
Stephan Richter 5 years ago
parent
commit
2b5fca5128
  1. 2
      pom.xml
  2. 6
      src/main/java/de/srsoftware/web4rail/actions/ActionList.java
  3. 23
      src/main/java/de/srsoftware/web4rail/actions/SpeedReduction.java

2
pom.xml

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>0.7.9</version>
<version>0.7.10</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

6
src/main/java/de/srsoftware/web4rail/actions/ActionList.java

@ -135,6 +135,8 @@ public class ActionList extends Vector<Action> implements Constants{ @@ -135,6 +135,8 @@ public class ActionList extends Vector<Action> implements Constants{
case "SetSignalsToStop":
add(new SetSignalsToStop());
break;
case "SpeedReduction":
return SpeedReduction.propForm(this,params);
case "TurnTrain":
add(new TurnTrain());
break;
@ -163,4 +165,8 @@ public class ActionList extends Vector<Action> implements Constants{ @@ -163,4 +165,8 @@ public class ActionList extends Vector<Action> implements Constants{
select.addTo(new Label("Action type:")).addTo(typeForm);
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm).addTo(win);
}
public int id() {
return id;
}
}

23
src/main/java/de/srsoftware/web4rail/actions/SpeedReduction.java

@ -5,18 +5,16 @@ import java.util.HashMap; @@ -5,18 +5,16 @@ import java.util.HashMap;
import org.json.JSONObject;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.Route;
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.tiles.Contact;
public class SpeedReduction extends Action{
public static final String MAX_SPEED = "max_speed";
private int maxSpeed;
private int maxSpeed = -1;
public SpeedReduction(int kmh) {
super();
@ -39,7 +37,7 @@ public class SpeedReduction extends Action{ @@ -39,7 +37,7 @@ public class SpeedReduction extends Action{
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 ms = params.get(MAX_SPEED);
if (ms == null) {
@ -49,25 +47,22 @@ public class SpeedReduction extends Action{ @@ -49,25 +47,22 @@ public class SpeedReduction extends Action{
int s = Integer.parseInt(ms);
if (s<0) error = t("Speed must not be less than zero!");
if (error == null) {
route.addAction(contact.trigger(),new SpeedReduction(s));
contact.plan().stream("Action added!");
return route.properties();
actionList.add(new SpeedReduction(s));
return t("Action added!");
}
} catch (NumberFormatException e) {
error = t("Not a valid number!");
}
}
Window win = Action.propForm(params);
String formId = "add-action-to-contact-"+contact.id();
String formId = "edit-speedreduction";
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_ROUTE).hideIn(form);
new Input(ID,route.id()).hideIn(form);
new Input(ACTION,ACTION_ADD_ACTION).hideIn(form);
new Input(CONTACT,contact.id()).hideIn(form);
new Input(REALM, REALM_ACTIONS).hideIn(form);
new Input(ID,actionList.id()).hideIn(form);
new Input(ACTION,ACTION_ADD).hideIn(form);
new Input(TYPE,SpeedReduction.class.getSimpleName()).hideIn(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);
return win;
}

Loading…
Cancel
Save