]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/NewComponentTypeAction.java
Externalize strings
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / NewComponentTypeAction.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.actions;
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.runtime.jobs.Job;
18 import org.simantics.DatabaseJob;
19 import org.simantics.Simantics;
20 import org.simantics.db.Resource;
21 import org.simantics.db.WriteGraph;
22 import org.simantics.db.common.request.WriteRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.layer0.adapter.ActionFactory;
25 import org.simantics.modeling.NewComponentType;
26 import org.simantics.modeling.ui.Activator;
27
28 public class NewComponentTypeAction implements ActionFactory {
29
30     @Override
31     public Runnable create(Object target) {
32         if(!(target instanceof Resource))
33             return null;
34         final Resource library = (Resource) target;
35         return new Runnable() {
36             @Override
37             public void run() {
38                 Job job = new DatabaseJob(Messages.NewComponentTypeAction_NewUserComponent) {
39                     @Override
40                     protected IStatus run(IProgressMonitor monitor) {
41                         try {
42                             Simantics.getSession().syncRequest(new WriteRequest() {
43                                 @Override
44                                 public void perform(WriteGraph graph) throws DatabaseException {
45                                     graph.markUndoPoint();
46                                         NewComponentType.createComponentType(graph, library);
47                                 }
48                             });
49                             return Status.OK_STATUS;
50                         } catch (DatabaseException e) {
51                             return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NewComponentTypeAction_ActivatorFailedToCreateNewUserComponent, e); 
52                         }
53                     }
54                 };
55                 job.schedule();
56             }
57         };
58     }
59
60 }