]> gerrit.simantics Code Review - simantics/platform.git/blob
0e51deac1225d2a6ae6744e9849ecaf8748de202
[simantics/platform.git] /
1 package org.simantics.diagram.profile.view;
2
3 import java.util.List;
4
5 import org.eclipse.jface.viewers.ISelection;
6 import org.simantics.Simantics;
7 import org.simantics.browsing.ui.swt.ModelledActionImpl;
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.OrderedSetUtils;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.SelectionHints;
14 import org.simantics.diagram.stubs.DiagramResource;
15 import org.simantics.utils.ui.ISelectionUtils;
16
17 public class RemoveEntriesAction extends ModelledActionImpl<Resource> {
18
19         public RemoveEntriesAction(Resource configuration) {
20                 super(configuration);
21         }
22         
23         public void run(Resource runtimeDiagram) {
24
25                 ISelection selection = getParameter(DiagramResource.URIs.ProfilesView_SelectedEntries);
26         final List<ResourcePair> selectedEntries = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, ResourcePair.class);
27         if(selectedEntries != null && !selectedEntries.isEmpty()) {
28                 System.err.println("RemoveEntriesAction has " + selection + " for " + runtimeDiagram);
29             try {
30                 Simantics.getSession().syncRequest(new WriteRequest() {
31
32                     @Override
33                     public void perform(WriteGraph graph) throws DatabaseException {
34                         
35                         DiagramResource DIA = DiagramResource.getInstance(graph);
36                         for(ResourcePair entry : selectedEntries) {
37                                 Resource list = graph.getPossibleObject(entry.getFirst(), DIA.HasEntries);
38                                 OrderedSetUtils.remove(graph, list, entry.getSecond());
39                         }
40                         
41                     }
42
43                 });
44             } catch (DatabaseException e) {
45                 e.printStackTrace();
46             }
47         }
48
49         }
50
51 }