tesis-dynaware / graph-editor

Eclipse Public License 1.0
132 stars 42 forks source link

How can I add one Node to another #41

Open marcusMintchip opened 2 years ago

marcusMintchip commented 2 years ago

Trying to achieve a UI that faces adding one Node to another Node,there's addNode(GModel,GNode) function ,so I've tried using node.getSubGraph() to get GModel and and another GNode but it couldn't work, Can anyone help me about this UI construction?

Here's the code I tried in Demo code createContent.md

marcusMintchip commented 2 years ago

` private void createContent() {

    header.getStyleClass().setAll(STYLE_CLASS_HEADER);
    header.setAlignment(Pos.CENTER);

    title.getStyleClass().setAll(STYLE_CLASS_TITLE);

    final Region filler = new Region();
    HBox.setHgrow(filler, Priority.ALWAYS);

    filler.setOnMouseClicked(mouseEvent -> {
        System.out.println("region clicked");
        GModel model = GraphFactory.eINSTANCE.createGModel();
        getNode().setSubgraph(model);
        GNode node = GraphFactory.eINSTANCE.createGNode();
        Commands.addNode(getNode().getSubgraph(), node);

// HBox subHeader = new HBox(); // subHeader.getStyleClass().setAll(STYLE_CLASS_HEADER); // subHeader.setAlignment(Pos.CENTER); // Label subTitle = new Label(); // subTitle.getStyleClass().setAll(STYLE_CLASS_TITLE); // subTitle.setText("subTitle"+getNode().getId()); // Region subFiller = new Region(); // HBox.setHgrow(filler,Priority.ALWAYS); // Button close = new Button(); // close.getStyleClass().setAll(STYLE_CLASS_BUTTON); // subHeader.getChildren().addAll(subTitle,subFiller,close); // contentRoot.getChildren().addAll(subHeader); });

    final Button closeButton = new Button();
    closeButton.getStyleClass().setAll(STYLE_CLASS_BUTTON);

    header.getChildren().addAll(title, filler, closeButton);
    contentRoot.getChildren().add(header);
    getRoot().getChildren().add(contentRoot);

    closeButton.setGraphic(AwesomeIcon.TIMES.node());
    closeButton.setCursor(Cursor.DEFAULT);
    closeButton.setOnAction(event -> Commands.removeNode(getGraphEditor().getModel(), getNode()));

    contentRoot.minWidthProperty().bind(getRoot().widthProperty());
    contentRoot.prefWidthProperty().bind(getRoot().widthProperty());
    contentRoot.maxWidthProperty().bind(getRoot().widthProperty());
    contentRoot.minHeightProperty().bind(getRoot().heightProperty());
    contentRoot.prefHeightProperty().bind(getRoot().heightProperty());
    contentRoot.maxHeightProperty().bind(getRoot().heightProperty());

    contentRoot.setLayoutX(BORDER_WIDTH);
    contentRoot.setLayoutY(BORDER_WIDTH);

    contentRoot.getStyleClass().setAll(STYLE_CLASS_BACKGROUND);
}`