一. 目标
在2个不同Table的2个Column间能建立Connection

二. 书写Connection模型

public class ColumnConnectionModel extends BaseModel {
private TableColumnModel target;
private TableColumnModel source;、
    public void setTarget(TableColumnModel target) {
        this.target = target;
        target.addTarget(this);
    }

public void setSource(TableColumnModel source) {
this.source = source;
source.addSource(this);
}



三. 修改TableColumn模型

必须修改与Connection相关的其他模型。

	public class TableColumnModel extends BaseModel {
	    private List<ColumnConnectionModel> sources = new ArrayList<ColumnConnectionModel>();
	    private List<ColumnConnectionModel> targets = new ArrayList<ColumnConnectionModel>();

	public void addSource(ColumnConnectionModel source) {
		this.sources.add(source);
		this.firePropertyChange(IPropertyConst.SOURCE_CONNECTION, null, null);
	}

	public void addTarget(ColumnConnectionModel target) {
		this.targets.add(target);
		this.firePropertyChange(IPropertyConst.TARGET_CONNECTION, null, null);
	}

 


四. 书写Connection的EditPart

public abstract class BaseConnectionEditPart extends AbstractConnectionEditPart implements
PropertyChangeListener {
 
public class ColumnConnectionEditPart extends BaseConnectionEditPart {
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new ConnectionEndpointEditPolicy());
}

@Override
protected IFigure createFigure() {
PolylineConnection connection = new PolylineConnection();
connection.setTargetDecoration(new PolygonDecoration());
connection.setSourceDecoration(new PolylineDecoration());
connection.setForegroundColor(ColorConstants.blue);
return connection;
}
}

 


注意:

  1. 先做了一个Connection的基础类,方便以后使用
  2. 由于Connection的特殊性,需要继承于AbstractConnectionEditPart
  3. 在ConnectionEditPart中注册了一个ConnectionEndpointEditPolicy
  4. connection.setTargetDecoration(new PolygonDecoration()) 设定目标的箭头:--|>
  5. connection.setSourceDecoration(new PolylineDecoration()) 设定起源的箭头:-->


五. 启动
GEF实践总结(六)Connection连线

 

六.    总结

  1. 添加Connection的Model
  2. 修改和Connection相关的Model
  3. Connection的EditPart需要继承于AbstractConnectionEditPart
  4. 了解TargetDecoration和SourceDecoration
  5. 区分PolygonDecoration和PolylineDecoration的样式区别

 

相关文章:

  • 2021-10-04
  • 2021-09-04
  • 2021-08-21
  • 2021-11-28
  • 2021-05-27
  • 2021-10-07
  • 2022-12-23
猜你喜欢
  • 2021-11-22
  • 2021-04-17
  • 2021-05-29
  • 2021-12-23
  • 2021-10-01
  • 2021-11-30
  • 2021-04-19
相关资源
相似解决方案