Search code examples
javajavafxeclipse-rcpe4eclipse-gef

E4 RCP + GEF5 application implementation


I want to build GEF5 based sentence visualiser, interface of which will have 2 parts:

  1. the input part - where you can put your sentence,
  2. the output part,which will be showing GEF5 graph

The easiest way of organising these parts is to use E4 RCP as they can have individual javafx..Panes

Here is the deal, E4 RCP uses parts as separated javafx..BorderPanes

public class DictionaryPart {
    @PostConstruct
    void initUI(BorderPane pane) {
        try {
            TextArea textbox = new TextArea();
            pane.setCenter(textbox);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

However,GEF5 examples include simple app realisation using javafx..Stage and IViewer interface.

public void start(final Stage primaryStage) throws Exception {
        // create graph
        graph = createGraph();

        // configure application
        Injector injector = Guice.createInjector(createModule());
        domain = injector.getInstance(IDomain.class);
        viewer = domain.getAdapter(
                AdapterKey.get(IViewer.class, IDomain.CONTENT_VIEWER_ROLE));
        primaryStage.setScene(createScene(viewer));

        primaryStage.setResizable(true);
        primaryStage.setWidth(getStageWidth());
        primaryStage.setHeight(getStageHeight());
        primaryStage.setTitle(title);
        primaryStage.show();

        // activate domain only after viewers have been hooked
        domain.activate();

        // set contents in the JavaFX application thread because it alters the
        // scene graph
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                viewer.getContents().setAll(Collections.singletonList(graph));
            }
        });
    }

    protected Scene createScene(IViewer viewer) {
        return new Scene(((IViewer) viewer).getCanvas());
    }

This code from my second class describing Part brings up Stage in front of my application, when i need just a Pane.

I just dont understand how do i implement GEF5 to E4 correctly? Is there any tutorials exept GEF documentation?

UPD: Found a Conversion of the GEF4 MVC Logo example to an e4 RCP application,But it is outdated.


Solution

  • Forced it to work like that:

    @PostConstruct
    void initUIPane(BorderPane pane){
        graph = createGraph();
        // configure application
        Injector injector = Guice.createInjector(createModule());
        domain = injector.getInstance(IDomain.class);
        viewer = domain.getAdapter(AdapterKey.get(IViewer.class, IDomain.CONTENT_VIEWER_ROLE));
        InfiniteCanvas canvas = (InfiniteCanvas)viewer.getCanvas();
        pane.setCenter(canvas);
        canvas.sceneProperty().addListener((observable, oldValue, newValue) -> {
          if (canvas.getScene() != null) {
            domain.activate();
            try {
                viewer.getContents().setAll(Collections.singletonList(graph));
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
    }