-
Particularly, when working with EMF models, what is considered a suitable method to generate the ElementID? For example, in: GNode node = new GNodeBuilder().id(???).build(); Until now, I have used the URIFragment, which is, by design of EMF, unique for each element in the resource. String id = eObj.eResource().getURIFragment(eObj); So far so good... or not? This ID seems the obvious and most straightforward way of mapping EMF EObjects to diagram elements, and it works seamlessly in both directions: EMF to GModel when generating the diagram and GModel to EMF when performing actions on the diagram like edit, select, etc. However, it turns out that this ID is not liked by everyone out there. I have tried to add some playwright tests, and it turns out that.. DOMException: Failed to execute 'querySelectorAll' on 'Document': 'xxxx/xxx/xx' is not a valid selector This error means that such ID cannot be used to look for elements in the DOM. It's not a GLSP's or playwright's error, but pure browser error, as explained in this stackoverflow answer.
Whereas for HTML 5 and newer, the rules are much more permissive:
Whether or not the browser (playwright chromium, in this case) should accept such ID with slashes is maybe out of scope here. However, to overcome this situation I see 2 alternatives:
Therefore, I come back to my original question. Is the URIFragment "as is" a best-practice for model element IDs, or is there another alternative? In case URIFragment is the preferred way, how to overcome the issue with playwright? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @dmm9, Thank you for reaching out! Overall, I'd like to mention the concept of the For example, if you use
Alternatively, if you're working with a node-based GLSP server, Given your testing requirements, I would recommend using UUIDs as element IDs. This method should align well with your testing framework and offer the compatibility you need. If you have any further questions or need more clarification, feel free to get in touch. We're always happy to assist! HTH and best regards, |
Beta Was this translation helpful? Give feedback.
Hi @dmm9,
Thank you for reaching out!
Overall, I'd like to mention the concept of the
*IdGenerator
, particularly in the context of the Java implementation of the GLSP server.It seems you're likely using this based on the code snippet you shared.
The
*IdGenerator
is essential for generating IDs forGModelElements
and therefor for managing the model elements, for example in theGModelIndex
.For example, if you use
EMFDiagramModule
as a base implementation, it is necessary to bind an availableEMFIdGenerator
.There are different implementations available already, just to name two here:
FragmentIdGenerator
- creates the same IDs as you mentioned above, i.e. EMF URI fragments as element IDsU…