Extend the frontend through extension points
Sirius Web is itself an application built on top of Sirius Components. You can customize many aspects of the UI by contributing components to its extension points.
1. Palette tool extension point
Contribute custom tools to the diagram palette by registering React components that accept PaletteToolComponentProps.
Tool components are responsible for deciding whether they should render (for example, only on specific diagram types) and can execute GraphQL queries/mutations.
Retrieve the editingContextId and representationId through the router params:
const { projectId: editingContextId, representationId } = useParams<EditProjectViewParams>();
Register the tool with the paletteToolExtensionPoint:
const papayaExtensionRegistry = new ExtensionRegistry();
papayaExtensionRegistry.addComponent(paletteToolExtensionPoint, {
identifier: 'papaya_customtool',
Component: PapayaOperationActivityLabelDetailToolContribution,
});
If the tool needs the click coordinates (for example to create nodes precisely), implement an IDiagramInputReferencePositionProvider.
The default implementation (GenericDiagramToolReferencePositionProvider) reads the palette coordinates from DiagramPaletteToolContributionComponentProps.
2. Tree item context menu extension point
Add custom entries to the tree explorer’s context menu with components that accept TreeItemContextMenuComponentProps.
Components should generally return a MenuItem (or similar), and must return null when they do not apply to the given tree/tree item.
export const DocumentTreeItemContextMenuContribution = forwardRef(
(
{ editingContextId, treeId, item, readOnly, expandItem, onClose }: TreeItemContextMenuComponentProps,
ref: React.ForwardedRef<HTMLLIElement>
) => {
const { httpOrigin } = useContext<ServerContextValue>(ServerContext);
if (!treeId.startsWith('explorer://') || !item.kind.startsWith('siriusWeb://document')) {
return null;
}
return (
<Fragment key="document-tree-item-context-menu-contribution">
<MenuItem
key="download"
onClick={onClose}
component="a"
href={`${httpOrigin}/api/editingcontexts/${editingContextId}/documents/${item.id}`}
type="application/octet-stream"
data-testid="download">
<ListItemIcon>
<GetAppIcon fontSize="small" />
</ListItemIcon>
<ListItemText primary="Download" />
</MenuItem>
</Fragment>
);
}
);
Register the component with treeItemContextMenuEntryExtensionPoint:
extensionRegistry.addComponent(treeItemContextMenuEntryExtensionPoint, {
identifier: 'document-custom-tree-menu-entry',
Component: DocumentTreeItemContextMenuContribution,
});
3. Add a workbench omnibox command
Papaya’s Show documentation command illustrates how to add a command that opens a link.
Register a Spring bean implementing IWorkbenchOmniboxCommandProvider.
In getCommands, return an OmniboxCommand with a stable ID, a label, icon URLs, and a description.
Return an empty list when the command does not apply to the current editing context or selection.
The workbench filters the returned commands by label as the user types.
To open a link in the browser, register a React component with omniboxCommandOverrideContributionExtensionPoint using the frontend extension registry’s putData method.
Set the contribution’s canHandle predicate to match the ID returned by the provider, such as showDocumentation.
The component receives OmniboxCommandComponentProps; forward onKeyDown to the command’s list item so keyboard navigation works.
In the click handler, open the link and call onClose() to dismiss the omnibox.