1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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.desktop.ui.internal;
14 import java.util.List;
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.swt.widgets.Display;
22 import org.simantics.Simantics;
23 import org.simantics.browsing.ui.swt.AdaptableHintContext;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.Resource;
26 import org.simantics.db.common.request.UniqueRead;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.db.layer0.SelectionHints;
29 import org.simantics.modeling.ModelingUtils;
30 import org.simantics.scl.runtime.tuple.Tuple0;
31 import org.simantics.utils.datastructures.hints.IHintContext;
33 public class ExportSharedLibrary extends AbstractHandler {
36 public Object execute(ExecutionEvent event) throws ExecutionException {
39 Resource lib = Simantics.sync(new UniqueRead<Resource>() {
42 public Resource perform(ReadGraph graph) throws DatabaseException {
43 List<Resource> ontologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
44 if(ontologies.size() == 1) return ontologies.iterator().next();
49 if(lib == null) return null;
51 IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);
52 context.setHint(SelectionHints.KEY_MAIN, lib);
54 IStructuredSelection sel = new StructuredSelection(context);
55 ModelingUtils.openWizard(Display.getCurrent(), sel, "org.simantics.modeling.ui.sharedOntologyExportWizard");
56 } catch (DatabaseException e) {
57 // TODO Auto-generated catch block