]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/NewSymbol.java
Allow client-logic in component type interface property name editing
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / NewSymbol.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.exception.DatabaseException;
8 import org.simantics.db.layer0.adapter.ActionFactory;
9 import org.simantics.modeling.userComponent.ComponentTypeCommands;
10 import org.simantics.utils.ui.ErrorLogger;
11
12 /**
13  * @author Tuukka Lehtonen
14  */
15 public class NewSymbol implements ActionFactory {
16
17     @Override
18     public Runnable create(Object target) {
19         if (!(target instanceof Resource))
20             return null;
21         final Resource componentType = (Resource) target;
22         return new Runnable() {
23             @Override
24             public void run() {
25                 try {
26                     Simantics.getSession().syncRequest(new WriteRequest() {
27                         @Override
28                         public void perform(WriteGraph graph) throws DatabaseException {
29                             graph.markUndoPoint();
30                             ComponentTypeCommands.createSymbol(graph, componentType);
31                         }
32                     });
33                 } catch (DatabaseException e) {
34                     ErrorLogger.defaultLogError(e);
35                 }
36             }
37         };
38     }
39
40 }