Java Code Examples for org.eclipse.gef.requests.ChangeBoundsRequest#setEditParts()

The following examples show how to use org.eclipse.gef.requests.ChangeBoundsRequest#setEditParts() . 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: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * When drag the margin guide, the attache editparts move with the guide.
 * Now do nothing
 * 
 * @param request
 */
private void eraseAttachedPartsFeedback( Request request )
{
	if ( attachedEditParts != null )
	{
		ChangeBoundsRequest req = new ChangeBoundsRequest( request
				.getType( ) );
		req.setEditParts( attachedEditParts );

		Iterator i = attachedEditParts.iterator( );

		while ( i.hasNext( ) )
			( (EditPart) i.next( ) ).eraseSourceFeedback( req );
		attachedEditParts = null;
	}
}
 
Example 2
Source File: UpdatePoolSizeCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void decreaseHeight() {
	ChangeBoundsRequest setRequest1 = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE) ; 
	List<EditPart> epToMove = new ArrayList<EditPart>();
	epToMove.add(gep);
	setRequest1.setEditParts(epToMove);
	setRequest1.setResizeDirection(PositionConstants.NORTH);
	setRequest1.setSizeDelta(new Dimension(0,-150));
	gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
	for(Object o : gep.getChildren()){
		if(o instanceof CustomPoolCompartmentEditPart){
			for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){
				lane.refresh();
			}
		}
		
	}
	
}
 
Example 3
Source File: UpdatePoolSizeCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void increaseHeight() {
	ChangeBoundsRequest setRequest1 = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE) ; 
	List<EditPart> epToMove = new ArrayList<EditPart>();
	epToMove.add(gep);
	setRequest1.setEditParts(epToMove);
	setRequest1.setResizeDirection(PositionConstants.SOUTH);
	setRequest1.setSizeDelta(new Dimension(0,150));
	gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
	for(Object o : gep.getChildren()){
		if(o instanceof CustomPoolCompartmentEditPart){
			for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){
				lane.refresh();
			}
		}
		
	}
}
 
Example 4
Source File: UpdatePoolSizeCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void increaseWidth() {
	ChangeBoundsRequest setRequest1 = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE) ; 
	List<EditPart> epToMove = new ArrayList<EditPart>();
	epToMove.add(gep);
	for(Object o : gep.getChildren()){
		if(o instanceof CustomPoolCompartmentEditPart){
			for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){
				epToMove.add(lane);
			}
		}
		
	}
	setRequest1.setEditParts(epToMove);
	setRequest1.setResizeDirection(PositionConstants.EAST);
	setRequest1.setSizeDelta(new Dimension(150,0));
	gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
}
 
Example 5
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Resizes a GraphicalEditPart
 * 
 * @param graphEP
 *            - The GraphicalEditPart that is to be resized
 * @param new_width
 *            - The new width of the EditPart
 * @param new_height
 *            - The new height of the EditPart
 */
public static void resizeGraphicalEditPart(GraphicalEditPart graphEP, int new_width, int new_height) {
	Dimension figuredim = graphEP.getFigure().getSize();
	ChangeBoundsRequest resize_req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
	resize_req.setSizeDelta(new Dimension(new_width - figuredim.width(), new_height - figuredim.height()));
	resize_req.setEditParts(graphEP);

	Command cmd = graphEP.getCommand(resize_req);
	if (cmd != null)
		cmd.execute();
}
 
Example 6
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Moves a GraphicalEditPart to the given location
 * 
 * @param graphEP
 *            - The GraphicalEditPart
 * @param new_X
 *            - The new x coordinate
 * @param new_Y
 *            - The new y coordinate
 */
public static void moveGraphicalEditPart(GraphicalEditPart graphEP, int new_X, int new_Y) {
	Rectangle figurebounds = graphEP.getFigure().getBounds();
	ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
	move_req.setMoveDelta(new Point(new_X - figurebounds.x(), new_Y - figurebounds.y()));
	move_req.setEditParts(graphEP);

	Command cmd = graphEP.getCommand(move_req);
	if (cmd != null && cmd.canExecute())
		cmd.execute();
}
 
