You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
package de.srsoftware.web4rail.actions; |
|
|
|
import java.util.HashMap; |
|
import java.util.List; |
|
|
|
import org.json.JSONObject; |
|
|
|
import de.srsoftware.web4rail.BaseClass; |
|
import de.srsoftware.web4rail.tags.Fieldset; |
|
import de.srsoftware.web4rail.tags.Input; |
|
import de.srsoftware.web4rail.tags.Label; |
|
import de.srsoftware.web4rail.tags.Window; |
|
|
|
public abstract class TextAction extends Action { |
|
|
|
public TextAction(BaseClass parent) { |
|
super(parent); |
|
} |
|
|
|
public static final String TEXT = "text"; |
|
protected String text = "Hello, world!"; |
|
|
|
|
|
public String fill(String tx,Context context) { |
|
if (isSet(context.block())) tx = tx.replace("%block%", context.block().name); |
|
if (isSet(context.contact())) tx = tx.replace("%contact%", context.contact().id().toString()); |
|
if (isSet(context.route())) tx = tx.replace("%route%", context.route().name()); |
|
if (isSet(context.train())) tx = tx.replace("%train%", context.train().name()); |
|
return tx; |
|
} |
|
|
|
@Override |
|
public JSONObject json() { |
|
JSONObject json = super.json(); |
|
json.put(TEXT, text); |
|
return json; |
|
} |
|
|
|
protected abstract Label label(); |
|
|
|
@Override |
|
public Action load(JSONObject json) { |
|
super.load(json); |
|
text = json.getString(TEXT); |
|
return this; |
|
} |
|
|
|
@Override |
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) { |
|
formInputs.add(t("Text"),new Input(TEXT, text)); |
|
return super.properties(preForm, formInputs, postForm,errors); |
|
} |
|
|
|
@Override |
|
protected Object update(HashMap<String, String> params) { |
|
LOG.debug("update: {}",params); |
|
if (params.containsKey(TEXT)) text = params.get(TEXT); |
|
return super.update(params); |
|
} |
|
}
|
|
|