I’ve been trying to set up a double click function that creates a popup that allows a user to view and update a node/group properties. I’ve created a Double Click listener and using the htmlinteraction example as a reference I can see how to access elements text/shape etc.
If I can access the main object components of an element with elem (via e.diagram.selection) - "SHAP’ or “TEXT”…
How can I access the properties of the element? In this case a property called prop1, below I try findObject but I/m guessing it’s a property as opposed to an object.
How do I write/update the property of the selected node/group?
Thanks,
Z
// Double Click
var info = document.getElementById("myInfo");
myDiagram.addDiagramListener("ObjectDoubleClicked", function (e) {
var sel = e.diagram.selection;
var str = "";
if (sel.count === 0) {
str = "Selecting nodes in the main Diagram will display information here.";
info.innerHTML = str;
return;
} else if (sel.count > 1) {
str = sel.count + " objects selected.";
info.innerHTML = str;
return;
}
var elem = sel.first();
var shape = elem.findObject("SHAPE");
var txtblock = elem.findObject("TEXT");
var propy1 = elem.findObject("prop1"); //doesn't read prop1 property of selected object
alert("display "+ txtblock.text + " "+ propy1); //null because is empty
From the use of findObject it appears that you are trying to capture the double click event just for a particular object. If that is the case it is a lot easier to implement the GraphObject.doubleClick event on that particular object (presumably within a template) than to implement the same functionality at the Diagram level for all double clicks.
The second argument to the event handler will be the GraphObject on which the event was declared. But you can get the GraphObject where the click actually happened via InputEvent.targetObject, on the first argument to the event handler.
Philosophically our design has tried to provide two different levels at which to control things, locally and globally. Locally means on the particular GraphObject; globally means on the Diagram or one of its helper objects such as its predefined Tools.
For the clicking events, yes, there’s no transaction implied, so if you want to make any changes to the diagram or model you very likely want to start and commit a transaction around your calls to Model.setDataProperty or whatever.
But for some other events, such as GraphObject.mouseDrop, something else, such as the DraggingTool, is responsible for the transaction.
The documentation should explain the expectations.