1 package org.simantics.export.core.manager;
3 import java.util.ArrayList;
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.eclipse.core.runtime.SubMonitor;
8 import org.simantics.databoard.binding.mutable.Variant;
9 import org.simantics.export.core.ExportContext;
10 import org.simantics.export.core.error.ExportException;
13 * This class exports content.
15 * @author toni.kalajainen@semantum.fi
16 * @author tuukka.lehtonen@semantum.fi
18 public class ExportManager {
20 public Variant options;
21 public ExportContext ctx;
23 public ExportManager(Variant options, ExportContext ctx) {
24 this.options = options;
34 * the progress monitor to use for reporting progress to the
35 * user. It is the caller's responsibility to call done() on the
36 * given monitor. Accepts <code>null</code>, indicating that no
37 * progress should be reported and that the operation cannot be
41 * @throws ExportException
43 public void execute(ExportContext ctx, IProgressMonitor monitor, ExportPlan plan) throws ExportException
45 // 10000 units for all actions and 10 units the cleanup of each
46 int totalWork = plan.totalWork(ctx) * 10000 + plan.actions.size() * 100;
47 monitor.beginTask( plan.label, totalWork );
48 SubMonitor mon = SubMonitor.convert(monitor, plan.label, totalWork);
54 for ( ExportAction action : plan.actions ) {
55 if ( monitor.isCanceled() ) return;
56 int work = action.work(ctx) * 10000;
57 mon.setTaskName( action.label(ctx) );
58 action.execute(ctx, mon.newChild(work), options);
62 for ( ExportAction action : plan.actions ) {
63 mon.setTaskName( "Cleanup: " + action.label(ctx) );
65 action.cleanup(ctx, mon.newChild(100), options);
66 } catch (ExportException ee) {
72 } catch (ExportException ee) {
73 monitor.setTaskName( ee.getClass().getName()+": "+ee.getClass().getName() );
79 * Validate the plan is executable.
82 * @param optionsBinding
84 * @return null or a label describing the expected problem
86 public List<String> validate(ExportContext ctx, ExportPlan plan)
88 List<String> result = new ArrayList<String>(0);
89 for ( ExportAction action : plan.actions ) {
90 List<String> problems = action.validate(ctx, options);
91 result.addAll( problems );