]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Removal prevention of different types of resources disabled 56/256/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 5 Jan 2017 14:09:37 +0000 (16:09 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 5 Jan 2017 21:30:19 +0000 (23:30 +0200)
This "safety feature" has been in the model browser for a long time but
it feels like its time to remove it as it is really basically only an
annoyance and seldom saves the user from any real peril.

refs #6942

Change-Id: I5081cc764c9fee068ddcd187d550f84f1870c7a1

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java

index 53df7072c66e4abeb257cb6b6fe9ad99fb129afb..2baadba199efd1d9890e4f8ee146be38deaed72b 100644 (file)
@@ -14,11 +14,8 @@ package org.simantics.db.layer0.util;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -34,7 +31,6 @@ import org.simantics.db.layer0.adapter.impl.AbstractRemover;
 import org.simantics.db.layer0.adapter.impl.EntityRemover;
 import org.simantics.db.layer0.exception.CannotRemoveException;
 import org.simantics.db.layer0.internal.SimanticsInternal;
-import org.simantics.utils.strings.AlphanumComparator;
 import org.simantics.utils.strings.EString;
 
 /**
@@ -50,7 +46,7 @@ public final class RemoverUtil {
        public static boolean canRemove(ReadGraph graph, Resource resource) throws DatabaseException {
         Remover remover = RemoverUtil.getPossibleRemover(graph, resource);
         if (remover != null) {
-            String problem = remover.canRemove(graph, new HashMap<Object, Object>(4));
+            String problem = remover.canRemove(graph, new HashMap<>(4));
             if (problem != null) return false;
         }
         return true;
@@ -92,7 +88,7 @@ public final class RemoverUtil {
 
     public static String testRemoval(ReadGraph graph, final Collection<Resource> rs, List<Remover> removers) throws DatabaseException {
         if (removers == null)
-            removers = new ArrayList<Remover>(rs.size());
+            removers = new ArrayList<>(rs.size());
 
         for (Resource r : rs) {
             Remover remover = graph.getPossibleAdapter(r, Remover.class);
@@ -100,8 +96,8 @@ public final class RemoverUtil {
                 removers.add(remover);
         }
 
-        Map<Object, Object> aux = new HashMap<Object, Object>();
-        List<String> errors = new ArrayList<String>(2);
+        Map<Object, Object> aux = new HashMap<>();
+        List<String> errors = new ArrayList<>(2);
         for (Remover remover : removers) {
             String error = remover.canRemove(graph, aux);
             if (error != null)
@@ -132,7 +128,7 @@ public final class RemoverUtil {
                     graph.addMetadata(cm.add("Removing " + r + "."));
                 }
 
-                List<Remover> removers = new ArrayList<Remover>(rs.size());
+                List<Remover> removers = new ArrayList<>(rs.size());
                 String error = testRemoval(graph, rs, removers);
                 if (error != null)
                     throw new CannotRemoveException(error);
@@ -167,30 +163,9 @@ public final class RemoverUtil {
             @Override
             public Boolean perform(WriteGraph graph) throws DatabaseException {
                 graph.markUndoPoint();
-                // 1. make sure that all resources are of the same type
-                Collection<Resource> principalTypes = null;
-                for (Resource r : rs) {
-                    Collection<Resource> pts = graph.getPrincipalTypes(r);
-                    if (principalTypes == null) {
-                        principalTypes = pts;
-                    } else if (!principalTypes.equals(pts)) {
-                        //return false;
-                        StringBuilder sb = new StringBuilder();
-                        sb.append("Removing resources of different types at the same time is currently not supported.\n\nThe selection contained resources of the following types:\n");
-                        Set<Resource> differentTypes = new HashSet<Resource>();
-                        Set<String> typeNames = new TreeSet<String>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
-                        for (Resource t : rs)
-                            differentTypes.addAll(graph.getPrincipalTypes(t));
-                        for (Resource t : differentTypes)
-                            typeNames.add(NameUtils.getSafeName(graph, t));
-                        for (String typeName : typeNames)
-                            sb.append("\t").append(typeName).append("\n");
-                        throw new CannotRemoveException(sb.toString());
-                    }
-                }
 
-                List<Remover> removers = new ArrayList<Remover>();
-                Map<Remover, String> removedResources = new HashMap<Remover, String>();
+                List<Remover> removers = new ArrayList<>();
+                Map<Remover, String> removedResources = new HashMap<>();
                 for (Resource r : rs) {
                     Remover remover = graph.getPossibleAdapter(r, Remover.class);
                     if (remover != null) {
@@ -199,8 +174,8 @@ public final class RemoverUtil {
                     }
                 }
 
-                Map<Object, Object> aux = new HashMap<Object, Object>();
-                List<String> errors = new ArrayList<String>(removers.size());
+                Map<Object, Object> aux = new HashMap<>();
+                List<String> errors = new ArrayList<>(removers.size());
                 for (Remover remover : removers) {
                     String error = remover.canRemove(graph, aux);
                     if (error != null)