private String getItemName(Entity entity) {
   mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class);
   if (mainItemComponent.itemIdentifier != null && !mainItemComponent.itemIdentifier.isEmpty()) {
     return mainItemComponent.itemIdentifier;
   } else {
     int type = EntityUtils.getType(entity);
     switch (type) {
       case EntityFactory.IMAGE_TYPE:
         return "Image";
       case EntityFactory.NINE_PATCH:
         return "9PatchImage";
       case EntityFactory.LABEL_TYPE:
         return "Label";
       case EntityFactory.COMPOSITE_TYPE:
         return "CompositeItem";
       case EntityFactory.PARTICLE_TYPE:
         return "ParticleEffect";
       case EntityFactory.LIGHT_TYPE:
         return "Light";
       case EntityFactory.SPINE_TYPE:
         return "Spine";
       case EntityFactory.SPRITE_TYPE:
         return "SpriteAnimation";
       case EntityFactory.SPRITER_TYPE:
         return "SpriterAnimation";
       case EntityFactory.COLOR_PRIMITIVE:
         return "Primitive";
       default:
         return "unknown";
     }
   }
 }
 private void backup() {
   if (entityId == null) {
     Object[] payload = getNotification().getBody();
     sourceName = (String) payload[0];
     targetName = (String) payload[1];
     entityId = EntityUtils.getEntityId(Sandbox.getInstance().getCurrentViewingEntity());
   }
 }
 private void collectData() {
   Object[] payload = getNotification().getBody();
   entityId = EntityUtils.getEntityId((Entity) payload[0]);
   dataFrom = (Vector2[][]) payload[1];
   dataTo = (Vector2[][]) payload[2];
   dataFrom = dataFrom.clone();
   dataTo = dataTo.clone();
 }
  @Override
  public void undoAction() {
    Entity viewingEntity = EntityUtils.getByUniqueId(entityId);
    LayerMapComponent layerMapComponent =
        ComponentRetriever.get(viewingEntity, LayerMapComponent.class);
    layerMapComponent.swap(targetName, sourceName);

    facade.sendNotification(DONE);
  }
  public void removeFromSelection(Set<Entity> selection) {

    if (tree == null) return;
    Array<Node> allSceneRootNodes = tree.getNodes().get(0).getChildren();

    for (int entityId : EntityUtils.getEntityId(selection)) {
      for (Node n : allSceneRootNodes) {
        if (n.getObject().equals(entityId)) {
          tree.getSelection().remove(n);
          break;
        }
      }
    }
  }
  private Node addTreeRoot(
      Entity entity,
      Node parentNode) { // was like this addTreeRoot(CompositeItem compoiteItem, Node parentNode)
    Node node = addTreeNode(entity, parentNode);
    if (parentNode == null) rootNode = node;

    NodeComponent nodeComponent = ComponentRetriever.get(entity, NodeComponent.class);

    if (nodeComponent != null) {
      for (Entity item : nodeComponent.children) {
        if (EntityUtils.getType(entity) == EntityFactory.COMPOSITE_TYPE) {
          addTreeRoot(item, node);
        } else {
          addTreeNode(item, node);
        }
      }
    }
    return node;
  }
  @Override
  public void undoAction() {
    Entity entity = EntityUtils.getByUniqueId(entityId);

    PolygonComponent polygonComponent = ComponentRetriever.get(entity, PolygonComponent.class);
    polygonComponent.vertices = dataFrom;

    // if it's image update polygon sprite data
    TextureRegionComponent textureRegionComponent =
        ComponentRetriever.get(entity, TextureRegionComponent.class);
    if (textureRegionComponent != null && textureRegionComponent.isPolygon) {
      DimensionsComponent dimensionsComponent =
          ComponentRetriever.get(entity, DimensionsComponent.class);
      dimensionsComponent.setPolygon(polygonComponent);
      textureRegionComponent.setPolygonSprite(polygonComponent);
    }

    Overlap2DFacade.getInstance().sendNotification(Overlap2D.ITEM_DATA_UPDATED, entity);
  }