@Override
  public boolean isValid(EditToolHandler handler, MapMouseEvent e, EventType eventType) {
    boolean goodState = handler.getCurrentState() != EditState.NONE;
    boolean releasedEvent = eventType == EventType.RELEASED;
    boolean noModifiers = !(e.modifiersDown());
    boolean button1 = e.button == MapMouseEvent.BUTTON1;
    boolean onlyButton1Down = e.buttons - (e.buttons & MapMouseEvent.BUTTON1) == 0;

    PrimitiveShape currentShape = handler.getCurrentShape();
    boolean shapeIsSet = currentShape != null;

    if (!(shapeIsSet && goodState && releasedEvent && noModifiers && button1 && onlyButton1Down))
      return false;

    int numPoints = currentShape.getNumPoints();
    boolean ready = numPoints == numOfPointsToAccept;

    return ready;
  }
 public void run(IProgressMonitor monitor) throws Exception {
   IToolContext context = handler.getContext();
   java.awt.Point point = new java.awt.Point(clickPoint.getX(), clickPoint.getY());
   ReferencedEnvelope bbox = handler.getContext().getBoundingBox(point, 7);
   FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
       context.getFeaturesInBbox(handler.getEditLayer(), bbox);
   FeatureIterator<SimpleFeature> it = fc.features();
   SimpleFeature feature = null;
   while (it.hasNext()) {
     SimpleFeature feat = it.next();
     if (feat.getID().equals(shape.getEditGeom().getFeatureIDRef().toString())) {
       feature = feat;
       break;
     }
   }
   it.close();
   oldFeature = getMap().getEditManagerInternal().getEditFeature();
   oldLayer = getMap().getEditManagerInternal().getEditLayer();
   editLayer = (Layer) handler.getEditLayer();
   oldFilter = editLayer.getFilter();
   getMap().getEditManagerInternal().setEditFeature(feature, editLayer);
   editLayer.setFilter(fidFilter(feature));
 }