1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.actions;
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;
28 public class NewComponentTypeAction implements ActionFactory {
31 public Runnable create(Object target) {
32 if(!(target instanceof Resource))
34 final Resource library = (Resource) target;
35 return new Runnable() {
38 Job job = new DatabaseJob("New User Component") {
40 protected IStatus run(IProgressMonitor monitor) {
42 Simantics.getSession().syncRequest(new WriteRequest() {
44 public void perform(WriteGraph graph) throws DatabaseException {
45 graph.markUndoPoint();
46 NewComponentType.createComponentType(graph, library);
49 return Status.OK_STATUS;
50 } catch (DatabaseException e) {
51 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create new user component.", e);