class ToggleStateAction extends ToggleAction {

  @Override
  public void setSelected(@NotNull AnActionEvent event, boolean selected) {
    ImageView image = getImageView();

    if (image == null) {
      return;
    }

    int[] states = image.getDrawableState();
    int state = myState.getIntValue();

    // image.setImageState(states, true) didn't work as expected. So I'm doing it this way.

    if (selected) {
      assert !Ints.contains(states, state);
      image.setImageState(ArrayUtil.append(states, state), false);
    }
    else {
      assert Ints.contains(states, state);

      int i = Ints.indexOf(states, state);
      image.setImageState(ArrayUtil.remove(states, i), false);
    }

    SceneManager manager = mySurface.getSceneManager();

    if (manager == null) {
      return;
    }

    manager.requestRender();
  }

    ToggleStateAction(@NotNull State state, @NotNull DesignSurface surface);

}