Scripting API
StarUML 8 runs extensions (main.js) and the codes in Script Console in an embedded JavaScript engine (QuickJS). This chapter describes the APIs available in scripts and the limitations compared to StarUML 7 or earlier.
You can also browse the APIs in Script Console (View > Script Console): type app. and the available properties are shown with auto-completion.
In the signatures below, [x] means that the argument x is optional. An element is a model element or a view element in the repository (an instance of type.Element).
Globals
Section titled “Globals”app: The application context described below.type(orapp.type) : The element classes and other classes (see Element classes (type)).console:log,debug,info,warnanderror. The arguments are joined by a space and printed in Script Console. Objects and elements are formatted in a readable form (e.g.UMLClass {_id: "AAAA...", name: "Class1"}).- In
main.js:exports,module,__filename(the absolute path ofmain.js) and__dirname(the absolute path of the extension folder).
All scripts (extensions and Script Console) share one global context. Use local variables in main.js instead of global variables to avoid conflicts with other extensions. A script running more than 30 seconds is interrupted.
Elements
Section titled “Elements”Elements can be read like ordinary JavaScript objects.
var cls = app.repository.select("@UMLClass")[0]console.log(cls.name, cls._id, cls._parent.name)cls.attributes.forEach(a => console.log(a.name, a.visibility))console.log(cls instanceof type.UMLClassifier) // true_id: The unique ID of the element (read-only)._type: The class name of the element (e.g."UMLClass", read-only)._parent: The parent element (the owner) of the element.- The other fields are the attributes of the metamodel (e.g.
name,ownedElements,attributes,model,left,fillColor). See the Metamodel documentation, or executeapp.metamodels.getMetaAttributes("UMLClass"). - The same element is always the same object (
a === b).
Methods of elements
Section titled “Methods of elements”All elements (type.Element) have the following methods.
| Method | Description |
|---|---|
getClass() |
Returns the class of the element (e.g. type.UMLClass). |
getClassName() |
Returns the class name of the element (e.g. "UMLClass"). |
getDisplayClassName() |
Returns the class name for display (e.g. "Class"). |
getMetaClass(), getMetaAttributes() |
Same as app.metamodels.getMetaClass(elem._type) and getMetaAttributes(elem._type). |
getNodeText() |
Returns the text shown in Model Explorer. |
getNodeIcon() |
Returns the icon shown in Model Explorer. |
getViewType() |
Returns the class name of the view for the model element (e.g. "UMLClassView" for a UMLClass). |
getPath() |
Returns the array of the elements from the project to the element. |
getPathname() |
Returns the path name of the element (e.g. "Model::Package1::Class1"). |
getParentField() |
Returns the name of the field of the parent containing the element (e.g. "ownedElements"). |
getOrdering(index) |
Returns the ordering number of the element in Model Explorer. |
getChildren() |
Returns the array of the child elements (the elements in the fields of kind obj and objs). |
getChildNodes([sort]) |
Returns the array of the child elements shown in Model Explorer. |
findByName(name) |
Returns the child element having the name, or null. |
lookup(name, [typeFilter], [namespace]) |
Finds an element by name in the namespace hierarchy of the element (from the element up to the project). typeFilter is a class (e.g. type.UMLClass) or a class name. |
lookdown(pathName) |
Finds a descendant element by the array of names (e.g. ["Package1", "Class1"]). |
traverse(fn) |
Calls fn(elem) for the element and all its descendants (pre-order). |
traverseDepthFirst(fn) |
Calls fn(elem) for the element and all its descendants (post-order). |
traverseUp(fn) |
Calls fn(elem) for the element and its ancestors. |
traverseField(field, fn), traverseFieldDepthFirst(field, fn) |
Calls fn(elem) recursively for the elements in the field (pre-order or post-order). |
canContain(elem), canContainKind(kind) |
Returns whether the element can contain the element or the elements of the class. |
isOneOfTheContainers(elem) |
Returns whether elem is the element or one of its ancestors. |
canCopy(), canDelete(), canHide() |
Returns whether the element can be copied, deleted or hidden. |
toString() |
Returns a string like "[UMLClass Class1]". |
The following methods are available for the elements of some classes.
| Class | Method | Description |
|---|---|---|
Model |
canContainDiagramKind(kind), canContainDiagram(diagram) |
Returns whether the model can contain the diagram. |
Model |
canRelocateTo(model) |
Returns whether the model can be moved to another model. |
ExtensibleModel |
hasTag(name), getTag(name), getTagValue(name) |
Checks a tag, returns the tag element or the value of the tag by name. |
View |
getDiagram() |
Returns the diagram containing the view. |
View |
getBoundingBox() |
Returns the bounding box {x1, y1, x2, y2} of the view. |
NodeView |
getRight(), getBottom() |
Returns the right (left + width) and the bottom (top + height) of the node. |
Diagram |
getViewOf(model, [viewType]) |
Returns the view of the model element in the diagram, or null. |
The position and the size of a node view can be read by the fields left, top, width and height. The points of an edge view (points) are a {points: [{x, y}, ...]} object.
Element classes (type)
Section titled “Element classes (type)”type.<ClassName> is the class of the elements (e.g. type.UMLClass, type.UMLAttribute, type.UMLClassView, type.Diagram). The classes are used for:
- Checking the class of an element:
elem instanceof type.UMLClassifier - Creating a new element (not yet added to the model):
new type.UMLOperation(). Add it to the model withapp.engine.addModelorOperationBuilder. - Passing as a type filter (e.g.
app.repository.getInstancesOf(type.UMLClass),app.elementPickerDialog.showDialog("Select", null, type.UMLClass)).
The classes have the following constants and static functions.
| Class | Constants and static functions |
|---|---|
type.Element |
getNewName(array, prefix) (a new name like prefix1, prefix2, … not used in array), getSuperType(cls), getCommonType(elems), mergeProps(elems, prop) (the value if all elements have the same value, otherwise null), AK_PRIM, AK_ENUM, AK_REF, AK_REFS, AK_OBJ, AK_OBJS, AK_VAR, AK_CUSTOM |
type.Tag |
TK_STRING, TK_REFERENCE, TK_BOOLEAN, TK_NUMBER, TK_ENUM |
type.View |
SK_NO, SK_YES, SK_PROPAGATE |
type.NodeView |
SZ_NONE, SZ_HORZ, SZ_VERT, SZ_RATIO, SZ_FREE (sizable), MM_NONE, MM_HORZ, MM_VERT, MM_FREE (movable) |
type.EdgeView |
LS_RECTILINEAR, LS_OBLIQUE, LS_ROUNDRECT, LS_CURVE, LS_DIRECT (line style), LM_SOLID, LM_DOT, LM_DASH (line mode), ES_FLAT, ES_STICK_ARROW, ES_SOLID_ARROW, ES_TRIANGLE, … (end style) |
type.LabelView |
DK_HORZ, DK_VERT |
type.EdgeParasiticView |
EP_HEAD, EP_MIDDLE, EP_TAIL |
type.Diagram |
LD_TB, LD_BT, LD_LR, LD_RL (layout direction) |
type.UMLModelElement |
VK_PUBLIC, VK_PROTECTED, VK_PRIVATE, VK_PACKAGE (visibility) |
type.UMLParameter |
DK_IN, DK_INOUT, DK_OUT, DK_RETURN (direction) |
type.UMLAttribute |
AK_NONE, AK_SHARED, AK_COMPOSITE (aggregation) |
type.UMLRelationshipEnd |
NK_UNSPECIFIED, NK_NAVIGABLE, NK_NOTNAVIGABLE (navigable) |
type.UMLGeneralNodeView |
SD_NONE, SD_LABEL, SD_DECORATION, SD_DECORATION_LABEL, SD_ICON, SD_ICON_LABEL (stereotype display) |
type.UMLMessage |
MS_SYNCHCALL, MS_ASYNCHCALL, MS_ASYNCHSIGNAL, MS_CREATEMESSAGE, MS_DELETEMESSAGE, MS_REPLY |
| Others | type.UMLFeature (FD_*), type.UMLEvent (EK_*), type.UMLConnector (CK_*), type.UMLTransition (TK_*), type.UMLExpansionRegion (EK_*), type.UMLUndirectedRelationshipView (EO_*), type.UMLSequenceDiagram (SN_AUTO, SN_CUSTOM) |
type also provides the following classes which are not elements.
type.Point:new type.Point(x, y)with the fieldsx,yand the methodcopy().type.Points: A list of points with the methodsadd(p),insert(index, p),remove(index),setPoint(index, p),getPoint(index),count(),clear(),copy(),assign(points)and__write()(returns a string like"10:20;30:40").type.Font:new type.Font(face, size, style)with the constantsFS_NORMAL,FS_BOLD,FS_ITALIC,FS_BOLD_ITALIC.
app.repository
Section titled “app.repository”The repository holds all elements of the project.
Retrieving elements
| Function | Description |
|---|---|
get(id) |
Returns the element of the ID, or null. |
select(selector) |
Returns the array of the elements matched by the selector expression (e.g. "@UMLClass", "Package1::Class1.attributes"). See Retrieving elements by query. Throws an error for an invalid selector. |
getAll() |
Returns the array of all elements. |
find(predicate) |
Returns the first element for which predicate(elem) returns true, or undefined. |
findAll(predicate) |
Returns the array of the elements for which predicate(elem) returns true. |
getInstancesOf(types) |
Returns the array of the elements of the classes (including subclasses). types is a class, a class name, or an array of them (e.g. ["UMLClass", "UMLInterface"]). |
search(keyword, [typeFilter]) |
Returns the array of the elements whose name contains the keyword (case-insensitive). typeFilter is a class or a class name (default Element). |
lookupAndFind(namespace, name, [typeFilter]) |
Finds an element by name from the namespace (as namespace.lookup()), or in the whole repository if not found. |
isElement(obj) |
Returns whether the object is an element. |
References and views
| Function | Description |
|---|---|
getRefsTo(elem, [filter]) |
Returns the array of the elements referencing the element. filter(e) filters the result. |
getRelationshipsOf(model, [filter]) |
Returns the array of the relationships (e.g. associations, generalizations) connected to the model element. filter(rel) filters the result. |
getViewsOf(model) |
Returns the array of the views of the model element (in all diagrams). |
getEdgeViewsOf(view) |
Returns the array of the edge views connected to the node view. |
Serialization
| Function | Description |
|---|---|
writeObject(elem) |
Returns the JSON string of the element and its children (the same format as .mdj files). |
readObject(data) |
Creates an element and its children from the JSON (a string or an object) and returns it. The element has no parent. |
Operations and undo
| Function | Description |
|---|---|
getOperationBuilder() |
Returns the OperationBuilder to make an operation changing several elements as one undoable step. See Using operations. |
doOperation(operation) |
Executes the operation made by OperationBuilder (builder.getOperation()). |
isModified() |
Returns whether the project is modified after it is saved. |
canUndo(), canRedo() |
Returns whether undo or redo is available. |
undo(), redo() |
Undoes or redoes the last operation. |
OperationBuilder has the following functions. The operators are recorded and executed in order when doOperation is called, so fill the fields of new elements before calling doOperation.
| Function | Description |
|---|---|
begin(name, [bypass]) |
Starts a new operation. name is shown in Edit > Undo. If bypass is true, the operation is not recorded in the undo history. |
end() |
Finishes the operation. |
discard() |
Discards the operation. |
getOperation() |
Returns the operation to pass to app.repository.doOperation(). |
insert(elem) |
Inserts a new element (and its children) into the repository. Also add it to a field of the parent by fieldInsert. |
remove(elem) |
Removes an element from the repository. Also remove it from the field of the parent by fieldRemove. |
fieldAssign(elem, field, value) |
Assigns a value to a field. For a points field, pass a type.Points object or the string of Points.__write(). |
fieldInsert(elem, field, value) |
Appends an element to an array field. |
fieldInsertAt(elem, field, value, pos) |
Inserts an element at the position of an array field. |
fieldRemove(elem, field, value) |
Removes an element from an array field. |
fieldRemoveAt(elem, field, value, pos) |
Removes the element at the position of an array field. |
fieldReorder(elem, field, value, pos) |
Moves an element to the position in an array field. |
fieldRelocate(elem, field, oldParent, newParent) |
Moves an element from the field of oldParent to the field of newParent. |
var cls = app.selections.getSelected()var builder = app.repository.getOperationBuilder()builder.begin("rename attributes")cls.attributes.forEach(a => builder.fieldAssign(a, "name", a.name.toUpperCase()))builder.end()app.repository.doOperation(builder.getOperation())app.project
Section titled “app.project”| Function | Description |
|---|---|
getProject() |
Returns the top-level project element (type.Project). |
getFilename() |
Returns the absolute path of the project file, or null if the project is not saved yet. |
newProject() |
Closes the current project and creates a new empty project. Returns the new project. |
closeProject() |
Closes the current project without asking to save. |
loadFromJson(data) |
Replaces the current project with the project of the JSON (a string or an object). Returns the loaded project. |
importFromJson(parent, data) |
Adds the element of the JSON (a string or an object, e.g. the result of writeObject) to the ownedElements of the parent. Returns the imported element. It is not recorded in the undo history, and the IDs in the JSON must not exist in the project. |
var project = app.project.getProject()console.log(project.name, app.project.getFilename())app.engine
Section titled “app.engine”The functions of app.engine change the model as undoable operations. Each call is one step in the undo history.
Properties
| Function | Description |
|---|---|
setProperty(elem, field, value) |
Sets the value of a field of the element. A field of an element reference accepts an element or null. |
setProperties(elem, values) |
Sets the values of several fields at once (e.g. { name: "Foo", isAbstract: true }). |
setElemsProperty(elems, field, value) |
Sets the value of a field of all the elements. |
Models
| Function | Description |
|---|---|
addModel(parent, field, model) |
Adds a new element (e.g. made by new type.UMLClass()) to the field of the parent. Returns the added element. |
addModelAndView(diagram, model, view, parent, [field], [containerView]) |
Adds a new model element to the parent and a new view of it to the diagram at once. Returns the added view. |
addViews(diagram, views) |
Adds new views to the diagram. |
addItem(elem, field, value) |
Adds an element to an array field of the element (e.g. a reference in UMLConstraint.constrainedElements). |
removeItem(elem, field, value) |
Removes an element from an array field of the element. |
deleteElements(models, views) |
Deletes the model elements (with their views) and the views. |
relocate(elem, newParent, field) |
Moves the element to the field of another parent. |
moveUp(parent, field, elem), moveDown(parent, field, elem) |
Moves the element up or down in the array field of the parent. |
Views
The functions below take an optional diagram editor as the first argument as in StarUML 7 or earlier: pass app.diagrams.getEditor() or omit it. They are applied to the views of the current diagram.
| Function | Description |
|---|---|
moveViews([editor], views, dx, dy) |
Moves the views by (dx, dy). |
moveViewsChangingContainer([editor], views, dx, dy, containerView, containerModel) |
Moves the views into another container view (e.g. a package view). |
moveParasiticView([editor], view, alpha, distance) |
Moves a label of an edge (e.g. the name label) to the angle and the distance from the edge. |
resizeNode([editor], node, left, top, right, bottom) |
Moves and resizes the node view. |
modifyEdge([editor], edge, points) |
Changes the points of the edge view (a type.Points object). |
reconnectEdge([editor], edge, points, newParticipant, newParticipantModel, isTailSide) |
Connects the tail (isTailSide is true) or the head of the edge to another view. |
setFillColor([editor], views, color) |
Sets the fill color (e.g. "#ffff00"). |
setLineColor([editor], views, color) |
Sets the line color. |
setFontColor([editor], views, color) |
Sets the font color. |
setFont([editor], views, face, size, color) |
Sets the font face, size and color. |
setFontFace([editor], views, face) |
Sets the font face (e.g. "Arial"). |
setFontSize([editor], views, size) |
Sets the font size. |
setLineStyle([editor], views, lineStyle) |
Sets the line style of edges (type.EdgeView.LS_RECTILINEAR, LS_OBLIQUE, LS_ROUNDRECT, LS_CURVE, LS_DIRECT). |
setStereotypeDisplay([editor], views, display) |
Sets how stereotypes are shown (type.UMLGeneralNodeView.SD_*, e.g. "icon"). |
setAutoResize([editor], views, autoResize) |
Sets whether the views are resized automatically. |
layoutDiagram([editor], diagram, [direction], [separations], [edgeLineStyle]) |
Lays out the diagram automatically. direction is type.Diagram.LD_TB (default), LD_BT, LD_LR or LD_RL. separations is {node, edge, rank}. edgeLineStyle is a line style of edges. |
var views = app.selections.getSelectedViews()app.engine.setFillColor(views, "#e0f0ff")app.engine.setFont(views, "Helvetica", 14, "#003366")
var diagram = app.diagrams.getCurrentDiagram()app.engine.layoutDiagram(diagram, type.Diagram.LD_LR, { node: 30, edge: 10, rank: 60 }, type.EdgeView.LS_RECTILINEAR)app.factory
Section titled “app.factory”The functions of app.factory create elements in the same way as the menus and the toolbox, and return the created element (or null if not created). See Creating elements for the details.
| Function | Description |
|---|---|
createModel(options) |
Creates a model element. |
createDiagram(options) |
Creates a diagram. |
createModelAndView(options) |
Creates a model element and its view in a diagram. Returns the view (the model is view.model). |
createViewOf(options) |
Creates a view of an existing model element in a diagram. Returns the view. |
createViewAndRelationships([editor], x, y, model, [containerView], [viewType]) |
Creates a view of the model element in the current diagram at (x, y) with the views of the relationships to the model elements already shown in the diagram (as dragging an element from Model Explorer). |
getModelIds() |
Returns the array of the IDs available in createModel (e.g. "UMLClass"). |
getDiagramIds() |
Returns the array of the IDs available in createDiagram (e.g. "UMLClassDiagram"). |
getModelAndViewIds() |
Returns the array of the IDs available in createModelAndView. |
The options object has the following fields.
| Field | Used in | Description |
|---|---|---|
id |
createModel, createDiagram, createModelAndView |
ID of the factory function (e.g. "UMLClass"). |
parent |
createModel, createDiagram, createModelAndView |
The parent element of the new element. |
field |
createModel, createModelAndView |
The field of the parent (default "ownedElements", e.g. "attributes"). |
diagram |
createModelAndView, createViewOf |
The diagram where the view is created. |
model |
createViewOf |
The model element of the view. |
x1, y1, x2, y2 |
createModelAndView |
The area of a new node view, or the start and end points of a new edge view. |
x, y |
createViewOf |
The position of the new view. |
tailView, headView, tailModel, headModel |
createModelAndView |
The views and the models connected by a new relationship. |
containerView |
createModelAndView, createViewOf |
The view containing the new view (e.g. a package view). |
modelInitializer |
createModel, createModelAndView |
A function (model) => {...} to initialize the new model element before it is added. |
viewInitializer |
createModelAndView, createViewOf |
A function (view) => {...} to initialize the new view. |
diagramInitializer |
createDiagram |
A function (diagram) => {...} to initialize the new diagram. |
model-init, view-init |
createModel, createModelAndView |
An object of the field values assigned to the new model element or view (e.g. { stereotype: "entity" }). |
var diagram = app.diagrams.getCurrentDiagram()var view = app.factory.createModelAndView({ id: "UMLClass", parent: diagram._parent, diagram: diagram, x1: 100, y1: 100, x2: 200, y2: 160, modelInitializer: m => { m.name = "Customer" }})console.log(view.model.name) // "Customer"app.commands
Section titled “app.commands”| Function | Description |
|---|---|
register(id, fn, [name]) |
Registers a command. fn is called when the command is executed. name is shown in the command palette. Use an ID like <extension-name>:<action>. |
execute(id, ...args) |
Executes the command (an extension’s command or a built-in command like "project:save"). The arguments are passed to the command function, and its return value is returned. |
get(id) |
Returns the function of a command registered by a script, or undefined. |
getIds() |
Returns the array of the IDs of all commands. |
commands |
An object of the command functions by ID. |
commandNames |
An object of the command names by ID. |
See Commands for the details.
app.selections
Section titled “app.selections”| Function | Description |
|---|---|
getSelected() |
Returns the first selected model element, or null. |
getSelectedModels() |
Returns the array of the selected model elements. |
getSelectedViews() |
Returns the array of the selected views in the current diagram. |
select(models, views) |
Selects the model elements and the views. |
selectModel(model) |
Selects a model element. |
selectViews(views) |
Selects the views (and their model elements). |
deselectAll() |
Deselects all elements. |
To select a view in the diagram editor, use app.diagrams.selectInDiagram(). See Working with Selections.
app.diagrams
Section titled “app.diagrams”Working diagrams
| Function | Description |
|---|---|
getCurrentDiagram() |
Returns the diagram shown in the diagram editor, or null. |
setCurrentDiagram(diagram) |
Shows the diagram in the diagram editor (opening it if not opened). |
openDiagram(diagram) |
Opens the diagram (adds it to Working Diagrams) and shows it. |
closeDiagram(diagram) |
Closes the diagram. |
closeOthers() |
Closes the diagrams other than the current diagram. |
closeAll() |
Closes all diagrams. |
nextDiagram(), previousDiagram() |
Shows the next or the previous diagram in Working Diagrams. |
getWorkingDiagrams() |
Returns the array of the opened diagrams. |
saveWorkingDiagrams(), restoreWorkingDiagrams() |
Saves or restores the opened diagrams of the project file. |
updateDiagram(diagram) |
Does nothing in StarUML 8 (the diagram is updated automatically). |
Diagram editor
| Function | Description |
|---|---|
repaint() |
Repaints the current diagram. |
selectAll(), deselectAll() |
Selects or deselects all views in the current diagram. |
selectInDiagram(view) |
Shows the diagram of the view, scrolls to the view and selects it. |
setZoomLevel(scale) |
Sets the zoom scale (e.g. 1 is 100%, 1.5 is 150%). |
getZoomLevel() |
Returns the zoom scale. |
toggleGrid(), showGrid(), hideGrid() |
Toggles, shows or hides the grid. |
isGridVisible() |
Returns whether the grid is shown. |
getViewportSize() |
Returns the size of the diagram editor as a type.Point (x is the width, y is the height). |
scrollTo(x, y) |
Scrolls the diagram editor to the position. |
getScrollPosition() |
Returns the scroll position as a type.Point. |
getDiagramArea() |
Returns the area {x1, y1, x2, y2} containing all views of the current diagram. |
getEditor() |
Returns the diagram editor. It has no functions in StarUML 8 and can only be passed to the functions of app.engine and app.factory. |
app.modelExplorer
Section titled “app.modelExplorer”| Function | Description |
|---|---|
select(elem, [scrollTo]) |
Selects the element in Model Explorer (expanding its ancestors). If scrollTo is true, scrolls to the element. |
app.toast
Section titled “app.toast”| Function | Description |
|---|---|
info(message) |
Shows an info message for some seconds. |
warning(message) |
Shows a warning message. |
error(message) |
Shows an error message. |
app.toolbar, app.toolbox, app.editorsHolder
Section titled “app.toolbar, app.toolbox, app.editorsHolder”| Function | Description |
|---|---|
app.toolbar.addButton({id, title, icon, command}) |
Adds a button to the toolbar. See Toolbar. |
app.toolbar.setSelected(id, selected) |
Shows the button as selected (on) or not. |
app.toolbox.groups |
An object of the groups of the toolbox by ID ({id, label, diagramTypes, items}). |
app.toolbox.items |
An object of the items of the toolbox by ID ({id, label, icon, rubberband, command, command-arg}). |
app.toolbox.activeItem |
The ID of the selected item ("toolbox-select" if the pointer is selected). |
app.toolbox.activeItemLocked |
Whether the selected item is locked (kept selected after creating an element). |
app.toolbox.setActiveItemLock(locked) |
Locks or unlocks the selected item. |
app.toolbox.selectItem(id) |
Selects the item. Pass null to select the pointer. |
app.toolbox.expandGroup(id), collapseGroup(id) |
Expands or collapses the group. |
toggle(), show(), hide(), isVisible() |
Toggles, shows, hides or checks the visibility of the toolbar, the toolbox or the editors (Properties, Documentation, …). |
app.dialogs
Section titled “app.dialogs”All dialogs return a Promise resolved when the dialog is closed. See Using Dialogs for examples.
| Function | Resolved with |
|---|---|
showInfoDialog(message) |
null |
showAlertDialog(message) |
null |
showErrorDialog(message) |
null |
showSimpleDialog(message) |
the button ID |
showConfirmDialog(message) |
the button ID ("ok" or "cancel") |
showSaveConfirmDialog([filename]) |
the button ID ("save", "dontsave" or "cancel") |
showInputDialog(message, [initialValue]) |
{buttonId, returnValue} (returnValue is the text) |
showTextDialog(message, [initialValue]) |
{buttonId, returnValue} (multi-line text) |
showSelectRadioDialog(message, options) |
{buttonId, returnValue} (returnValue is the value of the selected option). options is an array of {text, value, [checked]}. |
showSelectDropdownDialog(message, options) |
{buttonId, returnValue}. options is an array of {text, value}. |
showColorDialog([color]) |
{buttonId, returnValue} (returnValue is a color like "#ff0000") |
showFontDialog([font]) |
{buttonId, returnValue}. font and returnValue are {face, size, color}. |
The other dialogs of StarUML have the function showDialog, which also returns a Promise resolved with {buttonId, returnValue}.
| Function | Description |
|---|---|
app.elementPickerDialog.showDialog(title, [selected], [typeFilter]) |
Picks an element from the model tree. returnValue is the element. |
app.elementListPickerDialog.showDialog(title, elems) |
Picks an element from the list. returnValue is the element. |
app.elementListEditorDialog.showDialog(elem, field) |
Edits the list of the elements in the field of the element. |
app.tagEditorDialog.showDialog(elem) |
Edits the tags of the element. |
app.tagValueEditorDialog.showDialog([tag], [attr]) |
Edits the value of a tag. |
app.iconPickerDialog.showDialog(folder) |
Picks an icon of the built-in icon sets ("aws", "azure" or "gcp"). |
buttonId is "ok" when the user confirms the dialog.
app.preferences
Section titled “app.preferences”| Function | Description |
|---|---|
get(key, [defaultValue]) |
Returns the value of the preference (e.g. "java.gen.useTab"), or defaultValue if not set. |
set(key, value) |
Sets the value of the preference. |
The preferences of an extension are defined by preference JSON files. See Defining Preferences.
app.metamodels
Section titled “app.metamodels”| Function | Description |
|---|---|
getMetaClass(name) |
Returns the metaclass {name, kind, super, attributes} of the class name, or null. |
getMetaAttributes(name) |
Returns the array of the attributes of the class (including inherited ones). Each attribute is {name, kind, type, default, transient, visible, readOnly}. kind is one of prim, enum, ref, refs, obj, objs, var and custom. |
isKindOf(name, superName) |
Returns whether the class is the same as or a subclass of superName. |
app.metamodels.isKindOf("UMLClass", "UMLClassifier") // trueapp.metamodels.getMetaAttributes("UMLAttribute").map(a => a.name)| Property / Function | Description |
|---|---|
app.name |
The application name ("StarUML"). |
app.version |
The application version (e.g. "8.0.0"). |
app.platform |
The platform: "darwin", "win32" or "linux". |
app.appPath, app.getAppPath() |
The path of the application folder (containing resources/). |
app.userPath, app.getUserPath() |
The path of the user data folder (e.g. ~/Library/Application Support/StarUML on macOS). |
Events
Section titled “Events”app.repository, app.project, app.factory, app.selections, app.diagrams and app.preferences also provide the functions of EventEmitter: on, once, off (removeListener), addListener, removeAllListeners, listeners, listenerCount and emit. See Events for the available events.
Limitations
Section titled “Limitations”The following features of StarUML 7 or earlier are not supported in StarUML 8.
elements.js(defining element classes) andrules.js(validation rules). An extension having these files is not loaded and is marked as Extension error in Extension Manager.require(). Other JavaScript files, Node.js modules (fs,path, …) and Electron modules cannot be loaded. Callingrequire()throwsError: require() is not supported: <name>.- DOM and jQuery (
$), browser APIs (window,document,alert, …) and timers (setTimeout,setInterval). - Stylesheets (
stylesheets/). Useapp.toolbar.addButton()to add toolbar buttons. - HTML dialogs (
app.dialogs.showModalDialogUsingTemplate), file dialogs (app.dialogs.showOpenDialog,showSaveDialog) and panels (app.panelManager). app.menu.updateStates()and new context menus for other parts of the user interface (see Menus).app.preferences.register()(use preference JSON files, see Defining Preferences).- Reading and writing files (e.g.
app.project.save,load,importFromFile,exportToFile). - The events of the application (
app.on(...)) and the events not listed in Events. - The diagram editor API (
app.diagrams.getEditor()returns an object only for passing toapp.engine). - The other
appAPIs not listed above. - Debug menu (Reload, Show DevTools). Use Script Console and restart StarUML after modifying an extension.