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

The following examples show how to use org.eclipse.gef.requests.ChangeBoundsRequest#getEditParts() . 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: CustomResizableEditPolicyEx.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private boolean isMoveValid(final ChangeBoundsRequest request) {
    if (request.getEditParts() != null && !request.getEditParts().isEmpty()) {
        getHost().getParent().refresh();
        final PoolEditPart pe = getPoolEditPart(getHost());
        if (pe instanceof IGraphicalEditPart) {
            final Rectangle transformedRectangle = request.getTransformedRectangle(getHostFigure().getBounds()).expand(new Insets(10, 10, 10, 10));
            final Rectangle poolBounds = ((IGraphicalEditPart) pe).getFigure().getBounds();
            FiguresHelper.translateToAbsolute(getHostFigure(), transformedRectangle);
            FiguresHelper.translateToAbsolute(((IGraphicalEditPart) pe).getFigure(), poolBounds);
            if (poolBounds.x > transformedRectangle.x) {
                return false;
            }
            if (poolBounds.y > transformedRectangle.y) {
                return false;
            }
        }
    }
    return true;
}
 
Example 2
Source File: CustomResizableEditPolicyEx.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected boolean isResizeValid(final ChangeBoundsRequest request) {
    if (request.getEditParts() != null && !request.getEditParts().isEmpty()) {
        final IGraphicalEditPart ep = (IGraphicalEditPart) request.getEditParts().get(0);
        if (request.getSizeDelta().height <= 0 && request.getSizeDelta().width <= 0 && ep.resolveSemanticElement() instanceof SubProcessEvent) {
            return checkSubprocessEventCanReduce(request);
        } else if (ep.resolveSemanticElement() instanceof Lane) {
            if (request.getSizeDelta().height <= 0 && request.getSizeDelta().width <= 0) {
                return checkSwimLanesCanReduce(request);
            } else {
                return true;
            }
        } else if (ep.resolveSemanticElement() instanceof Pool) {
            if (request.getSizeDelta().height <= 0 && request.getSizeDelta().width <= 0) {
                return checkSwimLanesCanReduce(request);
            } else {
                return true;
            }
        }
        return !checkOverlapOtherFigures(request);
    }

    return true;
}
 
