Hi,
In case of ShapeNode, during undo operation, I'm able to get the diagram element in the 'item' field of ChangeItemCommand. May I know whether there is any way to find which value (text or border color or etc) has changed?
private getUndoRedoItem(index: number): Array<any> {
var undo: Array<any> = [];
if (this.diagram) {
var undoManager = (this.diagram as any).undoManager;
if (undoManager.undoHistory) {
var nextUndoCommmand = undoManager.undoHistory[undoManager.undoIndex + index];
if (nextUndoCommmand) {
if (nextUndoCommmand instanceof CompositeCommand) {
nextUndoCommmand.getCommands().forEach(f => {
if (f instanceof AddItemCommand) {
var cmd = f as AddItemCommand;
undo.push(cmd.item.getTag());
}
});
}
else if (nextUndoCommmand instanceof AddItemCommand) {
var cmd = nextUndoCommmand as AddItemCommand;
undo.push(cmd.item.getTag());
}
else if (nextUndoCommmand instanceof ChangeItemCommand) {
var cmd = nextUndoCommmand as ChangeItemCommand;
undo.push(cmd.item.getTag());
}
else {
var cmd2 = nextUndoCommmand;
var c = cmd2;
}
}
}
}
return undo;
}
Regards,
Kannan
Kannan Thirumal wrote on Aug 28
th, 2019 at 9:26am:
Hi,
It works fine with ShapeNode like this,
private setNodeBorderColor() {
var selection = this.diagram.getSelection();
if (selection && selection.items && selection.items.length > 0) {
if (selection.items[0] instanceof this.DiagramNode) {
var node = selection.items[0] as CompositeNode;
var change = new ChangeItemCommand(this.diagram, node);
this.setCompositeNodeBorderColor(node);
this.diagram.executeCommand(change);
}
else if (selection.items[0] instanceof ShapeNode) {
var shapeNode = selection.items[0] as ShapeNode;
var change = new ChangeItemCommand(this.diagram, shapeNode);
this.setShapeNodeBorderColor(shapeNode);
this.diagram.executeCommand(change);
}
}
}
private setShapeNodeBorderColor(node: ShapeNode) {
var borderColor = "Yellow";
var diagramElement = node.getTag().Data as DiagramElement;
diagramElement.borderColor = borderColor;
node.setStroke(borderColor);
node.setStrokeThickness(5);
}
private setCompositeNodeBorderColor(node: CompositeNode) {
var borderColor = "Orange";
var diagramElement = node.getTag().Data as DiagramElement;
diagramElement.borderColor = borderColor;
var background = node.getComponent("Background") as any;
background.pen = borderColor;
background.strokeThickness = this.strokeThickness;
background.margin.right = -node.bounds.width + 18;
background.margin.bottom = -node.bounds.height + 12;
node.invalidate();
}
May I know what is the issue with composite node?
Regards,
Kannan