tesis-dynaware / graph-editor

Eclipse Public License 1.0
132 stars 42 forks source link

Node properties for custom display #15

Closed DaRich closed 9 years ago

DaRich commented 9 years ago

For customizing nodes with skins it would be great if there was the possibility to add custom properties to a Node. With a map provided one could simply render custom JavaFX nodes which need additional parameters.

rmfisher commented 9 years ago

Just to clarify - you would like the GNode class to have properties? Or the skin class?

DaRich commented 9 years ago

The GNode class so that one can use the properties in the skin class for custom rendering.

eckig commented 9 years ago

There is no need for that. You should probably create a domain model and connect it to the graph model, as described here: https://github.com/tesis-dynaware/graph-editor/wiki/4.%20Connecting%20to%20Domain%20Models

This API works a bit different than the usual JavaFX components, but it works quite nicely ;-)

rmfisher commented 9 years ago

Yes, so the idea is that there is some other domain model 'behind' your graph, and that this model could store such information.

I'm not totally opposed to adding a properties map, if a good case can be made for it. But please read the page linked above first and see if it meets your needs.

DaRich commented 9 years ago

You are right. If I had access to the domain model the Issue could be closed. But how can I access my class from the EMF domain model in GNodeSkin?

rmfisher commented 9 years ago

This is not something we have worked through ourselves yet, so it is quite likely that the current API has room for improvement (issue #6 for example).

But perhaps you could do something like this?

Commands.addNode(model, node);
MyCustomSkinClass skin = (MyCustomSkinClass) graphEditor.getSkinLookup().lookupNode(node);
skin.setDomainReference(domainObject);

After you create a new node, you get the skin instance and set your domain model reference in it.

The domain object should be added to its model within the same compound command that adds the graph node to the graph model, as described in the wiki page.

DaRich commented 9 years ago

Thank you for your answer! Does not matter if the current API is smooth or not. With this approach I can get my properties, so I will close the issue.

Thank you for sharing your great work!

DaRich commented 9 years ago

I post an abstract of my solution if you are interested. It uses the CommandStack for searching the corresponding domain object by using the GNode of GNodeSkin as a key. This is not very nice, because the command list in BasicCommandStack is protected, but it could by solved by inheritance.