]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/LockAction.java
Allow simulation stop handling in Simantics/Sequences
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / LockAction.java
1 package org.simantics.modeling.ui.actions;
2
3 import org.simantics.Simantics;
4 import org.simantics.db.Resource;
5 import org.simantics.db.WriteGraph;
6 import org.simantics.db.common.request.WriteRequest;
7 import org.simantics.db.common.utils.Logger;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.adapter.ActionFactory;
10 import org.simantics.structural.stubs.StructuralResource2;
11
12 public class LockAction implements ActionFactory {
13
14     @Override
15     public Runnable create(Object target) {
16
17         if (!(target instanceof Resource))
18             return null;
19
20         final Resource resource = (Resource)target;
21
22         return new Runnable() {
23             @Override
24             public void run() {
25                 try {
26                     Simantics.getSession().markUndoPoint();
27                     Simantics.getSession().syncRequest(new WriteRequest() {
28                         @Override
29                         public void perform(WriteGraph graph) throws DatabaseException {
30                             StructuralResource2 STR = StructuralResource2.getInstance(graph);
31                             graph.claim(resource, STR.ComponentType_Locked, resource);
32                         }
33                     });
34                 } catch (DatabaseException e) {
35                     Logger.defaultLogError(e);
36                 }
37             }
38         };
39     }
40
41 }