在gef的编辑器视图中添加相关的上下文菜单,经常需要是实现org.eclipse.gef.ContextMenuProvider的类。在gef编辑器中注册。操作类似公共的快捷键设置。在编辑器视图的protected void configureGraphicalViewer()方法中添加相关的配置:
ContextMenuProvider provider = new LogicContextMenuProvider(viewer, getActionRegistry());
viewer.setContextMenu(provider);
getSite().registerContextMenu(
"org.eclipse.gef.examples.logic.editor.contextmenu",
provider, viewer);
viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)
.setParent(getCommonKeyHandler()));
关于ContextMenuProvider的实现类LogicContextMenuProvider代码如下:
package com.easyway.plugin.gef.diagram.logicdesigner;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IWorkbenchActionConstants;
import com.easyway.plugin.gef.diagram.logicdesigner.actions.IncrementDecrementAction;
/**
* 上下文菜单提供者的使用
* @author longgangbai
*
*/
publicclass LogicContextMenuProvider extends org.eclipse.gef.ContextMenuProvider
{
private ActionRegistry actionRegistry;
public LogicContextMenuProvider(EditPartViewer viewer, ActionRegistry registry) {
super(viewer);
setActionRegistry(registry);
}
/**
* 创建上下文菜单
*/
publicvoid buildContextMenu(IMenuManager manager) {
GEFActionConstants.addStandardActionGroups(manager);
IAction action;
action = getActionRegistry().getAction(GEFActionConstants.UNDO);
manager.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
action = getActionRegistry().getAction(GEFActionConstants.REDO);
manager.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
action = getActionRegistry().getAction(IWorkbenchActionConstants.PASTE);
if (action.isEnabled())
manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
action = getActionRegistry().getAction(IWorkbenchActionConstants.DELETE);
if (action.isEnabled())
manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
action = getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT);
if (action.isEnabled())
manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
action = getActionRegistry().getAction(IncrementDecrementAction.INCREMENT);
if (action.isEnabled())
manager.appendToGroup(GEFActionConstants.GROUP_REST, action);
action = getActionRegistry().getAction(IncrementDecrementAction.DECREMENT);
if (action.isEnabled())
manager.appendToGroup(GEFActionConstants.GROUP_REST, action);
// Alignment Actions
MenuManager submenu = new MenuManager(LogicMessages.AlignmentAction_AlignSubmenu_ActionLabelText);
action = getActionRegistry().getAction(GEFActionConstants.ALIGN_LEFT);
if (action.isEnabled())
submenu.add(action);
action = getActionRegistry().getAction(GEFActionConstants.ALIGN_CENTER);
if (action.isEnabled())
submenu.add(action);
action = getActionRegistry().getAction(GEFActionConstants.ALIGN_RIGHT);
if (action.isEnabled())
submenu.add(action);
submenu.add(new Separator());
action = getActionRegistry().getAction(GEFActionConstants.ALIGN_TOP);
if (action.isEnabled())
submenu.add(action);
action = getActionRegistry().getAction(GEFActionConstants.ALIGN_MIDDLE);
if (action.isEnabled())
submenu.add(action);
action = getActionRegistry().getAction(GEFActionConstants.ALIGN_BOTTOM);
if (action.isEnabled())
submenu.add(action);
if (!submenu.isEmpty())
manager.appendToGroup(GEFActionConstants.GROUP_REST, submenu);
action = getActionRegistry().getAction(IWorkbenchActionConstants.SAVE);
manager.appendToGroup(GEFActionConstants.GROUP_SAVE, action);
}
private ActionRegistry getActionRegistry() {
returnactionRegistry;
}
privatevoid setActionRegistry(ActionRegistry registry) {
actionRegistry = registry;
}
}
相关推荐
有关GEF应用的六个小例子,从最简单的例子开始,逐个增加功能,容易理解和学习。
GEF小组的ppt,展示了如何将GEF应用到Web上的一些思路和做法。
GEF入门系列,八进制 的GEF入门系列教程, 由社区经作者授权后整理而成GEF...提供上下文菜单和键盘命令; 提供图形的缩放功能; 提供一个大纲视图,显示编辑区域的缩略图,或是树状模型结构; 支持撤消/重做功能;
图形编辑框架,是Eclipse旗下的强有力的Tool Project。利用GEF可以轻松实现类似于Visual Editor的可视化图形编辑应用程序,即以图形化的方式展示和编辑模型。
GEF(Graphical Editor Framework)是一个图形化编辑框架,它允许...提供上下文菜单和键盘命令; 提供图形的缩放功能; 提供一个大纲视图,显示编辑区域的缩略图,或是树状模型结构; 支持撤消/重做功能; 等等。
GEF入门必读 GEF入门系列 GEF-whole-upload 感谢八进制
GEF: Graphical Editing Framework <br>...Draw2D应用为GEF的View,但又不仅仅限于此。依赖:org.eclipse.draw2d*** 本软件GEF-ALL-3.2.2完整版包含(Draw2D, GEF and Zest) 大小:6.6M 请用于Eclipse3.2.2环境下.
我下的资源的打包,希望有帮助,包括:GEF_Tutorial,GEF实例,入门教程,GEF-whole-upload
GEF简易教程-学习GEF的入门教程,不错的gef入门教程
GEF eclipse 插件
gef 绘图折线的实现方法。 gef API chm 格式
GEF.rar GEF.rar GEF.rar
Agenda Start things off What is GEF? GEF Demo Draw2d Overview Example GEF Overview Break Hands-on Activity: Shapes Example
GEF理解之第三部分,学习gef必备文档资料啊,值得下载
GEF理解之第一部分,学习gef必备文档资料啊,值得下载
GEF 入门系列 GEF
Eclipse插件GEF的介绍,对于学习GEF有很大帮助
GEF Example Source Code,
1. 往画布上添加多种节点 2. 节点之间的连线 3. 节点内容的编辑功能 4. 删除连线 5. 删除节点 6. 对节点的拖动以改变位置 运行这个例子的方法: 0. 必须要有一个Eclipse RCP的开发环境 1. 在你的Eclipse中要有GEF, ...
这是我自己在学习GEF的时候做的一些总结。 1、GEF中的概念比如Command,Tool,Request等等。 2、GEF中使用到的几种设计模式。 3、GEF中对鼠标键盘事件处理的机制、流程。