Zooming in Eclipse GEF to specific location
Hello I am new in Eclipse GEF and I am having problem with zooming.
Basically I would like to have this functionality: Whenever I close my Edito开发者_开发知识库r View I would like to have Editor zoomed with previous scale and most importantly to the same location.
I was trying to achieve such functionality via Viewport, but I got stuck.
Finally I have found solution via setViewLocation(Position p)
method.
The tricky part lies elsewhere - before executing such method viewport must be in valid state,
so best approach is to execute performUpdate()
on viewport's UpdateManager. Another tricky situation might occur if you are setting such position in GEF Editor because there setting location must be executed in initializeGraphicalViewer()
method NOT in configureGraphicalViewer()
method.
So in the end code should look like this:
@Override
protected void initializeGraphicalViewer() {
super.initializeGraphicalViewer();
final GraphicalViewer viewer = getGraphicalViewer();
viewer.setContents(getModel());
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getRootEditPart();
Viewport viewport = (Viewport) rootEditPart.getFigure();
viewport.getUpdateManager().performUpdate();
viewport.setViewLocation(getModel().getZoomPosition());
}
精彩评论