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 09:09 Go to next message
Melan Nimesh is currently offline Melan Nimesh
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 04:08 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien Pupier
Messages: 556
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 - BonitaSoft S.A.
My blog
My company Eclipse-related blog
Re: Drag and drop icon change [message #911856 is a reply to message #903899] Wed, 12 September 2012 09:06 Go to previous messageGo to next message
Melan Nimesh is currently offline Melan Nimesh
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 09:07 Go to previous message
Melan Nimesh is currently offline Melan Nimesh
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 12:32]

Report message to a moderator

Previous Topic:qvto: Exception when invoking a helper method
Next Topic:How I add text on GEF shapes..??
Goto Forum:
  


Current Time: Fri Jul 25 19:06:05 EDT 2014

Powered by FUDForum. Page generated in 0.01595 seconds