-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathworkflow-context-menu-item-provider.ts
More file actions
66 lines (61 loc) · 2.7 KB
/
workflow-context-menu-item-provider.ts
File metadata and controls
66 lines (61 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/********************************************************************************
* Copyright (c) 2022-2025 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Args, ContextMenuItemProvider, CreateNodeOperation, MenuItem, ModelState, Point, SetEditModeAction } from '@eclipse-glsp/server';
import { inject, injectable } from 'inversify';
import { GridSnapper } from '../handler/grid-snapper';
import { ModelTypes } from '../util/model-types';
@injectable()
export class WorkflowContextMenuItemProvider extends ContextMenuItemProvider {
@inject(ModelState)
protected modelState: ModelState;
getItems(selectedElementIds: string[], position: Point, args?: Args): MenuItem[] {
const editModeMenu: MenuItem = {
id: 'editMode',
label: 'Readonly Mode',
isToggled: this.modelState.isReadonly,
actions: [this.modelState.isReadonly ? SetEditModeAction.create('editable') : SetEditModeAction.create('readonly')]
};
if (this.modelState.isReadonly || selectedElementIds.length !== 0) {
return [editModeMenu];
}
const snappedPosition = GridSnapper.snap(position);
const newAutTask: MenuItem = {
id: 'newAutoTask',
label: 'Automated Task',
actions: [CreateNodeOperation.create(ModelTypes.AUTOMATED_TASK, { location: snappedPosition })]
};
const newManTask: MenuItem = {
id: 'newManualTask',
label: 'Manual Task',
actions: [CreateNodeOperation.create(ModelTypes.MANUAL_TASK, { location: snappedPosition })]
};
const hiddenItem: MenuItem = {
id: 'hiddenItem',
label: 'Should be hidden',
actions: [],
isVisible: false
};
const newChildMenu: MenuItem = {
id: 'new',
label: 'New',
actions: [],
children: [newAutTask, newManTask, hiddenItem],
icon: 'add',
group: '0_new'
};
return [newChildMenu, editModeMenu];
}
}