@Override
  protected boolean handleKeyDown(KeyEvent event) {
    int dx = 0;
    int dy = 0;

    if (event.keyCode == SWT.SHIFT) {
      shift = true;
    }

    if (event.keyCode == SWT.ARROW_DOWN) {
      dy = 1;

    } else if (event.keyCode == SWT.ARROW_LEFT) {
      dx = -1;

    } else if (event.keyCode == SWT.ARROW_RIGHT) {
      dx = 1;

    } else if (event.keyCode == SWT.ARROW_UP) {
      dy = -1;
    }

    ERDiagram diagram = (ERDiagram) this.getCurrentViewer().getContents().getModel();

    List selectedObject = this.getCurrentViewer().getSelectedEditParts();
    if (!selectedObject.isEmpty()) {

      CompoundCommand command = new CompoundCommand();

      for (Object object : selectedObject) {

        if (object instanceof ERTableEditPart || object instanceof NoteEditPart) {
          NodeElementEditPart editPart = (NodeElementEditPart) object;

          NodeElement nodeElement = (NodeElement) editPart.getModel();

          MoveElementCommand moveElementCommand =
              new MoveElementCommand(
                  diagram,
                  editPart.getFigure().getBounds(),
                  nodeElement.getX() + dx,
                  nodeElement.getY() + dy,
                  nodeElement.getWidth(),
                  nodeElement.getHeight(),
                  nodeElement);

          command.add(moveElementCommand);
        }
      }

      this.executeCommand(command.unwrap());
    }

    return super.handleKeyDown(event);
  }
Пример #2
0
  /**
   * コピーを実行します。 <br>
   * この時点のコピー対象をコピー領域に複製しておきます<br>
   */
  private void copy() {
    if (!calculateEnabled()) {
      return;
    }

    // コピー情報をクリアします。
    CopyManager.clear();

    // 選択されているノードのEditPartを取得します
    NodeSet nodeElementList = new NodeSet();

    for (Object object : this.getSelectedObjects()) {
      if (object instanceof NodeElementEditPart) {
        NodeElementEditPart editPart = (NodeElementEditPart) object;

        NodeElement nodeElement = (NodeElement) editPart.getModel();
        nodeElementList.addNodeElement(nodeElement, false);
      }
    }
    nodeElementList.setDirty();

    CopyManager.copy(nodeElementList);
  }