Search in sources :

Example 1 with UnexecutableCommand

use of org.eclipse.gef.commands.UnexecutableCommand in project cubrid-manager by CUBRID.

the class GefViewerKeyHandler method deleteHANodeByKey.

/**
	 * delete node by delete key,do not suppurt multi selected.
	 * 
	 * @param event KeyEvent
	 * @return if delete node return true,else return false
	 */
private boolean deleteHANodeByKey(KeyEvent event) {
    if (event.keyCode == SWT.DEL && getViewer().getSelectedEditParts().size() == 1) {
        GroupRequest deleteRequest = new GroupRequest(RequestConstants.REQ_DELETE);
        GraphicalEditPart editPart = getFocusEditPart();
        deleteRequest.setEditParts(editPart);
        Command command = editPart.getCommand(deleteRequest);
        if (command != null && !(command instanceof UnexecutableCommand)) {
            command.execute();
            return true;
        }
    }
    return false;
}
Also used : UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) Command(org.eclipse.gef.commands.Command) GroupRequest(org.eclipse.gef.requests.GroupRequest) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand)

Example 2 with UnexecutableCommand

use of org.eclipse.gef.commands.UnexecutableCommand in project cubrid-manager by CUBRID.

the class GefViewerKeyHandler method moveHANodesByKey.

/**
	 * move figures by keyboard.
	 * 
	 * @param event KeyEvent
	 * @return if handled the event return true else return false.
	 */
private boolean moveHANodesByKey(KeyEvent event) {
    List<?> selectedEditParts = getViewer().getSelectedEditParts();
    boolean flag = false;
    for (Object obj : selectedEditParts) {
        if (!(obj instanceof HANodePart)) {
            continue;
        }
        GraphicalEditPart editPart = (GraphicalEditPart) obj;
        Command command = null;
        if ((event.stateMask & SWT.ALT) == 0 && (event.stateMask & SWT.CTRL) == 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_LEFT || event.keyCode == SWT.ARROW_RIGHT || event.keyCode == SWT.ARROW_UP)) {
            HANode node = (HANode) editPart.getModel();
            ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
            request.setLocation(node.getLocation());
            request.setEditParts(editPart);
            //get move delta
            Point moveDelta = null;
            switch(event.keyCode) {
                case SWT.ARROW_LEFT:
                    moveDelta = new Point(-1, 0);
                    break;
                case SWT.ARROW_RIGHT:
                    moveDelta = new Point(1, 0);
                    break;
                case SWT.ARROW_UP:
                    moveDelta = new Point(0, -1);
                    break;
                case SWT.ARROW_DOWN:
                    moveDelta = new Point(0, 1);
                    break;
                default:
                    return true;
            }
            request.setMoveDelta(moveDelta);
            command = editPart.getCommand(request);
        }
        if (command != null && !(command instanceof UnexecutableCommand)) {
            command.execute();
            flag = true;
        }
    }
    return flag;
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) Command(org.eclipse.gef.commands.Command) Point(org.eclipse.draw2d.geometry.Point) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) HANode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HANode) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) HANodePart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HANodePart)

Aggregations

GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 Command (org.eclipse.gef.commands.Command)2 UnexecutableCommand (org.eclipse.gef.commands.UnexecutableCommand)2 HANode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.HANode)1 HANodePart (com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HANodePart)1 Point (org.eclipse.draw2d.geometry.Point)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 GroupRequest (org.eclipse.gef.requests.GroupRequest)1