blob: a6a7de7ea401f8b342ba0fafc372c38b8ff43201 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*******************************************************************************
* Copyright (c) 2001, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.adt.design;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardNavigationEditPolicy;
/**
* This key handler is designed to be re-used by both the WSDL and XSD editor
*/
public class BaseGraphicalViewerKeyHandler extends GraphicalViewerKeyHandler
{
public BaseGraphicalViewerKeyHandler(GraphicalViewer viewer)
{
super(viewer);
}
public boolean keyPressed(KeyEvent event)
{
int direction = -1;
boolean isAltDown = (event.stateMask & SWT.ALT) != 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 ? KeyBoardNavigationEditPolicy.OUT_TO_PARENT : PositionConstants.NORTH;
break;
}
case SWT.ARROW_DOWN : {
direction = isAltDown ? KeyBoardNavigationEditPolicy.IN_TO_FIRST_CHILD : PositionConstants.SOUTH;
break;
}
}
if (direction != -1)
{
GraphicalEditPart focusEditPart = getFocusEditPart();
KeyBoardNavigationEditPolicy policy = (KeyBoardNavigationEditPolicy)focusEditPart.getEditPolicy(KeyBoardNavigationEditPolicy.KEY);
if (policy != null)
{
EditPart target = policy.getRelativeEditPart(focusEditPart, direction);
if (target != null)
{
navigateTo(target, event);
return true;
}
}
}
switch (event.keyCode)
{
case SWT.PAGE_DOWN :
if (scrollPage(event, PositionConstants.SOUTH))
return true;
break;
case SWT.PAGE_UP :
if (scrollPage(event, PositionConstants.NORTH))
return true;
}
return super.keyPressed(event);
}
private boolean scrollPage(KeyEvent event, int direction)
{
if (!(getViewer().getControl() instanceof FigureCanvas))
return false;
FigureCanvas figCanvas = (FigureCanvas) getViewer().getControl();
Point loc = figCanvas.getViewport().getViewLocation();
Rectangle area = figCanvas.getViewport().getClientArea(Rectangle.SINGLETON).scale(.8);
if (direction == PositionConstants.NORTH)
{
figCanvas.scrollToY(loc.y - area.height);
}
else
{
figCanvas.scrollToY(loc.y + area.height);
}
return true;
}
}
|