Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » ScrollPane and EditParts
ScrollPane and EditParts [message #898435] Thu, 26 July 2012 07:39 Go to next message
tom maxx is currently offline tom maxx
Messages: 20
Registered: July 2012
Junior Member
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
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
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
tom maxx is currently offline tom maxx
Messages: 20
Registered: July 2012
Junior Member
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
tom maxx is currently offline tom maxx
Messages: 20
Registered: July 2012
Junior Member
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
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
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
tom maxx is currently offline tom maxx
Messages: 20
Registered: July 2012
Junior Member
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: Fri Apr 18 16:59:48 EDT 2014

Powered by FUDForum. Page generated in 0.01570 seconds