1 package org.simantics.modeling.ui.actions;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
7 import org.simantics.Simantics;
8 import org.simantics.db.Resource;
9 import org.simantics.db.WriteGraph;
10 import org.simantics.db.common.request.WriteRequest;
11 import org.simantics.db.common.utils.Logger;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.adapter.ActionFactory;
14 import org.simantics.db.layer0.adapter.ActionFactory2;
15 import org.simantics.db.layer0.util.RemoverUtil;
17 public class Delete implements ActionFactory, ActionFactory2 {
20 public Runnable create(Object target) {
21 return create(Collections.singletonList(target));
25 public Runnable create(Collection<?> target) {
27 final ArrayList<Resource> resources = new ArrayList<Resource>();
29 for(Object o : target) {
30 if(!(o instanceof Resource))
32 resources.add((Resource)o);
35 return new Runnable() {
39 for(Resource r : resources) {
41 Simantics.getSession().syncRequest(new WriteRequest() {
44 public void perform(WriteGraph graph) throws DatabaseException {
45 RemoverUtil.remove(graph, r);
49 } catch (DatabaseException e) {
50 Logger.defaultLogError(e);