Java Code Examples for org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart#getEditPolicy()

The following examples show how to use org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart#getEditPolicy() . 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: SWTBotTestUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param gmfEditor
 * @param selectedElementName
 * @param elementIndex
 * @param isEvent
 * @param dropLocation
 */
public static void selectElementInContextualPaletteAndDragIt(final SWTBotGefEditor gmfEditor,
        final String selectedElementName, final int elementIndex,
        final Point dropLocation) {
    SWTBotGefEditPart element;
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(selectedElementName);
    Assert.assertNotNull("Error: No Edit Part \'" + selectedElementName + "\' found.", gep);
    element = gep.parent();
    element.select();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    final NextElementEditPolicy nextElementEditPolicy = (NextElementEditPolicy) graphicalEditPart
            .getEditPolicy(NextElementEditPolicy.NEXT_ELEMENT_ROLE);

    final IFigure toolbarFigure = nextElementEditPolicy.getFigure(elementIndex);
    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);
    gmfEditor.drag(location.x, location.y, dropLocation.x, dropLocation.y);
}
 
Example 2
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add an element from the contextual palette of one element.
 *
 * @param pSourceElement
 * @param pContextualPaletteId (see org.bonitasoft.studio.qa.util.SWTBotConstants.java)
 * @param pOrientation (org.eclipse.draw2d.PositionConstants)
 */
public void addElementAfter(final String pSourceElement, final int pContextualPaletteId, final int pOrientation) {
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(pSourceElement);
    Assert.assertNotNull("Error: No Edit Part \'" + pSourceElement + "\' found.", gep);
    final SWTBotGefEditPart element = gep.parent();
    element.select();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    final NextElementEditPolicy nextElementEditPolicy = (NextElementEditPolicy) graphicalEditPart
            .getEditPolicy(NextElementEditPolicy.NEXT_ELEMENT_ROLE);

    final IFigure toolbarFigure = nextElementEditPolicy.getFigure(pContextualPaletteId);
    final Point dropLocation = computeTargetLocation(pSourceElement, pOrientation);

    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);

    final Point delta = getDelta(pSourceElement);

    gmfEditor.drag(location.x, location.y, delta.x + dropLocation.x, delta.y + dropLocation.y);
}
 
Example 3
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void selectElementInContextualPaletteAndDragIt(final String pFromElement, final int pContextualPaletteId,
        final Point pDropLocation) {
    SWTBotGefEditPart element;
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(pFromElement);
    Assert.assertNotNull("Error: No Edit Part \'" + pFromElement + "\' found.", gep);
    element = gep.parent();
    element.select();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    final NextElementEditPolicy nextElementEditPolicy = (NextElementEditPolicy) graphicalEditPart
            .getEditPolicy(NextElementEditPolicy.NEXT_ELEMENT_ROLE);

    final IFigure toolbarFigure = nextElementEditPolicy.getFigure(pContextualPaletteId);
    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);
    gmfEditor.drag(location.x, location.y, pDropLocation.x, pDropLocation.y);
}
 
Example 4
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Click on one of the lane size control (+,-)
 *
 * @param pLane
 * @param pLaneSizeId (see org.bonitasoft.studio.qa.util.SWTBotConstants.java)
 */
public void updateLaneSize(final String pLane, final int pLaneSizeId) {
    SWTBotGefEditPart element;
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(pLane);
    Assert.assertNotNull("Error: No Edit Part \'" + pLane + "\' found.", gep);
    element = gep.parent();
    element.select();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    final UpdateSizeLaneSelectionEditPolicy updateSizeLaneEditPolicy = (UpdateSizeLaneSelectionEditPolicy) graphicalEditPart
            .getEditPolicy(UpdateSizeLaneSelectionEditPolicy.UPDATE_LANE_SIZE_SELECTION_FEEDBACK_ROLE);
    final IFigure toolbarFigure = updateSizeLaneEditPolicy.getFigure(pLaneSizeId);

    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);
    gmfEditor.click(location.x, location.y);
}
 
Example 5
Source File: EnlargeContainerEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void eraseSourceFeedback(Request request) {
	boundsCache.clear();
	for (IGraphicalEditPart iGraphicalEditPart : containerHierachy) {
		EditPolicy editPolicy = iGraphicalEditPart.getEditPolicy(FixedBendpointEditPolicy.ROLE);
		if (editPolicy != null) {
			editPolicy.eraseSourceFeedback(request);
		}
	}
	containerHierachy = null;
	super.eraseSourceFeedback(request);
}
 
Example 6
Source File: EnlargeContainerEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void showContainerFeedback(ChangeBoundsRequest request) {
	for (IGraphicalEditPart containerEditPart : containerHierachy) {
		IFigure containerFigure = containerEditPart.getFigure();
		Rectangle feedbackBounds = getOriginalBounds(containerFigure);
		containerFigure.getParent().translateToAbsolute(feedbackBounds);
		feedbackBounds = calculateFeedbackBounds(request, feedbackBounds, containerFigure);
		containerFigure.translateToRelative(feedbackBounds);
		setBounds(containerFigure, feedbackBounds);
		EditPolicy editPolicy = containerEditPart.getEditPolicy(FixedBendpointEditPolicy.ROLE);
		if (editPolicy != null) {
			editPolicy.showSourceFeedback(request);
		}
	}
}
 
