示例#1
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;
  }
示例#2
0
  /**
   * Creates a RemoveKeyOperation.
   *
   * @param label - the label for this operation.
   * @param editor - the editor object.
   * @param row - The RowInfo object that identifies the key to be removed.
   */
  public RemoveKeyOperation(String label, StringEditorPart editor, List<RowInfo> rows) {
    super(label, editor);

    this.rows = new ArrayList<RowInfo>();

    // only array items and string nodes are added to the list of rows
    // if an array header is selected, all of its children will be added

    for (RowInfo info : rows) {
      if (info instanceof RowInfoLeaf) {
        if (!this.rows.contains(info)) {
          this.rows.add(info);
        }
      } else {
        for (RowInfoLeaf leaf : info.getChildren()) {
          if (!this.rows.contains(leaf)) {
            this.rows.add(leaf);
          }
        }
      }
    }
  }