问题
I have been using this example to make a diagram with Alloyui, but I don't find the way to make a custom node in JAVA.
I've tried to simply add it in AvaliableFields, but doesn't seem to work:
diagramBuilder.setAvailableFields(
new NodeType(
"diagram-node-custom-icon",
"Custom",
"custom"
));
I have already done this in another example, directly in the javascript and works:
Y.DiagramNodeCustom = Y.Component.create({
NAME: 'diagram-node',
ATTRS: {
type: {
value: 'custom'
},
myAtt: {
validator: Y.Lang.isString,
value: ''
},
myAtt2: {
validator: Y.Lang.isString,
value: ''
}
},
EXTENDS: Y.DiagramNodeTask,
prototype: {
getPropertyModel: function () {
var instance = this;
var model = Y.DiagramNodeTask.superclass.getPropertyModel.apply(instance, arguments);
model.push({
attributeName: 'myAtt',
name: '123'
});
model.push({
attributeName: 'myAtt2',
name: '456'
});
return model;
}
}
});
But I'm trying only to touch the java part. Any ideas?
回答1:
Seems like this add-on doesn't accept custom nodes, so I am working with Javascript.
回答2:
Here's an example, I hope it helps you:
var Y = YUI().use(
'aui-diagram-builder',
function (Y) {
Y.DiagramNodeCustom = Y.Component.create({
NAME: 'diagram-node',
ATTRS: {
type: {
value: 'custom'
},
customAttr: {
validator: Y.Lang.isString,
value: 'A Custom default'
}
},
EXTENDS: Y.DiagramNodeTask,
prototype: {
getPropertyModel: function () {
var instance = this;
var model = Y.DiagramNodeTask.superclass.getPropertyModel.apply(instance, arguments);
model.push({
attributeName: 'customAttr',
name: 'Custom Attribute'
});
return model;
}
}
});
Y.DiagramBuilder.types['custom'] = Y.DiagramNodeCustom;
var availableFields = [{
iconClass: 'diagram-node-start-icon',
label: 'Start',
type: 'start'
}, {
iconClass: 'diagram-node-task-icon',
label: 'Task',
type: 'task'
}, {
iconClass: 'diagram-node-custom-icon',
label: 'Custom',
type: 'custom'
}, {
iconClass: 'diagram-node-end-icon',
label: 'End',
type: 'end'
}];
diagram = new Y.DiagramBuilder({
availableFields: availableFields,
boundingBox: '#myDiagramContainer',
srcNode: '#myDiagramBuilder'
}).render();
});
.diagram-node-custom .diagram-node-content {
background: url(http://a.deviantart.net/avatars/m/e/mercedes77.gif?5) no-repeat scroll center transparent;
}
.diagram-node-custom-icon {
background: url(http://dribbble.s3.amazonaws.com/users/1266/screenshots/213334/emoticon-0188-nyancat.gif) no-repeat scroll center transparent;
}
<div id="myDiagramContainer">
<div id="myDiagramBuilder" width=100></div>
</div>
<button id="myButton"></button>
See also https://github.com/mstahv/diagram-builder
来源:https://stackoverflow.com/questions/33362280/add-custom-node-to-alloyui-diagrambuilder-in-java