Esempio n. 1
0
  /**
   * This method tells the CategoryNode what it's containing category is.
   *
   * @see arlut.csd.ganymede.rmi.CategoryNode
   */
  public void setCategory(Category category) {
    DBBaseCategory cat;
    String path;

    /* -- */

    if (category == null) {
      parent = null;
      return;
    }

    if (!(category instanceof DBBaseCategory)) {
      // we need a local reference

      try {
        path = category.getPath();
      } catch (RemoteException ex) {
        throw new RuntimeException("couldn't get path of remote category: " + ex);
      }

      if (debug) {
        System.err.println("** Attempting to find local copy of category " + path);
      }

      // getCategoryNode could also return a DBObjectBase, but not
      // in this context

      if (editor == null) {
        cat = (DBBaseCategory) store.getCategoryNode(path);
      } else {
        cat = (DBBaseCategory) editor.getCategoryNode(path);
      }

      if (cat == null) {
        throw new RuntimeException("setCategory: couldn't find local parent category");
      }

      parent = cat;
    } else {
      parent = (DBBaseCategory) category;
    }
  }
Esempio n. 2
0
  /**
   * This method can be used to move a Category from another Category to this Category, or to move a
   * Category around within this Category.
   *
   * @param catPath the fully specified path of the node to be moved
   * @param prevNodeName the name of the node that the catPath node is to be placed after in this
   *     category, or null if the node is to be placed at the first element of this category
   * @see arlut.csd.ganymede.rmi.Category
   */
  public synchronized void moveCategoryNode(String catPath, String prevNodeName) {
    if (debug) {
      System.err.println("DBBaseCategory.moveCategoryNode(" + catPath + "," + prevNodeName + ")");
    }

    CategoryNode categoryNode;
    DBBaseCategory oldCategory;

    try {
      categoryNode = editor.getCategoryNode(catPath);
      oldCategory = (DBBaseCategory) categoryNode.getCategory();
    } catch (RemoteException ex) {
      Ganymede.logError(ex);
      throw new RuntimeException("wow, surprising remote local exception");
    }

    if (oldCategory == this) {
      if (debug) {
        System.err.println("DBBaseCategory.moveCategoryNode(): moving node within category");
      }

      contents.removeElement(categoryNode);
    } else {
      if (debug) {
        System.err.println(
            "DBBaseCategory.moveCategoryNode(): moving node from "
                + oldCategory.getPath()
                + " to "
                + getPath());
      }

      try {
        oldCategory.removeNode(categoryNode);
      } catch (RemoteException ex) {
        throw new RuntimeException("Local category threw a remote exception.. ? " + ex);
      }
    }

    try {
      categoryNode.setCategory(this);
    } catch (RemoteException ex) {
      throw new RuntimeException("Local category node threw a remote exception.. ? " + ex);
    }

    if (prevNodeName == null) {
      contents.insertElementAt(categoryNode, 0);
    } else {
      for (int i = 0; i < contents.size(); i++) {
        CategoryNode cNode = (CategoryNode) contents.elementAt(i);

        try {
          if (cNode.getName().equals(prevNodeName)) {
            contents.insertElementAt(categoryNode, i + 1);
            return;
          }
        } catch (RemoteException ex) {
        }
      }

      throw new RuntimeException(
          "Couldn't move category node " + catPath + " after non-existent " + prevNodeName);
    }
  }