コード例 #1
0
  private int getTotalWork(
      CheckWizardPage options, IPlottingSystem system, final IFunctionService funcService) {

    try {
      int ret = 1;
      if (options.is(PersistWizardConstants.ORIGINAL_DATA)) {
        Collection<ITrace> traces = system.getTraces();
        ret += traces != null ? traces.size() : 0;
      }
      if (options.is(PersistWizardConstants.IMAGE_HIST)) {
        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()) {
            ret += data.size();
          }
        }
      }

      final ITrace trace = system.getTraces().iterator().next();
      if (options.is(PersistWizardConstants.MASK) && trace instanceof IImageTrace) {
        IImageTrace image = (IImageTrace) trace;
        final String name = options.getString(PersistWizardConstants.MASK);
        if (image.getMask() != null) {
          ret += 1;
        }
      }

      final Collection<IRegion> regions = system.getRegions();
      if (options.is(PersistWizardConstants.REGIONS) && regions != null && !regions.isEmpty()) {
        ret += regions.size();
      }

      if (options.is(PersistWizardConstants.DIFF_META)) {
        if (trace != null && trace instanceof IImageTrace && trace.getData() != null) {
          ret += 1;
        }
      }

      if (options.is(PersistWizardConstants.FUNCTIONS)) {
        if (funcService != null) {
          Map<String, IFunction> functions = funcService.getFunctions();
          if (functions != null) ret += functions.size();
        }
      }

      return ret;
    } catch (Exception ne) {
      logger.error("Cannot estimate work, assuming 100 things to do!", ne);
      return 100;
    }
  }
コード例 #2
0
  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();
  }