ベンドポイントを永続化するコマンド


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

コネクションのロード
ソースのEditPartがロードされてrefresh()-refreshSourceConnections()-addSourceConnection(ConnectionEditPart connection, int index)と呼び出されて、
コネクションのEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart)のsetSource(EditPart editPart)が呼び出される。
その中でsetParent(EditPart parent) - addNotify()-installRouter()-refreshRouterChange()-refreshBendpoints()・・・
と呼び出される






org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart
refreshBendpoints モデルからベンドポイントをロードしている


   protected void refreshBendpoints() {
       RelativeBendpoints bendpoints = (RelativeBendpoints) getEdge()
           .getBendpoints();
       List modelConstraint = bendpoints.getPoints();
       List figureConstraint = new ArrayList();
       for (int i = 0; i < modelConstraint.size(); i++) {
           org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint wbp = (org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint) modelConstraint
               .get(i);
           RelativeBendpoint rbp = new RelativeBendpoint(getConnectionFigure());
           rbp.setRelativeDimensions(new Dimension(wbp.getSourceX(), wbp
               .getSourceY()), new Dimension(wbp.getTargetX(), wbp
               .getTargetY()));
           if (modelConstraint.size() == 1) {
           	rbp.setWeight(0.5f);
           } else {
           	rbp.setWeight(i / ((float) modelConstraint.size() - 1));
           }
           figureConstraint.add(rbp);
       }
       getConnectionFigure().setRoutingConstraint(figureConstraint);
   }



setRoutingConstraintが呼び出される順番

ConnectionEditPartのrefreshBendpoints()






installBendpointEditPolicy



ConnectionBendpointEditPolicy






ベンドポイントの移動リクエストに反応するポリシー

org.eclipse.gef.RequestConstants.REQ_MOVE_BENDPOINT "move bendpoint"
抽象クラス org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.ConnectionBendpointEditPolicy
具象クラス org.eclipse.gmf.runtime.diagram.ui.editpolicies.ConnectionBendpointEditPolicy
いちいちテンプレートメソッド・・・


public Command getCommand(Request request) {
	if (REQ_MOVE_BENDPOINT.equals(request.getType())) {
		if (getLineSegMode() != LineMode.OBLIQUE) {
			return getMoveLineSegCommand((BendpointRequest) request);
		} else {
			if (getFeedbackState().isDeleting)
				return getDeleteBendpointCommand(
					(BendpointRequest) request);
			return getMoveBendpointCommand((BendpointRequest) request);
		}
	}
	if (REQ_CREATE_BENDPOINT.equals(request.getType()))
		return getCreateBendpointCommand((BendpointRequest) request);

	return null;
}

protected Command getBendpointsChangedCommand(Connection connection, Edge edge) {
	Point ptRef1 = connection.getSourceAnchor().getReferencePoint();
	getConnection().translateToRelative(ptRef1);

	Point ptRef2 = connection.getTargetAnchor().getReferencePoint();
	getConnection().translateToRelative(ptRef2);

       TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
           .getEditingDomain();
       
       SetConnectionBendpointsCommand sbbCommand = new SetConnectionBendpointsCommand(
           editingDomain);
       sbbCommand.setEdgeAdapter(new EObjectAdapter(edge));
	sbbCommand.setNewPointList(connection.getPoints(), ptRef1, ptRef2);

	return new ICommandProxy(sbbCommand);
}


フィガーのベンドポイントからモデルへセットするコマンド
org.eclipse.gmf.runtime.diagram.ui.internal.commands.SetConnectionBendpointsCommand


public void setNewPointList(
	PointList newPointList,
	ConnectionAnchor sourceAnchor,
	ConnectionAnchor targetAnchor) {

	this.newPointList = new PointList(newPointList.size());
	for (int i = 0; i < newPointList.size(); i++) {
		this.newPointList.addPoint(newPointList.getPoint(i));
	}
	if (sourceAnchor != null) {
		sourceRefPoint = sourceAnchor.getReferencePoint();
		sourceAnchor.getOwner().translateToRelative(sourceRefPoint);
	}
	if (targetAnchor != null) {
		targetRefPoint = targetAnchor.getReferencePoint();
		targetAnchor.getOwner().translateToRelative(
			targetRefPoint);
	}
}

protected CommandResult doExecuteWithResult(
           IProgressMonitor progressMonitor, IAdaptable info)
       throws ExecutionException {
       
	Assert.isNotNull(newPointList);
	Assert.isNotNull(sourceRefPoint);
	Assert.isNotNull(targetRefPoint);

	Edge edge =
		(Edge) getEdgeAdaptor().getAdapter(Edge.class);
	Assert.isNotNull(edge);

	List newBendpoints = new ArrayList();
	int numOfPoints = newPointList.size();
	for (short i = 0; i < numOfPoints; i++) {
		Dimension s = newPointList.getPoint(i).getDifference(sourceRefPoint);
		Dimension t = newPointList.getPoint(i).getDifference(targetRefPoint);
		newBendpoints.add(new RelativeBendpoint(s.width, s.height, t.width, t.height));
	}

	RelativeBendpoints points = (RelativeBendpoints) edge.getBendpoints();
	points.setPoints(newBendpoints);
	return CommandResult.newOKCommandResult();
}
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。