Java源码示例:org.eclipse.gef.requests.ChangeBoundsRequest
示例1
@Override
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentCreationEditPolicy());
installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new RegionCompartmentCanonicalEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
// Removes the collapse expand handler
installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableEditPolicyEx());
installEditPolicy(EditPolicyRoles.SNAP_FEEDBACK_ROLE, new SimpleSnapFeedbackPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, new XYLayoutEditPolicy() {
// This is required when live feedback is used
@Override
protected Object getConstraintFor(ChangeBoundsRequest request, GraphicalEditPart child) {
if (request instanceof SetPreferredSizeRequest || RequestConstants.REQ_ADD.equals(request.getType())) {
return super.getConstraintFor(request, child);
}
request.setSizeDelta(new Dimension(0, 0));
request.setMoveDelta(new Point(0, 0));
return super.getConstraintFor(request, child);
}
});
}
示例2
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();
}
}
}
}
}
示例3
@Override
protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
// If REQ_DROP is delivered 2 times in a row it is a "real" drop and not only a
// hover over existing elements in the same region
if (RequestConstants.REQ_DROP.equals(request.getType()) && RequestConstants.REQ_DROP.equals(lastRequest)) {
Rectangle rect = getOriginalBounds();
getHostFigure().getParent().translateToRelative(rect);
getHostFigure().setBounds(rect);
super.showChangeBoundsFeedback(request);
lastRequest = (String) request.getType();
return;
}
super.eraseChangeBoundsFeedback(request);
enforceConstraintForMove(request);
if (connectionStart) {
updateOriginalBounds();
connectionStart = false;
}
Rectangle bounds = request.getTransformedRectangle(getOriginalBounds());
getHostFigure().getParent().translateToRelative(bounds);
getHostFigure().setBounds(bounds);
getHostFigure().getParent().setConstraint(getHostFigure(), bounds);
lastRequest = (String) request.getType();
}
示例4
@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
if (RequestConstants.REQ_DROP.equals(request.getType())) {
return super.getMoveCommand(request);
}
if (request instanceof SetPreferredSizeRequest) {
SetPreferredSizeRequest req = new SetPreferredSizeRequest(REQ_RESIZE_CHILDREN);
req.setEditParts(getHost());
req.setCenteredResize(request.isCenteredResize());
req.setConstrainedMove(request.isConstrainedMove());
req.setConstrainedResize(request.isConstrainedResize());
req.setSnapToEnabled(request.isSnapToEnabled());
req.setMoveDelta(request.getMoveDelta());
req.setSizeDelta(request.getSizeDelta());
req.setLocation(request.getLocation());
req.setExtendedData(request.getExtendedData());
req.setResizeDirection(request.getResizeDirection());
return getHost().getParent().getCommand(req);
}
NULL_REQUEST.setEditParts(getHost());
return getHost().getParent().getCommand(NULL_REQUEST);
}
示例5
@Override
protected ResizeTracker getResizeTracker(int direction) {
return new ResizeTracker((GraphicalEditPart) getHost(), direction) {
@Override
protected void enforceConstraintsForResize(ChangeBoundsRequest request) {
Rectangle locationAndSize = getOriginalBounds();
final Rectangle origRequestedBounds = request.getTransformedRectangle(locationAndSize);
final Rectangle modified = origRequestedBounds.getCopy();
checkAndPrepareConstraint(request, modified);
Dimension newDelta = new Dimension(modified.width - locationAndSize.width,
modified.height - locationAndSize.height);
request.setSizeDelta(newDelta);
final Point moveDelta = request.getMoveDelta();
request.setMoveDelta(new Point(moveDelta.x - origRequestedBounds.x + modified.x,
moveDelta.y - origRequestedBounds.y + modified.y));
}
};
}
示例6
@Override
protected Object getConstraintFor(ChangeBoundsRequest request,
GraphicalEditPart child) {
if (request instanceof AlignmentRequest) {
return super.getConstraintFor(request, child);
}
final Rectangle rect = (Rectangle) super.getConstraintFor(request,
child);
final Rectangle cons = getCurrentConstraintFor(child);
final int newTreePosition = TreeLayoutUtil.getNewTreeNodePosition(
request.getLocation(),
TreeLayoutUtil.getSiblings((IGraphicalEditPart) child));
if (cons instanceof TreeLayoutConstraint) {
final TreeLayoutConstraint treeLayoutConstraint = (TreeLayoutConstraint) cons;
return new TreeLayoutConstraint(rect,
treeLayoutConstraint.isRoot(), newTreePosition);
}
return new TreeLayoutConstraint(rect, false, newTreePosition);
}
示例7
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;
}
示例8
private Rectangle getDummyLineFigureBounds( ChangeBoundsRequest request )
{
Rectangle bounds = new Rectangle( );
EditorRulerEditPart source = getRulerEditPart( );
if ( source.isHorizontal( ) )
{
bounds.x = getCurrentPositionZoomed( request );
bounds.y = source.getGuideLayer( ).getBounds( ).y;
bounds.width = 1;
bounds.height = source.getGuideLayer( ).getBounds( ).height;
}
else
{
bounds.x = source.getGuideLayer( ).getBounds( ).x;
bounds.y = getCurrentPositionZoomed( request );
bounds.width = source.getGuideLayer( ).getBounds( ).width;
bounds.height = 1;
}
return bounds;
}
示例9
private int getCurrentPositionZoomed( ChangeBoundsRequest request )
{
int newPosition;
if ( getGuideEditPart( ).isHorizontal( ) )
{
newPosition = getGuideEditPart( ).getZoomedPosition( )
+ request.getMoveDelta( ).y;
}
else
{
newPosition = getGuideEditPart( ).getZoomedPosition( )
+ request.getMoveDelta( ).x;
}
return newPosition;
}
示例10
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;
}
示例11
/**
* Generates a draw2d constraint object derived from the specified child
* EditPart using the provided Request. The returned constraint will be
* translated to the application's model later using
* {@link #translateToModelConstraint(Object)}.
*
* @param request
* the ChangeBoundsRequest
* @param child
* the child EditPart for which the constraint should be
* generated
* @return the draw2d constraint
*/
protected Object getConstraintFor( ChangeBoundsRequest request,
GraphicalEditPart child )
{
IFigure figure = child.getFigure( );
Rectangle rect = new PrecisionRectangle(figure.getBounds());
figure.translateToAbsolute(rect);
rect = request.getTransformedRectangle( rect );
figure.translateToRelative(rect);
rect.translate( getLayoutOrigin( ).getNegated( ) );
if (figure instanceof IOutsideBorder)
{
Border border = ((IOutsideBorder)figure).getOutsideBorder( );
if (border != null)
{
Insets insets = border.getInsets( figure );
rect.shrink( insets.right, insets.bottom );
}
}
return getConstraintFor( rect );
}
示例12
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;
}
示例13
/**
* creates the command to move the shapes left or right.
*/
protected Command getCommand() {
if (_container == null) {
return null;
}
CompoundCommand command = new CompoundCommand("Multiple Shape Move");
TransactionalEditingDomain editingDomain = _container.getEditingDomain();
Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
ZoomManager zoomManager = ((DiagramRootEditPart)
getCurrentViewer().getRootEditPart()).getZoomManager();
spSizeDelta.scale(1/zoomManager.getZoom());
command.add(_container.getCommand(getSourceRequest()));
for (IGraphicalEditPart sp : _subProcesses) {
Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
spDim.expand(spSizeDelta);
SetBoundsCommand setBounds =
new SetBoundsCommand(editingDomain,"MultipleShape Move", sp, spDim);
command.add(new ICommandProxy(setBounds));
}
return command;
}
示例14
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();
}
}
}
}
示例15
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));
}
示例16
/**
* {@inheritDoc}
*/
@Override
protected Command createChangeConstraintCommand(final ChangeBoundsRequest request, final EditPart child, final Object constraint) {
final ERDiagram diagram = (ERDiagram) getHost().getModel();
final List selectedEditParts = getHost().getViewer().getSelectedEditParts();
if (!(child instanceof NodeElementEditPart)) {
return null;
}
return createChangeConstraintCommand(diagram, selectedEditParts, (NodeElementEditPart) child, (Rectangle) constraint);
}
示例17
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;
}
示例18
private boolean isTargetaCollapseSubprocess(final ChangeBoundsRequest request) {
if(request.getLocation() == null){
return false ;
}
final EditPart ep = getHost().getParent().getViewer().findObjectAt(request.getLocation()) ;
return ep instanceof IGraphicalEditPart && ((IGraphicalEditPart) ep).resolveSemanticElement() instanceof SubProcessEvent && isCollapsed(ep);
}
示例19
protected boolean checkOverlapOtherFigures(final ChangeBoundsRequest request) {
if (FiguresHelper.AVOID_OVERLAP_ENABLE) {
getHost().getParent().refresh();
for (final Object c : getHost().getParent().getChildren()) {
if (c instanceof IGraphicalEditPart) {
if (!c.equals(getHost()) && ((IGraphicalEditPart) c).getFigure().intersects(request.getTransformedRectangle(getHostFigure().getBounds()))) {
return true;
}
}
}
}
return false;
}
示例20
@Override
public Command getCommand(Request request) {
if (request instanceof ChangeBoundsRequest) {
return createUpdateAllBendpointsCommand((ChangeBoundsRequest) request);
}
return super.getCommand(request);
}
示例21
private List<Connection> getSourceConnections(ChangeBoundsRequest request) {
List<Connection> result = new ArrayList<>();
@SuppressWarnings("unchecked")
List<IGraphicalEditPart> sourceConnections = filter(getHost().getSourceConnections(), request);
for (IGraphicalEditPart iGraphicalEditPart : sourceConnections) {
Connection connection = (Connection) iGraphicalEditPart.getFigure();
result.add(connection);
}
return result;
}
示例22
private List<Connection> getTargetConnections(ChangeBoundsRequest request) {
List<Connection> result = new ArrayList<>();
@SuppressWarnings("unchecked")
List<IGraphicalEditPart> targetConnections = filter(getHost().getTargetConnections(), request);
for (IGraphicalEditPart iGraphicalEditPart : targetConnections) {
Connection connection = (Connection) iGraphicalEditPart.getFigure();
result.add(connection);
}
return result;
}
示例23
private void justKeepConnectionsInPlace(ChangeBoundsRequest request) {
if (connectionStart) {
IFigure figure = getHostFigure();
originalBounds = getHostFigure().getBounds().getCopy();
figure.translateToAbsolute(originalBounds);
originalBounds.translate(request.getMoveDelta().getNegated()).resize(request.getSizeDelta().getNegated());
router.initBoxDrag(originalBounds, getSourceConnections(request), getTargetConnections(request));
connectionStart = false;
}
// XXX: always pass in original bounds so that initial locations are forced
router.updateBoxDrag(originalBounds);
}
示例24
private void routeInResponseToBoxDrag(ChangeBoundsRequest request) {
if (connectionStart) {
IFigure figure = getHostFigure();
originalBounds = getHostFigure().getBounds().getCopy();
figure.translateToAbsolute(originalBounds);
originalBounds.translate(request.getMoveDelta().getNegated()).resize(request.getSizeDelta().getNegated());
router.initBoxDrag(originalBounds, getSourceConnections(request), getTargetConnections(request));
connectionStart = false;
}
router.updateBoxDrag(request.getTransformedRectangle(originalBounds));
}
示例25
protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
if (request.getEditParts().get(0) != getHost()) {
// XXX: policy is also called for composites
justKeepConnectionsInPlace(request);
} else {
routeInResponseToBoxDrag(request);
}
}
示例26
@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);
}
}
}
示例27
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;
}
示例28
@Override
public void showSourceFeedback(Request request) {
if (containerHierachy == null) {
containerHierachy = collectContainerHierachy();
}
if (!RequestConstants.REQ_RESIZE.equals(request.getType())
&& !RequestConstants.REQ_MOVE.equals(request.getType()))
return;
showContainerFeedback((ChangeBoundsRequest) request);
}
示例29
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);
}
}
}
示例30
@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;
}