@eclipse-glsp-examples/workflow-server 0.9.0-next.397cddd.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/LICENSE +277 -0
  2. package/lib/app.d.ts +2 -0
  3. package/lib/app.d.ts.map +1 -0
  4. package/lib/app.js +37 -0
  5. package/lib/app.js.map +1 -0
  6. package/lib/graph-extension.d.ts +60 -0
  7. package/lib/graph-extension.d.ts.map +1 -0
  8. package/lib/graph-extension.js +156 -0
  9. package/lib/graph-extension.js.map +1 -0
  10. package/lib/handler/create-activity-node-handler.d.ts +23 -0
  11. package/lib/handler/create-activity-node-handler.d.ts.map +1 -0
  12. package/lib/handler/create-activity-node-handler.js +45 -0
  13. package/lib/handler/create-activity-node-handler.js.map +1 -0
  14. package/lib/handler/create-automated-task-handler.d.ts +9 -0
  15. package/lib/handler/create-automated-task-handler.d.ts.map +1 -0
  16. package/lib/handler/create-automated-task-handler.js +42 -0
  17. package/lib/handler/create-automated-task-handler.js.map +1 -0
  18. package/lib/handler/create-category-handler.d.ts +25 -0
  19. package/lib/handler/create-category-handler.d.ts.map +1 -0
  20. package/lib/handler/create-category-handler.js +41 -0
  21. package/lib/handler/create-category-handler.js.map +1 -0
  22. package/lib/handler/create-decision-node-handler.d.ts +9 -0
  23. package/lib/handler/create-decision-node-handler.d.ts.map +1 -0
  24. package/lib/handler/create-decision-node-handler.js +42 -0
  25. package/lib/handler/create-decision-node-handler.js.map +1 -0
  26. package/lib/handler/create-edge-handler.d.ts +22 -0
  27. package/lib/handler/create-edge-handler.d.ts.map +1 -0
  28. package/lib/handler/create-edge-handler.js +31 -0
  29. package/lib/handler/create-edge-handler.js.map +1 -0
  30. package/lib/handler/create-fork-node-handler.d.ts +6 -0
  31. package/lib/handler/create-fork-node-handler.d.ts.map +1 -0
  32. package/lib/handler/create-fork-node-handler.js +39 -0
  33. package/lib/handler/create-fork-node-handler.js.map +1 -0
  34. package/lib/handler/create-fork-or-join-node-handler.d.ts +22 -0
  35. package/lib/handler/create-fork-or-join-node-handler.d.ts.map +1 -0
  36. package/lib/handler/create-fork-or-join-node-handler.js +21 -0
  37. package/lib/handler/create-fork-or-join-node-handler.js.map +1 -0
  38. package/lib/handler/create-join-node-handler.d.ts +6 -0
  39. package/lib/handler/create-join-node-handler.d.ts.map +1 -0
  40. package/lib/handler/create-join-node-handler.js +39 -0
  41. package/lib/handler/create-join-node-handler.js.map +1 -0
  42. package/lib/handler/create-manual-task-handler.d.ts +9 -0
  43. package/lib/handler/create-manual-task-handler.d.ts.map +1 -0
  44. package/lib/handler/create-manual-task-handler.js +42 -0
  45. package/lib/handler/create-manual-task-handler.js.map +1 -0
  46. package/lib/handler/create-merge-node-handler.d.ts +9 -0
  47. package/lib/handler/create-merge-node-handler.d.ts.map +1 -0
  48. package/lib/handler/create-merge-node-handler.js +42 -0
  49. package/lib/handler/create-merge-node-handler.js.map +1 -0
  50. package/lib/handler/create-task-handler.d.ts +24 -0
  51. package/lib/handler/create-task-handler.d.ts.map +1 -0
  52. package/lib/handler/create-task-handler.js +48 -0
  53. package/lib/handler/create-task-handler.js.map +1 -0
  54. package/lib/handler/create-weighted-edge-handler.d.ts +22 -0
  55. package/lib/handler/create-weighted-edge-handler.d.ts.map +1 -0
  56. package/lib/handler/create-weighted-edge-handler.js +33 -0
  57. package/lib/handler/create-weighted-edge-handler.js.map +1 -0
  58. package/lib/handler/create-workflow-node-operation-handler.d.ts +24 -0
  59. package/lib/handler/create-workflow-node-operation-handler.d.ts.map +1 -0
  60. package/lib/handler/create-workflow-node-operation-handler.js +62 -0
  61. package/lib/handler/create-workflow-node-operation-handler.js.map +1 -0
  62. package/lib/handler/grid-snapper.d.ts +22 -0
  63. package/lib/handler/grid-snapper.d.ts.map +1 -0
  64. package/lib/handler/grid-snapper.js +20 -0
  65. package/lib/handler/grid-snapper.js.map +1 -0
  66. package/lib/index.d.ts +17 -0
  67. package/lib/index.d.ts.map +1 -0
  68. package/lib/index.js +21 -0
  69. package/lib/index.js.map +1 -0
  70. package/lib/labeledit/workflow-label-edit-validator.d.ts +21 -0
  71. package/lib/labeledit/workflow-label-edit-validator.d.ts.map +1 -0
  72. package/lib/labeledit/workflow-label-edit-validator.js +55 -0
  73. package/lib/labeledit/workflow-label-edit-validator.js.map +1 -0
  74. package/lib/layout/workflow-layout-configurator.d.ts +22 -0
  75. package/lib/layout/workflow-layout-configurator.d.ts.map +1 -0
  76. package/lib/layout/workflow-layout-configurator.js +38 -0
  77. package/lib/layout/workflow-layout-configurator.js.map +1 -0
  78. package/lib/marker/workflow-model-validator.d.ts +29 -0
  79. package/lib/marker/workflow-model-validator.d.ts.map +1 -0
  80. package/lib/marker/workflow-model-validator.js +150 -0
  81. package/lib/marker/workflow-model-validator.js.map +1 -0
  82. package/lib/model/workflow-navigation-target-resolver.d.ts +24 -0
  83. package/lib/model/workflow-navigation-target-resolver.d.ts.map +1 -0
  84. package/lib/model/workflow-navigation-target-resolver.js +40 -0
  85. package/lib/model/workflow-navigation-target-resolver.js.map +1 -0
  86. package/lib/provider/abstract-next-or-previous-navigation-target-provider.d.ts +29 -0
  87. package/lib/provider/abstract-next-or-previous-navigation-target-provider.d.ts.map +1 -0
  88. package/lib/provider/abstract-next-or-previous-navigation-target-provider.js +60 -0
  89. package/lib/provider/abstract-next-or-previous-navigation-target-provider.js.map +1 -0
  90. package/lib/provider/next-node-navigation-target-provider.d.ts +24 -0
  91. package/lib/provider/next-node-navigation-target-provider.d.ts.map +1 -0
  92. package/lib/provider/next-node-navigation-target-provider.js +28 -0
  93. package/lib/provider/next-node-navigation-target-provider.js.map +1 -0
  94. package/lib/provider/node-documentation-navigation-target-provider.d.ts +24 -0
  95. package/lib/provider/node-documentation-navigation-target-provider.d.ts.map +1 -0
  96. package/lib/provider/node-documentation-navigation-target-provider.js +50 -0
  97. package/lib/provider/node-documentation-navigation-target-provider.js.map +1 -0
  98. package/lib/provider/previous-node-navigation-target-provider.d.ts +24 -0
  99. package/lib/provider/previous-node-navigation-target-provider.d.ts.map +1 -0
  100. package/lib/provider/previous-node-navigation-target-provider.js +28 -0
  101. package/lib/provider/previous-node-navigation-target-provider.js.map +1 -0
  102. package/lib/provider/workflow-command-palette-action-provider.d.ts +25 -0
  103. package/lib/provider/workflow-command-palette-action-provider.d.ts.map +1 -0
  104. package/lib/provider/workflow-command-palette-action-provider.js +92 -0
  105. package/lib/provider/workflow-command-palette-action-provider.js.map +1 -0
  106. package/lib/provider/workflow-context-menu-item-provider.d.ts +21 -0
  107. package/lib/provider/workflow-context-menu-item-provider.d.ts.map +1 -0
  108. package/lib/provider/workflow-context-menu-item-provider.js +54 -0
  109. package/lib/provider/workflow-context-menu-item-provider.js.map +1 -0
  110. package/lib/util/model-types.d.ts +35 -0
  111. package/lib/util/model-types.d.ts.map +1 -0
  112. package/lib/util/model-types.js +60 -0
  113. package/lib/util/model-types.js.map +1 -0
  114. package/lib/workflow-diagram-configuration.d.ts +28 -0
  115. package/lib/workflow-diagram-configuration.d.ts.map +1 -0
  116. package/lib/workflow-diagram-configuration.js +125 -0
  117. package/lib/workflow-diagram-configuration.js.map +1 -0
  118. package/lib/workflow-diagram-module.d.ts +27 -0
  119. package/lib/workflow-diagram-module.d.ts.map +1 -0
  120. package/lib/workflow-diagram-module.js +99 -0
  121. package/lib/workflow-diagram-module.js.map +1 -0
  122. package/lib/workflow-glsp-server.d.ts +23 -0
  123. package/lib/workflow-glsp-server.d.ts.map +1 -0
  124. package/lib/workflow-glsp-server.js +54 -0
  125. package/lib/workflow-glsp-server.js.map +1 -0
  126. package/lib/workflow-model-index.d.ts +20 -0
  127. package/lib/workflow-model-index.d.ts.map +1 -0
  128. package/lib/workflow-model-index.js +43 -0
  129. package/lib/workflow-model-index.js.map +1 -0
  130. package/lib/workflow-popup-factory.d.ts +21 -0
  131. package/lib/workflow-popup-factory.d.ts.map +1 -0
  132. package/lib/workflow-popup-factory.js +54 -0
  133. package/lib/workflow-popup-factory.js.map +1 -0
  134. package/package.json +61 -0
  135. package/src/app.ts +35 -0
  136. package/src/graph-extension.ts +186 -0
  137. package/src/handler/create-activity-node-handler.ts +34 -0
  138. package/src/handler/create-automated-task-handler.ts +30 -0
  139. package/src/handler/create-category-handler.ts +36 -0
  140. package/src/handler/create-decision-node-handler.ts +30 -0
  141. package/src/handler/create-edge-handler.ts +25 -0
  142. package/src/handler/create-fork-node-handler.ts +24 -0
  143. package/src/handler/create-fork-or-join-node-handler.ts +26 -0
  144. package/src/handler/create-join-node-handler.ts +24 -0
  145. package/src/handler/create-manual-task-handler.ts +30 -0
  146. package/src/handler/create-merge-node-handler.ts +30 -0
  147. package/src/handler/create-task-handler.ts +38 -0
  148. package/src/handler/create-weighted-edge-handler.ts +27 -0
  149. package/src/handler/create-workflow-node-operation-handler.ts +56 -0
  150. package/src/handler/grid-snapper.ts +32 -0
  151. package/src/index.ts +19 -0
  152. package/src/labeledit/workflow-label-edit-validator.ts +39 -0
  153. package/src/layout/workflow-layout-configurator.ts +28 -0
  154. package/src/marker/workflow-model-validator.ts +137 -0
  155. package/src/model/workflow-navigation-target-resolver.ts +40 -0
  156. package/src/provider/abstract-next-or-previous-navigation-target-provider.ts +53 -0
  157. package/src/provider/next-node-navigation-target-provider.ts +31 -0
  158. package/src/provider/node-documentation-navigation-target-provider.ts +52 -0
  159. package/src/provider/previous-node-navigation-target-provider.ts +31 -0
  160. package/src/provider/workflow-command-palette-action-provider.ts +124 -0
  161. package/src/provider/workflow-context-menu-item-provider.ts +38 -0
  162. package/src/util/model-types.ts +55 -0
  163. package/src/workflow-diagram-configuration.ts +122 -0
  164. package/src/workflow-diagram-module.ts +107 -0
  165. package/src/workflow-glsp-server.ts +37 -0
  166. package/src/workflow-model-index.ts +31 -0
  167. package/src/workflow-popup-factory.ts +46 -0
