Bugfixes + implemented deleting and update of BlockContacts

This commit is contained in:
Stephan Richter
2020-12-20 14:44:35 +01:00
parent 6d9a4d9120
commit 49a19c8b17
11 changed files with 40 additions and 27 deletions

View File

@@ -152,7 +152,11 @@ public abstract class Block extends StretchableTile{
if (!internalContacts.isEmpty()) {
Tag ul = new Tag("ul");
for (BlockContact contact : internalContacts) {
new Tag("li").content(contact.toString()).addTo(ul);
Tag li = new Tag("li").content(contact.toString()+NBSP);
contact.button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(li);
contact.button(t("delete"),Map.of(ACTION,ACTION_DROP)).addTo(li);
li.addTo(ul);
}
ul.addTo(fieldset);
}

View File

@@ -18,7 +18,7 @@ public class BlockContact extends Contact {
super.addr(address);
Block block = (Block) parent();
block.removeContact(this);
if (address != 0) block.register(this);
if (address != 0) block.register(this).register();
return this;
}

View File

@@ -157,16 +157,21 @@ public class Contact extends Tile{
String action = params.get(ACTION);
Id id = Id.from(params);
if (action == null) return t("Missing ACTION on call to {}.process()",Contact.class.getSimpleName());
Contact contact;
Contact contact = isSet(id) ? BaseClass.get(id) : null;
switch (action) {
case ACTION_ANALYZE:
if (id == null) return t("Missing ID on call to {}.process()",Contact.class.getSimpleName());
contact = BaseClass.get(id);
if (contact == null) return t("No contact with id {} found!",id);
if (isNull(id)) return t("Missing ID on call to {}.process()",Contact.class.getSimpleName());
if (isNull(contact)) return t("No contact with id {} found!",id);
Tag propMenu = contact.properties();
propMenu.children().insertElementAt(new Tag("div").content(t("Trigger a feedback sensor to assign it with this contact!")), 1);
plan.learn(contact);
return propMenu;
case ACTION_DROP:
if (isNull(id)) return t("Missing ID on call to {}.process()",Contact.class.getSimpleName());
if (isNull(contact)) return t("No contact with id {} found!",id);
contact.remove();
if (contact instanceof BlockContact) return contact.properties();
return t("Removed {}.",id);
case ACTION_UPDATE:
return plan.update(params);
}

View File

@@ -236,7 +236,7 @@ public class Relay extends Tile implements Device{
@Override
public String toString() {
return getClass().getSimpleName()+" ("+(isSet(name) && !name.isEmpty() ? name+")" : "")+" @("+x+", "+y+")";
return t(getClass().getSimpleName())+" ("+(isSet(name) && !name.isEmpty() ? name+")" : "")+" @("+x+", "+y+")";
}
@Override

View File

@@ -158,8 +158,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
public JSONObject json() {
JSONObject json = super.json();
json.put(TYPE, getClass().getSimpleName());
JSONObject pos = new JSONObject(Map.of(X,x,Y,y));
json.put(POS, pos);
json.put(POS, new JSONObject(Map.of(X,x,Y,y)));
if (isSet(route)) json.put(ROUTE, route.id());
if (isSet(oneWay)) json.put(ONEW_WAY, oneWay);
if (disabled) json.put(DISABLED, true);
@@ -353,7 +352,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
public static void saveAll(String filename) throws IOException {
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
for (Tile tile : BaseClass.listElements(Tile.class)) {
if (isNull(tile) || tile instanceof Shadow) continue;
if (isNull(tile) || tile instanceof Shadow || tile instanceof BlockContact) continue;
file.append(tile.json()+"\n");
}
file.close();
@@ -454,9 +453,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
@Override
public BaseClass remove() {
while (!routes.isEmpty()) {
routes.first().remove();
}
while (!routes.isEmpty()) routes.first().remove();
return super.remove();
}
@@ -465,9 +462,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
String childAsString = child.toString();
if (childAsString.length()>20) childAsString = childAsString.substring(0, 20)+"";
LOG.debug("Removing {} from {}",childAsString,this);
if (child instanceof Route) {
routes.remove(child);
}
if (child instanceof Route) routes.remove(child);
if (child == train) train = null;
if (child == route) route = null;