Before modifying the model, it is the developer’s responsibility to verify that the operation is allowed.

The Open API does not block modifications automatically, even if an element is read-only. Failing to check permissions may result in invalid model state or runtime issues.

When an Element Is Read-Only

An element may be non-editable in the following cases:

  • It belongs to a read-only module (used project)
  • It is not locked in a Teamwork Cloud environment
  • It is restricted by custom or domain-specific rules
  • It is restricted by plugin-level or application-level permissions

Permissions are evaluated through multiple handlers registered in the system (Teamwork, modules, proxies, diagrams, etc.).

Types of Permission Checks

Different operations require different permission checks.

1. Checking Property Editing

Use when modifying primitive properties or references (e.g., name, type, visibility).

boolean editable = element.isEditable();
CODE
  • Returns whether the element can be edited
  • Covers:
    • Element-level permissions
    • Project state
    • Teamwork locks

2. Checking If Children Can Be Created

Use when creating new elements inside a parent.

boolean canCreate = element.canAddChild();
CODE
  • Checks if the parent allows any children
  • Does not validate a specific child type

3. Checking If a Specific Child Can Be Added

Use when adding an element to a parent.

Basic check

boolean allowed = parent.canAdd(child);
CODE

This validates:

  • Type compatibility (e.g., cannot add a child of a kind which a parent is not allowed to own)
  • Ownership constraints
  • Teamwork permissions (if enabled)

Full permission check

import com.nomagic.magicdraw.uml.permissions.ElementPermissionsManager;

boolean allowed = ElementPermissionsManager
    .getElementPermissionsManager()
    .canAddChild(parent, child);
CODE

This includes:

  • Registered permission handlers
  • Custom rules
  • Environment-specific restrictions

4. Checking Deletion Permission

Use before removing an element from the model.

boolean canDelete = element.canBeDeleted();
CODE

or

import com.nomagic.magicdraw.uml.permissions.ElementPermissionsManager;

boolean canDelete = ElementPermissionsManager
    .getElementPermissionsManager()
    .canDelete(element);
CODE

Deletion requires:

  • Element is editable
  • Parent allows removal
  • Project is editable

5. Checking Moving Permission

Moving an element is effectively:

  • Removing from old parent
  • Adding to new parent
boolean canMove = element.canChangeParent(elements, newParent);
CODE

This performs:

  • Ownership validation
  • Cycle prevention
  • Permission checks (edit + add)

Using ElementPermissionsManager

The ElementPermissionsManager provides a centralized permission evaluation layer.

import com.nomagic.magicdraw.uml.permissions.ElementPermissionsManager;

ElementPermissionsManager manager =
    ElementPermissionsManager.getElementPermissionsManager();

boolean editable = manager.isElementEditable(element);
boolean canCreate = manager.canCreateChildIn(element);
boolean canAdd = manager.canAddChild(parent, child);
boolean canDelete = manager.canDelete(element);
CODE

Key characteristics:

  • Aggregates multiple permission sources
  • Delegates to registered ElementPermissions handlers
  • Supports caching for performance
  • Used internally by the platform

Plugging Custom Permission Logic

You can define custom rules by implementing:

import com.nomagic.magicdraw.uml.permissions.ElementPermissions;

public interface ElementPermissions
{
    boolean isElementEditable(BaseElement element);
    boolean canCreateChildIn(BaseElement element);
    boolean canAddChild(BaseElement parent, BaseElement child);
    boolean canDelete(BaseElement element);
}
CODE

Then register it:

import com.nomagic.magicdraw.uml.permissions.ElementPermissionsManager;

ElementPermissionsManager
    .getElementPermissionsManager()
    .addPermissionsHandler(new MyPermissionsHandler());
CODE

Custom handlers are:

  • Combined with existing handlers
  • Evaluated by the permissions manager
  • Suitable for:
    • Domain-specific restrictions
    • Tooling constraints
    • Validation layers

Recommended Usage Pattern

Always check permissions before modifying the model:

if (!element.isEditable())
{
    return;
}

if (!parent.canAdd(child))
{
    return;
}

child.setOwner(parent);
CODE

For more complex scenarios, prefer the manager:

import com.nomagic.magicdraw.uml.permissions.ElementPermissionsManager;

ElementPermissionsManager manager =
    ElementPermissionsManager.getElementPermissionsManager();

if (!manager.canAddChild(parent, child))
{
    return;
}
CODE

Key Takeaways