在gef相关的编辑器类中采用快捷键处理器KeyHandler中注册相关类的Action并在
protected KeyHandler getCommonKeyHandler(){
if (sharedKeyHandler == null){
sharedKeyHandler = new KeyHandler();
sharedKeyHandler.put(
KeyStroke.getPressed(SWT.F2, 0),
getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT));
}
returnsharedKeyHandler;
}
在gef视图编辑器类中的方法protectedvoid configureGraphicalViewer()中添加如下代码:
ScrollingGraphicalViewer viewer =(ScrollingGraphicalViewer)getGraphicalViewer();
ScalableFreeformRootEditPart root = new ScalableFreeformRootEditPart();
viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)
.setParent(getCommonKeyHandler()));
在大纲视图中的使用如下:
getViewer().setKeyHandler(getCommonKeyHandler());