Skip to main content



      Home
Home » Eclipse Projects » GEF » ScrollPane and EditParts
ScrollPane and EditParts [message #898435] Thu, 26 July 2012 07:39 Go to next message
Eclipse UserFriend
I want to use a ScrollPane to create a scrollable figure (with subfigures). So I created a ScrollModel which contains the bounds of the ScrollPane and a SrcollModel:

public class ScrollEditPart
...
protected IFigure createFigure()
{
	ScrollPane scrollPane = new ScrollPane();
	scrollPane.setBorder(new LineBorder());
	// scrollPane.setBounds(new Rectangle(0,0, 250, 500));	

	return scrollPane;
}

...	

@Override
protected List<?> getModelChildren()
{
	return ((ScrollModel)getModel()).getChildren();
}
...


I have a ContentModel which describes the bounds of a rectangle. The figure of the rectangle is in the ContentEditPart:

public class ContentEditPart
...
protected IFigure createFigure()
{
	RectangleFigure figure = new RectangleFigure();
	figure.setOutline(false);
	//figure.setBounds(new Rectangle(0,0, 500, 1250));	

	RectangleFigure rect1 = new RectangleFigure();
	//rect1.setBounds(new Rectangle(50,50, 50, 650));
	rect1.setBackgroundColor(ColorConstants.red);
	figure.add(rect1);

	return figure;
}
...



If I run my application, I see the rectangles. But I can't scroll them, because GEF creates the the figure via the createFigure-method in the Editpart and calls the add-method of the figure. But the ScrollPane has a setContents-method which has to be called.

The following example works. But I can't use it, because it doesn't fit in my model:
public class ScrollEditPart
...
protected IFigure createFigure()
{
	RectangleFigure figure = new RectangleFigure();
	figure.setOutline(false);
	//figure.setBounds(new Rectangle(0,0, 500, 1250));	

	RectangleFigure rect1 = new RectangleFigure();
	//rect1.setBounds(new Rectangle(50,50, 50, 650));
	rect1.setBackgroundColor(ColorConstants.red);
	figure.add(rect1);


	ScrollPane scrollPane = new ScrollPane();
	scrollPane.setBorder(new LineBorder());
	// scrollPane.setBounds(new Rectangle(0,0, 250, 500));	

	scrollPane.setContents(figure);
	// scrollPane.add(figure); // <- doesn't work

	return scrollPane;
}
...	


Can someone help me?
Re: ScrollPane and EditParts [message #898494 is a reply to message #898435] Thu, 26 July 2012 09:32 Go to previous messageGo to next message
Eclipse UserFriend
Tom,

I think you have to override the ScrollEditPart's getContentPane() because that's the figure which GEF uses to add children to.
public class ScrollEditPart
...
protected IFigure createFigure()
{
	ScrollPane scrollPane = new ScrollPane();
	scrollPane.setBorder(new LineBorder());
	// scrollPane.setBounds(new Rectangle(0,0, 250, 500));	

        Figure contents = new Figure();
        contents.setLayoutManager(new XYLayout());
        scrollPane.setContents(contents);

	return scrollPane;
}
...
public IFigure getContentPane() {
	return ((ScrollPane) getFigure()).getContents();
}

Re: ScrollPane and EditParts [message #898528 is a reply to message #898494] Thu, 26 July 2012 10:16 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the hint!
Re: ScrollPane and EditParts [message #898731 is a reply to message #898528] Fri, 27 July 2012 07:39 Go to previous messageGo to next message
Eclipse UserFriend
Now my ScrollPane works fine.
I have only a small problem. When I scroll down there is a empty area. Is it possible to delete this area? If I have scrolled down I want to see the bottom of my figure at the bottom of the ScrollPane-Viewport.

I tried to set the maximum in the RangeModel in the refreshVisual-method of the EditPart
(scrollPane.getViewport().getVerticalRangeModel().setMaximum(...))
but it didn't work Sad
Re: ScrollPane and EditParts [message #898767 is a reply to message #898731] Fri, 27 July 2012 09:46 Go to previous messageGo to next message
Eclipse UserFriend
This should be done automatically for you, I think it's a layout problem.

Try to debug a little.

I would look at the ViewPort's readjustScrollBars(), this is when the extent of the scrollbars are set.
And also the ViewportLayout's layout() where is set the bounds of the contents figure.
Re: ScrollPane and EditParts [message #899033 is a reply to message #898767] Mon, 30 July 2012 05:39 Go to previous message
Eclipse UserFriend
Hi Jan,

you're right. It was my fault. I must use the FreeformViewport.
Thanks!
Previous Topic:CommandStack
Next Topic:Nodes are too close to each other vertically
Goto Forum:
  


Current Time: Wed Jul 23 14:41:59 EDT 2025

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

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

Back to the top