]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / sharedontology / wizard / SharedOntologyExporter.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.sharedontology.wizard;
13
14 import java.io.File;
15 import java.io.IOException;
16 import java.lang.reflect.InvocationTargetException;
17
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;
29
30 /**
31  * @author Antti Villberg
32  */
33 public class SharedOntologyExporter implements IRunnableWithProgress {
34
35     ExportPlan exportModel;
36
37     public SharedOntologyExporter(ExportPlan exportModel) {
38         this.exportModel = exportModel;
39     }
40
41     @Override
42     public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
43         SubMonitor progress = SubMonitor.convert(monitor, 50);
44         try {
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);
52         } finally {
53             monitor.done();
54         }
55     }
56
57     void exportModel(SubMonitor mon) throws IOException, DatabaseException, SerializationException, BindingException{
58         try {
59             doExport(mon, exportModel.exportLocation, exportModel.model);
60
61         } catch (DatabaseException e) {
62             e.printStackTrace();
63             Logger.defaultLogError(e);
64             mon.setCanceled(true);
65             ShowMessage.showError("Export failed.", "Internal application error in export. See log for details.");
66         } finally {
67             mon.setWorkRemaining(0);
68         }
69     }
70     
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);
73     }
74         
75 }