From 76411b6022a6f025ed868398d3d437f937cff0ff Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 5 Jan 2017 16:09:37 +0200 Subject: [PATCH] Removal prevention of different types of resources disabled 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 --- .../simantics/db/layer0/util/RemoverUtil.java | 43 ++++--------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java index 53df7072c..2baadba19 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java @@ -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(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 rs, List removers) throws DatabaseException { if (removers == null) - removers = new ArrayList(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 aux = new HashMap(); - List errors = new ArrayList(2); + Map aux = new HashMap<>(); + List 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 removers = new ArrayList(rs.size()); + List 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 principalTypes = null; - for (Resource r : rs) { - Collection 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 differentTypes = new HashSet(); - Set typeNames = new TreeSet(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 removers = new ArrayList(); - Map removedResources = new HashMap(); + List removers = new ArrayList<>(); + Map 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 aux = new HashMap(); - List errors = new ArrayList(removers.size()); + Map aux = new HashMap<>(); + List errors = new ArrayList<>(removers.size()); for (Remover remover : removers) { String error = remover.canRemove(graph, aux); if (error != null) -- 2.47.1