@@ -0,0 +1,38 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { CreateWorkflowNodeOperationHandler } from './create-workflow-node-operation-handler';
17
+ import { injectable } from 'inversify';
18
+ import { Args, ORIGIN_POINT, Point } from '@eclipse-glsp/protocol';
19
+ import { GModelState, GNode } from '@eclipse-glsp/server-node';
20
+ import { TaskNode, TaskNodeBuilder } from '../graph-extension';
21
+ import { ModelTypes } from '../util/model-types';
22
+
23
+ @injectable()
24
+ export abstract class CreateTaskHandler extends CreateWorkflowNodeOperationHandler {
25
+ createNode(relativeLocation: Point | undefined, args: Args | undefined): GNode | undefined {
26
+ return this.builder(relativeLocation, this.modelState).build();
27
+ }
28
+
29
+ protected builder(point: Point | undefined, modelState: GModelState): TaskNodeBuilder {
30
+ return TaskNode.builder()
31
+ .position(point ?? ORIGIN_POINT)
32
+ .addCssClass('task')
33
+ .name(this.label.replace(' ', '') + this.modelState.index.getAllByClass(TaskNode).length)
34
+ .type(this.elementTypeIds[0])
35
+ .taskType(ModelTypes.toNodeType(this.elementTypeIds[0]))
36
+ .children();
37
+ }
38
+ }
@@ -0,0 +1,27 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { CreateEdgeOperationHandler, GEdge, GModelElement, GModelState } from '@eclipse-glsp/server-node';
17
+ import { WeightedEdge } from '../graph-extension';
18
+ import { ModelTypes } from '../util/model-types';
19
+
20
+ export class CreateWeightedEdgeHandler extends CreateEdgeOperationHandler {
21
+ elementTypeIds = [ModelTypes.WEIGHTED_EDGE];
22
+ label = 'Weighted edge';
23
+
24
+ createEdge(source: GModelElement, target: GModelElement, modelState: GModelState): GEdge | undefined {
25
+ return WeightedEdge.builder().sourceId(source.id).targetId(target.id).probability('medium').addCssClass('medium').build();
26
+ }
27
+ }
@@ -0,0 +1,56 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import {
17
+ CreateNodeOperation,
18
+ CreateNodeOperationHandler,
19
+ GCompartment,
20
+ GModelElement,
21
+ GModelState,
22
+ Point
23
+ } from '@eclipse-glsp/server-node';
24
+ import { injectable, inject } from 'inversify';
25
+ import { Category } from '../graph-extension';
26
+ import { ModelTypes } from '../util/model-types';
27
+ import { GridSnapper } from './grid-snapper';
28
+
29
+ @injectable()
30
+ export abstract class CreateWorkflowNodeOperationHandler extends CreateNodeOperationHandler {
31
+ @inject(GModelState)
32
+ protected modelState: GModelState;
33
+
34
+ getLocation(operation: CreateNodeOperation): Point | undefined {
35
+ return GridSnapper.snap(operation.location);
36
+ }
37
+
38
+ getContainer(operation: CreateNodeOperation): GModelElement | undefined {
39
+ const container = super.getContainer(operation);
40
+
41
+ if (container instanceof Category) {
42
+ const structComp = this.getCategoryCompartment(container);
43
+ if (structComp) {
44
+ return structComp;
45
+ }
46
+ }
47
+ return container;
48
+ }
49
+
50
+ getCategoryCompartment(category: Category): GCompartment | undefined {
51
+ return category.children
52
+ .filter(child => child instanceof GCompartment)
53
+ .map(child => child as GCompartment)
54
+ .find(comp => ModelTypes.STRUCTURE === comp.type);
55
+ }
56
+ }
@@ -0,0 +1,32 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { Point } from '@eclipse-glsp/server-node';
17
+
18
+ export class GridSnapper {
19
+ public static GRID_X = 10.0;
20
+ public static GRID_Y = 10.0;
21
+
22
+ public static snap(originalPoint: Point | undefined): Point | undefined {
23
+ if (originalPoint) {
24
+ return {
25
+ x: Math.round(originalPoint.x / this.GRID_X) * this.GRID_X,
26
+ y: Math.round(originalPoint.y / this.GRID_Y) * this.GRID_Y
27
+ };
28
+ } else {
29
+ return undefined;
30
+ }
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import 'reflect-metadata';
17
+ import { launch } from './app';
18
+
19
+ launch();
@@ -0,0 +1,39 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { GModelElement, GModelState, LabelEditValidator, ValidationStatus } from '@eclipse-glsp/server-node';
17
+ import { inject, injectable } from 'inversify';
18
+ import { TaskNode } from '../graph-extension';
19
+
20
+ @injectable()
21
+ export class WorkflowLabelEditValidator implements LabelEditValidator {
22
+ @inject(GModelState)
23
+ protected modelState: GModelState;
24
+
25
+ validate(label: string, element: GModelElement): ValidationStatus {
26
+ if (label.length < 1) {
27
+ return { severity: ValidationStatus.Severity.ERROR, message: 'Name must not be empty' };
28
+ }
29
+ const taskNodes = this.modelState.index.getAllByClass<TaskNode>(TaskNode);
30
+ const hasDuplicate = taskNodes
31
+ .filter(e => !(e.id === element.id))
32
+ .map(task => task.name)
33
+ .some(name => name === label);
34
+ if (hasDuplicate) {
35
+ return { severity: ValidationStatus.Severity.WARNING, message: 'Name should be unique' };
36
+ }
37
+ return { severity: ValidationStatus.Severity.OK };
38
+ }
39
+ }
@@ -0,0 +1,28 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { GlspLayoutConfigurator, SModelIndex } from '@eclipse-glsp/layout-elk';
17
+ import { GGraph } from '@eclipse-glsp/server-node';
18
+ import { LayoutOptions } from 'elkjs';
19
+ import { injectable } from 'inversify';
20
+
21
+ @injectable()
22
+ export class WorkflowLayoutConfigurator extends GlspLayoutConfigurator {
23
+ protected graphOptions(sgraph: GGraph, index: SModelIndex): LayoutOptions | undefined {
24
+ return {
25
+ 'elk.algorithm': 'layered'
26
+ };
27
+ }
28
+ }
@@ -0,0 +1,137 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { GModelElement, Marker, ModelValidator, GModelState, MarkerKind, GCompartment, GLabel } from '@eclipse-glsp/server-node';
17
+ import { inject, injectable } from 'inversify';
18
+ import { ActivityNode, TaskNode } from '../graph-extension';
19
+
20
+ @injectable()
21
+ export class WorkflowModelValidator implements ModelValidator {
22
+ @inject(GModelState)
23
+ protected readonly modelState: GModelState;
24
+
25
+ validate(elements: GModelElement[]): Marker[] {
26
+ const markers: Marker[] = [];
27
+ for (const element of elements) {
28
+ if (element instanceof TaskNode) {
29
+ markers.push(...this.validateTaskNode(element));
30
+ } else if (element instanceof ActivityNode) {
31
+ if (element.nodeType === 'decisionNode') {
32
+ markers.push(...this.validateDecisionNode(element));
33
+ } else if (element.nodeType === 'mergeNode') {
34
+ markers.push(...this.validateMergeNode(element));
35
+ }
36
+ }
37
+ if (element.children) {
38
+ markers.push(...this.validate(element.children));
39
+ }
40
+ }
41
+ return markers;
42
+ }
43
+
44
+ protected validateTaskNode(taskNode: TaskNode): Marker[] {
45
+ const markers: Marker[] = [];
46
+ const automated = this.validateTaskNode_isAutomated(taskNode);
47
+ if (automated) {
48
+ markers.push(automated);
49
+ }
50
+ const upperCase = this.validateTaskNode_labelStartsUpperCase(taskNode);
51
+ if (upperCase) {
52
+ markers.push(upperCase);
53
+ }
54
+ return markers;
55
+ }
56
+
57
+ protected validateTaskNode_isAutomated(taskNode: TaskNode): Marker | undefined {
58
+ if (taskNode.taskType === 'automated') {
59
+ return { kind: MarkerKind.INFO, description: 'This is an automated task', elementId: taskNode.id, label: 'Automated task' };
60
+ }
61
+ return undefined;
62
+ }
63
+
64
+ protected validateTaskNode_labelStartsUpperCase(taskNode: TaskNode): Marker | undefined {
65
+ const gCompartment = taskNode.children.find(child => child instanceof GCompartment);
66
+ if (gCompartment) {
67
+ const gLabels = gCompartment.children.filter(child => child instanceof GLabel).map(element => element as GLabel);
68
+ if (gLabels.length > 0 && gLabels[0].text.charAt(0) === gLabels[0].text.charAt(0).toLowerCase()) {
69
+ return {
70
+ kind: MarkerKind.WARNING,
71
+ description: 'Task node names should start with upper case letters',
72
+ elementId: taskNode.id,
73
+ label: 'Task node label in upper case'
74
+ };
75
+ }
76
+ }
77
+ return undefined;
78
+ }
79
+
80
+ protected validateDecisionNode(decisionNode: ActivityNode): Marker[] {
81
+ const markers: Marker[] = [];
82
+ const oneIncoming = this.validateDecisionNode_hasOneIncomingEdge(decisionNode);
83
+ if (oneIncoming) {
84
+ markers.push(oneIncoming);
85
+ }
86
+ return markers;
87
+ }
88
+
89
+ protected validateDecisionNode_hasOneIncomingEdge(decisionNode: ActivityNode): Marker | undefined {
90
+ const edges = this.modelState.index.getIncomingEdges(decisionNode);
91
+ if (edges.length > 1) {
92
+ return {
93
+ kind: MarkerKind.ERROR,
94
+ description: 'Decision node may only have one incoming edge.',
95
+ elementId: decisionNode.id,
96
+ label: 'Too many incoming edges'
97
+ };
98
+ } else if (edges.length === 0) {
99
+ return {
100
+ kind: MarkerKind.ERROR,
101
+ description: 'Decision node must have one incoming edge.',
102
+ elementId: decisionNode.id,
103
+ label: 'Missing incoming edge'
104
+ };
105
+ }
106
+ return undefined;
107
+ }
108
+
109
+ protected validateMergeNode(mergeNode: ActivityNode): Marker[] {
110
+ const markers: Marker[] = [];
111
+ const oneOutgoing = this.validateMergeNode_hasOneOutgoingEdge(mergeNode);
112
+ if (oneOutgoing) {
113
+ markers.push(oneOutgoing);
114
+ }
115
+ return markers;
116
+ }
117
+
118
+ protected validateMergeNode_hasOneOutgoingEdge(mergeNode: ActivityNode): Marker | undefined {
119
+ const edges = this.modelState.index.getOutgoingEdges(mergeNode);
120
+ if (edges.length > 1) {
121
+ return {
122
+ kind: MarkerKind.ERROR,
123
+ description: 'Merge node may only have one outgoing edge.',
124
+ elementId: mergeNode.id,
125
+ label: 'Too many outgoing edges'
126
+ };
127
+ } else if (edges.length === 0) {
128
+ return {
129
+ kind: MarkerKind.ERROR,
130
+ description: 'Merge node must have one outgoing edge.',
131
+ elementId: mergeNode.id,
132
+ label: 'Missing outgoing edge'
133
+ };
134
+ }
135
+ return undefined;
136
+ }
137
+ }
@@ -0,0 +1,40 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { NavigationTarget } from '@eclipse-glsp/protocol';
17
+ import { GModelState } from '@eclipse-glsp/server-node';
18
+ import { NavigationTargetResolution } from '@eclipse-glsp/server-node/lib/features/navigation/navigation-target-resolution';
19
+ import { NavigationTargetResolver } from '@eclipse-glsp/server-node/lib/features/navigation/navigation-target-resolver';
20
+ import { inject, injectable } from 'inversify';
21
+ import { TaskNode } from '../graph-extension';
22
+
23
+ @injectable()
24
+ export class WorkflowNavigationTargetResolver extends NavigationTargetResolver {
25
+ @inject(GModelState)
26
+ protected readonly modelState: GModelState;
27
+
28
+ async resolve(navigationTarget: NavigationTarget): Promise<NavigationTargetResolution> {
29
+ if (navigationTarget.args && navigationTarget.args['name']) {
30
+ const name = navigationTarget.args['name'];
31
+ const taskNodes = this.modelState.index.getAllByClass<TaskNode>(TaskNode);
32
+ const element = taskNodes.find(node => name === node.name);
33
+ if (element) {
34
+ return new NavigationTargetResolution([element.id]);
35
+ }
36
+ return new NavigationTargetResolution([], this.createArgsWithWarning(`Couldn't find element with name ${name}`));
37
+ }
38
+ return NavigationTargetResolution.EMPTY;
39
+ }
40
+ }
@@ -0,0 +1,53 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { Args, EditorContext, NavigationTarget } from '@eclipse-glsp/protocol';
17
+ import { NavigationTargetProvider } from '@eclipse-glsp/server-node/lib/features/navigation/navigation-target-provider';
18
+ import { inject, injectable } from 'inversify';
19
+ import { GEdge, GModelState } from '@eclipse-glsp/server-node';
20
+ import { TaskNode } from '../graph-extension';
21
+
22
+ @injectable()
23
+ export abstract class AbstractNextOrPreviousNavigationTargetProvider implements NavigationTargetProvider {
24
+ abstract targetTypeId: string;
25
+
26
+ @inject(GModelState)
27
+ protected readonly modelState: GModelState;
28
+
29
+ getTargets(editorContext: EditorContext): NavigationTarget[] {
30
+ const sourceUri = this.modelState.sourceUri;
31
+ const edges: GEdge[] = [];
32
+ editorContext.selectedElementIds
33
+ .map(id => this.modelState.index.get(id))
34
+ .filter(e => e instanceof TaskNode)
35
+ .map(e => e as TaskNode)
36
+ .map(taskNode => edges.push(...this.getEdges(taskNode)));
37
+ return edges.map(edge => this.getSourceOrTarget(edge)).map(id => this.createNavigationTarget(sourceUri, id));
38
+ }
39
+
40
+ protected createNavigationTarget(sourceURI: string | undefined, id: string): NavigationTarget {
41
+ return { uri: sourceURI ?? '', args: this.createElementIdMap(id) };
42
+ }
43
+
44
+ protected createElementIdMap(id: string): Args {
45
+ const map: Args = {};
46
+ map[NavigationTarget.ELEMENT_IDS] = id;
47
+ return map;
48
+ }
49
+
50
+ protected abstract getEdges(taskNode: TaskNode): GEdge[];
51
+
52
+ protected abstract getSourceOrTarget(edge: GEdge): string;
53
+ }
@@ -0,0 +1,31 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { GEdge } from '@eclipse-glsp/graph';
17
+ import { TaskNode } from '../graph-extension';
18
+ import { AbstractNextOrPreviousNavigationTargetProvider } from './abstract-next-or-previous-navigation-target-provider';
19
+ import { injectable } from 'inversify';
20
+
21
+ @injectable()
22
+ export class NextNodeNavigationTargetProvider extends AbstractNextOrPreviousNavigationTargetProvider {
23
+ targetTypeId = 'next';
24
+ protected getEdges(taskNode: TaskNode): GEdge[] {
25
+ return this.modelState.index.getOutgoingEdges(taskNode);
26
+ }
27
+
28
+ protected getSourceOrTarget(edge: GEdge): string {
29
+ return edge.targetId;
30
+ }
31
+ }
@@ -0,0 +1,52 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { Args, EditorContext, NavigationTarget } from '@eclipse-glsp/protocol';
17
+ import { GModelState } from '@eclipse-glsp/server-node';
18
+ import { NavigationTargetProvider } from '@eclipse-glsp/server-node/lib/features/navigation/navigation-target-provider';
19
+ import { inject, injectable } from 'inversify';
20
+ import { TaskNode } from '../graph-extension';
21
+ import { JsonOpenerOptions } from '@eclipse-glsp/server-node/lib/features/navigation/json-opener-options';
22
+
23
+ @injectable()
24
+ export class NodeDocumentationNavigationTargetProvider implements NavigationTargetProvider {
25
+ targetTypeId = 'documentation';
26
+
27
+ @inject(GModelState)
28
+ protected readonly modelState: GModelState;
29
+
30
+ getTargets(editorContext: EditorContext): NavigationTarget[] {
31
+ if (editorContext.selectedElementIds.length === 1) {
32
+ const taskNode = this.modelState.index.findByClass(editorContext.selectedElementIds[0], TaskNode);
33
+ if (!taskNode || !(taskNode.id === 'task0')) {
34
+ return [];
35
+ }
36
+
37
+ const sourceUri = this.modelState.sourceUri;
38
+ if (!sourceUri) {
39
+ return [];
40
+ }
41
+
42
+ const docUri = sourceUri.replace('.wf', '.md');
43
+ const args: Args = {};
44
+ args['jsonOpenerOptions'] = new JsonOpenerOptions({
45
+ start: { line: 2, character: 3 },
46
+ end: { line: 2, character: 7 }
47
+ }).toJson();
48
+ return [{ uri: docUri, args: args }];
49
+ }
50
+ return [];
51
+ }
52
+ }
@@ -0,0 +1,31 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 STMicroelectronics and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { GEdge } from '@eclipse-glsp/graph';
17
+ import { TaskNode } from '../graph-extension';
18
+ import { AbstractNextOrPreviousNavigationTargetProvider } from './abstract-next-or-previous-navigation-target-provider';
19
+ import { injectable } from 'inversify';
20
+
21
+ @injectable()
22
+ export class PreviousNodeNavigationTargetProvider extends AbstractNextOrPreviousNavigationTargetProvider {
23
+ targetTypeId = 'previous';
24
+ protected getEdges(taskNode: TaskNode): GEdge[] {
25
+ return this.modelState.index.getIncomingEdges(taskNode);
26
+ }
27
+
28
+ protected getSourceOrTarget(edge: GEdge): string {
29
+ return edge.sourceId;
30
+ }
31
+ }