-package org.simantics.export.ui;\r
-\r
-import java.io.IOException;\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.SubMonitor;\r
-import org.eclipse.jface.operation.IRunnableWithProgress;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.wizard.IWizardPage;\r
-import org.eclipse.jface.wizard.Wizard;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.ui.IExportWizard;\r
-import org.eclipse.ui.IWorkbench;\r
-import org.osgi.service.prefs.BackingStoreException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.export.core.ExportContext;\r
-import org.simantics.export.core.Exports;\r
-import org.simantics.export.core.error.ExportException;\r
-import org.simantics.export.core.manager.ExportManager;\r
-import org.simantics.export.core.manager.ExportPlan;\r
-import org.simantics.export.core.manager.ExportWizardResult;\r
-import org.simantics.export.core.util.ExporterUtils;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.datastructures.collections.CollectionUtils;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-public class ExportCoreWizard extends Wizard implements IExportWizard {\r
-\r
- ExportContext ctx;\r
- List<String> selection;\r
-\r
- ContentSelectionPage contentPage;\r
- OptionsPage optionsPage;\r
-\r
- public ExportCoreWizard() {\r
- setWindowTitle("Export PDF files");\r
- setNeedsProgressMonitor(true);\r
- }\r
-\r
- public void init(IWorkbench workbench, final IStructuredSelection selection) {\r
- try {\r
- // Create export context\r
- ctx = ExportContext.create( SimanticsUI.getSessionContext(), selection );\r
-\r
- // Create extension point registry\r
- ctx.eep = Exports.createExtensionPoint();\r
-\r
- } catch (DatabaseException e) {\r
- ExceptionUtils.logAndShowError(e);\r
- }\r
- }\r
-\r
- @Override\r
- public boolean performFinish() {\r
-\r
- // User clicked finish on the first page. Preapare options page.\r
- if ( getContainer().getCurrentPage() == contentPage ) {\r
- contentPage.validatePage();\r
- optionsPage.update( contentPage.getContentSelection() );\r
- }\r
-\r
- final boolean[] canceled = new boolean[1];\r
-\r
- try {\r
- contentPage.savePrefs();\r
- optionsPage.savePrefs();\r
- } catch (ExportException e) {\r
- e.printStackTrace();\r
- ExceptionUtils.logError(e);\r
- }\r
-\r
- try {\r
- final ExportPlan plan = new ExportPlan();\r
- final ExportWizardResult wizardResult = optionsPage.getOutput();\r
- final ExportManager em = new ExportManager( wizardResult.options, ctx );\r
- wizardResult.createPlan( ctx, plan );\r
- System.out.println(wizardResult);\r
-\r
- List<String> exportProblems = em.validate(ctx, plan);\r
- if ( !exportProblems.isEmpty() ) {\r
- CollectionUtils.unique(exportProblems);\r
- WizardPage cp = (WizardPage) getContainer().getCurrentPage();\r
- String str = CollectionUtils.toString(exportProblems, "\n");\r
- cp.setErrorMessage( str );\r
- return false;\r
- }\r
-\r
- getContainer().run(true, true, new IRunnableWithProgress() {\r
- @Override\r
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {\r
- SubMonitor mon = SubMonitor.convert(monitor, plan.label, 1000000);\r
- try {\r
- em.execute(ctx, mon.newChild(1000000, SubMonitor.SUPPRESS_NONE), plan);\r
- } catch (Exception e) {\r
- throw new InvocationTargetException(e);\r
- } finally {\r
- canceled[0] = monitor.isCanceled();\r
- monitor.done();\r
- }\r
- }\r
- });\r
-\r
- try {\r
- ctx.store.flush();\r
- } catch (BackingStoreException e) {\r
- ErrorLogger.defaultLogError("Failed to persist wizard preferences.", e);\r
- ExceptionUtils.logError(e);\r
- }\r
- } catch (InvocationTargetException e) {\r
- Throwable t = e.getTargetException();\r
- WizardPage cp = (WizardPage) getContainer().getCurrentPage();\r
-\r
- if ( t instanceof ExportException && t.getCause()!=null) {\r
- ExportException ee = (ExportException) t;\r
- if ( ee.getCause() != null ) t = ee.getCause();\r
- }\r
-\r
- if (canceled[0]) {\r
- cp.setErrorMessage("Export canceled.");\r
- } else if (t instanceof IOException) {\r
- ErrorLogger.defaultLogError("An I/O problem occurred while exporting the model. See exception for details.", t);\r
- cp.setErrorMessage("An I/O problem occurred while exporting the model.\nMessage: " + t.getMessage());\r
- } else {\r
- ErrorLogger.defaultLogError("Unexpected exception while exporting the model. See exception for details.", t);\r
- cp.setErrorMessage("Unexpected exception while exporting the model. See error log for details.\nMessage: " + t.getMessage());\r
- }\r
- return false;\r
- } catch (InterruptedException e) {\r
- ExceptionUtils.logAndShowError(e);\r
- } catch (ExportException e) {\r
- ExceptionUtils.logAndShowError(e);\r
- }\r
-\r
- return true;\r
- }\r
-\r
- @Override\r
- public void addPages() {\r
- super.addPages();\r
- try {\r
- contentPage = new ContentSelectionPage(ctx);\r
- optionsPage = new OptionsPage(ctx);\r
- addPage( contentPage );\r
- addPage( optionsPage );\r
- } catch (ExportException e) {\r
- e.printStackTrace();\r
- ExceptionUtils.logError(e); \r
- }\r
- }\r
-\r
- @Override\r
- public IWizardPage getNextPage(IWizardPage page) {\r
- if ( page == optionsPage ) {\r
- try {\r
- optionsPage.getOutput();\r
- } catch (ExportException e) {\r
- return null;\r
- }\r
- }\r
-\r
- if ( page == contentPage ) {\r
- contentPage.validatePage();\r
- optionsPage.update( ExporterUtils.sortContent( contentPage.getContentSelection() ) );\r
- }\r
- return super.getNextPage(page);\r
- }\r
-\r
-}\r
+package org.simantics.export.ui;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.osgi.service.prefs.BackingStoreException;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.export.core.ExportContext;
+import org.simantics.export.core.Exports;
+import org.simantics.export.core.error.ExportException;
+import org.simantics.export.core.manager.ExportManager;
+import org.simantics.export.core.manager.ExportPlan;
+import org.simantics.export.core.manager.ExportWizardResult;
+import org.simantics.export.core.util.ExporterUtils;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.utils.datastructures.collections.CollectionUtils;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.ExceptionUtils;
+
+public class ExportCoreWizard extends Wizard implements IExportWizard {
+
+ ExportContext ctx;
+ List<String> selection;
+
+ ContentSelectionPage contentPage;
+ OptionsPage optionsPage;
+
+ public ExportCoreWizard() {
+ setWindowTitle("Export PDF files");
+ setNeedsProgressMonitor(true);
+ }
+
+ public void init(IWorkbench workbench, final IStructuredSelection selection) {
+ try {
+ // Create export context
+ ctx = ExportContext.create( SimanticsUI.getSessionContext(), selection );
+
+ // Create extension point registry
+ ctx.eep = Exports.createExtensionPoint();
+
+ } catch (DatabaseException e) {
+ ExceptionUtils.logAndShowError(e);
+ }
+ }
+
+ @Override
+ public boolean performFinish() {
+
+ // User clicked finish on the first page. Preapare options page.
+ if ( getContainer().getCurrentPage() == contentPage ) {
+ contentPage.validatePage();
+ optionsPage.update( contentPage.getContentSelection() );
+ }
+
+ final boolean[] canceled = new boolean[1];
+
+ try {
+ contentPage.savePrefs();
+ optionsPage.savePrefs();
+ } catch (ExportException e) {
+ e.printStackTrace();
+ ExceptionUtils.logError(e);
+ }
+
+ try {
+ final ExportPlan plan = new ExportPlan();
+ final ExportWizardResult wizardResult = optionsPage.getOutput();
+ final ExportManager em = new ExportManager( wizardResult.options, ctx );
+ wizardResult.createPlan( ctx, plan );
+ System.out.println(wizardResult);
+
+ List<String> exportProblems = em.validate(ctx, plan);
+ if ( !exportProblems.isEmpty() ) {
+ CollectionUtils.unique(exportProblems);
+ WizardPage cp = (WizardPage) getContainer().getCurrentPage();
+ String str = CollectionUtils.toString(exportProblems, "\n");
+ cp.setErrorMessage( str );
+ return false;
+ }
+
+ getContainer().run(true, true, new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ SubMonitor mon = SubMonitor.convert(monitor, plan.label, 1000000);
+ try {
+ em.execute(ctx, mon.newChild(1000000, SubMonitor.SUPPRESS_NONE), plan);
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ canceled[0] = monitor.isCanceled();
+ monitor.done();
+ }
+ }
+ });
+
+ try {
+ ctx.store.flush();
+ } catch (BackingStoreException e) {
+ ErrorLogger.defaultLogError("Failed to persist wizard preferences.", e);
+ ExceptionUtils.logError(e);
+ }
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ WizardPage cp = (WizardPage) getContainer().getCurrentPage();
+
+ if ( t instanceof ExportException && t.getCause()!=null) {
+ ExportException ee = (ExportException) t;
+ if ( ee.getCause() != null ) t = ee.getCause();
+ }
+
+ if (canceled[0]) {
+ cp.setErrorMessage("Export canceled.");
+ } else if (t instanceof IOException) {
+ ErrorLogger.defaultLogError("An I/O problem occurred while exporting the model. See exception for details.", t);
+ cp.setErrorMessage("An I/O problem occurred while exporting the model.\nMessage: " + t.getMessage());
+ } else {
+ ErrorLogger.defaultLogError("Unexpected exception while exporting the model. See exception for details.", t);
+ cp.setErrorMessage("Unexpected exception while exporting the model. See error log for details.\nMessage: " + t.getMessage());
+ }
+ return false;
+ } catch (InterruptedException e) {
+ ExceptionUtils.logAndShowError(e);
+ } catch (ExportException e) {
+ ExceptionUtils.logAndShowError(e);
+ }
+
+ return true;
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ try {
+ contentPage = new ContentSelectionPage(ctx);
+ optionsPage = new OptionsPage(ctx);
+ addPage( contentPage );
+ addPage( optionsPage );
+ } catch (ExportException e) {
+ e.printStackTrace();
+ ExceptionUtils.logError(e);
+ }
+ }
+
+ @Override
+ public IWizardPage getNextPage(IWizardPage page) {
+ if ( page == optionsPage ) {
+ try {
+ optionsPage.getOutput();
+ } catch (ExportException e) {
+ return null;
+ }
+ }
+
+ if ( page == contentPage ) {
+ contentPage.validatePage();
+ optionsPage.update( ExporterUtils.sortContent( contentPage.getContentSelection() ) );
+ }
+ return super.getNextPage(page);
+ }
+
+}