0

I am writing a simulation software for my Masters and it consists on a "Graph container" where you can link nodes to generate equations according to what I link. These equations will, then, enable me to simulate my model. I am using Java 8 and JavaFX for that, with Scene Builder and FXML.

Searching on the web, I found the Graph-Editor (https://github.com/tesis-dynaware/graph-editor), which will help me a lot with what I need. Following the Tutorial on the project's site, I could reproduce it and it is running. But on my software I do not need to create a new window as the tutorial does to use the graphs - instead, I want to have a TabPane that enables me to create as many models as I need, like a text editor, and if I want I can save it on XML, etc...

My problem is: I tried to put the graphs from the tutorial inside the Tab they do on the tutorial (with the getView method) and it is not working. I tried it in two different ways, which result in an empty Tab, with no nodes and no error on the console.

First try

I tried putting into a Pane and set the GraphEditor inside the Pane.

My java code:

private GraphEditor graphEditor = new DefaultGraphEditor();
@FXML
private Pane graphEditorPane;

@FXML
public void initialize(){

    graphEditorPane = new Pane(graphEditor.getView());

    GModel model = GraphFactory.eINSTANCE.createGModel();
    graphEditor.setModel(model);
    addNodes(model);

}

My FXML code:

<TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
  <tabs>
    <Tab text="Modelo 1">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0">
          <children>
            <Pane fx:id="graphEditorPane" prefHeight="571.0" prefWidth="1000.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
          </children>
        </AnchorPane>
      </content>
    </Tab>
  </tabs>
</TabPane>

Second way

I have seen their demo source code and what I understood was that they created an instance of their GraphEditorContainer object and then their FXML file has that GraphEditorContainer, but mine doesn't work that way. Maybe I got what they did wrong (I am a beginner in Java and JavaFX).

My java code:

private GraphEditor graphEditor = new DefaultGraphEditor();
@FXML
private GraphEditorContainer graphEditorContainer;

@FXML
public void initialize(){

    graphEditorContainer = new GraphEditorContainer();

    GModel model = GraphFactory.eINSTANCE.createGModel();
    graphEditor.setModel(model);
    graphEditorContainer.setGraphEditor(graphEditor);

    addNodes(model);

}

My FXML code:

<?import de.tesis.dynaware.grapheditor.GraphEditorContainer?>

<TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
  <tabs>
    <Tab text="Modelo 1">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0"> 
          <children>
            <GraphEditorContainer fx:id="graphEditorContainer" minWidth="0" minHeight="0" maxWidth="+Infinity" maxHeight="+Infinity"/>
          </children>
        </AnchorPane>
      </content>
    </Tab>
  </tabs>
</TabPane>

I could put the code that opens the window and draws the nodes in the handleNew function (code below), but not in the Tab.

Stage secondaryStage = new Stage();
GraphEditor graphEditor = new DefaultGraphEditor();
Scene scene = new Scene(graphEditor.getView(), 800, 600);
secondaryStage.setScene(scene);
secondaryStage.show();

GModel model = GraphFactory.eINSTANCE.createGModel();
graphEditor.setModel(model);
addNodes(model);

If it's possible could you help me?

Thank You

  • There is too much information in this question, and apparently you have two problems rather than a single one. Wouldn't that be clearer to take the problems one after the other ? Also, did you start by making their demo work on your environment ? – Dici Aug 06 '16 at 23:53
  • Hello, Dici. I actually have one problem that I need to solve, which is to put the nodes inside a tab. These are just two ways I tried to solve the same problem. I am still a beginner, so I am not sure what information is useful and what is not, so I chose to put all that I knew in the post :) Good idea, I will try to make the demo work here in Eclipse. – Marina Oncken Aug 10 '16 at 11:15

1 Answers1

0

Error on console:

javafx.fxml.LoadException: GraphEditorContainer is not a valid type.

simply means that you didn't put the import for GraphEditorContainer in the FXML file. Something like

<? import com.somecompany.somepackage.GraphEditorContainer ?>

near the top of the FXML file (with the other imports), obviously edited for the correct package name.

In the controller, it is always a mistake to initialize @FXML-annotated fields, for obvious reasons, so replace

@FXML
private GraphEditorContainer graphEditorContainer = new    GraphEditorContainer();

with

@FXML
private GraphEditorContainer graphEditorContainer ;

Using custom (or 3rd party) controls in SceneBuilder is covered in Adding a custom component to SceneBuilder 2.0

Community
  • 1
  • 1
James_D
  • 201,275
  • 16
  • 291
  • 322
  • Thank you very much! I added the import into FXML (I edited my post to show it), but then the FXML is loaded with an empty `Tab`, without the nodes that I want. As @Dici mentioned, I think adding the custom component into SceneBuilder is different problem from my main problem (inserting nodes in the tab), what do you think? Thank you for the page about this, I will surely use it! – Marina Oncken Aug 10 '16 at 13:09