| Summary: | FXHoverTool throws exception if FXViewer is contained within a Scene containing other Nodes | ||
|---|---|---|---|
| Product: | [Tools] GEF | Reporter: | Colin Sharples <ctg> |
| Component: | GEF FX | Assignee: | gef-inbox <gef-inbox> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | matthias.wienand |
| Version: | 0.2.0 | ||
| Target Milestone: | 4.0.0 (Neon) M7 | ||
| Hardware: | PC | ||
| OS: | Windows 10 | ||
| Whiteboard: | |||
I switched to the latest integration build (201604090202), and have seen that DefaultTargetPolicyResolver has already been changed to return an empty list rather than throwing IAE. This bug can be closed. Okay, maybe not. FXTypeTool is not checking whether the target belongs to the viewer, so is getting a NPE at line 152:
targetNode = activeViewer.getRootPart().getVisual();
It should be checking that activeViewer is not null before going on.
I added a null check to FXTypeTool. The code is published on the master branch. Therefore, I resolve this ticket as fixed for 4.0.0 M7. |
Actual GEF4 version used is 1.0.0.201603221726 I created an e4 RCP application using JavaFX as the renderer, based on the e(fx)clipse target platform. The e(fx)clipse platform creates the primary Stage, and supplies each part with a container (usually BorderPane) that is part of a pre-existing Scene. When creating an FXViewer, therefore, it is going to be part of a scene graph that contains nodes that have nothing to do with the FXViewer. Here is the postConstruct of the part that creates the FXViewer: @PostConstruct public void postConstruct(BorderPane container) { Injector injector = Guice.createInjector(createGuiceModule()); FXDomain domain = injector.getInstance(FXDomain.class); FXViewer viewer = domain.getAdapter(FXViewer.class); container.setCenter(viewer.getCanvas()); viewer.getCanvas().sceneProperty().addListener((observable, oldValue, newValue) -> { domain.activate(); viewer.getAdapter(ContentModel.class).getContents().setAll(createContents()); }); } Note that the domain activate and contents creation have to be postponed until the Scene has actually been realized and set on the viewer. The issue is that FXHoverTool throws exceptions whenever the mouse moves through any of the nodes that are not part of the FXViewer, i.e. any of the nodes created by e4. The exception is in the event handler created in createHoverFilter(), where it calls the targetPolicyResolver.getTargetPolicies() method. The handler only checks that the event target is a Node, not whether the node actually belongs to an IViewer in the domain, but DefaultTargetPolicyResolver throws an exception if the Node does not belong to an IViewer. I don't really see the point of throwing an IllegalArgumentException in this case - could it not simply return an empty list instead?