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