Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How initially scroll when editor opens?
How initially scroll when editor opens? [message #1005021] Thu, 24 January 2013 10:33 Go to next message
Fredrik Attebrant is currently offline Fredrik AttebrantFriend
Messages: 34
Registered: June 2012
Member

I'm developing an GEF-based editor.
It displays a diagram with a timeline and I would like to have it "scrolled" to a position corresponding to today's date when the editor opens.
I've implemented an action that scrolls the diagram but can someone help me figure out where this can be done when the editor is opened?

The "go to today" action basically does:

int todayOffset = getOffsetFromStart();
FigureCanvas canvas = (FigureCanvas) ppEditor.getGraphicalViewer().getControl();
canvas.scrollToX(todayOffset);



Thanks,
--Fredrik
Re: How initially scroll when editor opens? [message #1005449 is a reply to message #1005021] Fri, 25 January 2013 13:41 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi, I did that extending the root edit part and its setContents method:
public class MyFreeformRootEditPart extends ScalableFreeformRootEditPart {

	@Override
	public void setContents(EditPart editpart) {
		super.setContents(editpart);
		scrollToStart();
	}
}
Re: How initially scroll when editor opens? [message #1007356 is a reply to message #1005449] Tue, 05 February 2013 15:40 Go to previous messageGo to next message
Fredrik Attebrant is currently offline Fredrik AttebrantFriend
Messages: 34
Registered: June 2012
Member

Tried this without success. Seems to be too early somehow.
For a simpler example I tried it with the Shapes example and got the same problem:
It only scrolls a little bit.

Any ideas on what is wrong?

In the ShapesEditor:
	protected void configureGraphicalViewer() {
		super.configureGraphicalViewer();

		GraphicalViewer viewer = getGraphicalViewer();
		viewer.setEditPartFactory(new ShapesEditPartFactory());
		viewer.setRootEditPart(new MyScalableFreeformRootEditPart());
		viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer));




and then the new "RootEditPart":

public class MyScalableFreeformRootEditPart extends
        ScalableFreeformRootEditPart {

    @Override
    public void setContents(EditPart editpart) {
        super.setContents(editpart);
        scrollToStart(editpart);
    }

    /**
     * @param programPlan
     * 
     */
    private void scrollToStart(EditPart editpart) {
        FigureCanvas canvas = (FigureCanvas) editpart.getViewer().getControl();
        int theOffset = 80;
        canvas.scrollToX(theOffset);
    }
}
Re: How initially scroll when editor opens? [message #1007506 is a reply to message #1007356] Wed, 06 February 2013 08:58 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Try this
private void scrollToStart(EditPart editpart) {
    final FigureCanvas canvas = (FigureCanvas) editpart.getViewer().getControl();

    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {  
	    if (!canvas.isDisposed()) {
	        canvas.scrollToX(80);
	    }
        }
    });
}
Re: How initially scroll when editor opens? [message #1007587 is a reply to message #1007506] Wed, 06 February 2013 15:20 Go to previous message
Fredrik Attebrant is currently offline Fredrik AttebrantFriend
Messages: 34
Registered: June 2012
Member

That did the trick - looks kinda cool since the scrolling to today is visible to the user...
Thanks!
--Fredrik
Previous Topic:Direct Edit with copy/paste
Next Topic: table-style graph
Goto Forum:
  


Current Time: Tue Mar 19 02:27:44 GMT 2024

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

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

Back to the top