public PersistenceExportWizard() {

    setWindowTitle("Export");
    setNeedsProgressMonitor(true);

    this.page = new PlotDataConversionPage();
    page.setDescription(
        "Please choose the location of the file to export. (This file will be a nexus HDF5 file.)");
    addPage(page);

    this.options = new CheckWizardPage("Export Options", createDefaultOptions());
    Map<String, String> stringOptions = new HashMap<String, String>(1);
    stringOptions.put(PersistWizardConstants.MASK, "");
    options.setStringValues(stringOptions);
    options.setDescription("Please choose things to export.");

    addPage(options);
  }
  public boolean canFinish() {
    if (page.isPageComplete() && getContainer().getCurrentPage() == page) {
      options.setDescription("Please choose the things to save in '" + page.getPath() + "'.");
      options.setOptionEnabled(PersistWizardConstants.ORIGINAL_DATA, false);
      options.setOptionEnabled(PersistWizardConstants.IMAGE_HIST, false);
      options.setOptionEnabled(PersistWizardConstants.MASK, false);
      options.setOptionEnabled(PersistWizardConstants.REGIONS, false);
      options.setOptionEnabled(PersistWizardConstants.DIFF_META, false);
      options.setOptionEnabled(PersistWizardConstants.FUNCTIONS, false);

      File file = null;
      IPersistentFile pf = null;

      PERSIST_BLOCK:
      try {
        IPersistenceService service = ServiceLoader.getPersistenceService();
        file = new File(page.getAbsoluteFilePath());
        if (!file.exists()) break PERSIST_BLOCK;
        pf = service.getPersistentFile(file.getAbsolutePath());
        final List<String> names = pf.getMaskNames(null);
        if (names != null && !names.isEmpty()) {
          options.setStringValue(PersistWizardConstants.MASK, names.get(0));
        }

      } catch (Throwable ne) {
        logger.error("Cannot read persistence file at " + file);
      } finally {
        if (pf != null) pf.close();
      }

      final IPlottingSystem system = getPlottingSystem();
      if (system != null) {
        if (system != null) {
          ITrace trace = system.getTraces().iterator().next();
          if (trace != null) {

            options.setOptionEnabled(PersistWizardConstants.ORIGINAL_DATA, true);

            if (trace instanceof IImageTrace && ((IImageTrace) trace).getMask() != null) {
              options.setOptionEnabled(PersistWizardConstants.MASK, true);
            }
          }

          boolean requireHistory = false;
          final IToolPageSystem tsystem =
              (IToolPageSystem) system.getAdapter(IToolPageSystem.class);
          final IToolPage tool = tsystem.getActiveTool();
          if (tool != null
              && tool.getToolId().equals("org.dawb.workbench.plotting.tools.imageCompareTool")) {
            final Map<String, IDataset> data = (Map<String, IDataset>) tool.getToolData();
            if (data != null && !data.isEmpty()) requireHistory = true;
          }
          options.setOptionEnabled(PersistWizardConstants.IMAGE_HIST, requireHistory);

          final Collection<IRegion> regions = system.getRegions();
          if (regions != null && !regions.isEmpty()) {
            options.setOptionEnabled(PersistWizardConstants.REGIONS, true);
          }

          if (trace != null && trace instanceof IImageTrace && trace.getData() != null) {
            IMetadata meta = ((Dataset) trace.getData()).getMetadata();
            if (meta != null && (meta instanceof IDiffractionMetadata)) {
              options.setOptionEnabled(PersistWizardConstants.DIFF_META, true);
            }
          }

          final IWorkbenchPart part = EclipseUtils.getPage().getActivePart();
          if (part != null) {
            final IFunctionService funcService =
                (IFunctionService) part.getAdapter(IFunctionService.class);
            if (funcService != null) {
              options.setOptionEnabled(PersistWizardConstants.FUNCTIONS, true);
            }
          }
        }
      }
    }
    return super.canFinish();
  }