5.15日 重新审视hellogef程序(1)

在hellogef的基础上进行了功能添加。

首先是,hellogef.editors的HelloEditor.java里面的程序,我之前修改了哪些?是要完成什么功能?

原来的程序:

protected void configureGraphicalViewer(){

            super.configureGraphicalViewer();
            getGraphicalViewer().setRootEditPart(new MyRootEditPart());
            getGraphicalViewer().setEditPartFactory(new PartFactory());

}

 

现在的程序:

protected void configureGraphicalViewer() {

             super.configureGraphicalViewer();
             getGraphicalViewer().setRootEditPart(new MyRootEditPart());
             getGraphicalViewer().setEditPartFactory(new PartFactory());

             EditPartViewer viewer = getGraphicalViewer();
             ContextMenuProvider provider = new CbmEditorContextMenuProvider(viewer, getActionRegistry());
             
             viewer.setContextMenu(provider);
             getSite().registerContextMenu(provider, viewer);
             viewer.setKeyHandler(new GraphicalViewerKeyHandler((GraphicalViewer) viewer).setParent(getCommonKeyHandler()));
}

 

protected KeyHandler getCommonKeyHandler(){

                   KeyHandler sharedKeyHandler = null;
                   if (sharedKeyHandler == null){
                        sharedKeyHandler = new KeyHandler();
                        sharedKeyHandler.put(KeyStroke.getPressed(SWT.F2, 0),getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT));
                   }
                   return sharedKeyHandler;
}

其中用到的CbmEditorContextMenuProvider是自己定义的。放在hellogef.action里,新建了一个calss:CbmEditorContextMenuProvider.java

 

public class CbmEditorContextMenuProvider extends ContextMenuProvider {
            private ActionRegistry actionRegistry;

            public CbmEditorContextMenuProvider(EditPartViewer viewer, ActionRegistry registry) {
                 super(viewer);
                 actionRegistry = registry;
            }

            public void buildContextMenu(IMenuManager menu) {

            // Add standard action groups to the menu
                 GEFActionConstants.addStandardActionGroups(menu);
            // Add actions to the menu
                 menu.appendToGroup(GEFActionConstants.GROUP_UNDO,getAction(ActionFactory.UNDO.getId()));
                 menu.appendToGroup(GEFActionConstants.GROUP_UNDO, getAction(ActionFactory.REDO.getId()));
                 menu.appendToGroup(GEFActionConstants.GROUP_EDIT, getAction(ActionFactory.DELETE.getId()));
              }

            private IAction getAction(String actionId) {
                 return actionRegistry.getAction(actionId);
              }
}

 

完成的功能:选择节点,点击右键可以出来几个选项,redo undo delete和一些用不到的东西(至少现在觉得用不到)。

想完善的部分:1.屏蔽不需要的那些。

                     2.不同的节点点击右键可以出来不同的选项么?

                     3.右键选项中可以有这样的效果吗?比如,选项是速度,点击后跳出一个框,然后可以编辑速度的大小。

 

 

posted @ 2014-05-15 15:36  behappylee  阅读(167)  评论(0编辑  收藏  举报