Example 7
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void showAttachedPartsFeedback( ChangeBoundsRequest request )
{
	ChangeBoundsRequest req = new ChangeBoundsRequest( request.getType( ) );
	req.setEditParts( getAttachedEditParts( ) );

	if ( getGuideEditPart( ).isHorizontal( ) )
		req.setMoveDelta( new Point( 0, request.getMoveDelta( ).y ) );
	else
		req.setMoveDelta( new Point( request.getMoveDelta( ).x, 0 ) );

	Iterator i = getAttachedEditParts( ).iterator( );

	while ( i.hasNext( ) )
		( (EditPart) i.next( ) ).showSourceFeedback( req );
}
 
Example 8
Source File: MultipleShapesHorizontalMoveTool.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Erases the guide and the feedback shown by the container
 * of the elements.
 */
protected void eraseSourceFeedback() {
	if (guideline.getParent() != null) {
		guideline.getParent().remove(guideline);
	}


	if (_container != null) {
		_container.eraseSourceFeedback(getSourceRequest());
	}

	ChangeBoundsRequest request = 
		new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
	request.setEditParts(Collections.emptyList());
	request.setSizeDelta(new Dimension(0, 0));
	request.setMoveDelta(new Point(0, 0));
	for (IGraphicalEditPart part : _movingShapes) {
		part.eraseSourceFeedback(request);
	}

	ChangeBoundsRequest spRequest = new ChangeBoundsRequest(
			RequestConstants.REQ_RESIZE);
	spRequest.setEditParts(Collections.emptyList());
	spRequest.setSizeDelta(new Dimension(0, 0));
	spRequest.setMoveDelta(new Point(0, 0));
	for (IGraphicalEditPart sp : _subProcesses) {
		sp.eraseSourceFeedback(spRequest);
	}
}
 
Example 9
Source File: MultipleShapesVerticalMoveTool.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Erases the guide and the feedback shown by the container
 * of the elements.
 */
protected void eraseSourceFeedback() {
	if (guideline.getParent() != null) {
		guideline.getParent().remove(guideline);
	}


	if (_container != null) {
		_container.eraseSourceFeedback(getSourceRequest());
	}

	ChangeBoundsRequest request = 
		new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
	request.setEditParts(Collections.emptyList());
	request.setSizeDelta(new Dimension(0, 0));
	request.setMoveDelta(new Point(0, 0));
	for (IGraphicalEditPart part : _movingShapes) {
		part.eraseSourceFeedback(request);
	}

	ChangeBoundsRequest spRequest = new ChangeBoundsRequest(
			RequestConstants.REQ_RESIZE);
	spRequest.setEditParts(Collections.emptyList());
	spRequest.setSizeDelta(new Dimension(0, 0));
	spRequest.setMoveDelta(new Point(0, 0));
	for (IGraphicalEditPart sp : _subProcesses) {
		sp.eraseSourceFeedback(spRequest);
	}
}
 
Example 10
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static void resizeActivitiesFigure(final IGraphicalEditPart parentEp, final String text) {

        final int lineNumber = text.length() / LINE_LENGTH;

        final ChangeBoundsRequest req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);

        final int currentWidth = parentEp.getFigure().getSize().width;
        final int defaultWidth = parentEp.getFigure().getPreferredSize().width;
        final int withDeltaFromDefault = currentWidth - defaultWidth;

        final int currentHeight = parentEp.getFigure().getSize().height;
        final int defaultHeight = parentEp.getFigure().getPreferredSize().height;
        final int heightDeltaFromDefault = currentHeight - defaultHeight;

        req.setSizeDelta(new Dimension(20 * lineNumber - withDeltaFromDefault, 10 * lineNumber - heightDeltaFromDefault));
        req.setConstrainedResize(true);
        req.setCenteredResize(true);
        req.setResizeDirection(PositionConstants.CENTER);
        req.setEditParts(parentEp);
        // avoid to perform request on element creation (figure have no size)
        if (currentWidth > 0 && currentHeight > 0 && req.getSizeDelta().width > 0 && req.getSizeDelta().height > 0) {
            final Command cmd = parentEp.getCommand(req);
            if (cmd != null) {
                parentEp.getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
            }
        }

    }
 
