/**
   * Update the view content according to the entity given in parameter if it can handle it in its
   * current state The returned IEntity will be the one currently managed by this view
   *
   * @param e an IEntity
   * @return IEntity that is currently managed by this view
   */
  public IEntity registerEntity(IEntity e) {
    switch (state) {
      case CONFIRM:
        Toast.makeText(ctx, TEXT_SELECT_ENT_WHEN_DRAWING, Toast.LENGTH_LONG).show();
        return this.entity;

      default:
        if (this.entity != null) {
          this.entity.deleteObserver(this); // do not observe old entity anymore
        }
        this.entity = e; // register the new entity
        this.entity.addObserver(this); // observe the new entity
        this.icon = e.getIcon();
        this.msg = e.getType() + e.getMessage();
        switch (entity.getState()) {
          case SAVED:
            state = State.DELETION;
            break;

          case NEW:
            state = State.SELECTION;
            break;

          case ON_MAP:
            state = State.CONFIRM;
            break;
        }
        updateUI();
        show();
        return entity;
    }
  }
  @Override
  public void update(Observable o, Object arg) {
    if (arg instanceof IEntity) {
      IEntity e = (IEntity) arg;
      switch (e.getState()) {
        case SAVED:
          hide();
          break;

        case ON_MAP:
          if (e instanceof IShapedEntity) {
            IShapedEntity sEnt = (IShapedEntity) e;

            if (sEnt.isPersistable()) {
              actionBtn.setEnabled(true);
              actionBtn.setTextColor(Color.WHITE);

            } else {
              actionBtn.setEnabled(false);
              actionBtn.setTextColor(Color.GRAY);
            }
            state = State.CONFIRM;
            updateUI();
            show();
          }
          break;
      }

    } else if (arg instanceof IUndoRedoEngine) {
      IUndoRedoEngine engine = (IUndoRedoEngine) arg;

      if (engine.canRedo()) {
        redoView.setEnabled(true);
        redoView.setAlpha(OPAQUE);
      } else {
        redoView.setEnabled(false);
        redoView.setAlpha(TRANSLUCENT);
      }

      if (engine.canUndo()) {
        undoView.setEnabled(true);
        undoView.setAlpha(OPAQUE);
      } else {
        undoView.setEnabled(false);
        undoView.setAlpha(TRANSLUCENT);
      }

    } else {
      Log.w(TAG, "I don't know how to update myself with this object " + arg + " !");
    }
  }