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.ReadGraph;
25 import org.simantics.db.common.request.ReadRequest;
26 import org.simantics.db.common.utils.Logger;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.modeling.ModelingUtils;
29 import org.simantics.modeling.ModelingUtils.LibraryInfo;
30 import org.simantics.utils.ui.dialogs.ShowMessage;
33 * @author Antti Villberg
35 public class ModelExporter implements IRunnableWithProgress {
37 ExportPlan exportModel;
39 public ModelExporter(ExportPlan exportModel) {
40 this.exportModel = exportModel;
44 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
45 SubMonitor progress = SubMonitor.convert(monitor, 50);
47 exportModel(progress.newChild(50, SubMonitor.SUPPRESS_NONE));
48 } catch (IOException e) {
49 throw new InvocationTargetException(e);
50 } catch (DatabaseException e) {
51 throw new InvocationTargetException(e);
52 } catch (BindingException e) {
53 throw new InvocationTargetException(e);
59 void exportModel(SubMonitor mon) throws IOException, DatabaseException, SerializationException, BindingException{
61 doExport(mon, exportModel.exportLocation, exportModel.model);
63 } catch (DatabaseException e) {
65 Logger.defaultLogError(e);
66 mon.setCanceled(true);
67 ShowMessage.showError("Export failed.", "Internal application error in export. See log for details.");
69 mon.setWorkRemaining(0);
73 public static void doExport(IProgressMonitor monitor, final File location, final LibraryInfo info) throws DatabaseException, IOException {
74 Simantics.sync(new ReadRequest() {
77 public void run(ReadGraph graph) throws DatabaseException {
78 ModelingUtils.exportModel(graph, info.library.getResource(), location.getAbsolutePath(), "", 1);