]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/Delete.java
(refs #7561) Allow extra parameters to the application of type alias
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / Delete.java
1 package org.simantics.modeling.ui.actions;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6
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;
16
17 public class Delete implements ActionFactory, ActionFactory2 {
18
19         @Override
20     public Runnable create(Object target) {
21                 return create(Collections.singletonList(target));
22         }
23
24         @Override
25     public Runnable create(Collection<?> target) {
26
27                 final ArrayList<Resource> resources = new ArrayList<Resource>();
28                 
29                 for(Object o : target) {
30                         if(!(o instanceof Resource))
31                                 return null;
32                         resources.add((Resource)o);
33                 }
34         
35         return new Runnable() {
36             @Override
37             public void run() {
38
39                 for(Resource r : resources) {
40                         try {
41                                                 Simantics.getSession().syncRequest(new WriteRequest() {
42
43                                                         @Override
44                                                         public void perform(WriteGraph graph) throws DatabaseException {
45                                                                 RemoverUtil.remove(graph, r);
46                                                         }
47
48                                                 });
49                                         } catch (DatabaseException e) {
50                                                 Logger.defaultLogError(e);
51                                         }
52                 }
53                 
54             }
55         };
56     }
57
58 }