예제 #1
0
 public int compare(RowInfoLeaf o1, RowInfoLeaf o2) {
   int compareValue = 0;
   // if either object return null for getPosition(), results are
   // unexpected anyway, so this test will only pass (test only to
   // prevent from crashing)
   if (o1.getPosition() != null && o2.getPosition() != null) {
     compareValue =
         o1.getPosition().compareTo(o2.getPosition()) * -1; // multiply by -1 to invert order
   }
   return compareValue;
 }
예제 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
   * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
   */
  @Override
  public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {

    /*
     * Remove all selected items
     *
     * Put all array items of some array together to remove in reverse order
     * due to indexing problems.
     */
    Map<RowInfo, TreeSet<RowInfoLeaf>> mapForRemovingArrayItems =
        new HashMap<RowInfo, TreeSet<RowInfoLeaf>>();

    for (RowInfo row : rows) {
      if (row instanceof RowInfoLeaf) {
        RowInfoLeaf leaf = (RowInfoLeaf) row;
        if (leaf.getParent() == null) {
          // string
          getEditor().removeRow(row.getKey());
        } else {
          // array item - accumulate and remove all at once to avoid
          // index problems
          TreeSet<RowInfoLeaf> childrenList = mapForRemovingArrayItems.get(leaf.getParent());
          if (childrenList == null) {
            childrenList = new TreeSet<RowInfoLeaf>(new LeavesInvertedPositionComparator());
            mapForRemovingArrayItems.put(leaf.getParent(), childrenList);
          }
          childrenList.add(leaf);
        }
      } else {
        // array
        getEditor().removeRow(row.getKey());
      }
    }

    if (!mapForRemovingArrayItems.isEmpty()) {
      // remove array items that were accumulated
      for (TreeSet<RowInfoLeaf> childrenList : mapForRemovingArrayItems.values()) {
        for (RowInfoLeaf leaf : childrenList) {
          getEditor().removeRow(leaf.getKey(), leaf.getPosition());
        }
      }
    }

    getEditor().refresh();
    return Status.OK_STATUS;
  }