Search in sources :

Example 1 with KeyBoardAccessibilityEditPolicy

use of org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardAccessibilityEditPolicy in project webtools.sourceediting by eclipse.

the class KeyboardDragImpl method performKeyboardDrag.

public void performKeyboardDrag(GraphicalEditPart movingElement, int direction) {
    KeyBoardAccessibilityEditPolicy policy = (KeyBoardAccessibilityEditPolicy) movingElement.getEditPolicy(KeyBoardAccessibilityEditPolicy.KEY);
    EditPart rightElement = policy.getRelativeEditPart(movingElement, direction);
    policy = (KeyBoardAccessibilityEditPolicy) rightElement.getEditPolicy(KeyBoardAccessibilityEditPolicy.KEY);
    EditPart leftElement = (policy != null) ? policy.getRelativeEditPart(rightElement, direction) : null;
    // TODO: add support for extenders
    if (!(movingElement instanceof XSDBaseFieldEditPart))
        return;
    XSDBaseFieldEditPart movingField = (XSDBaseFieldEditPart) movingElement;
    XSDBaseFieldEditPart leftField = (XSDBaseFieldEditPart) leftElement;
    XSDBaseFieldEditPart rightField = (XSDBaseFieldEditPart) rightElement;
    Object movingObject = movingField.getModel();
    BaseDragAndDropCommand command = null;
    if (movingObject instanceof XSDElementDeclarationAdapter || movingObject instanceof XSDWildcard) {
        command = new XSDElementDragAndDropCommand(movingField, leftField, rightField, direction);
    } else if (movingObject instanceof XSDAttributeDeclarationAdapter) {
        command = new XSDAttributeDragAndDropCommand(movingField, leftField, rightField, direction);
    }
    if (command != null && command.canExecute()) {
        command.execute();
        // This is to reselect the moved item
        try {
            IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
            if (editor != null && editor.getAdapter(ISelectionProvider.class) != null) {
                ISelectionProvider provider = (ISelectionProvider) editor.getAdapter(ISelectionProvider.class);
                if (provider != null) {
                    provider.setSelection(new StructuredSelection(movingElement.getModel()));
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : KeyBoardAccessibilityEditPolicy(org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardAccessibilityEditPolicy) XSDBaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart) XSDAttributeDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter) XSDBaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) XSDWildcard(org.eclipse.xsd.XSDWildcard) IEditorPart(org.eclipse.ui.IEditorPart) XSDAttributeDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.XSDAttributeDragAndDropCommand) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) XSDElementDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.XSDElementDragAndDropCommand) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) BaseDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand)

Example 2 with KeyBoardAccessibilityEditPolicy

use of org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardAccessibilityEditPolicy in project webtools.sourceediting by eclipse.

the class BaseGraphicalViewerKeyHandler method keyPressed.

public boolean keyPressed(KeyEvent event) {
    int direction = -1;
    boolean isAltDown = (event.stateMask & SWT.ALT) != 0;
    boolean isCtrlDown = (event.stateMask & SWT.CTRL) != 0;
    switch(event.keyCode) {
        case SWT.ARROW_LEFT:
            {
                direction = PositionConstants.WEST;
                break;
            }
        case SWT.ARROW_RIGHT:
            {
                direction = PositionConstants.EAST;
                break;
            }
        case SWT.ARROW_UP:
            {
                direction = isAltDown ? KeyBoardAccessibilityEditPolicy.OUT_TO_PARENT : PositionConstants.NORTH;
                break;
            }
        case SWT.ARROW_DOWN:
            {
                direction = isAltDown ? KeyBoardAccessibilityEditPolicy.IN_TO_FIRST_CHILD : PositionConstants.SOUTH;
                break;
            }
    }
    if (direction != -1) {
        GraphicalEditPart focusEditPart = getFocusEditPart();
        KeyBoardAccessibilityEditPolicy policy = (KeyBoardAccessibilityEditPolicy) focusEditPart.getEditPolicy(KeyBoardAccessibilityEditPolicy.KEY);
        if (policy != null) {
            EditPart target = policy.getRelativeEditPart(focusEditPart, direction);
            if (target != null) {
                if (isCtrlDown) {
                    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
                    Object keyboardDrag = editor.getAdapter(IKeyboardDrag.class);
                    if (keyboardDrag instanceof IKeyboardDrag) {
                        ((IKeyboardDrag) keyboardDrag).performKeyboardDrag(focusEditPart, direction);
                        return true;
                    }
                } else {
                    navigateTo(target, event);
                    return true;
                }
            }
        }
    }
    switch(event.keyCode) {
        case SWT.PAGE_DOWN:
            {
                if (scrollPage(event, PositionConstants.SOUTH))
                    return true;
            }
        case SWT.PAGE_UP:
            {
                if (scrollPage(event, PositionConstants.NORTH))
                    return true;
            }
        case SWT.F3:
        case SWT.CR:
            {
                IWorkbench workbench = PlatformUI.getWorkbench();
                IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
                ActionRegistry registry = (ActionRegistry) editorPart.getAdapter(ActionRegistry.class);
                if (registry != null) {
                    IAction action = registry.getAction(OpenInNewEditor.ID);
                    if (action != null)
                        action.run();
                }
            }
    }
    return super.keyPressed(event);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) KeyBoardAccessibilityEditPolicy(org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardAccessibilityEditPolicy) IAction(org.eclipse.jface.action.IAction) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) IEditorPart(org.eclipse.ui.IEditorPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

EditPart (org.eclipse.gef.EditPart)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 IEditorPart (org.eclipse.ui.IEditorPart)2 KeyBoardAccessibilityEditPolicy (org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardAccessibilityEditPolicy)2 Point (org.eclipse.draw2d.geometry.Point)1 ActionRegistry (org.eclipse.gef.ui.actions.ActionRegistry)1 IAction (org.eclipse.jface.action.IAction)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 XSDAttributeDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter)1 XSDElementDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)1 BaseDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand)1 XSDAttributeDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.XSDAttributeDragAndDropCommand)1 XSDElementDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.XSDElementDragAndDropCommand)1 XSDBaseFieldEditPart (org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart)1 XSDWildcard (org.eclipse.xsd.XSDWildcard)1