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.sharedontology.wizard;
15 import java.io.IOException;
16 import java.lang.reflect.InvocationTargetException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.SubMonitor;
20 import org.eclipse.jface.operation.IRunnableWithProgress;
21 import org.simantics.Simantics;
22 import org.simantics.databoard.binding.error.BindingException;
23 import org.simantics.databoard.serialization.SerializationException;
24 import org.simantics.db.common.utils.Logger;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.modeling.ModelingUtils;
27 import org.simantics.modeling.ModelingUtils.LibraryInfo;
28 import org.simantics.utils.ui.dialogs.ShowMessage;
31 * @author Antti Villberg
33 public class SharedOntologyExporter implements IRunnableWithProgress {
35 ExportPlan exportModel;
37 public SharedOntologyExporter(ExportPlan exportModel) {
38 this.exportModel = exportModel;
42 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
43 SubMonitor progress = SubMonitor.convert(monitor, 50);
45 exportModel(progress.newChild(50, SubMonitor.SUPPRESS_NONE));
46 } catch (IOException e) {
47 throw new InvocationTargetException(e);
48 } catch (DatabaseException e) {
49 throw new InvocationTargetException(e);
50 } catch (BindingException e) {
51 throw new InvocationTargetException(e);
57 void exportModel(SubMonitor mon) throws IOException, DatabaseException, SerializationException, BindingException{
59 doExport(mon, exportModel.exportLocation, exportModel.model);
61 } catch (DatabaseException e) {
63 Logger.defaultLogError(e);
64 mon.setCanceled(true);
65 ShowMessage.showError("Export failed.", "Internal application error in export. See log for details.");
67 mon.setWorkRemaining(0);
71 public static void doExport(IProgressMonitor monitor, File location, final LibraryInfo info) throws DatabaseException, IOException {
72 ModelingUtils.exportSharedOntology(monitor, Simantics.getSession(), location,Constants.SHARED_LIBRARY_FORMAT, Constants.SHARED_LIBRARY_CURRENT_VERSION, info);