org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart Java Examples

The following examples show how to use org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private void showLineFeedback(ConnectionEditPart connectionEditPart) {
	// XXX: copied from InitialPointsOfRequestDataManager
	List<?> children = connectionEditPart.getChildren();
	Connection connection = connectionEditPart.getConnectionFigure();
	for (Object child : children) {
		if (child instanceof ExternalXtextLabelEditPart) {
			IFigure figure = ((ExternalXtextLabelEditPart) child).getFigure();
			Object currentConstraint = connection.getLayoutManager().getConstraint(figure);
			if (currentConstraint instanceof EdgeLabelLocator) {
				EdgeLabelLocator edgeLabelLocator = (EdgeLabelLocator) currentConstraint;
				edgeLabelLocator.setFeedbackData(getInitialPoints(connection),
						new Vector(edgeLabelLocator.getOffset().x, edgeLabelLocator.getOffset().y),
						SetLabelsOffsetOperation.isEdgeWithObliqueRoutingStyle(connectionEditPart));
			}
		}
	}
}
 
Example #2
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("restriction")
protected Command getBendpointsChangedCommand(ConnectionEditPart part) {
	Connection connection = part.getConnectionFigure();
	Point ptRef1 = connection.getSourceAnchor().getReferencePoint();
	connection.translateToRelative(ptRef1);

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

	TransactionalEditingDomain editingDomain = getHost().getEditingDomain();

	SetConnectionBendpointsAndLabelCommmand sbbCommand = new SetConnectionBendpointsAndLabelCommmand(editingDomain);
	sbbCommand.setEdgeAdapter(new EObjectAdapter((EObject) part.getModel()));
	sbbCommand.setNewPointList(connection.getPoints(), ptRef1, ptRef2);
	sbbCommand.setLabelsToUpdate(part, getInitialPoints(connection));

	return new ICommandProxy(sbbCommand);
}
 
Example #3
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void eraseChangeBoundsFeedback(ChangeBoundsRequest request) {
	connectionStart = true;
	router.commitBoxDrag();
	for (ConnectionEditPart connectionEditPart : getAllConnectionParts(request)) {
		List<?> children = connectionEditPart.getChildren();
		Connection connection = connectionEditPart.getConnectionFigure();
		for (Object child : children) {
			if (child instanceof ExternalXtextLabelEditPart) {
				IFigure figure = ((ExternalXtextLabelEditPart) child).getFigure();
				Object currentConstraint = connection.getLayoutManager().getConstraint(figure);
				if (currentConstraint instanceof EdgeLabelLocator) {
					EdgeLabelLocator edgeLabelLocator = (EdgeLabelLocator) currentConstraint;
					edgeLabelLocator.eraseFeedbackData();
				}
			}
		}
	}

}
 
Example #4
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public Command createUpdateAllBendpointsCommand(ChangeBoundsRequest request) {
	CompoundCommand result = new CompoundCommand();
	for (ConnectionEditPart part : getAllConnectionParts(request)) {
		result.add(getBendpointsChangedCommand(part));
	}
	if (result.size() == 0) {
		return null;
	}
	return result;
}
 
Example #5
Source File: CustomPasteCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param part
 * @param toCopy
 * @return
 */
private boolean canHandlePaste(IGraphicalEditPart part, List<IGraphicalEditPart> toCopy) {
	if (part instanceof ConnectionEditPart) {
		ConnectionEditPart connPart = (ConnectionEditPart) part;
		if (!toCopy.contains(connPart.getSource()) || !toCopy.contains(connPart.getTarget())) {
			return false;
		}
	}
	final Element toCopyElement = (Element) part.resolveSemanticElement();
	return targetElement instanceof Container && !(toCopyElement instanceof Container);
}
 
Example #6
Source File: CustomPasteCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param toCopy
 * @return
 */
private List<IGraphicalEditPart> getConnections(List<IGraphicalEditPart> toCopy) {
	List<IGraphicalEditPart> res = new ArrayList<IGraphicalEditPart>();
	for (IGraphicalEditPart part : toCopy) {
		if (part instanceof ConnectionEditPart) {
			res.add(part);
		}
	}
	return res;
}
 
Example #7
Source File: ExtractAsCallActivityTransactionalCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param processEp
 * @param flow
 * @return
 */
protected ConnectionEditPart findConnectionPart(final MainProcessEditPart processEp, final Connection flow) {
    INodeEditPart nodePart = (INodeEditPart) GMFTools.findEditPart(processEp, flow.getSource());
    for (Object transition : nodePart.getSourceConnections()) {
        if (((ConnectionEditPart) transition).resolveSemanticElement().equals(flow)) {
            return (ConnectionEditPart) transition;
        }
    }
    return null;
}
 
