]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/UnlockAction.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 / UnlockAction.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 UnlockAction 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.deny(resource, STR.ComponentType_Locked);
32                         }
33                     });
34                 } catch (DatabaseException e) {
35                     Logger.defaultLogError(e);
36                 }
37             }
38         };
39     }
40
41 }