Java Code Examples for org.eclipse.gef.editparts.AbstractConnectionEditPart#getModel()

The following examples show how to use org.eclipse.gef.editparts.AbstractConnectionEditPart#getModel() . 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: ERDiagramBendpointEditPolicy.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getCreateBendpointCommand(final BendpointRequest bendpointrequest) {
    final AbstractConnectionEditPart connectionEditPart = (AbstractConnectionEditPart) getHost();
    final ConnectionElement connection = (ConnectionElement) connectionEditPart.getModel();

    if (connection.getSource() == connection.getTarget()) {
        return null;
    }

    final Point point = bendpointrequest.getLocation();
    getConnection().translateToRelative(point);

    final CreateBendpointCommand createBendpointCommand = new CreateBendpointCommand(connection, point.x, point.y, bendpointrequest.getIndex());

    return createBendpointCommand;
}
 
Example 2
Source File: ERDiagramBendpointEditPolicy.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
protected Command getCreateBendpointCommand(BendpointRequest bendpointrequest) {
    final AbstractConnectionEditPart connectionEditPart = (AbstractConnectionEditPart) getHost();
    final WalkerConnection connection = (WalkerConnection) connectionEditPart.getModel();

    if (connection.getSourceWalker() == connection.getTargetWalker()) {
        return null;
    }

    final Point point = bendpointrequest.getLocation();
    getConnection().translateToRelative(point);

    final CreateBendpointCommand createBendpointCommand =
            new CreateBendpointCommand(connection, point.x, point.y, bendpointrequest.getIndex());

    return createBendpointCommand;
}
 
Example 3
Source File: ERDiagramBendpointEditPolicy.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getCreateBendpointCommand(
		BendpointRequest bendpointrequest) {
	AbstractConnectionEditPart connectionEditPart = (AbstractConnectionEditPart) this
			.getHost();
	ConnectionElement connection = (ConnectionElement) connectionEditPart
			.getModel();

	if (connection.getSource() == connection.getTarget()) {
		return null;
	}

	Point point = bendpointrequest.getLocation();
	this.getConnection().translateToRelative(point);

	CreateBendpointCommand createBendpointCommand = new CreateBendpointCommand(
			connection, point.x, point.y, bendpointrequest.getIndex());

	return createBendpointCommand;
}
 
Example 4
Source File: ERDiagramLayoutEditPolicy.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
public static Command createChangeConstraintCommand(final ERDiagram diagram, final List selectedEditParts, final NodeElementEditPart editPart, final Rectangle rectangle) {
    try {
        final NodeElement nodeElement = (NodeElement) editPart.getModel();
        final Rectangle currentRectangle = editPart.getFigure().getBounds();

        boolean move = false;

        if (rectangle.width == currentRectangle.width && rectangle.height == currentRectangle.height) {
            move = true;
        }

        boolean nothingToDo = false;

        if (move && !(editPart instanceof CategoryEditPart)) {
            for (final Object selectedEditPart : selectedEditParts) {
                if (selectedEditPart instanceof CategoryEditPart) {
                    final CategoryEditPart categoryEditPart = (CategoryEditPart) selectedEditPart;
                    final Category category = (Category) categoryEditPart.getModel();

                    if (category.contains(nodeElement)) {
                        nothingToDo = true;
                    }
                }
            }
        }

        final List<Command> bendpointMoveCommandList = new ArrayList<Command>();

        final int oldX = nodeElement.getX();
        final int oldY = nodeElement.getY();

        final int diffX = rectangle.x - oldX;
        final int diffY = rectangle.y - oldY;

        for (final Object obj : editPart.getSourceConnections()) {
            final AbstractConnectionEditPart connection = (AbstractConnectionEditPart) obj;

            if (selectedEditParts.contains(connection.getTarget())) {
                final ConnectionElement connectionElement = (ConnectionElement) connection.getModel();

                final List<Bendpoint> bendpointList = connectionElement.getBendpoints();

                for (int index = 0; index < bendpointList.size(); index++) {
                    final Bendpoint bendPoint = bendpointList.get(index);

                    if (bendPoint.isRelative()) {
                        break;
                    }

                    final MoveBendpointCommand moveCommand = new MoveBendpointCommand(connection, bendPoint.getX() + diffX, bendPoint.getY() + diffY, index);
                    bendpointMoveCommandList.add(moveCommand);
                }

            }
        }

        final CompoundCommand compoundCommand = new CompoundCommand();

        if (!nothingToDo) {
            final Command changeConstraintCommand = createChangeConstraintCommandForNodeElement(diagram, selectedEditParts, editPart, rectangle);

            if (bendpointMoveCommandList.isEmpty()) {
                return changeConstraintCommand;

            }

            compoundCommand.add(changeConstraintCommand);

        } else {
            compoundCommand.add(new NothingToDoCommand());
        }

        for (final Command command : bendpointMoveCommandList) {
            compoundCommand.add(command);
        }

        return compoundCommand;

    } catch (final Exception e) {
        ERDiagramActivator.log(e);
        return null;
    }
}