Example #8
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<ConnectionEditPart> filter(List<ConnectionEditPart> allConnectionParts,
		ChangeBoundsRequest request) {
	if (request.getEditParts() == null)
		return allConnectionParts;
	List<ConnectionEditPart> result = Lists.newArrayList();
	for (ConnectionEditPart input : allConnectionParts) {
		if(!(request.getEditParts().contains(input.getTarget())
				&& request.getEditParts().contains(input.getSource()))) {
			result.add(input);
		}
	}
	return result;
}
 
Example #9
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void showSourceFeedback(Request request) {
	if (RequestConstants.REQ_DROP.equals(request.getType())) {
		return;
	}
	if (request instanceof ChangeBoundsRequest) {
		showChangeBoundsFeedback((ChangeBoundsRequest) request);
		for (ConnectionEditPart cep : getAllConnectionParts((ChangeBoundsRequest) request)) {
			showLineFeedback(cep);
		}
	}
}
 
Example #10
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<ConnectionEditPart> getAllConnectionParts(ChangeBoundsRequest request) {
	List<ConnectionEditPart> conns = new ArrayList<>();
	conns.addAll(getHost().getSourceConnections());
	conns.addAll(getHost().getTargetConnections());
	return filter(conns, request);
}
 
Example #11
Source File: CrossflowShortcutsDecoratorProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
public void refresh() {
	removeDecoration();
	EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class);
	Image image = CrossflowDiagramEditorPlugin.getInstance().getBundledImage("icons/shortcut.gif"); //$NON-NLS-1$
	if (editPart instanceof ShapeEditPart) {
		setDecoration(getDecoratorTarget().addShapeDecoration(image, IDecoratorTarget.Direction.SOUTH_WEST, 0,
				false));
	} else if (editPart instanceof ConnectionEditPart) {
		setDecoration(getDecoratorTarget().addConnectionDecoration(image, 50, false));
	}
}
 