Example 3
Source File: CustomDragDropEditPolicy.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private boolean isSourceAndTargetAreEventSubProc(final ChangeBoundsRequest request) {
    final EditPartViewer hostViewer = getHost().getViewer();
    if(hostViewer.findObjectAt(request.getLocation()) instanceof IGraphicalEditPart){
        final IGraphicalEditPart target = (IGraphicalEditPart) hostViewer.findObjectAt(request.getLocation());
        if(target.resolveSemanticElement() instanceof SubProcessEvent){
            for(final Object ep : request.getEditParts()){
                if(ep instanceof IGraphicalEditPart){
                    if(((IGraphicalEditPart) ep).resolveSemanticElement() instanceof SubProcessEvent){
                        return true ;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 4
Source File: CustomDragDropEditPolicy.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param request
 * @return
 */
private boolean isInvalidBoundaryMove(final ChangeBoundsRequest request) {
    for(final Object ep : request.getEditParts()){
        if(((IGraphicalEditPart)ep).resolveSemanticElement() instanceof BoundaryEvent){
            final EditPart objectAt = getHost().getViewer().findObjectAt(request.getLocation());
            if(objectAt instanceof IGraphicalEditPart){
                final IGraphicalEditPart target = (IGraphicalEditPart) objectAt;
                final EObject targetEObject = target.resolveSemanticElement();
                return !(targetEObject instanceof Activity);
            }else{
                return false;
            }
        }
    }
    return false;
}
 
Example 5
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 6
Source File: EnlargeContainerEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked" })
private PrecisionRectangle calculateFeedbackBounds(ChangeBoundsRequest request, Rectangle feedbackBounds,
		IFigure containerFigure) {
	PrecisionRectangle result = new PrecisionRectangle(feedbackBounds.getCopy());
	List<IGraphicalEditPart> editParts = request.getEditParts();
	for (IGraphicalEditPart editPart : editParts) {
		PrecisionRectangle transformedRect = new PrecisionRectangle(editPart.getFigure().getBounds().getCopy());
		editPart.getFigure().translateToAbsolute(transformedRect);
		result.union((Rectangle) transformedRect);
	}
	PrecisionDimension preferredSize = new PrecisionDimension(containerFigure.getPreferredSize().getCopy());
	containerFigure.translateToAbsolute(preferredSize);

	if (result.preciseWidth() < preferredSize.preciseWidth() + SPACEING) {
		result.setPreciseWidth(preferredSize.preciseWidth() + SPACEING);
	}
	if (result.preciseHeight() < preferredSize.preciseHeight() + SPACEING) {
		result.setPreciseHeight(preferredSize.preciseHeight() + SPACEING);
	}
	if (result.x < feedbackBounds.x) {
		result.x = feedbackBounds.x;
	}
	if (result.y < feedbackBounds.y) {
		result.y = feedbackBounds.y;
	}
	return result;
}
 
Example 7
Source File: ReportFlowLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected Command getAddCommand( Request req )
{
	EditPart parent = getHost( );
	ChangeBoundsRequest request = (ChangeBoundsRequest) req;
	List editParts = request.getEditParts( );
	CompoundCommand command = new CompoundCommand( );
	for ( int i = 0; i < editParts.size( ); i++ )
	{
		EditPart child = (EditPart) editParts.get( i );
		command.add( createAddCommand( parent,
				child,
				getInsertionReference( request ) ) );
	}
	return command.unwrap( );
}
 
Example 8
Source File: ChangeBoundsRequestUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isMovingToAnotherProcess(final EditPart host, final ChangeBoundsRequest request) {
    //find the target EditPart on which we will move the getHost()
    if (host.getViewer().findObjectAt(request.getLocation()) instanceof IGraphicalEditPart) {
        final IGraphicalEditPart target = (IGraphicalEditPart) host.getViewer().findObjectAt(request.getLocation());
        EObject source = null;
        for (final Object e : request.getEditParts()) {
            source = ((IGraphicalEditPart) e).resolveSemanticElement();
        }
        return areInSameProcess(source, target.resolveSemanticElement());
    }
    return true;
}
 
Example 9
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 10
Source File: CustomDragDropEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean isALabelEditPart(final ChangeBoundsRequest request) {
    for (final Object selectedEditPart : request.getEditParts()) {
        if (selectedEditPart instanceof LabelEditPart) {
            return true;
        }
    }
    return false;
}
 
Example 11
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Command getCommand(Request req) {
	if (!(req instanceof ChangeBoundsRequest))
		return super.getCommand(req);
	ChangeBoundsRequest request = (ChangeBoundsRequest) req;
	Command commandChain = null;
	for (Object part : request.getEditParts()) {
		if (!(part instanceof ProcessPart))
			continue;
		Command command = getCommand((ProcessPart) part, request);
		commandChain = CommandUtil.chain(command, commandChain);
	}
	return commandChain;
}
 
Example 12
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Command getCommand(Request request) {
	if (!(request instanceof ChangeBoundsRequest))
		return null;
	ChangeBoundsRequest req = (ChangeBoundsRequest) request;
	Dimension sizeDelta = req.getSizeDelta();
	if (sizeDelta.height != 0 || sizeDelta.width != 0)
		return null;
	Command commandChain = null;
	for (Object o : req.getEditParts()) {
		if (!(o instanceof ProcessPart))
			continue;
		ProcessPart part = (ProcessPart) o;
		XYLayoutCommand command = new XYLayoutCommand();
		command.setProcessNode(part.getModel());
		Rectangle bounds = (part.getModel()).figure.getBounds().getCopy();
		part.getModel().figure.translateToAbsolute(bounds);
		Rectangle moveResize = new Rectangle(req.getMoveDelta(), sizeDelta);
		bounds.resize(moveResize.getSize());
		bounds.translate(moveResize.getLocation());
		part.getModel().figure.translateToRelative(bounds);
		command.setConstraint(bounds);
		if (commandChain == null) {
			commandChain = command;
		} else {
			commandChain = commandChain.chain(command);
		}
	}
	return commandChain;
}
 
Example 13
Source File: CustomCreationEditPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Command getReparentCommand(final ChangeBoundsRequest request) {
	final CompoundCommand cc = new CompoundCommand();
	if(getHost() instanceof ITextAwareEditPart){
		return UnexecutableCommand.INSTANCE;
	}
	if(request.getExtendedData().get("DELETE_FROM_LANE") != null){
		return super.getReparentCommand(request);
	}
	if(getHost() instanceof CustomPoolCompartmentEditPart
			&& request.getEditParts().get(0) != null
			&& ((EditPart) request.getEditParts().get(0)).getParent() instanceof CustomLaneCompartmentEditPart){
		return UnexecutableCommand.INSTANCE;
	}

	if(getHost() instanceof CustomSubprocessEventCompartmentEditPart
			&& request.getEditParts().get(0) != null){
		for(final Object child : request.getEditParts()){
			if(child instanceof IGraphicalEditPart){
				if(!((IGraphicalEditPart) child).getTargetConnections().isEmpty() ||
						!((IGraphicalEditPart) child).getSourceConnections().isEmpty()){
					return  UnexecutableCommand.INSTANCE;
				} else {
					if (child instanceof StartTimerEvent2EditPart
							&& !(((IGraphicalEditPart) child).getParent() instanceof CustomSubprocessEventCompartmentEditPart)
							&& !((IGraphicalEditPart)child).getParent().equals(getHost())){
						final Command editCommand = editTimerEventValue((IGraphicalEditPart)child);
						if (editCommand.canExecute()){
							cc.add(editCommand);
						}
					}
				}
			}
	}
	}
	if(getHost() instanceof CustomSubProcessEvent2EditPart){
		return  UnexecutableCommand.INSTANCE;
	}

	if(getHost() instanceof CustomLaneEditPart){
		if( request.getLocation() != null){
			return   UnexecutableCommand.INSTANCE;
		}

	}
	cc.add(super.getReparentCommand(request));
	return cc;
}