Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Moving Diagram with Mouse
Moving Diagram with Mouse [message #1772094] Tue, 05 September 2017 13:29 Go to next message
Umut Kazan is currently offline Umut KazanFriend
Messages: 25
Registered: February 2017
Junior Member
I want to move my diagram with mouse button(left click or middle button).
How can i do that? This topic couldn't help me much -> https://www.eclipse.org/forums/index.php/t/78645/.

Thank you in advance
Re: Moving Diagram with Mouse [message #1772101 is a reply to message #1772094] Tue, 05 September 2017 13:59 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Which version of GEF are you using?

For the current version (GEF 5.x), you can implement an IOnDragHandler that accesses ViewportPolicy to scroll/pan in response to relative mouse movement. The handler can be registered at the root part, and it can disregard events that are processed by other handlers, so that only mouse drags on the background are considered for scrolling.

You can take a look at PanOrZoomOnScrollHandler for an example on how to use ViewportPolicy (and PanningSupport):
	@Override
	public void startScroll(ScrollEvent event) {
		this.viewportPolicy = determineViewportPolicy();
		init(viewportPolicy);
		// delegate to scroll() to perform panning/zooming
		scroll(event);
	}

	public void scroll(ScrollEvent event) {
		// each event is tested for suitability so that you can switch between
		// multiple scroll actions instantly when pressing/releasing modifiers
		if (isPan(event)) {
			pan(event);
		} else if (isZoom(event)) {
			zoom(event);
		}
	}

	protected void pan(ScrollEvent event) {
		// Determine horizontal and vertical translation.
		Dimension delta = computePanTranslation(event);
		// change viewport via operation
		viewportPolicy.scroll(true, delta.width, delta.height);
		// restrict panning to contents
		if (isContentRestricted()) {
			panningSupport.removeFreeSpace(viewportPolicy, Pos.TOP_LEFT, true);
			panningSupport.removeFreeSpace(viewportPolicy, Pos.BOTTOM_RIGHT,
					false);
		}
	}

	public void endScroll() {
		commit(viewportPolicy);
		this.viewportPolicy = null;
	}

The ViewportPolicy is initialised when the interaction starts, and it is committed when the interaction ends. In response to interaction callbacks, such as scroll() or drag(), the ViewportPolicy is used to scroll the viewer. Additionally, PanningSupport can be used to restrict scrolling to the contents.

You can take a look at FocusAndSelectOnClickHandler for an example on how to determine if another (more specific) handler already processed the event:
if (host instanceof IRootPart) {
			// check if click on background (either one of the root visuals, or
			// an unregistered visual)
			if (!isRegistered(e.getTarget())
					|| isRegisteredForHost(e.getTarget())) {
				// click on background


The solution differs when using the older GEF4 1.x or GEF Legacy (3.x).

Best regards,
Matthias
Re: Moving Diagram with Mouse [message #1772105 is a reply to message #1772101] Tue, 05 September 2017 14:46 Go to previous messageGo to next message
Umut Kazan is currently offline Umut KazanFriend
Messages: 25
Registered: February 2017
Junior Member
Thank you very much Matthias,

We are using gef_3.8.1...

I will dig into your response and start to work from there. In the meantime if you have more to say about what to do regarding gef_3 i appreciate it

Thanks again
Re: Moving Diagram with Mouse [message #1772110 is a reply to message #1772105] Tue, 05 September 2017 15:59 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
For GEF-Legacy, the solution given in the forum thread that is referenced in your opening post should be the way to go. However, I was not involved with development back in the day, so I do not know my way around either. What exactly is problematic?

Best regards,
Matthias
Re: Moving Diagram with Mouse [message #1772153 is a reply to message #1772110] Wed, 06 September 2017 07:43 Go to previous message
Umut Kazan is currently offline Umut KazanFriend
Messages: 25
Registered: February 2017
Junior Member
I am a newbie in gef and should work more to explain what is the problem but thank you, i will try harder to solve this according to forum thread in my first post. If something comes up i will try to explain later.

Thank you for your guidance.

Umut
Previous Topic:Edges with common Start Point
Next Topic:Bend Connections routed by OrthogonalRouter (GEF 5)
Goto Forum:
  


Current Time: Fri Apr 26 07:12:31 GMT 2024

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

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

Back to the top