public IStatus execute(final IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    Display display = (Display) info.getAdapter(Display.class);

    // set map extent
    try {
      monitor.subTask(Messages.get("OpenMapOperation_calcLayersBounds"));

      if (map.getLayers().isEmpty()) {
        display.asyncExec(
            new Runnable() {
              public void run() {
                MessageBox box = new MessageBox(page.getWorkbenchWindow().getShell());
                box.setText(Messages.get("OpenMapOperation_noLayersText"));
                box.setMessage(Messages.get("OpenMapOperation_noLayersMsg"));
                box.open();
              }
            });
        return Status.CANCEL_STATUS;
      }

      final ReferencedEnvelope bbox =
          map.getMaxExtent() == null
              ? calcLayersBounds(map.getLayers(), map.getCRS(), monitor)
              : map.getMaxExtent();

      if (map.getMaxExtent() == null && bbox != null) {
        log.info("### No map max extent -> using calculated values: " + bbox);
        map.setMaxExtent(bbox);
      }
      if (bbox == null && !map.getLayers().isEmpty()) {
        display.syncExec(
            new Runnable() {
              public void run() {
                MessageBox box = new MessageBox(page.getWorkbenchWindow().getShell());
                box.setText(Messages.get("OpenMapOperation_bboxErrorText"));
                box.setMessage(Messages.get("OpenMapOperation_bboxErrorMsg"));
                box.open();
              }
            });
      } else {
        map.setVisible(true);
      }
      return Status.OK_STATUS;
    } catch (Exception e) {
      throw new ExecutionException(e.getLocalizedMessage(), e);
    }
  }
  private ReferencedEnvelope calcLayersBounds(
      Collection<ILayer> layers, CoordinateReferenceSystem crs, IProgressMonitor monitor)
      throws Exception {
    log.debug("### mapCRS: " + crs); // $NON-NLS-1$

    ReferencedEnvelope result = null; // new ReferencedEnvelope( crs );
    for (ILayer layer : layers) {
      try {
        IGeoResource res = layer.getGeoResource();
        if (res == null) {
          continue;
        }
        ReferencedEnvelope bbox =
            SetLayerBoundsOperation.obtainBoundsFromResources(layer, crs, monitor);
        if (!bbox.getCoordinateReferenceSystem().equals(crs)) {
          bbox = bbox.transform(crs, true);
        }
        log.debug("layer: " + layer + ", bbox= " + bbox); // $NON-NLS-1$ //$NON-NLS-2$

        if (result == null) {
          result = bbox;
        } else {
          result.expandToInclude(bbox);
        }
        log.debug("result: bbox=  " + result); // $NON-NLS-1$
      } catch (Exception e) {
        // XXX mark layers!?
        log.debug("", e); // $NON-NLS-1$
        log.warn(
            "skipping layer: " + layer.getLabel() + " (" + e.toString(),
            e); //$NON-NLS-1$ //$NON-NLS-2$
        layer.setLayerStatus(
            new LayerStatus(
                Status.WARNING,
                LayerStatus.UNSPECIFIED,
                Messages.get("LayerStatus_noCrs"),
                e)); //$NON-NLS-1$
      }
    }
    return result != null ? result : ReferencedEnvelope.EVERYTHING.transform(crs, true);
  }
 public OpenMapOperation(IMap map, IWorkbenchPage page) {
   super(Messages.get("OpenMapOperation_titlePrefix") + map.getLabel());
   this.map = map;
   this.page = page;
 }