Toolbox
If you want to add your tool items in Toolbox, you need to define a toolbox JSON in your extension. The toolbox JSON files should be placed in toolbox/ folder in your extension.
my-extension/└─ toolbox/ └─ toolbox.jsonTool Group
Section titled “Tool Group”The toolbox JSON defines an array of Tool Group definitions as below:
[ { "label": "Tool Group 1", "id": "tool-group-1", "diagram-types": [ "UMLClassDiagram" ], "items": [ { "label": "Tool Item 1", "id": "tool-item-1", "icon": "icon-UMLClass", "rubberband": "rect", "command": "my:add-element", "command-arg": { "id": "UMLClass", "stereotype": "my-stereotype" } }, ... ] }, ...]label: The tool group title shown in the Toolbox.id: Unique identifier.diagram-types: A list of diagram types. The tool group will be shown only when one of the diagram-types is active. (e.g."UMLClassDiagram","UMLUseCaseDiagram", …)items: A list of tool item definitions.
Tool Item
Section titled “Tool Item”A tool item represents an element that users can create on a diagram.
label: The tool item title shown in the Toolboxid: Unique identifier of the tool item.icon: Icon name. You can specify already defined icon names (e.g."icon-UMLClass","icon-UMLPackage", …).rubberband: A type of rubberband. One of"rect"(for sizable node-type elements),"line"(for edge-type elements),"point"(for fixed-size node-type elements).command: A command name to be executed.command-arg: An argument object will be passed to the command.
Since StarUML 8 does not support defining new element classes (elements.js), a tool item can create only the elements of existing classes (e.g. UMLClass with a stereotype).
Command
Section titled “Command”A command used for tool item should create an element on a diagram. We strongly recommend to use app.factory.createModelAndView() function to create an element. See the section for more detail.
Toolbox will pass options object to the command. The passed options parameter contains:
parent: The parent element where the created model element to be contained.diagram: The active diagram.x1,y1,x2,y2: The user dragged area on the diagram.tailView,headView,tailModel,headModel: The connected elements (for edge-type elements).containerView: The view element where the created view element to be contained.- … :
command-argare combined.
You can pass the options to app.factory.createModelAndView() as it is. The fields in model-init and view-init of the options are assigned to the created model element and view element respectively.
function handleAddElement (options) { options = Object.assign(options, { 'model-init': { 'stereotype': options.stereotype }, 'view-init': { 'stereotypeDisplay': 'icon', 'suppressAttributes': true, 'suppressOperations': true } }) return app.factory.createModelAndView(options)}
app.commands.register('my:add-element', handleAddElement)