读书人

GEF Connection 选中后展示连线

发布时间: 2012-12-18 12:43:41 作者: rapoo

GEF Connection 选中后显示连线

关键字:GEF Connection 选中后显示连线

?

GEF(Graphics Editor Framework)是一个挺复杂的图形编辑的框架结构。基本的概念就很多,我是参考《Eclipse插件开发》这本书学习的,这本书对与GEF的内容讲解的不好。 下个星期自己把这部分的内容整理一下。

?

说说连线 后显示的问题:

第一步:

覆盖refresh()函数,不让其调用refreshSourceConnections();和refreshTargetConnections()函数。

第二步:

在editorpart中增加

private void refreshRelateConnection() {Map<Object,EditPart> modelToEditPart = new HashMap<Object,EditPart>();List<?> editParts = this.getParent().getChildren();for(Object o : editParts) {EditPart editPart = (EditPart)o;if(!(editPart instanceof BlockEditpart)) {continue;}modelToEditPart.put(editPart.getModel(), editPart);}List<?> ee = getSourceConnections();for (int i = 0; i < ee.size(); i++) {ConnectionModel c = getModelSourceConnections().get(i);BlockEditpart e = (BlockEditpart)modelToEditPart.get(c.getTarget());ConnectionEditPart cep = (ConnectionEditPart)ee.get(i);e.addTargetConnection(cep, 0);}ee = getTargetConnections();for (int i = 0; i < ee.size(); i++) {ConnectionModel c = getModelTargetConnections().get(i);BlockEditpart e = (BlockEditpart)modelToEditPart.get(c.getSource());ConnectionEditPart cep = (ConnectionEditPart)ee.get(i);e.addSourceConnection(cep, 0);}}

?刷新对应连线,有连个注意点,第一,如何得到对应Node的Editorpart,这个采用了最蠢的方法,遍历所有的Editorparts,不知道有没有更好的方法;第二,不能用到的Editorpart直接调用refreshSourceConnections(); refreshTargetConnections();,因为这样使用的话,原始Node的所有连线是画好了,相关Node的连线又没有画好。

办法有点儿蠢,不过效果达到了。

读书人网 >编程

热点推荐