Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » ScrollingGraphicalViewer: Auto right scroll when width increases
ScrollingGraphicalViewer: Auto right scroll when width increases [message #916643] Wed, 19 September 2012 09:12 Go to next message
Jason Lin is currently offline Jason LinFriend
Messages: 12
Registered: July 2012
Junior Member
(1)First Scenario
Figure 1. The element in the most right of canvas.
index.php/fa/11555/0/
Figure 2. Hover the element,the button pad shows and the canvas increase size, but not scroll right.
Thus we can't see the right area of context button pad.
index.php/fa/11556/0/

(2) Seconde Scenario
Figure 3. Expand the element and the scrollbars shows but not scroll right
index.php/fa/11557/0/
Figure 4. Scroll manually
index.php/fa/11558/0/

I want to solve this problem by:
(1) add border/inset to ScrollingGraphicalViewer. But can't find it how to add it.
(This approach is not fit to second scenario)
(2) auto scroll to right if the size expand because of drag&drop or others.

Unfortunately, I still can't implement even one of them in graphiti after reading some articles and codes for hours.

So,
If the approach is incorrect, then what is the right way?
If correct, how to do it?

Thanks in advanced.

Jason, Lin
  • Attachment: 1.png
    (Size: 11.00KB, Downloaded 360 times)
  • Attachment: 2.png
    (Size: 12.81KB, Downloaded 361 times)
  • Attachment: 3.png
    (Size: 13.30KB, Downloaded 350 times)
  • Attachment: 4.png
    (Size: 18.40KB, Downloaded 359 times)

[Updated on: Wed, 19 September 2012 09:17]

Report message to a moderator

Re: ScrollingGraphicalViewer: auto right scrolling when expand [message #918781 is a reply to message #916643] Fri, 21 September 2012 10:42 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1635
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Lin,

that's a difficult issue. We stumbled over that already before published
Graphiti as open source and tried to solve that somehow. Unfortunatly all
possible solutions we came about had major drawbacks. I can't remember the
details but also in discussions with GEF committers we could find a real
solution.

However, there is a special mode you can switch the Graphiti diagram editor
into: you can override the method getDiagramScrollingBehavior in the tool
behavior provider to enable permanently visible scroll bars that allow the
positioning of the diagram so that selection of context buttons of shapes at
the border are possible. However, this is only a workaround achieved by
some hacks. It might happen that this will not work with future GEF versions
any more. That's also the reason why this is deprecated inside Graphiti...

Michael
Re: ScrollingGraphicalViewer: auto right scrolling when expand [message #921552 is a reply to message #918781] Mon, 24 September 2012 08:07 Go to previous messageGo to next message
Jason Lin is currently offline Jason LinFriend
Messages: 12
Registered: July 2012
Junior Member
Michael,

I'm very happy to see your reply.

Last week, I also have tried some ways to deal with this issue.
One way is adding a PropertyChangeListener to horizontal ScrollBar RangeModel. But similarly it's only a workaround achieved by hacks. What's worse, it will affect selection behaviors in the framework. That's the reason why I decide to shelve this feature currently.

Hope that there could be a beautiful way to customize ScrollBar behavior in the future.

Best Regards,
Lin
        /**
	 * Add listener to Horizontal ScrollBar
	 */
	private void addHorizontalAutoScrollListener(){
		final FigureCanvas canvas = getFigureCanvas();
		PropertyChangeListener horizontalChangeAutoRightListener = new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				RangeModel model = canvas.getViewport().getHorizontalRangeModel();		
				ScrollBar sb = canvas.getHorizontalBar();
				if(event.getPropertyName().equalsIgnoreCase("maximum")){
					if((Integer)event.getNewValue() > (Integer)event.getOldValue()){
						//Scroll to most right
						canvas.scrollToX(model.getMaximum()-model.getExtent());
					}
				}else if(event.getPropertyName().equalsIgnoreCase("minimum")){
					if((Integer)event.getNewValue() < (Integer)event.getOldValue() ){
						//Scroll to most left
						canvas.scrollToX((Integer)event.getNewValue());
					}
				}
			}
		};

		canvas.getViewport().getHorizontalRangeModel().addPropertyChangeListener(horizontalChangeAutoRightListener);
	}
Re: ScrollingGraphicalViewer: auto right scrolling when expand [message #1070104 is a reply to message #918781] Wed, 17 July 2013 08:42 Go to previous messageGo to next message
satish tiwari is currently offline satish tiwariFriend
Messages: 1
Registered: July 2013
Junior Member
Hi,

I am having same graphiti scroll bar issue as it is mentioned above by Jason Lin.
Please let me know is there any solution for this issue.

Regards,
Satish
Re: ScrollingGraphicalViewer: auto right scrolling when expand [message #1229175 is a reply to message #1070104] Wed, 08 January 2014 21:41 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 617
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

I've found that I can automatically scroll the canvas when needed (for example to fully show the Button Pad) using a Job that runs in the UI thread. In my ToolBehaviorProvider I override getContextButtonPad() which is called by the Graphiti framework to get the contents of the Button Pad. The following code calculates the top, right and bottom edges of the visible area of the canvas and the Button Pad. The IContextButtonPadData returned from the super() call contains the location and size of the Button Pad. According to the Graphiti javadoc for IContextButtonPadData.getPadLocation(), "These are not the outer bounds of the context button pad, but the inner rectangle, around which the context button pad is shown"; the extra 30 pixels account for the actual width and height of the Pad itself.

The 1/2 second start delay when scheduling the job prevents the canvas from jittering when the mouse is unintentionally moved over a shape.


		IContextButtonPadData data = super.getContextButtonPad(context);
		final FigureCanvas canvas = (FigureCanvas)editor.getGraphicalViewer().getControl();
		Rectangle canvasBounds = canvas.getViewport().getBounds();
		final int hOffset = canvas.getViewport().getHorizontalRangeModel().getValue();
		final int vOffset = canvas.getViewport().getVerticalRangeModel().getValue();
		final int canvasRight = canvasBounds.width + hOffset;
		final int canvasBottom = canvasBounds.height + vOffset;
		final int canvasTop = vOffset;
		IRectangle padBounds = data.getPadLocation();
		final int padRight = padBounds.getX() + padBounds.getWidth() + 30;
		final int padTop = padBounds.getY() - 30;
		final int padBottom = padBounds.getY() + padBounds.getHeight() + 30;
		
		if (padRight>canvasRight || padTop<canvasTop || padBottom>canvasBottom) {
			Job job = new Job("scroll") {
				@Override
				protected IStatus run (IProgressMonitor monitor) {
					Display.getDefault().asyncExec(new Runnable() {
						@Override
						public void run() {
							if (padRight>canvasRight)
								canvas.scrollToX(hOffset + padRight - canvasRight);
							if (padTop<canvasTop)
								canvas.scrollToY(vOffset + padTop - canvasTop);
							if (padBottom>canvasBottom)
								canvas.scrollToY(vOffset + padBottom - canvasBottom);
						}
					});
					return Status.OK_STATUS;
				}			 		
			};	
			job.schedule(600);
		}



Hope this helps.

Bob
Re: ScrollingGraphicalViewer: auto right scrolling when expand [message #1229899 is a reply to message #1229175] Fri, 10 January 2014 13:46 Go to previous message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 617
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

After playing around with this some more, I have decided to use another approach - the proposed solution is kind of annoying because it still causes the diagram canvas to jitter as the mouse is moved across shapes.

Instead I've decided to increase the size of the canvas' margin border, which adds enough space on all edges of the canvas to display the button pad. This needs to be done immediately after setting the Diagram into the Graphical Viewer contents, like so:


		GraphicalViewer viewer = getGraphicalViewer();
		viewer.setContents(diagram);
		EditPart ep = viewer.getRootEditPart().getContents();
		if (ep instanceof AbstractGraphicalEditPart) {
			IFigure fig = ((AbstractGraphicalEditPart)ep).getFigure();
			fig.setBorder(new MarginBorder(50));
		}




This can usually be handled in the Diagram Editor's initializeGraphicalViewer() method.
Previous Topic:Non-deterministic behaviour in CustomFeature
Next Topic:Disable Image Decorators
Goto Forum:
  


Current Time: Mon Nov 24 00:22:41 GMT 2014

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

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