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) {
}
}
}
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);
}
Aggregations