I am trying to zoom within my GEF application using Eclipse 4. I have already managed to get the zoom functionality working within an Eclipse 3 environment by using a ZoomManager and Actions:
ZoomManager manager = rootEditPart.getZoomManager();
getActionRegistry().registerAction(new ZoomInAction(manager));
getActionRegistry().registerAction(new ZoomOutAction(manager));
Now I try to migrate my project to an Eclipse 4 environment. As far as I know Actions were replaced by Commands in Eclipse 4. I have already added a "ZoomIn command" and a "ZoomIn handler" in my application. And I also found an example where a ScalableFreeformLayeredPane is used.
private static ScalableFreeformLayeredPane root;
@Inject
@Optional
private void subscribeTopicViewZoomIn(@UIEventTopic(Events.TOPIC_VIEW_ZOOMIN) Map<String, String> event) {
double curScale = root.getScale();
if (curScale <= 2.9)
root.setScale(curScale + 0.1);
}
My Problem is, that I have no Idea how to get this ScalableFreeformLayeredPane connected with my ScrollingGraphicalViewer which I am using to display my model:
private static ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
private static Model model = new Model();
@PostConstruct
public void postConstruct(Composite parent) {
viewer.createControl(parent);
viewer.setEditPartFactory(editPartFactory);
viewer.setEditDomain(new DefaultEditDomain(this));
CreateModel();
viewer.setContents(model);
}
Can someone help me please or provide an example? Or is there maybe another way without using a ScalableFreeformLayeredPane?
Thanks! Thomas
I finally found a solution that works for me:
private ZoomManager manager;
@Override
protected void initializeGraphicalViewer() {
double[] zoomLevels;
ArrayList<String> zoomContributions;
ScalableRootEditPart rootEditPart = (ScalableRootEditPart) viewer.getRootEditPart();
manager = rootEditPart.getZoomManager();
zoomLevels = new double[] {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0};
manager.setZoomLevels(zoomLevels);
zoomContributions = new ArrayList<String>();
manager.setZoomLevelContributions(zoomContributions);
}
With this configuration I can use commands and events to access the ZoomManager:
@Inject
@Optional
private void subscribeTopicViewZoomIn(@UIEventTopic(Events.TOPIC_VIEW_ZOOMIN) Map<String, String> event) {
manager.setZoom(manager.getNextZoomLevel());
updateZoomCombo();
}