Example 11
Source File: CustomResizableEditPolicyEx.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Command getMoveCommand(final ChangeBoundsRequest request) {
    if (request.getEditParts() != null && !request.getEditParts().isEmpty() && request.getEditParts().get(0) instanceof CustomLaneEditPart) {
        return null;// DON'T MOVE A LANE
    }

    if (!request.getEditParts().isEmpty() && request.getEditParts().get(0) instanceof CustomSubProcessEvent2EditPart && checkOverlapOtherFigures(request)
            && request.getEditParts() != null) {
        return null; // DON'T MOVE A SUBPROCESS EVENT IF LOCATION NOT VALID
    }

    final CompoundCommand cc = new CompoundCommand("Move");
    cc.add(super.getMoveCommand(request));
    if (request.getEditParts() != null && !request.getEditParts().isEmpty()) {
        for (final Object ep : request.getEditParts()) {
            if (ep instanceof SubProcessEvent2EditPart) {
                for (final Object c : ((SubProcessEvent2EditPart) ep).getChildren()) {
                    if (c instanceof CustomSubprocessEventCompartmentEditPart) {
                        final ChangeBoundsRequest childRequest = new ChangeBoundsRequest(REQ_MOVE_CHILDREN);
                        final List eps = new ArrayList();
                        for (final Object child : ((CustomSubprocessEventCompartmentEditPart) c).getChildren()) {
                            eps.add(child);
                        }
                        childRequest.setEditParts(eps);
                        childRequest.setMoveDelta(request.getMoveDelta());
                        final HashMap<Object, Object> map = new HashMap<Object, Object>();
                        map.put(MOVE_COMPARTMENT_CHILDREN, MOVE_COMPARTMENT_CHILDREN);
                        childRequest.setExtendedData(map);
                        if (!eps.isEmpty()) {
                            cc.add(((CustomSubprocessEventCompartmentEditPart) c).getCommand(childRequest));
                        }
                    }
                }
            }
        }
    }
    return cc.unwrap();

}
 
Example 12
Source File: MultipleShapesHorizontalMoveTool.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
* Shows a nice guideline to show the move to
* the right or the left.
*/
protected void showSourceFeedback() {
 if (_container == null) {
	 return;
 }
 if (guideline.getParent() == null) {
	 addFeedback(guideline);
 }
 Rectangle bounds = Rectangle.SINGLETON.getCopy();
 bounds.x = getCurrentPositionZoomed();

 Rectangle containerBounds = _container.getFigure().getBounds().getCopy();
 _container.getFigure().translateToAbsolute(containerBounds);

 ((DiagramEditPart) getCurrentViewer().getContents())
 .getFigure().translateToRelative(containerBounds);
 bounds.y = containerBounds.y;
 bounds.width = 1;
 bounds.height = containerBounds.height;

 ZoomManager zoomManager = ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager();
 bounds.performScale(zoomManager.getZoom()) ;

 guideline.setBounds(bounds);
 guideline.setVisible(getState() == STATE_DRAG_IN_PROGRESS);

 ChangeBoundsRequest request = 
	 new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
 request.setMoveDelta(((ChangeBoundsRequest) getSourceRequest()).getMoveDelta());
 request.setSizeDelta(new Dimension(0, 0));
 request.setEditParts(_movingShapes);

 for (IGraphicalEditPart part : _movingShapes) {
	 part.showSourceFeedback(request);
 }

 ChangeBoundsRequest spRequest = new ChangeBoundsRequest(
		 RequestConstants.REQ_RESIZE);
 Point moveDelta  = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
 Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
 spRequest.setSizeDelta(spSizeDelta);
 spRequest.setMoveDelta(new Point(0, 0));
 spRequest.setEditParts(_subProcesses);

 for (IGraphicalEditPart sp : _subProcesses) {
	 sp.showSourceFeedback(spRequest);
 }
 ((DiagramEditPart) getCurrentViewer().getContents()).getRoot().refresh();
}
 
Example 13
Source File: MultipleShapesVerticalMoveTool.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Shows a nice guideline to show the move 
 */
