X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.export.core%2Fsrc%2Forg%2Fsimantics%2Fexport%2Fcore%2Fmanager%2FExportManager.java;h=ecfbbd0d28907d87ce48c330808fc7faca258ccf;hp=5ca1a33f409ec7c1097814b245c449bd7b963335;hb=48ea5bf055156f92d497a9a45bc05ac9d85b6f43;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.export.core/src/org/simantics/export/core/manager/ExportManager.java b/bundles/org.simantics.export.core/src/org/simantics/export/core/manager/ExportManager.java index 5ca1a33f4..ecfbbd0d2 100644 --- a/bundles/org.simantics.export.core/src/org/simantics/export/core/manager/ExportManager.java +++ b/bundles/org.simantics.export.core/src/org/simantics/export/core/manager/ExportManager.java @@ -1,97 +1,97 @@ -package org.simantics.export.core.manager; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubMonitor; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.export.core.ExportContext; -import org.simantics.export.core.error.ExportException; - -/** - * This class exports content. - * - * @author toni.kalajainen@semantum.fi - * @author tuukka.lehtonen@semantum.fi - */ -public class ExportManager { - - public Variant options; - public ExportContext ctx; - - public ExportManager(Variant options, ExportContext ctx) { - this.options = options; - this.ctx = ctx; - } - - /** - * Execute export plan - * - * @param ctx - * export context - * @param monitor - * the progress monitor to use for reporting progress to the - * user. It is the caller's responsibility to call done() on the - * given monitor. Accepts null, indicating that no - * progress should be reported and that the operation cannot be - * cancelled. - * @param plan - * export plan - * @throws ExportException - */ - public void execute(ExportContext ctx, IProgressMonitor monitor, ExportPlan plan) throws ExportException - { - // 10000 units for all actions and 10 units the cleanup of each - int totalWork = plan.totalWork(ctx) * 10000 + plan.actions.size() * 100; - monitor.beginTask( plan.label, totalWork ); - SubMonitor mon = SubMonitor.convert(monitor, plan.label, totalWork); - - try { - - try { - // 1. Export - for ( ExportAction action : plan.actions ) { - if ( monitor.isCanceled() ) return; - int work = action.work(ctx) * 10000; - mon.setTaskName( action.label(ctx) ); - action.execute(ctx, mon.newChild(work), options); - } - } finally { - // 2. Cleanup - for ( ExportAction action : plan.actions ) { - mon.setTaskName( "Cleanup: " + action.label(ctx) ); - try { - action.cleanup(ctx, mon.newChild(100), options); - } catch (ExportException ee) { - ee.printStackTrace(); - } - } - } - - } catch (ExportException ee) { - monitor.setTaskName( ee.getClass().getName()+": "+ee.getClass().getName() ); - throw ee; - } - } - - /** - * Validate the plan is executable. - * - * @param ctx - * @param optionsBinding - * @param options - * @return null or a label describing the expected problem - */ - public List validate(ExportContext ctx, ExportPlan plan) - { - List result = new ArrayList(0); - for ( ExportAction action : plan.actions ) { - List problems = action.validate(ctx, options); - result.addAll( problems ); - } - return result; - } - - -} +package org.simantics.export.core.manager; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.export.core.ExportContext; +import org.simantics.export.core.error.ExportException; + +/** + * This class exports content. + * + * @author toni.kalajainen@semantum.fi + * @author tuukka.lehtonen@semantum.fi + */ +public class ExportManager { + + public Variant options; + public ExportContext ctx; + + public ExportManager(Variant options, ExportContext ctx) { + this.options = options; + this.ctx = ctx; + } + + /** + * Execute export plan + * + * @param ctx + * export context + * @param monitor + * the progress monitor to use for reporting progress to the + * user. It is the caller's responsibility to call done() on the + * given monitor. Accepts null, indicating that no + * progress should be reported and that the operation cannot be + * cancelled. + * @param plan + * export plan + * @throws ExportException + */ + public void execute(ExportContext ctx, IProgressMonitor monitor, ExportPlan plan) throws ExportException + { + // 10000 units for all actions and 10 units the cleanup of each + int totalWork = plan.totalWork(ctx) * 10000 + plan.actions.size() * 100; + monitor.beginTask( plan.label, totalWork ); + SubMonitor mon = SubMonitor.convert(monitor, plan.label, totalWork); + + try { + + try { + // 1. Export + for ( ExportAction action : plan.actions ) { + if ( monitor.isCanceled() ) return; + int work = action.work(ctx) * 10000; + mon.setTaskName( action.label(ctx) ); + action.execute(ctx, mon.newChild(work), options); + } + } finally { + // 2. Cleanup + for ( ExportAction action : plan.actions ) { + mon.setTaskName( "Cleanup: " + action.label(ctx) ); + try { + action.cleanup(ctx, mon.newChild(100), options); + } catch (ExportException ee) { + ee.printStackTrace(); + } + } + } + + } catch (ExportException ee) { + monitor.setTaskName( ee.getClass().getName()+": "+ee.getClass().getName() ); + throw ee; + } + } + + /** + * Validate the plan is executable. + * + * @param ctx + * @param optionsBinding + * @param options + * @return null or a label describing the expected problem + */ + public List validate(ExportContext ctx, ExportPlan plan) + { + List result = new ArrayList(0); + for ( ExportAction action : plan.actions ) { + List problems = action.validate(ctx, options); + result.addAll( problems ); + } + return result; + } + + +}