今天我要继续修改前面的例子.
运行效果如下图所示:
代码下载
为了达到这样的效果,我们必须修改原来的model,现在的model UML图是这样的:
一些需要考虑的问题:
1.Layout:
因为这里出现了好3个组合的关系,意味着有parent--children的关系,那么我们必须考虑为parent的figure设置什么Layout来管理children.
2.Command:
不同的事件需要不同的Command,这一次我还是只是增加和修改了对应的CreateCommand.
3.Policy:
根据不同的Layout使用不同的LayoutPolicy
下面的表格显示了我的结构:
因为model做了比较大的修改,所以源代码很多地方都改过了:P
有些地方千万不要忘记了:
比如ContainerPart里的两个方法需要覆写:
ContainerEditPart.java
代码下载
参考资源:
GEF学习教程1-Unplugged版
GEF学习教程2-Unplugged版
运行效果如下图所示:
代码下载
为了达到这样的效果,我们必须修改原来的model,现在的model UML图是这样的:
一些需要考虑的问题:
1.Layout:
因为这里出现了好3个组合的关系,意味着有parent--children的关系,那么我们必须考虑为parent的figure设置什么Layout来管理children.
2.Command:
不同的事件需要不同的Command,这一次我还是只是增加和修改了对应的CreateCommand.
3.Policy:
根据不同的Layout使用不同的LayoutPolicy
下面的表格显示了我的结构:
model | Figure | Figure使用的Layout
| EditPart | EditPart安装的EditPolicy |
Content | ContentFigure | XYLayout | ContentPart | XYLayoutEditPolicy |
Container | ContainerFigure | ToolbarLayout | ContainerPart | OrderLayoutEditPolicy |
Column | ColumnFigure | FlowLayout | ColumnPart | FlowLayoutEditPolicy |
Node | NodeFigure | ToolbarLayout | NodePart | 无 |
因为model做了比较大的修改,所以源代码很多地方都改过了:P
有些地方千万不要忘记了:
比如ContainerPart里的两个方法需要覆写:
ContainerEditPart.java
@Override
protected List getModelChildren() {
return ((Container) getModel()).getChildren();
}
@Override
protected void refreshVisuals() {
Rectangle constraint = ((Container) getModel()).getConstraint();
((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), constraint);
}
protected List getModelChildren() {
return ((Container) getModel()).getChildren();
}
@Override
protected void refreshVisuals() {
Rectangle constraint = ((Container) getModel()).getConstraint();
((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), constraint);
}
代码下载
参考资源:
GEF学习教程1-Unplugged版
GEF学习教程2-Unplugged版