Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Drag and drop icon change(Drag and drop icon change)
Drag and drop icon change [message #902787] Mon, 20 August 2012 13:09 Go to next message
Melan Nimesh is currently offline Melan NimeshFriend
Messages: 6
Registered: April 2011
Location: Colombo
Junior Member
Hi,

I enabled drag and drop support from the palette in my GMF Editor using the following post http://wiki.eclipse.org/GMF_Newsgroup_Q_and_A#How_to_enable_drag-n-drop_from_the_palette.3F

Is there a way to change the drag icon to indicate to the user that it is illegal to drop what they are dragging at the current location.

Thanks.


Re: Drag and drop icon change [message #903899 is a reply to message #902787] Mon, 27 August 2012 08:08 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

Please take a look to http://www.bonitasoft.org/websvn/filedetails.php?repname=Bonita+Open+Solution&path=%2Fbonita-studio%2Ftags%2Fbonita-studio-5.7.2%2Fplugins%2Forg.bonitasoft.studio.diagram.custom%2Fsrc%2Forg%2Fbonitasoft%2Fstudio%2Fdiagram%2Fcustom%2FeditPolicies%2FCustomCreationEditPolicy.java
There is a setCursor called.

regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: Drag and drop icon change [message #911856 is a reply to message #903899] Wed, 12 September 2012 13:06 Go to previous messageGo to next message
Melan Nimesh is currently offline Melan NimeshFriend
Messages: 6
Registered: April 2011
Location: Colombo
Junior Member
Hi,

Thanks for the reply. It works for changing mouse over icon, dragging tool items does not show any change, is that to be expected?

Thanks,
Melan
Re: Drag and drop icon change [message #911857 is a reply to message #903899] Wed, 12 September 2012 13:07 Go to previous messageGo to next message
Melan Nimesh is currently offline Melan NimeshFriend
Messages: 6
Registered: April 2011
Location: Colombo
Junior Member
I was able not get it to work by implementing my own custom DragDropEditPolicy.


a snippet of my code follows.

import java.awt.MouseInfo;
import java.awt.Point;

import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
import org.eclipse.wb.swt.SWTResourceManager;

/**
 * Installing <b>FeedbackIndicateDragDropEditPolicy</b> will indicate a feedback when drag a node
 * to the canvas from the tool palette
 */
public class FeedbackIndicateDragDropEditPolicy extends DragDropEditPolicy {
	
	private IFigure feedbackFigure;
	private Image feedbackImage;

	private static final String ALLOW_DROP_ICON_PATH = "/icons/custom/check.png";
	private static final String NOT_ALLOW_DROP_ICON_PATH = "/icons/custom/exclamation.png";

	/**
	 * {@inheritDoc}
	 */
	protected Command getDropCommand(ChangeBoundsRequest request) {
		if ((getHost() instanceof ShapeCompartmentEditPart)) {
			/* avoiding drag and drop nodes between compartments. */
			return null;
		}
		return super.getDragCommand(request);
	}

	/**
	 * {@inheritDoc}
	 */
	public void showTargetFeedback(Request request) {
		super.showTargetFeedback(request);
		if (request instanceof CreateUnspecifiedTypeRequest) {
			if (getHost() instanceof ShapeCompartmentEditPart) {
				ShapeCompartmentEditPart host = (ShapeCompartmentEditPart) getHost();
				Command command = host.getCommand(request);
				if (command != null) {
					if (command.canExecute()) {
						showFeedBackFigure(true);
					} else {
						showFeedBackFigure(false);
					}
				} else {
					showFeedBackFigure(false);
				}
			} else {
				showFeedBackFigure(false);
			}
		}
	}

	/**
	 * {@inheritDoc}
	 */
	public void eraseTargetFeedback(Request request) {
		if (feedbackFigure != null) {
			removeFeedback(feedbackFigure);
			feedbackFigure = null;
		}
		super.eraseTargetFeedback(request);
	}

	/**
	 * Get feedback figure
	 * @param allowDrop true if, acceptable for certain node.
	 * @return
	 */
	public IFigure getFeedbackFigure(boolean allowDrop) {
		if (feedbackFigure == null) {
			Image feedbackImage = SWTResourceManager.getImage(this.getClass(),
					(allowDrop) ? ALLOW_DROP_ICON_PATH : NOT_ALLOW_DROP_ICON_PATH);
			IFigure figure = new ImageFigure(feedbackImage);
			addFeedback(figure);
			this.feedbackImage = feedbackImage;
			feedbackFigure = figure;
		}
		return feedbackFigure;
	}

	/**
	 * Show feedback figure in canvas
	 * @param allowDrop  true if, acceptable for certain node.
	 */
	private void showFeedBackFigure(boolean allowDrop) {
		Point pointer = MouseInfo.getPointerInfo().getLocation();
		IFigure feedbackFigure = getFeedbackFigure(allowDrop);
		int x = (int) pointer.getX();
		int y = (int) pointer.getY();
		Control ctrl = getHost().getViewer().getControl();
		FigureCanvas canvas = (FigureCanvas) ctrl;
		int horizontal = canvas.getHorizontalBar().getSelection();
		int vertical = canvas.getVerticalBar().getSelection();
		horizontal += 15;
		vertical -= 15;
		org.eclipse.swt.graphics.Point p = canvas.toDisplay(0, 0);
		feedbackFigure.setBounds(new Rectangle((x - p.x) + horizontal, (y - p.y) + vertical,
				feedbackImage.getBounds().width, feedbackImage.getBounds().height));
	}

}


Thanks,

[Updated on: Wed, 19 September 2012 16:32]

Report message to a moderator

icon7.gif  Re: Drag and drop icon change [message #1495770 is a reply to message #911857] Tue, 02 December 2014 13:55 Go to previous message
vignesh ramani is currently offline vignesh ramaniFriend
Messages: 2
Registered: December 2014
Junior Member
Hey please look into Vainolo's GEF tutorials. There is a tutorial on drag and drop. Perhaps you can get some idea when you look into those codes.
Previous Topic:Get ElementType from containing feature and target EClass
Next Topic:Create multiple nodes from a single palette entry
Goto Forum:
  


Current Time: Tue Apr 23 16:09:14 GMT 2024

Powered by FUDForum. Page generated in 0.03714 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top