1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.sharedontology.wizard;
\r
14 import java.io.File;
\r
15 import java.io.IOException;
\r
16 import java.lang.reflect.InvocationTargetException;
\r
18 import org.eclipse.core.runtime.IProgressMonitor;
\r
19 import org.eclipse.core.runtime.SubMonitor;
\r
20 import org.eclipse.jface.operation.IRunnableWithProgress;
\r
21 import org.simantics.Simantics;
\r
22 import org.simantics.databoard.binding.error.BindingException;
\r
23 import org.simantics.databoard.serialization.SerializationException;
\r
24 import org.simantics.db.common.utils.Logger;
\r
25 import org.simantics.db.exception.DatabaseException;
\r
26 import org.simantics.modeling.ModelingUtils;
\r
27 import org.simantics.modeling.ModelingUtils.LibraryInfo;
\r
28 import org.simantics.utils.ui.dialogs.ShowMessage;
\r
31 * @author Antti Villberg
\r
33 public class SharedOntologyExporter implements IRunnableWithProgress {
\r
35 ExportPlan exportModel;
\r
37 public SharedOntologyExporter(ExportPlan exportModel) {
\r
38 this.exportModel = exportModel;
\r
42 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
\r
43 SubMonitor progress = SubMonitor.convert(monitor, 50);
\r
45 exportModel(progress.newChild(50, SubMonitor.SUPPRESS_NONE));
\r
46 } catch (IOException e) {
\r
47 throw new InvocationTargetException(e);
\r
48 } catch (DatabaseException e) {
\r
49 throw new InvocationTargetException(e);
\r
50 } catch (BindingException e) {
\r
51 throw new InvocationTargetException(e);
\r
57 void exportModel(SubMonitor mon) throws IOException, DatabaseException, SerializationException, BindingException{
\r
59 doExport(mon, exportModel.exportLocation, exportModel.model);
\r
61 } catch (DatabaseException e) {
\r
62 e.printStackTrace();
\r
63 Logger.defaultLogError(e);
\r
64 mon.setCanceled(true);
\r
65 ShowMessage.showError("Export failed.", "Internal application error in export. See log for details.");
\r
67 mon.setWorkRemaining(0);
\r
71 public static void doExport(IProgressMonitor monitor, File location, final LibraryInfo info) throws DatabaseException, IOException {
\r
72 ModelingUtils.exportSharedOntology(monitor, Simantics.getSession(), location,Constants.SHARED_LIBRARY_FORMAT, Constants.SHARED_LIBRARY_CURRENT_VERSION, info);
\r