/** @return layer's units */
  private Unit<?> getLayerUnits(final ILayer layer) {

    CoordinateReferenceSystem crs = LayerUtil.getCrs(layer);

    Unit<?> units = GeoToolsUtils.getDefaultCRSUnit(crs);

    return units;
  }
  /** @return map's units */
  private Unit<?> getMapUnits() {

    IMap map = getCurrentMap();
    assert map != null;

    CoordinateReferenceSystem crs = MapUtil.getCRS(map);
    Unit<?> mapUnits = GeoToolsUtils.getDefaultCRSUnit(crs);

    return mapUnits;
  }
  public void run(IProgressMonitor monitor) throws Exception {

    final ILayer editLayer = handler.getEditLayer();
    final Point mouseLocation = position;

    final EditBlackboard layerBlackboard = handler.getEditBlackboard(editLayer);
    final boolean includeSegmentsInCurrent = true;
    final SnapBehaviour snapBehaviour = SnapBehaviour.CURRENT_LAYER;

    final CoordinateReferenceSystem mapCrs = handler.getContext().getCRS();
    final int snappingRadius = PreferenceUtil.instance().getSnappingRadius();

    final SnapSegmentFinder segmentFinder = new SnapSegmentFinder(mapCrs);
    List<LineSegment> linesList = new ArrayList<LineSegment>();
    LineSegment closestSnapSegment;
    closestSnapSegment =
        segmentFinder.getClosestSnapSegment(
            handler,
            layerBlackboard,
            mouseLocation,
            includeSegmentsInCurrent,
            snapBehaviour,
            snappingRadius);

    if (closestSnapSegment != null) {
      CoordinateReferenceSystem layerCrs = editLayer.getCRS();
      closestSnapSegment = GeoToolsUtils.reproject(closestSnapSegment, mapCrs, layerCrs);
    }
    linesList.add(closestSnapSegment);
    if (this.mapMouseEvent.isShiftDown()) {
      this.segmentCopyContext.addSegments(linesList);
    } else {
      this.segmentCopyContext.setReferenceLineSegment(closestSnapSegment);
    }
    this.segmentCopyContext.setMode(PrecisionToolsMode.WAITING);

    System.out.println("\nSegment: " + closestSnapSegment.toString());
  }