예제 #1
0
  private TreeNode pasteCollection(EntryEditor editor, TreeNode parent, String data) {
    Shell shell = editor.getSite().getShell();
    Thype parentThype = ValueData.of(parent).element().thype();
    SpreadSheetTable table = new SpreadSheetTable(data);
    if (parentThype instanceof ArrayThype) {
      if (table.numCols() != 1) {
        String title = "Invalid content";
        S msg = new S();
        msg.addf("You can only paste a single column table" + " onto an array node!");
        MessageDialog.openError(shell, title, msg.toString());
        return parent;
      }

      parent = ElementHelper.copyOnNeed(parent, editor);
      if (parent == null) {
        return null;
      }

      addArrayElements(parent, table, range(0, table.numRows()), log);
    } else if (parentThype instanceof MapThype) {
      if (table.numCols() != 2) {
        String title = "Invalid content";
        S msg = new S();
        msg.addf("You can only paste a two-column table" + " onto a map node!");
        MessageDialog.openError(shell, title, msg.toString());
        return null;
      }

      parent = ElementHelper.copyOnNeed(parent, editor);
      if (parent == null) {
        return null;
      }

      addMapElements(parent, table, range(0, table.numRows()), log);
    } else {
      ElementHelper.unsupportedThype(parentThype);
      return null;
    }

    return parent;
  }