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;
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;
/**
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;
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);
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)
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);
@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) {
}
}
- 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)