package xdean.tool.api;

import java.net.URL;
import java.util.List;

import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.StringProperty;

/**
 * Tool item, it has 3 properties<br>
 * 1. text<br>
 * 2. icon<br>
 * 3. children<br>
 * and an action {@code onClick}
 *
 * @author XDean
 *
 */
public interface ITool {

  StringProperty textProperty();

  default String getText() {
    return textProperty().get();
  }

  ObjectProperty<URL> iconUrlProperty();

  default URL getIconUrl() {
    return iconUrlProperty().get();
  }

  ListProperty<ITool> childrenProperty();

  default List<ITool> getChildren() {
    ListProperty<ITool> children = childrenProperty();
    return children.subList(0, children.size());
  }

  ObjectProperty<ITool> parentProperty();

  default ITool getParent() {
    return parentProperty().get();
  }

  void onClick();

}

@@ -809,32 +809,515 @@
 ize());%0D%0A  %7D%0D%0A%0D%0A
+  default void addChild(ITool tool) %7B%0D%0A    tool.removeFromParent();%0D%0A    this.childrenProperty().add(tool);%0D%0A    tool.parentProperty().set(this);%0D%0A  %7D%0D%0A%0D%0A  default boolean removeChild(ITool tool) %7B%0D%0A    if (childrenProperty().remove(tool)) %7B%0D%0A      tool.parentProperty().set(null);%0D%0A      return true;%0D%0A    %7D%0D%0A    return false;%0D%0A  %7D%0D%0A%0D%0A  default boolean removeFromParent() %7B%0D%0A    ITool parent = parentProperty().get();%0D%0A    return parent != null && parent.removeChild(this);%0D%0A  %7D%0D%0A%0D%0A
   ObjectProperty

add default methods