项目中用到的一些GMF技巧

上一篇 / 下一篇  2008-07-21 10:28:24

正在做一个GMF相关的项目,使用了一些GMF技巧,都是上网上搜得,现在记一下,忘了好找

1. 双击节点打开新的Diagram
http://wiki.eclipse.org/Diagram_Partitioning

2. 禁用PopupBar和ConnectionHandler功能(鼠标停止在图形上时出现的连线符号)
http://www.cnblogs.com/bjzhanghao/archive/2006/10/26/541262.html中的第23项

3. 屏蔽删除节点的功能
在需要禁用该功能的EditPart的createDefaultEditPolicies()方法的最后加下面的语句:
        installEditPolicy(EditPolicy.COMPONENT_ROLE, new ComponentEditPolicy(){

            @Override
            protected Command createDeleteCommand(GroupRequest deleteRequest) {
                // TODO Auto-generated method stub
                return UnexecutableCommand.INSTANCE;
            }
        });

4. 屏蔽标签的编辑功能
在标签EditPart中重载
    protected boolean isEditable() {
        return false;
    }

5. 拷贝节点内容
使用EcoreUtil.copyAll

6. 去掉palette
将DiagramEdit的构造函数(我的是ModelDiagramEditor)改为
    public ModelDiagramEditor() {
        super(false);
    }

7. 改变Diagram中节点的排列方向
参见http://wiki.eclipse.org/index.php/GMF_Tutorial_Part_3中Custom Layout部分

8. 使Compartment初始时是折叠的
修改Compartment对应ViewFactory的setupCompartmentCollapsed函数
    protected void setupCompartmentCollapsed(View view) {
        DrawerStyle drawerStyle = (DrawerStyle) view
                .getStyle(NotationPackage.eINSTANCE.getDrawerStyle());
        if (drawerStyle != null) {
            drawerStyle.setCollapsed(true);
        }
    }
但是这里可能有个GMF的Bug,更新时有些问题,我的解决方法是:
重载Compartment对应的CanonicalEditPolicy中的refreshSemantic方法,改为
    protected void refreshSemantic() {
        super.refreshSemantic();
        EditPart rootEP= (EditPart) getHost().getRoot().getChildren().get(0); //我的Diagram根节点只有1个
        CanonicalEditPolicy policy = (CanonicalEditPolicy) rootEP.getEditPolicy(EditPolicyRoles.CANONICAL_ROLE);
        policy.refresh();
    }

9. 双击节点执行操作
重载对应EditPart类的performRequest方法
    public void performRequest(Request request) {
        if(request.getType().equals(RequestConstants.REQ_OPEN)){
            ...
            return;
        }
        super.performRequest(request);
    }
10. 删除右键菜单里不需要的菜单项
参见http://www.cnblogs.com/bjzhanghao/archive/2006/10/26/541262.html中的第41项

TAG: GMF Eclipse

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

我的栏目

日历

« 2008-10-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 327
  • 日志数: 10
  • 建立时间: 2008-06-14
  • 更新时间: 2008-07-21

RSS订阅

Open Toolbar