/**
   * Sets the selection to the given selection and fires selection changed. The ISelection should be
   * an {@link IStructuredSelection}or it will be ignored.
   *
   * @see ISelectionProvider#setSelection(ISelection)
   */
  public void setSelection(ISelection newSelection, boolean dispatch) {
    if (!(newSelection instanceof IStructuredSelection)) return;

    List editparts = ((IStructuredSelection) newSelection).toList();
    List selection = primGetSelectedEditParts();

    setFocus(null);
    for (int i = 0; i < selection.size(); i++)
      ((EditPart) selection.get(i)).setSelected(EditPart.SELECTED_NONE);
    selection.clear();

    editparts = flitterEditpart(editparts);
    // for create handle
    selection.addAll(editparts);

    for (int i = 0; i < editparts.size(); i++) {
      EditPart part = (EditPart) editparts.get(i);
      if (i == editparts.size() - 1) part.setSelected(EditPart.SELECTED_PRIMARY);
      else part.setSelected(EditPart.SELECTED);
    }

    if (dispatch) {
      fireSelectionChanged();
    }
  }
  public void setActiveTool(ToolEntry tool) {
    EditPart part = getFocusEditPart();
    if (part instanceof GraphicalEditPart) {
      IFigure fig = ((GraphicalEditPart) part).getFigure();
      if (fig instanceof Clickable) {
        part.setSelected(EditPart.SELECTED_NONE);
        ((Clickable) fig).getModel().setArmed(false);
        ((Clickable) fig).getModel().setPressed(false);
        ((Clickable) fig).getModel().setSelected(false);
      }
    }
    super.setActiveTool(null);

    if (tool instanceof PaletteItem && !listener.isDragging()) {
      insertIntoEditor((PaletteItem) tool);
    }
  }