]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/AddEntriesAction.java
Better support for ontological profiles
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / AddEntriesAction.java
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 AddEntriesAction extends ModelledActionImpl<Resource> {
18
19         public AddEntriesAction(Resource configuration) {
20                 super(configuration);
21         }
22         
23         public void run(final Resource runtimeDiagram) {
24
25                 ISelection selection = getParameter(DiagramResource.URIs.ProfilesView_SelectedAvailableEntries);
26         final List<Resource> selectedEntries = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
27         if(selectedEntries != null && !selectedEntries.isEmpty()) {
28             try {
29                 Simantics.getSession().syncRequest(new WriteRequest() {
30
31                     @Override
32                     public void perform(WriteGraph graph) throws DatabaseException {
33                         
34                         DiagramResource DIA = DiagramResource.getInstance(graph);
35                         Resource activeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
36                         Resource list = graph.getPossibleObject(activeProfile, DIA.HasEntries);
37                         
38                         for(Resource entry : selectedEntries) {
39                                 OrderedSetUtils.add(graph, list, entry);
40                         }
41                         
42                     }
43
44                 });
45             } catch (DatabaseException e) {
46                 e.printStackTrace();
47             }
48         }
49
50         }
51
52 }