Fixed a crashbug in Editor when deleting selections with wires and comps
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 15 Sep 2019 19:31:35 +0000 (21:31 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 15 Sep 2019 19:31:35 +0000 (21:31 +0200)
net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java
net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java

index 61fd0a6..839c2b5 100644 (file)
@@ -71,7 +71,9 @@ public class WireHandle extends Handle
        @Override
        public void reqDelete()
        {
-               model.destroyWire(parent);
+               // this wire could already be removed implicitly when removing a selection containing both wires and components
+               if (model.getWireByName(parent.name) != null)
+                       model.destroyWire(parent);
        }
 
        @Override
index f9eef5d..17d0a44 100644 (file)
@@ -117,24 +117,24 @@ public class LogicModel
                return wiresUnmodifiable;
        }
 
-       public <T extends ModelComponent> T getComponentByName(String name, Class<T> expectedComponentClass)
-       {
-               return getByName(name, expectedComponentClass, components);
-       }
-
-       public ModelWire getWireByName(String name)
+       public ModelComponent getComponentByName(String name)
        {
-               return getByName(name, ModelWire.class, wires);
+               return components.get(name);
        }
 
        @SuppressWarnings("unchecked")
-       private static <T> T getByName(String name, Class<T> expectedClass, Map<String, ? super T> map)
+       public <T extends ModelComponent> T getComponentByName(String name, Class<T> expectedComponentClass)
        {
-               Object comp = map.get(name);
+               ModelComponent comp = components.get(name);
                Objects.requireNonNull(comp, "Invaild path, component " + name + " not found");
-               if (expectedClass.isInstance(comp))
+               if (expectedComponentClass.isInstance(comp))
                        return (T) comp;
-               throw new IllegalArgumentException("The component " + name + " is not an instance of " + expectedClass);
+               throw new IllegalArgumentException("The component " + name + " is not an instance of " + expectedComponentClass);
+       }
+
+       public ModelWire getWireByName(String name)
+       {
+               return wires.get(name);
        }
 
        public <T extends ModelComponent> T getComponentBySubmodelPath(String path, Class<T> modelClass)