Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2025 Google, Inc. and others.
* Copyright (c) 2011, 2026 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,6 +13,7 @@
package org.eclipse.wb.internal.core.gef.policy.nonvisual;

import org.eclipse.wb.core.gef.command.EditCommand;
import org.eclipse.wb.core.gef.policy.PolicyUtils;
import org.eclipse.wb.core.model.JavaInfo;
import org.eclipse.wb.gef.core.policies.ILayoutRequestValidator;
import org.eclipse.wb.gef.core.requests.ChangeBoundsRequest;
Expand Down Expand Up @@ -162,7 +163,7 @@ protected void eraseLayoutTargetFeedback(Request request) {
////////////////////////////////////////////////////////////////////////////
private void showCreationFeedback(CreateRequest request) {
JavaInfo newInfo = (JavaInfo) request.getNewObject();
Point location = request.getLocation();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
showFeedback(GefMessages.NonVisualLayoutEditPolicy_newFeedback, newInfo, location);
}

Expand All @@ -171,7 +172,7 @@ private void showPasteFeedback(PasteRequest request) {
try {
List<JavaInfoMemento> mementos = (List<JavaInfoMemento>) request.getMemento();
JavaInfo newInfo = mementos.get(0).create(m_rootInfo);
Point location = request.getLocation();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
showFeedback(GefMessages.NonVisualLayoutEditPolicy_copyFeedback, newInfo, location);
} catch (Throwable e) {
DesignerPlugin.log(e);
Expand Down Expand Up @@ -210,7 +211,7 @@ private void showMoveFeedback(ChangeBoundsRequest request) {
final JavaInfo info = part.getNonVisualInfo().getJavaInfo();
BeanFigure figure = new BeanFigure(info.getDescription().getIcon());
String text = ExecutionUtils.runObjectLog(() -> info.getVariableSupport().getTitle(), null);
figure.update(text, request.getLocation());
figure.update(text, PolicyUtils.getAbsoluteLocation(getHost(), request));
//
m_moveFeedbackFigures[i] = figure;
addFeedback(figure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.wb.gef.core.requests;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.Request;
import org.eclipse.gef.requests.DropRequest;
import org.eclipse.gef.requests.LocationRequest;
Expand All @@ -24,7 +23,6 @@
*/
public abstract class AbstractCreateRequest extends LocationRequest implements DropRequest {
private Dimension m_size;
private Point m_location;

////////////////////////////////////////////////////////////////////////////
//
Expand All @@ -38,40 +36,6 @@ public AbstractCreateRequest(Object type) {
super(type);
}

/**
* @deprecated Use {@link #getRelativeLocation()} instead.
*/
@Override
@Deprecated
public Point getLocation() {
return super.getLocation();
}

/**
* @deprecated Use {@link #setRelativeLocation(Point)} instead.
*/
@Override
@Deprecated
public void setLocation(Point p) {
super.setLocation(p);
}

/**
* @return The current mouse location.
*/
public Point getRelativeLocation() {
return m_location;
}

/**
* Sets the current location.
*
* @param p The current location.
*/
public void setRelativeLocation(Point location) {
m_location = location;
}

////////////////////////////////////////////////////////////////////////////
//
// Access
Expand Down Expand Up @@ -102,7 +66,6 @@ public void setSize(Dimension size) {
public void copyStateFrom(Request _source) {
if (_source instanceof AbstractCreateRequest source) {
setLocation(source.getLocation());
setRelativeLocation(source.getRelativeLocation());
setSize(source.getSize());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
public class ChangeBoundsRequest extends GroupRequest implements DropRequest {
private static final int SNAP_TO = 16;
private Point m_mouseAbsoluteLocation;
private Point m_mouseLocation;
private Point m_moveDelta = new Point();
private Dimension m_resizeDelta = new Dimension();
Expand Down Expand Up @@ -57,38 +56,18 @@ public ChangeBoundsRequest(Object type) {
// Access
//
////////////////////////////////////////////////////////////////////////////
/**
* Returns the <b>absolute<b> location of the mouse pointer.
*
* @deprecated Use {@link #getRelativeLocation()} instead.
*/
@Override
@Deprecated
public Point getLocation() {
return m_mouseAbsoluteLocation;
}

/**
* Sets the <b>absolute<b> location of the mouse pointer.
*
* @deprecated Use {@link #setRelativeLocation(Point)} instead.
*/
@Deprecated
public void setLocation(Point absoluteLocation) {
m_mouseAbsoluteLocation = absoluteLocation;
}

/**
* Returns the location of the mouse pointer.
*/
public Point getRelativeLocation() {
@Override
public final Point getLocation() {
return m_mouseLocation;
}

/**
* Sets the location of the mouse pointer.
*/
public void setRelativeLocation(Point location) {
public void setLocation(Point location) {
m_mouseLocation = location;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2025 Google, Inc. and others.
* Copyright (c) 2011, 2026 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -15,8 +15,6 @@
import org.eclipse.wb.gef.core.requests.AbstractCreateRequest;
import org.eclipse.wb.internal.gef.core.SharedCursors;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.Request;
import org.eclipse.swt.SWT;
Expand All @@ -43,13 +41,11 @@ public AbstractCreationTool() {
//
////////////////////////////////////////////////////////////////////////////
@Override
@SuppressWarnings("deprecation")
protected boolean handleButtonDown(int button) {
if (button == 1) {
if (m_state == STATE_INITIAL) {
m_state = STATE_DRAG;
((AbstractCreateRequest) getTargetRequest()).setRelativeLocation(getLocation());
((AbstractCreateRequest) getTargetRequest()).setLocation(getAbsoluteLocation());
((AbstractCreateRequest) getTargetRequest()).setLocation(getLocation());
lockTargetEditPart(getTargetEditPart());
}
} else {
Expand Down Expand Up @@ -115,20 +111,15 @@ protected boolean handleDragInProgress() {
* Sets the location (and size if the user is performing size-on-drop) of the request.
*/
@Override
@SuppressWarnings("deprecation")
protected void updateTargetRequest() {
super.updateTargetRequest();
AbstractCreateRequest request = (AbstractCreateRequest) getTargetRequest();
if (m_state == STATE_DRAG_IN_PROGRESS) {
Point start = getAbsoluteStartLocation();
Rectangle bounds = new Rectangle(start, getDragMoveDelta());
request.setRelativeLocation(getStartLocation());
request.setLocation(bounds.getLocation());
request.setSize(bounds.getSize());
request.setLocation(getStartLocation());
request.setSize(getDragMoveDelta());
} else {
request.setSize(null);
request.setRelativeLocation(getLocation());
request.setLocation(getAbsoluteLocation());
request.setLocation(getLocation());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,12 @@ protected Request createTargetRequest() {
* location and type.
*/
@Override
@SuppressWarnings("deprecation")
protected void updateTargetRequest() {
super.updateTargetRequest();
ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
request.setEditParts(getOperationSet());
request.setMoveDelta(new Point(getDragMoveDelta()));
request.setLocation(getAbsoluteLocation());
request.setRelativeLocation(getLocation());
request.setLocation(getLocation());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ private void updateRequest() {
// set request data
getRequest().setMoveDelta(corner);
getRequest().setSizeDelta(resize);
getRequest().setLocation(getAbsoluteLocation());
getRequest().setRelativeLocation(getLocation());
getRequest().setLocation(getLocation());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.LayerManager;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gef.requests.DropRequest;

import java.lang.reflect.Method;
import java.util.Objects;
Expand Down Expand Up @@ -171,6 +172,17 @@ public static Rectangle getAbsoluteBounds(GraphicalEditPart editPart) {
return bounds;
}

/**
* @return absolute mouse coordinates of given {@link DropRequest}.
* @since 1.24
*/
public static Point getAbsoluteLocation(GraphicalEditPart editPart, DropRequest request) {
GraphicalEditPart contents = (GraphicalEditPart) editPart.getViewer().getContents();
Point location = request.getLocation().getCopy();
contents.getFigure().translateToRelative(location);
return location;
}

////////////////////////////////////////////////////////////////////////////
//
// Geometry utilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.wb.core.gef.command.EditCommand;
import org.eclipse.wb.core.gef.figure.TextFeedback;
import org.eclipse.wb.core.gef.policy.PolicyUtils;
import org.eclipse.wb.core.model.IObjectInfo;
import org.eclipse.wb.draw2d.FigureUtils;
import org.eclipse.wb.draw2d.RectangleFigure;
Expand Down Expand Up @@ -164,7 +165,7 @@ private void showResizeFeedback(ChangeBoundsRequest request) {
m_resizeFeedback.setBounds(bounds);
// update text feedback
m_textFeedback.setText(Integer.toString(bounds.width - 2));
m_textFeedback.setLocation(request.getLocation().getTranslated(10, 10));
m_textFeedback.setLocation(PolicyUtils.getAbsoluteLocation(getHost(), request).translate(10, 10));
}

private void eraseResizeFeedback(ChangeBoundsRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ private void showMoveFeedback(ChangeBoundsRequest request) {
}
addFeedback(m_moveFeedback);
// Case 42313
Point moveLocation = isKeyboardMoving() ? moveDelta : request.getLocation();
Point moveLocation = isKeyboardMoving() ? moveDelta : PolicyUtils.getAbsoluteLocation(getHost(), request);
// do drag
placementsSupport.drag(
moveLocation,
Expand Down Expand Up @@ -535,7 +535,7 @@ public void showResizeFeedback(ChangeBoundsRequest request) {
// do drag
Dimension sizeDelta = request.getSizeDelta();
Point moveLocation =
isKeyboardMoving ? new Point(sizeDelta.width, sizeDelta.height) : request.getLocation();
isKeyboardMoving ? new Point(sizeDelta.width, sizeDelta.height) : PolicyUtils.getAbsoluteLocation(getHost(), request);
// do drag
getPlacementsSupport().drag(
moveLocation,
Expand Down Expand Up @@ -565,7 +565,7 @@ public void showResizeFeedback(ChangeBoundsRequest request) {
// update text feedback
if (m_textFeedback != null) {
m_textFeedback.setText(getSizeHintString(getHost(), widgetBounds.width, widgetBounds.height));
m_textFeedback.setLocation(request.getLocation().getTranslated(10, 10));
m_textFeedback.setLocation(PolicyUtils.getAbsoluteLocation(getHost(), request).translate(10, 10));
}
}

Expand Down Expand Up @@ -614,7 +614,7 @@ private void showCreationFeedback(CreateRequest request) {
removeFeedback(m_createFeedback);
m_createFeedback = null;
}
Point location = request.getLocation().getCopy();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
translateAbsoluteToModel(location);
IAbstractComponentInfo newWidget = (IAbstractComponentInfo) request.getNewObject();
Image image = newWidget.getImage();
Expand Down Expand Up @@ -723,7 +723,7 @@ private void showPasteFeedback(final PasteRequest request) {
m_createFeedback = null;
}
//
Point location = request.getLocation().getCopy();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
translateAbsoluteToModel(location);
//
Rectangle widgetBounds;
Expand Down Expand Up @@ -783,7 +783,7 @@ private void showPasteFeedback(final PasteRequest request) {
}
}
placementsSupport.drag(
request.getLocation(),
PolicyUtils.getAbsoluteLocation(getHost(), request),
List.copyOf(pastedModels),
widgetBounds,
List.of(relativeBounds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void showCreationFeedback(CreateRequest request) {
}
m_feedbacksDrawer.removeFeedbacks();
// prepare
Point location = request.getLocation().getCopy();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
translateAbsoluteToModel(location);
AbstractComponentInfo newWidget = (AbstractComponentInfo) request.getNewObject();
Image image = newWidget.getImage();
Expand Down Expand Up @@ -247,12 +247,12 @@ private void showAddFeedback(ChangeBoundsRequest request) {
layoutComponents[j++] = m_layout.createLayoutComponent(model);
}
// the position of the mouse inside the dragging rectangle
Point hotSpot = request.getLocation().getCopy();
Point hotSpot = PolicyUtils.getAbsoluteLocation(getHost(), request);
PolicyUtils.translateAbsoluteToModel((GraphicalEditPart) firstEditPart.getParent(), hotSpot);
hotSpot.performTranslate(request.getMoveDelta().getNegated());
hotSpot.performTranslate(-offsetX, -offsetY);
// current mouse position in model coordinates
Point topLeft = request.getLocation().getCopy();
Point topLeft = PolicyUtils.getAbsoluteLocation(getHost(), request);
translateAbsoluteToModel(topLeft);
{
// start re-parenting
Expand Down Expand Up @@ -305,7 +305,7 @@ private void showMoveFeedback(ChangeBoundsRequest request) {
return;
}
// prepare
Point location = request.getLocation().getCopy();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
m_feedbacksDrawer.removeFeedbacks();
LayoutDesigner layoutDesigner = m_layout.getLayoutDesigner();
// start dragging
Expand Down Expand Up @@ -383,7 +383,7 @@ private void showPasteFeedback(PasteRequest request) {
List<AbstractComponentInfo> pastedModels = new ArrayList<>(mementos.size());
// prepare
request.setObjects(pastedModels);
Point location = request.getLocation().getCopy();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
LayoutDesigner layoutDesigner = m_layout.getLayoutDesigner();
translateAbsoluteToModel(location);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void showResizeFeedback(ChangeBoundsRequest request) {
hideAlignmentFigures();
// prepare
int direction = request.getResizeDirection();
Point location = request.getLocation().getCopy();
Point location = PolicyUtils.getAbsoluteLocation(getHost(), request);
PolicyUtils.translateAbsoluteToModel(this, location);
LayoutDesigner layoutDesigner = m_layout.getLayoutDesigner();
AbstractComponentInfo hostModel = (AbstractComponentInfo) getHostModel();
Expand Down
Loading