Add custom node to Alloyui DiagramBuilder in JAVA

2019-08-05 20:10发布

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?

标签: java alloy-ui
2条回答
SAY GOODBYE
2楼-- · 2019-08-05 20:52

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

查看更多
做自己的国王
3楼-- · 2019-08-05 21:10

Seems like this add-on doesn't accept custom nodes, so I am working with Javascript.

查看更多
登录 后发表回答