protected void showSourceFeedback() {
	if (_container == null) {
		return;
	}
	if (guideline.getParent() == null) {
		addFeedback(guideline);
	}
	Rectangle bounds = Rectangle.SINGLETON.getCopy();
	bounds.y = getCurrentPositionZoomed();

	Rectangle containerBounds = _container.getFigure().getBounds().getCopy();



	_container.getFigure().translateToAbsolute(containerBounds);

	((DiagramEditPart) getCurrentViewer().getContents())
	.getFigure().translateToRelative(containerBounds);


	bounds.x = containerBounds.x ;
	bounds.height = 1;
	bounds.width = containerBounds.width ;

	ZoomManager zoomManager = ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager();
	bounds.performScale(zoomManager.getZoom()) ;
	
	guideline.setBounds(bounds);
	guideline.setVisible(getState() == STATE_DRAG_IN_PROGRESS);

	ChangeBoundsRequest request = 
		new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
	request.setMoveDelta(((ChangeBoundsRequest) getSourceRequest()).getMoveDelta());
	request.setSizeDelta(new Dimension(0, 0));
	request.setEditParts(_movingShapes);

	for (IGraphicalEditPart part : _movingShapes) {
		part.showSourceFeedback(request);
	}

	ChangeBoundsRequest spRequest = new ChangeBoundsRequest(
			RequestConstants.REQ_RESIZE);
	Point moveDelta  = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
	Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
	spRequest.setSizeDelta(spSizeDelta);
	spRequest.setMoveDelta(new Point(0, 0));
	spRequest.setEditParts(_subProcesses);

	for (IGraphicalEditPart sp : _subProcesses) {
		sp.showSourceFeedback(spRequest);
	}
	((DiagramEditPart) getCurrentViewer().getContents()).getRoot().refresh();
}
 
Example 14
Source File: CustomResizeHandle.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected DragTracker createDragTracker() {
	return new ResizeTracker(getOwner(), cursorDirection){
		@Override
		protected void updateSourceRequest() {
			ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
			Dimension d = getDragMoveDelta();

			Point location = new Point(getLocation());
			Point moveDelta = new Point(0, 0);
			Dimension resizeDelta = new Dimension(0, 0);

			if (getOwner() != null) {

				if(isContrained){
					request.setConstrainedResize(true);
					int origHeight = getOwner().getFigure().getBounds().height;
					int origWidth = getOwner().getFigure().getBounds().width;
					float ratio = 1;

					if (origWidth != 0 && origHeight != 0)
						ratio = ((float) origHeight / (float) origWidth);

					if (getResizeDirection() == PositionConstants.SOUTH_EAST) {
						if (d.height > (d.width * ratio))
							d.width = (int) (d.height / ratio);
						else
							d.height = (int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.NORTH_WEST) {
						if (d.height < (d.width * ratio))
							d.width = (int) (d.height / ratio);
						else
							d.height = (int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.NORTH_EAST) {
						if (-(d.height) > (d.width * ratio))
							d.width = -(int) (d.height / ratio);
						else
							d.height = -(int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.SOUTH_WEST) {
						if (-(d.height) < (d.width * ratio))
							d.width = -(int) (d.height / ratio);
						else
							d.height = -(int) (d.width * ratio);
					}
				}
			}else{
				request.setConstrainedResize(false);
			}

			request.setCenteredResize(getCurrentInput().isModKeyDown(SWT.MOD1));

			if ((getResizeDirection() & PositionConstants.NORTH) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					resizeDelta.height -= d.height;
				}
				moveDelta.y += d.height;
				resizeDelta.height -= d.height;
			}
			if ((getResizeDirection() & PositionConstants.SOUTH) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					moveDelta.y -= d.height;
					resizeDelta.height += d.height;
				}
				resizeDelta.height += d.height;
			}
			if ((getResizeDirection() & PositionConstants.WEST) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					resizeDelta.width -= d.width;
				}
				moveDelta.x += d.width;
				resizeDelta.width -= d.width;
			}
			if ((getResizeDirection() & PositionConstants.EAST) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					moveDelta.x -= d.width;
					resizeDelta.width += d.width;
				}
				resizeDelta.width += d.width;
			}

			request.setMoveDelta(moveDelta);
			request.setSizeDelta(resizeDelta);
			request.setLocation(location);
			request.setEditParts(getOperationSet());

			request.getExtendedData().clear();
		}

		@Override
		protected List<IGraphicalEditPart> createOperationSet() {
			ArrayList<IGraphicalEditPart> res = new ArrayList<IGraphicalEditPart>();
			for (Object selection : getCurrentViewer().getSelectedEditParts()) {
				if (isResizable((IGraphicalEditPart)selection)) {
					res.add((IGraphicalEditPart)selection);
				}
			}
			return res;
		}
	};
}