Example #1
0
  public boolean moveToGroup(String group) {
    String currentParent = Group.substractParentName(getName());
    if (group.equals(currentParent)) return false;

    // String oldName = getName();
    String newName;
    if (group.equals(nullString)) newName = Group.substractObjectName(getName());
    else newName = group + Constants.GROUP_SEPARATOR + Group.substractObjectName(getName());

    // object with new name already exists, add suffix // !!!
    Object obj;
    boolean renameNeeded = false;
    while ((obj = Group.getRoot().findObject(newName, true)) != null) {
      if (obj == this) // it's me :) already moved, fix data
      {
        name = newName;
        return true;
      } else {
        renameNeeded = true;
        newName = StringUtils.incrementName(newName, Constants.MOVE_SUFFIX);
      }
    }

    if (renameNeeded) return rename(newName);

    getParent().removeObject(Group.substractObjectName(getName()));
    setParent(null);
    Group.getRoot().addSubObject(newName, this, true);

    name = newName;
    unconditionalValidation();

    return true;
  }
Example #2
0
  public Flexible copyToGroup(String group) {

    String newName;
    if (group.equals(nullString)) newName = Group.substractObjectName(getName());
    else newName = group + Constants.GROUP_SEPARATOR + Group.substractObjectName(getName());

    // object with new name already exists, add suffix ///!!!
    while (Group.getRoot().findObject(newName, true) != null)
      newName = StringUtils.incrementName(newName, Constants.COPY_SUFFIX);

    Box grBox =
        new Box(
            newName,
            null,
            startVertex.getX(),
            startVertex.getY(),
            endVertex.getX(),
            endVertex.getY());
    grBox.setColor(getColor());
    Group.getRoot().addSubObject(newName, grBox, true);

    // ViewState view = ViewState.getInstance();
    // grBox.move(20 - view.getRx(), 20 - view.getRy());

    unconditionalValidation();
    return grBox;
  }
Example #3
0
  public boolean rename(String newName) {
    String newObjName = Group.substractObjectName(newName);
    String oldObjName = Group.substractObjectName(getName());

    if (!oldObjName.equals(newObjName)) {
      getParent().removeObject(oldObjName);
      String fullName = StringUtils.replaceEnding(getName(), oldObjName, newObjName);
      name = fullName;
      getParent().addSubObject(newObjName, this);
    }

    // move if needed
    moveToGroup(Group.substractParentName(newName));

    return true;
  }
Example #4
0
  public void destroy() {
    super.destroy();
    if (getParent() != null) getParent().removeObject(Group.substractObjectName(name));

    if (!startVertex.isDestroyed()) startVertex.destroy();

    if (!endVertex.isDestroyed()) endVertex.destroy();
  }