Example #12
Source File: SetLabelsOffsetOperation.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Set labels to update according to a connectionEditPart (all labels of this
 * connection will be update). <BR>
 * This method must be called after having called the
 * {@link #setNewPointList(PointList)} method.
 *
 * @param connectionEditPart The connection from which to get the potential
 *                           three labels to update
 */
public void setLabelsToUpdate(ConnectionEditPart connectionEditPart) {
	List<LabelEditPart> labelEditPartsToUpdate = new ArrayList<>();
	List<?> children = connectionEditPart.getChildren();
	for (Object child : children) {
		if (child instanceof LabelEditPart) {
			Object view = ((LabelEditPart) child).getModel();
			if (view instanceof Node) {
				labelEditPartsToUpdate.add((LabelEditPart) child);
			}
		}
	}

	computeGMFLabelsOffset(labelEditPartsToUpdate, connectionEditPart);
}
 
Example #13
Source File: SetLabelsOffsetOperation.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Update {@link Bounds} of the labels {@link Node}.
 *
 * @param labelEditPartsToUpdate List of labels to update
 * @param connectionEditPart     The connection having these labels
 */
private void computeGMFLabelsOffset(List<LabelEditPart> labelEditPartsToUpdate,
		ConnectionEditPart connectionEditPart) {
	labelsWithNewOffset = new HashMap<>();
	// For each label, compute the new offset
	for (LabelEditPart labelEditPartToUpdate : labelEditPartsToUpdate) {
		computeGMFLabelOffset(labelEditPartToUpdate, connectionEditPart);
	}

}
 
Example #14
Source File: SetLabelsOffsetOperation.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
	 * Update {@link Bounds} of a label {@link Node}.
	 *
	 * @param labelEdgeEditPart  the editPart of the edge label to be updated
	 * @param connectionEditPart The connection having these labels
	 */
	private void computeGMFLabelOffset(LabelEditPart labelEditPartToUpdate, ConnectionEditPart connectionEditPart) {
		Point newLabelOffset = null;
		Node labelNodeToUpdate = (Node) labelEditPartToUpdate.getModel();
		if (connectionEditPart.getModel() instanceof Edge) {
			PointList oldBendpoints = oldBendPointsList;
			if (oldBendpoints == null) {
//				System.out.println("read current points");
				oldBendpoints = connectionEditPart.getConnectionFigure().getPoints();
			}
			boolean isEdgeWithObliqueRoutingStyle = isEdgeWithObliqueRoutingStyle(connectionEditPart);
			LayoutConstraint layoutConstraint = labelNodeToUpdate.getLayoutConstraint();
			if (layoutConstraint instanceof Location) {
				Location point = (Location) layoutConstraint;
				newLabelOffset = new EdgeLabelQuery(oldBendpoints, newPointList, isEdgeWithObliqueRoutingStyle,
						new Point(point.getX(), point.getY()), labelEditPartToUpdate.getFigure().getSize(),
						labelEditPartToUpdate.getKeyPoint(), false).calculateGMFLabelOffset();
//				System.out.println("queried label offset = " + newLabelOffset);
				if ((newLabelOffset.x == 0) && (newLabelOffset.y == 0)) {
					newLabelOffset = null;
				}
			}
		}

		if (newLabelOffset != null) {
//			System.out.println("store label offset");
			labelsWithNewOffset.put(labelNodeToUpdate, newLabelOffset);
		}
	}
 
Example #15
Source File: SetLabelsOffsetOperation.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isEdgeWithObliqueRoutingStyle(org.eclipse.gef.ConnectionEditPart part) {
	Edge edge = (Edge) part.getModel();
	ConnectorStyle style = (ConnectorStyle) edge.getStyle(NotationPackage.Literals.CONNECTOR_STYLE);
	if (style != null) {
		return Routing.MANUAL_LITERAL == style.getRouting();
	}
	return false;
}
 
Example #16
Source File: SetConnectionBendpointsAndLabelCommmand.java    From statecharts with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Set labels to update according to a connectionEditPart (all labels of this
 * connection will be update). This method must be used if the edge figure is
 * updated (through feedback) during the move. Indeed, in this case, we can not
 * use the figure to retrieve the old points.<BR>
 * This method must be called after having called the
 * {@link #setNewPointList(PointList, org.eclipse.draw2d.ConnectionAnchor, org.eclipse.draw2d.ConnectionAnchor)}
 * of {@link #setNewPointList(PointList, Point, Point)} method.
 *
 * @param connectionEditPart The connection from which to get the potential
 *                           three labels to update
 * @param originalPoints     The points of the edge before the move.
 */
public void setLabelsToUpdate(ConnectionEditPart connectionEditPart, PointList originalPoints) {
	setLabelsOperation.setLabelsToUpdate(connectionEditPart, originalPoints);
}
 
Example #17
Source File: SetConnectionBendpointsAndLabelCommmand.java    From statecharts with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Set labels to update according to a connectionEditPart (all labels of this
 * connection will be update). <BR>
 * This method must be called after having called the
 * {@link #setNewPointList(PointList, org.eclipse.draw2d.ConnectionAnchor, org.eclipse.draw2d.ConnectionAnchor)}
 * of {@link #setNewPointList(PointList, Point, Point)} method.
 *
 * @param connectionEditPart The connection from which to get the potential
 *                           three labels to update
 */
public void setLabelsToUpdate(ConnectionEditPart connectionEditPart) {
	setLabelsOperation.setLabelsToUpdate(connectionEditPart);
	setLabelsOperation.setNewPointList(connectionEditPart.getConnectionFigure().getPoints());
}
 
Example #18
Source File: SetLabelsOffsetCommand.java    From statecharts with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Set labels to update according to a connectionEditPart (all labels of this
 * connection will be update). This method must be used if the edge figure is
 * updated (through feedback) during the move. Indeed, in this case, we can not
 * use the figure to retrieve the old points.<BR>
 * This method must be called after having called the
 * {@link #setNewPointList(PointList)} method.
 *
 * @param connectionEditPart
 *            The connection from which to get the potential three labels to
 *            update
 * @param originalPoints
 *            The points of the edge before the move.
 */
public void setLabelsToUpdate(ConnectionEditPart connectionEditPart, PointList originalPoints) {
	setLabelsOperation.setLabelsToUpdate(connectionEditPart, originalPoints);
}
 
Example #19
Source File: SetLabelsOffsetCommand.java    From statecharts with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Set labels to update according to a connectionEditPart (all labels of this
 * connection will be update). <BR>
 * This method must be called after having called the
 * {@link #setNewPointList(PointList)} method.
 *
 * @param connectionEditPart
 *            The connection from which to get the potential three labels to
 *            update
 */
public void setLabelsToUpdate(ConnectionEditPart connectionEditPart) {
	setLabelsOperation.setLabelsToUpdate(connectionEditPart);
}
 
Example #20
Source File: SetLabelsOffsetOperation.java    From statecharts with Eclipse Public License 1.0 2 votes vote down vote up
/**
	 * Set labels to update according to a connectionEditPart (all labels of this
	 * connection will be update). This method must be used if the edge figure is
	 * updated (through feedback) during the move. Indeed, in this case, we can not
	 * use the figure to retrieve the old points.<BR>
	 * This method must be called after having called the
	 * {@link #setNewPointList(PointList)} method.
	 *
	 * @param connectionEditPart The connection from which to get the potential
	 *                           three labels to update
	 * @param originalPoints     The points of the edge before the move.
	 */
	public void setLabelsToUpdate(ConnectionEditPart connectionEditPart, PointList originalPoints) {
		oldBendPointsList = originalPoints;
		setLabelsToUpdate(connectionEditPart);
//		System.out.println("set labels to update");
	}