Example 7
Source File: SWTBotTestUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static void increasePoolWidth(final SWTBotGefEditor editor, final String poolName) {
    final SWTBotGefEditPart poolPart = editor.getEditPart(poolName).parent();
    poolPart.select();

    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) poolPart.part();
    final UpdateSizePoolSelectionEditPolicy addPoolSizeElementEditPolicy = (UpdateSizePoolSelectionEditPolicy) graphicalEditPart
            .getEditPolicy(UpdateSizePoolSelectionEditPolicy.UPDATE_POOL_SIZE_SELECTION_FEEDBACK_ROLE);

    final IFigure toolbarFigure = addPoolSizeElementEditPolicy.getFigure(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT);
    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);
    editor.click(location.x, location.y);
}
 
Example 8
Source File: SWTBotTestUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static void increasePoolHeight(final SWTBotGefEditor editor, final String poolName) {
    final SWTBotGefEditPart poolPart = editor.getEditPart(poolName).parent();
    poolPart.select();

    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) poolPart.part();
    final UpdateSizePoolSelectionEditPolicy addPoolSizeElementEditPolicy = (UpdateSizePoolSelectionEditPolicy) graphicalEditPart
            .getEditPolicy(UpdateSizePoolSelectionEditPolicy.UPDATE_POOL_SIZE_SELECTION_FEEDBACK_ROLE);

    final IFigure toolbarFigure = addPoolSizeElementEditPolicy.getFigure(UpdateSizePoolSelectionEditPolicy.ADD_BOTTOM);
    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);
    editor.click(location.x, location.y);
}
 
Example 9
Source File: EnlargeContainerEditPolicy.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Command getCommand(Request request) {
	if (!RequestConstants.REQ_RESIZE.equals(request.getType())
			&& !RequestConstants.REQ_MOVE.equals(request.getType())) {
		return null;
	}

	if (request instanceof SetPreferredSizeRequest) {
		showSourceFeedback(request);
	}

	ChangeBoundsRequest cbr = (ChangeBoundsRequest) request;
	CompoundCommand result = new CompoundCommand();

	// Update Bounds of the container hierarchy
	if (containerHierachy != null) {
		for (IGraphicalEditPart currentContainer : containerHierachy) {
			IFigure figure = currentContainer.getFigure();
			SetBoundsCommand boundsCommand = new SetBoundsCommand(getHost().getEditingDomain(),
					DiagramUIMessages.SetLocationCommand_Label_Resize,
					new EObjectAdapter(currentContainer.getNotationView()), figure.getBounds());
			result.add(new ICommandProxy(boundsCommand));
			FixedBendpointEditPolicy editPolicy = (FixedBendpointEditPolicy) currentContainer
					.getEditPolicy(FixedBendpointEditPolicy.ROLE);
			if (editPolicy != null) {
				Command command = editPolicy.getCommand(cbr);
				result.add(command);
			}

			// Update child bounds of elements that stand in the way...
			List<IGraphicalEditPart> children = currentContainer.getParent().getChildren();
			for (IGraphicalEditPart childPart : children) {
				if (cbr.getEditParts().contains(childPart))
					continue;
				IFigure childFigure = childPart.getFigure();
				if (childPart == currentContainer)
					continue;
				SetBoundsCommand childBoundsCommand = new SetBoundsCommand(getHost().getEditingDomain(),
						DiagramUIMessages.SetLocationCommand_Label_Resize,
						new EObjectAdapter(childPart.getNotationView()), childFigure.getBounds());
				result.add(new ICommandProxy(childBoundsCommand));
			}
		}
	}
	return result;
}
 
Example 10
Source File: SWTBotTestUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static void selectElementInContextualPaletteAndDragIt(final SWTBotGefEditor gmfEditor,
        final String selectedElementName, final int elementIndex,
        final int position) {
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(selectedElementName);
    Assert.assertNotNull("Error: No Edit Part \'" + selectedElementName + "\' found.", gep);
    final SWTBotGefEditPart element = gep.parent();
    element.select();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    final NextElementEditPolicy nextElementEditPolicy = (NextElementEditPolicy) graphicalEditPart
            .getEditPolicy(NextElementEditPolicy.NEXT_ELEMENT_ROLE);

    final IFigure toolbarFigure = nextElementEditPolicy.getFigure(elementIndex);
    Point dropLocation = null;

    final int xPaletteDelta = computeXPaletteDelta(elementIndex);
    final int yPaletteDelta = computeYPaletteDelta(elementIndex);

    final Rectangle bounds = graphicalEditPart.getFigure().getBounds();
    switch (position) {
        case PositionConstants.NORTH:
            dropLocation = bounds.getTop().getCopy().translate(xPaletteDelta, -Y_MARGIN);
            break;
        case PositionConstants.SOUTH:
            dropLocation = bounds.getBottom().getCopy().translate(xPaletteDelta, Y_MARGIN);
            break;
        case PositionConstants.WEST:
            dropLocation = bounds.getLeft().getCopy().translate(-X_MARGIN, yPaletteDelta);
            break;
        case PositionConstants.EAST:
            dropLocation = bounds.getRight().getCopy().translate(X_MARGIN, yPaletteDelta);
            break;
        case PositionConstants.NORTH_EAST:
            dropLocation = bounds.getTopRight().getCopy().translate(X_MARGIN, -Y_MARGIN);
            break;
        case PositionConstants.NORTH_WEST:
            dropLocation = bounds.getTopLeft().getCopy().translate(-X_MARGIN, Y_MARGIN);
            break;
        case PositionConstants.SOUTH_EAST:
            dropLocation = bounds.getBottomRight().getCopy().translate(X_MARGIN, Y_MARGIN);
            break;
        case PositionConstants.SOUTH_WEST:
            dropLocation = bounds.getBottomLeft().getCopy().translate(-X_MARGIN, -Y_MARGIN);
            break;
        default:
            throw new RuntimeException("Invalid position specified");
    }

    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);

    gmfEditor.drag(location.x, location.y, dropLocation.x, dropLocation.y);
}