added new action TriggerContact
This commit is contained in:
@@ -3,7 +3,6 @@ package de.srsoftware.web4rail.actions;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -102,6 +101,7 @@ public abstract class Action extends BaseClass {
|
||||
SetSpeed.class,
|
||||
SetSignalsToStop.class,
|
||||
FinishRoute.class,
|
||||
TriggerContact.class,
|
||||
TurnTrain.class,
|
||||
StopAuto.class,
|
||||
PowerOff.class,
|
||||
|
||||
@@ -32,7 +32,7 @@ public class SetRelay extends Action {
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
if (relay != null) {
|
||||
if (isSet(relay)) {
|
||||
json.put(RELAY, relay.id());
|
||||
json.put(Relay.STATE, state);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class SetRelay extends Action {
|
||||
public Action load(JSONObject json) {
|
||||
super.load(json);
|
||||
String relayId = json.getString(RELAY);
|
||||
if (relayId != null) {
|
||||
if (isSet(relayId)) {
|
||||
relay = Relay.get(relayId);
|
||||
state = json.getBoolean(Relay.STATE);
|
||||
}
|
||||
@@ -67,8 +67,8 @@ public class SetRelay extends Action {
|
||||
select.addTo(new Label(t("Select relay:")+NBSP)).addTo(form);
|
||||
|
||||
Select state = new Select(Relay.STATE);
|
||||
state.addOption(true,relay == null?Relay.DEFAULT_LABEL_A:relay.stateLabelA);
|
||||
state.addOption(false,relay == null?Relay.DEFAULT_LABEL_B:relay.stateLabelB);
|
||||
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);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SetRelay extends Action {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (relay == null) return t("[click here to setup relay]");
|
||||
if (isNull(relay)) return "["+t("click here to setup relay")+"]";
|
||||
return t("Set "+relay+" to "+(state?relay.stateLabelA:relay.stateLabelB));
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ public class SetRelay extends Action {
|
||||
String relayId = params.get(RELAY);
|
||||
relay = Relay.get(relayId);
|
||||
String st = params.get(Relay.STATE);
|
||||
if (st != null) state = st.equals("true");
|
||||
if (isSet(st)) state = st.equals("true");
|
||||
return properties(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
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.tiles.Contact;
|
||||
|
||||
public class TriggerContact extends Action {
|
||||
|
||||
private Contact contact = null;
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) throws IOException {
|
||||
if (isSet(contact)) {
|
||||
System.err.println("triggering "+contact);
|
||||
contact.trigger(200);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
if (isSet(contact)) json.put(CONTACT, contact.id());
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action load(JSONObject json) {
|
||||
super.load(json);
|
||||
String contactId = json.getString(CONTACT);
|
||||
if (isSet(contactId)) contact = Contact.get(contactId);
|
||||
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 = Contact.selector(contact);
|
||||
select.addTo(new Label(t("Select contact:")+NBSP)).addTo(form);
|
||||
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return isSet(contact) ? t("Trigger {}",contact) : "["+t("click here to setup contact")+"]";
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
LOG.debug("update: {}",params);
|
||||
String contactId = params.get(CONTACT);
|
||||
if (isSet(contactId)) contact = Contact.get(contactId);
|
||||
return properties(params);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user