preparing lookup tables
This commit is contained in:
@@ -135,6 +135,8 @@ public class Application extends BaseClass{
|
||||
return History.action(params);
|
||||
case REALM_LOCO:
|
||||
return Locomotive.action(params,plan);
|
||||
case REALM_LOOKUP:
|
||||
return LookupTable.action(params);
|
||||
case REALM_MAINTENANCE:
|
||||
return MaintnanceTask.action(params);
|
||||
case REALM_PLAN:
|
||||
|
||||
@@ -226,7 +226,7 @@ public abstract class BaseClass implements Constants{
|
||||
}
|
||||
}
|
||||
|
||||
public class FormInput extends ArrayList<Map.Entry<String, Tag>>{
|
||||
public static class FormInput extends ArrayList<Map.Entry<String, Tag>>{
|
||||
|
||||
private static final long serialVersionUID = -2371203388908395216L;
|
||||
|
||||
@@ -352,7 +352,7 @@ public abstract class BaseClass implements Constants{
|
||||
return l+NBSP+unit;
|
||||
}
|
||||
|
||||
public Form form(String id,List<Map.Entry<String, Tag>> elements) {
|
||||
public static Form form(String id,List<Map.Entry<String, Tag>> elements) {
|
||||
Form form = new Form(id);
|
||||
|
||||
Table table = new Table();
|
||||
@@ -383,8 +383,11 @@ public abstract class BaseClass implements Constants{
|
||||
return o==null;
|
||||
}
|
||||
|
||||
public static boolean isSet(Object o) {
|
||||
return o != null;
|
||||
public static boolean isSet(Object...o) {
|
||||
for (Object x : o) {
|
||||
if (x == null) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
|
||||
@@ -49,6 +49,7 @@ public interface Constants {
|
||||
public static final String REALM_FUNCTION = "function";
|
||||
public static final String REALM_HISTORY = "history";
|
||||
public static final String REALM_LOCO = "loco";
|
||||
public static final String REALM_LOOKUP = "lookup";
|
||||
public static final String REALM_MAINTENANCE = "maintenance";
|
||||
public static final String REALM_ROUTE = "route";
|
||||
public static final String REALM_PLAN = "plan";
|
||||
|
||||
56
src/main/java/de/srsoftware/web4rail/LookupTable.java
Normal file
56
src/main/java/de/srsoftware/web4rail/LookupTable.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package de.srsoftware.web4rail;
|
||||
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
import de.srsoftware.web4rail.tags.Window;
|
||||
|
||||
public class LookupTable extends BaseClass{
|
||||
|
||||
private static final String ADD_FORM = "add_lookup";
|
||||
private static final String COLUMNS = "columns";
|
||||
private static final String ROWS = "rows";
|
||||
|
||||
public static Object action(Params params) {
|
||||
String action = params.getString(ACTION);
|
||||
if (isNull(action)) throw new NullPointerException(ACTION+" should not be null!");
|
||||
|
||||
switch (action) {
|
||||
case ACTION_ADD:
|
||||
return addForm(params);
|
||||
}
|
||||
return plan.properties(t("Unknown action: {}",action));
|
||||
}
|
||||
|
||||
private static Object addForm(Params params) {
|
||||
String name = params.getString(NAME);
|
||||
String cols = params.getString(COLUMNS);
|
||||
String rows = params.getString(ROWS);
|
||||
if (isSet(name,cols,rows)) return create(name,cols,rows);
|
||||
Window win = new Window(ADD_FORM, t("add lookup table"));
|
||||
FormInput formInputs = new FormInput();
|
||||
|
||||
formInputs.add(t(NAME), new Input(NAME, t("lookup")+'-'+timestamp()));
|
||||
|
||||
formInputs.add(t(ROWS), selector(ROWS));
|
||||
formInputs.add(t(COLUMNS), selector(COLUMNS));
|
||||
Form form = form(ADD_FORM+"_form", formInputs);
|
||||
new Input(REALM, REALM_LOOKUP).hideIn(form);
|
||||
new Input(ACTION, ACTION_ADD).hideIn(form);
|
||||
return form.addTo(win);
|
||||
}
|
||||
|
||||
private static Object create(String name, String cols, String rows2) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Select selector(String name) {
|
||||
Select selector = new Select(name);
|
||||
selector.addOption(REALM_LOCO, t("Locomotives"));
|
||||
selector.addOption(REALM_TRAIN, t("Trains"));
|
||||
selector.addOption(REALM_TRAIN+"_length", t("TrainLength"));
|
||||
return selector;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -609,6 +609,13 @@ public class Plan extends BaseClass{
|
||||
LoadCallback.fire();
|
||||
}
|
||||
|
||||
private Fieldset lookupTables() {
|
||||
Fieldset fieldset = new Fieldset(t("lookup tables"));
|
||||
Button button = button(t("add"),Map.of(REALM,REALM_LOOKUP,ACTION,ACTION_ADD));
|
||||
button.addTo(fieldset);
|
||||
return fieldset;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the main menu attached to the plan
|
||||
* @return
|
||||
@@ -763,6 +770,7 @@ public class Plan extends BaseClass{
|
||||
|
||||
postForm.add(relayProperties());
|
||||
postForm.add(routeProperties());
|
||||
postForm.add(lookupTables());
|
||||
return super.properties(preForm, formInputs, postForm, errorMessages);
|
||||
}
|
||||
|
||||
|
||||
@@ -156,8 +156,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
case ACTION_UPDATE:
|
||||
return train.update(params);
|
||||
}
|
||||
String message = t("Unknown action: {}",action);
|
||||
return train.properties(message);
|
||||
return train.properties(t("Unknown action: {}",action));
|
||||
}
|
||||
|
||||
public Train add(Car car) {
|
||||
|
||||
Reference in New Issue
Block a user