@eclipse-glsp/server 1.1.0-next.3d7585d.42 → 1.1.0-next.44bd1e0.43

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 (175) hide show
  1. package/lib/common/command/command-stack.d.ts +38 -8
  2. package/lib/common/command/command-stack.d.ts.map +1 -1
  3. package/lib/common/command/command-stack.js +75 -6
  4. package/lib/common/command/command-stack.js.map +1 -1
  5. package/lib/common/command/command-stack.spec.d.ts +2 -0
  6. package/lib/common/command/command-stack.spec.d.ts.map +1 -0
  7. package/lib/common/command/command-stack.spec.js +207 -0
  8. package/lib/common/command/command-stack.spec.js.map +1 -0
  9. package/lib/common/command/command.d.ts +30 -4
  10. package/lib/common/command/command.d.ts.map +1 -1
  11. package/lib/common/command/command.js +69 -0
  12. package/lib/common/command/command.js.map +1 -1
  13. package/lib/common/command/command.spec.d.ts +2 -0
  14. package/lib/common/command/command.spec.d.ts.map +1 -0
  15. package/lib/common/command/command.spec.js +86 -0
  16. package/lib/common/command/command.spec.js.map +1 -0
  17. package/lib/common/command/recording-command.d.ts +75 -0
  18. package/lib/common/command/recording-command.d.ts.map +1 -0
  19. package/lib/common/command/recording-command.js +99 -0
  20. package/lib/common/command/recording-command.js.map +1 -0
  21. package/lib/common/command/recording-command.spec.d.ts +17 -0
  22. package/lib/common/command/recording-command.spec.d.ts.map +1 -0
  23. package/lib/common/command/recording-command.spec.js +62 -0
  24. package/lib/common/command/recording-command.spec.js.map +1 -0
  25. package/lib/common/command/undo-redo-action-handler.d.ts +28 -0
  26. package/lib/common/command/undo-redo-action-handler.d.ts.map +1 -0
  27. package/lib/common/command/undo-redo-action-handler.js +72 -0
  28. package/lib/common/command/undo-redo-action-handler.js.map +1 -0
  29. package/lib/common/di/diagram-module.d.ts +3 -0
  30. package/lib/common/di/diagram-module.d.ts.map +1 -1
  31. package/lib/common/di/diagram-module.js +12 -0
  32. package/lib/common/di/diagram-module.js.map +1 -1
  33. package/lib/common/features/contextactions/tool-palette-item-provider.d.ts +1 -1
  34. package/lib/common/features/contextactions/tool-palette-item-provider.d.ts.map +1 -1
  35. package/lib/common/features/contextactions/tool-palette-item-provider.js +2 -4
  36. package/lib/common/features/contextactions/tool-palette-item-provider.js.map +1 -1
  37. package/lib/common/{gmodel → features/layout}/computed-bounds-action-handler.d.ts +8 -3
  38. package/lib/common/features/layout/computed-bounds-action-handler.d.ts.map +1 -0
  39. package/lib/common/{gmodel → features/layout}/computed-bounds-action-handler.js +8 -3
  40. package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -0
  41. package/lib/common/features/layout/layout-operation-handler.d.ts +12 -3
  42. package/lib/common/features/layout/layout-operation-handler.d.ts.map +1 -1
  43. package/lib/common/features/layout/layout-operation-handler.js +26 -10
  44. package/lib/common/features/layout/layout-operation-handler.js.map +1 -1
  45. package/lib/common/features/model/model-state.d.ts +0 -2
  46. package/lib/common/features/model/model-state.d.ts.map +1 -1
  47. package/lib/common/features/model/model-state.js +0 -1
  48. package/lib/common/features/model/model-state.js.map +1 -1
  49. package/lib/common/features/model/model-submission-handler.d.ts +2 -0
  50. package/lib/common/features/model/model-submission-handler.d.ts.map +1 -1
  51. package/lib/common/features/model/model-submission-handler.js +7 -2
  52. package/lib/common/features/model/model-submission-handler.js.map +1 -1
  53. package/lib/common/features/model/save-model-action-handler.d.ts +2 -2
  54. package/lib/common/features/model/save-model-action-handler.d.ts.map +1 -1
  55. package/lib/common/features/model/save-model-action-handler.js +5 -5
  56. package/lib/common/features/model/save-model-action-handler.js.map +1 -1
  57. package/lib/common/gmodel/apply-label-edit-operation-handler.d.ts +4 -5
  58. package/lib/common/gmodel/apply-label-edit-operation-handler.d.ts.map +1 -1
  59. package/lib/common/gmodel/apply-label-edit-operation-handler.js +12 -21
  60. package/lib/common/gmodel/apply-label-edit-operation-handler.js.map +1 -1
  61. package/lib/common/gmodel/change-bounds-operation-handler.d.ts +9 -6
  62. package/lib/common/gmodel/change-bounds-operation-handler.d.ts.map +1 -1
  63. package/lib/common/gmodel/change-bounds-operation-handler.js +14 -14
  64. package/lib/common/gmodel/change-bounds-operation-handler.js.map +1 -1
  65. package/lib/common/gmodel/change-routing-points-operation-handler.d.ts +5 -5
  66. package/lib/common/gmodel/change-routing-points-operation-handler.d.ts.map +1 -1
  67. package/lib/common/gmodel/change-routing-points-operation-handler.js +11 -14
  68. package/lib/common/gmodel/change-routing-points-operation-handler.js.map +1 -1
  69. package/lib/common/{operations → gmodel}/cut-operation-handler.d.ts +5 -4
  70. package/lib/common/gmodel/cut-operation-handler.d.ts.map +1 -0
  71. package/lib/common/{operations → gmodel}/cut-operation-handler.js +13 -11
  72. package/lib/common/gmodel/cut-operation-handler.js.map +1 -0
  73. package/lib/common/gmodel/delete-operation-handler.d.ts +6 -6
  74. package/lib/common/gmodel/delete-operation-handler.d.ts.map +1 -1
  75. package/lib/common/gmodel/delete-operation-handler.js +13 -10
  76. package/lib/common/gmodel/delete-operation-handler.js.map +1 -1
  77. package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts +11 -7
  78. package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts.map +1 -1
  79. package/lib/common/gmodel/gmodel-create-edge-operation-handler.js +12 -13
  80. package/lib/common/gmodel/gmodel-create-edge-operation-handler.js.map +1 -1
  81. package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts +32 -5
  82. package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts.map +1 -1
  83. package/lib/common/gmodel/gmodel-create-node-operation-handler.js +45 -3
  84. package/lib/common/gmodel/gmodel-create-node-operation-handler.js.map +1 -1
  85. package/lib/common/gmodel/gmodel-diagram-module.d.ts +8 -8
  86. package/lib/common/gmodel/gmodel-diagram-module.d.ts.map +1 -1
  87. package/lib/common/gmodel/gmodel-diagram-module.js +15 -21
  88. package/lib/common/gmodel/gmodel-diagram-module.js.map +1 -1
  89. package/lib/common/gmodel/gmodel-operation-handler.d.ts +23 -0
  90. package/lib/common/gmodel/gmodel-operation-handler.d.ts.map +1 -0
  91. package/lib/common/gmodel/gmodel-operation-handler.js +43 -0
  92. package/lib/common/gmodel/gmodel-operation-handler.js.map +1 -0
  93. package/lib/common/gmodel/index.d.ts +2 -1
  94. package/lib/common/gmodel/index.d.ts.map +1 -1
  95. package/lib/common/gmodel/index.js +2 -1
  96. package/lib/common/gmodel/index.js.map +1 -1
  97. package/lib/common/gmodel/paste-operation-handler.d.ts +7 -6
  98. package/lib/common/gmodel/paste-operation-handler.d.ts.map +1 -1
  99. package/lib/common/gmodel/paste-operation-handler.js +20 -15
  100. package/lib/common/gmodel/paste-operation-handler.js.map +1 -1
  101. package/lib/common/gmodel/reconnect-edge-operation-handler.d.ts +5 -5
  102. package/lib/common/gmodel/reconnect-edge-operation-handler.d.ts.map +1 -1
  103. package/lib/common/gmodel/reconnect-edge-operation-handler.js +11 -14
  104. package/lib/common/gmodel/reconnect-edge-operation-handler.js.map +1 -1
  105. package/lib/common/index.d.ts +2 -1
  106. package/lib/common/index.d.ts.map +1 -1
  107. package/lib/common/index.js +2 -1
  108. package/lib/common/index.js.map +1 -1
  109. package/lib/common/operations/compound-operation-handler.d.ts +5 -5
  110. package/lib/common/operations/compound-operation-handler.d.ts.map +1 -1
  111. package/lib/common/operations/compound-operation-handler.js +37 -9
  112. package/lib/common/operations/compound-operation-handler.js.map +1 -1
  113. package/lib/common/operations/create-operation-handler.d.ts +8 -40
  114. package/lib/common/operations/create-operation-handler.d.ts.map +1 -1
  115. package/lib/common/operations/create-operation-handler.js +26 -85
  116. package/lib/common/operations/create-operation-handler.js.map +1 -1
  117. package/lib/common/operations/operation-action-handler.d.ts +10 -1
  118. package/lib/common/operations/operation-action-handler.d.ts.map +1 -1
  119. package/lib/common/operations/operation-action-handler.js +37 -22
  120. package/lib/common/operations/operation-action-handler.js.map +1 -1
  121. package/lib/common/operations/operation-handler-registry.d.ts +11 -2
  122. package/lib/common/operations/operation-handler-registry.d.ts.map +1 -1
  123. package/lib/common/operations/operation-handler-registry.js +31 -2
  124. package/lib/common/operations/operation-handler-registry.js.map +1 -1
  125. package/lib/common/operations/operation-handler.d.ts +28 -11
  126. package/lib/common/operations/operation-handler.d.ts.map +1 -1
  127. package/lib/common/operations/operation-handler.js +50 -1
  128. package/lib/common/operations/operation-handler.js.map +1 -1
  129. package/lib/common/test/mock-util.d.ts +7 -0
  130. package/lib/common/test/mock-util.d.ts.map +1 -1
  131. package/lib/common/test/mock-util.js +20 -37
  132. package/lib/common/test/mock-util.js.map +1 -1
  133. package/package.json +4 -3
  134. package/src/common/command/command-stack.spec.ts +239 -0
  135. package/src/common/command/command-stack.ts +99 -14
  136. package/src/common/command/command.spec.ts +93 -0
  137. package/src/common/command/command.ts +89 -4
  138. package/src/common/command/recording-command.spec.ts +74 -0
  139. package/src/common/command/recording-command.ts +119 -0
  140. package/src/common/command/undo-redo-action-handler.ts +57 -0
  141. package/src/common/di/diagram-module.ts +13 -0
  142. package/src/common/features/contextactions/tool-palette-item-provider.ts +2 -4
  143. package/src/common/{gmodel → features/layout}/computed-bounds-action-handler.ts +9 -4
  144. package/src/common/features/layout/layout-operation-handler.ts +26 -11
  145. package/src/common/features/model/model-state.ts +0 -3
  146. package/src/common/features/model/model-submission-handler.ts +6 -2
  147. package/src/common/features/model/save-model-action-handler.ts +5 -6
  148. package/src/common/gmodel/apply-label-edit-operation-handler.ts +13 -15
  149. package/src/common/gmodel/change-bounds-operation-handler.ts +12 -8
  150. package/src/common/gmodel/change-routing-points-operation-handler.ts +8 -7
  151. package/src/common/{operations → gmodel}/cut-operation-handler.ts +9 -8
  152. package/src/common/gmodel/delete-operation-handler.ts +16 -10
  153. package/src/common/gmodel/gmodel-create-edge-operation-handler.ts +16 -10
  154. package/src/common/gmodel/gmodel-create-node-operation-handler.ts +54 -6
  155. package/src/common/gmodel/gmodel-diagram-module.ts +22 -27
  156. package/src/common/gmodel/gmodel-operation-handler.ts +31 -0
  157. package/src/common/gmodel/index.ts +2 -1
  158. package/src/common/gmodel/paste-operation-handler.ts +19 -11
  159. package/src/common/gmodel/reconnect-edge-operation-handler.ts +8 -7
  160. package/src/common/index.ts +2 -1
  161. package/src/common/operations/compound-operation-handler.ts +14 -12
  162. package/src/common/operations/create-operation-handler.ts +17 -74
  163. package/src/common/operations/operation-action-handler.ts +51 -27
  164. package/src/common/operations/operation-handler-registry.ts +18 -3
  165. package/src/common/operations/operation-handler.ts +38 -13
  166. package/src/common/test/mock-util.ts +21 -36
  167. package/lib/common/gmodel/apply-label-edit-operation-handler.spec.d.ts +0 -2
  168. package/lib/common/gmodel/apply-label-edit-operation-handler.spec.d.ts.map +0 -1
  169. package/lib/common/gmodel/apply-label-edit-operation-handler.spec.js +0 -38
  170. package/lib/common/gmodel/apply-label-edit-operation-handler.spec.js.map +0 -1
  171. package/lib/common/gmodel/computed-bounds-action-handler.d.ts.map +0 -1
  172. package/lib/common/gmodel/computed-bounds-action-handler.js.map +0 -1
  173. package/lib/common/operations/cut-operation-handler.d.ts.map +0 -1
  174. package/lib/common/operations/cut-operation-handler.js.map +0 -1
  175. package/src/common/gmodel/apply-label-edit-operation-handler.spec.ts +0 -40
@@ -15,24 +15,28 @@
15
15
  ********************************************************************************/
16
16
  import { GModelRoot, GNode } from '@eclipse-glsp/graph';
17
17
  import { ChangeBoundsOperation, Dimension, MaybePromise, Point } from '@eclipse-glsp/protocol';
18
- import { inject, injectable } from 'inversify';
19
- import { ModelState } from '../features/model/model-state';
20
- import { OperationHandler } from '../operations/operation-handler';
18
+ import { injectable } from 'inversify';
19
+ import { Command } from '../command/command';
20
+ import { GModelOperationHandler } from './gmodel-operation-handler';
21
21
 
22
+ /**
23
+ * Applies {@link ChangeBoundsOperation} directly to the GModel.
24
+ */
22
25
  @injectable()
23
- export class ChangeBoundsOperationHandler implements OperationHandler {
26
+ export class GModelChangeBoundsOperationHandler extends GModelOperationHandler {
24
27
  operationType = ChangeBoundsOperation.KIND;
25
28
 
26
- @inject(ModelState)
27
- protected modelState: ModelState;
29
+ createCommand(operation: ChangeBoundsOperation): MaybePromise<Command | undefined> {
30
+ return this.commandOf(() => this.executeChangeBounds(operation));
31
+ }
28
32
 
29
- execute(operation: ChangeBoundsOperation): MaybePromise<void> {
33
+ protected executeChangeBounds(operation: ChangeBoundsOperation): void {
30
34
  for (const element of operation.newBounds) {
31
35
  this.changeElementBounds(element.elementId, element.newSize, element.newPosition);
32
36
  }
33
37
  }
34
38
 
35
- changeElementBounds(elementId: string, newSize: Dimension, newPosition: Point | undefined): void {
39
+ protected changeElementBounds(elementId: string, newSize: Dimension, newPosition: Point | undefined): void {
36
40
  const index = this.modelState.index;
37
41
  const nodeToUpdate = index.findByClass(elementId, GNode);
38
42
  if (!nodeToUpdate) {
@@ -15,20 +15,21 @@
15
15
  ********************************************************************************/
16
16
 
17
17
  import { ChangeRoutingPointsOperation, MaybePromise } from '@eclipse-glsp/protocol';
18
- import { inject, injectable } from 'inversify';
19
- import { ModelState } from '../features/model/model-state';
20
- import { OperationHandler } from '../operations/operation-handler';
18
+ import { injectable } from 'inversify';
19
+ import { Command } from '../command/command';
21
20
  import { GLSPServerError } from '../utils/glsp-server-error';
22
21
  import { applyRoutingPoints } from '../utils/layout-util';
22
+ import { GModelOperationHandler } from './gmodel-operation-handler';
23
23
 
24
24
  @injectable()
25
- export class ChangeRoutingPointsOperationHandler implements OperationHandler {
25
+ export class GModelChangeRoutingPointsOperationHandler extends GModelOperationHandler {
26
26
  operationType = ChangeRoutingPointsOperation.KIND;
27
27
 
28
- @inject(ModelState)
29
- protected modelState: ModelState;
28
+ createCommand(operation: ChangeRoutingPointsOperation): MaybePromise<Command | undefined> {
29
+ return this.commandOf(() => this.executeChangeRoutingPoints(operation));
30
+ }
30
31
 
31
- execute(operation: ChangeRoutingPointsOperation): MaybePromise<void> {
32
+ executeChangeRoutingPoints(operation: ChangeRoutingPointsOperation): MaybePromise<void> {
32
33
  if (!operation.newRoutingPoints) {
33
34
  throw new GLSPServerError('Incomplete change routingPoints action');
34
35
  }
@@ -16,20 +16,21 @@
16
16
  import { CutOperation, DeleteElementOperation, MaybePromise } from '@eclipse-glsp/protocol';
17
17
  import { inject, injectable } from 'inversify';
18
18
  import { ActionDispatcher } from '../actions/action-dispatcher';
19
- import { OperationHandler } from './operation-handler';
19
+ import { Command } from '../command/command';
20
+ import { GModelOperationHandler } from './gmodel-operation-handler';
20
21
 
21
22
  @injectable()
22
- export class CutOperationHandler implements OperationHandler {
23
- operationType = CutOperation.KIND;
23
+ export class GModelCutOperationHandler extends GModelOperationHandler {
24
+ readonly operationType = CutOperation.KIND;
24
25
 
25
26
  @inject(ActionDispatcher)
26
27
  protected actionDispatcher: ActionDispatcher;
27
28
 
28
- execute(operation: CutOperation): MaybePromise<void> {
29
- const cutableElementIds = this.getElementToCut(operation);
30
- if (cutableElementIds.length > 0) {
31
- this.actionDispatcher.dispatch(DeleteElementOperation.create(cutableElementIds));
32
- }
29
+ createCommand(operation: CutOperation): MaybePromise<Command | undefined> {
30
+ const cuttableElementIds = this.getElementToCut(operation);
31
+ return cuttableElementIds.length > 0 //
32
+ ? this.commandOf(() => this.actionDispatcher.dispatch(DeleteElementOperation.create(cuttableElementIds)))
33
+ : undefined;
33
34
  }
34
35
 
35
36
  protected getElementToCut(cutOperation: CutOperation): string[] {
@@ -16,32 +16,38 @@
16
16
  import { GEdge, GModelElement, GNode } from '@eclipse-glsp/graph';
17
17
  import { DeleteElementOperation, MaybePromise } from '@eclipse-glsp/protocol';
18
18
  import { inject, injectable } from 'inversify';
19
+ import { Command } from '../command/command';
19
20
  import { GModelIndex } from '../features/model/gmodel-index';
20
- import { ModelState } from '../features/model/model-state';
21
- import { OperationHandler } from '../operations/operation-handler';
22
21
  import { Logger } from '../utils/logger';
22
+ import { GModelOperationHandler } from './gmodel-operation-handler';
23
23
 
24
24
  @injectable()
25
- export class GModelDeleteOperationHandler implements OperationHandler {
25
+ export class GModelDeleteOperationHandler extends GModelOperationHandler {
26
26
  @inject(Logger)
27
27
  protected logger: Logger;
28
28
 
29
- protected allDependantsIds: Set<string>;
30
-
31
- @inject(ModelState) protected readonly modelState: ModelState;
29
+ protected allDependentsIds: Set<string>;
32
30
 
33
31
  get operationType(): string {
34
32
  return DeleteElementOperation.KIND;
35
33
  }
36
34
 
37
- execute(operation: DeleteElementOperation): MaybePromise<void> {
35
+ createCommand(operation: DeleteElementOperation): MaybePromise<Command | undefined> {
38
36
  const elementIds = operation.elementIds;
37
+ if (!elementIds || elementIds.length === 0) {
38
+ this.logger.warn('Elements to delete are not specified');
39
+ return undefined;
40
+ }
41
+ return this.commandOf(() => this.deleteElements(elementIds));
42
+ }
43
+
44
+ deleteElements(elementIds: string[]): MaybePromise<void> {
39
45
  if (!elementIds || elementIds.length === 0) {
40
46
  this.logger.warn('Elements to delete are not specified');
41
47
  return;
42
48
  }
43
49
  const index = this.modelState.index;
44
- this.allDependantsIds = new Set<string>();
50
+ this.allDependentsIds = new Set<string>();
45
51
  const success = elementIds.every(eId => this.delete(eId, index));
46
52
  if (!success) {
47
53
  this.logger.warn('Could not delete all elements as requested (see messages above to find out why)');
@@ -49,7 +55,7 @@ export class GModelDeleteOperationHandler implements OperationHandler {
49
55
  }
50
56
 
51
57
  protected delete(elementId: string, index: GModelIndex): boolean {
52
- if (this.allDependantsIds.has(elementId)) {
58
+ if (this.allDependentsIds.has(elementId)) {
53
59
  return true;
54
60
  }
55
61
 
@@ -73,7 +79,7 @@ export class GModelDeleteOperationHandler implements OperationHandler {
73
79
  if (index > -1) {
74
80
  this.modelState.root.children.splice(index, 1);
75
81
  }
76
- this.allDependantsIds.add(dependant.id);
82
+ this.allDependentsIds.add(dependant.id);
77
83
  });
78
84
 
79
85
  return true;
@@ -16,10 +16,11 @@
16
16
 
17
17
  import { GEdge, GModelElement, GPort } from '@eclipse-glsp/graph';
18
18
  import { GNode } from '@eclipse-glsp/graph/lib/gnode';
19
- import { CreateEdgeOperation } from '@eclipse-glsp/protocol';
20
- import { inject, injectable } from 'inversify';
21
- import { ModelState } from '../features/model/model-state';
22
- import { CreateOperationHandler } from '../operations/create-operation-handler';
19
+ import { CreateEdgeOperation, MaybePromise, TriggerEdgeCreationAction } from '@eclipse-glsp/protocol';
20
+ import { injectable } from 'inversify';
21
+ import { Command } from '../command/command';
22
+ import { CreateOperationHandler, CreateOperationKind } from '../operations/create-operation-handler';
23
+ import { GModelOperationHandler } from './gmodel-operation-handler';
23
24
 
24
25
  /**
25
26
  * An abstract base implementation of {@link CreateEdgeOperation} handlers for diagram implementations
@@ -27,15 +28,20 @@ import { CreateOperationHandler } from '../operations/create-operation-handler';
27
28
  * (i.e. all operation handlers directly modify the graphical model).
28
29
  */
29
30
  @injectable()
30
- export abstract class GModelCreateEdgeOperationHandler extends CreateOperationHandler {
31
- @inject(ModelState)
32
- protected modelState: ModelState;
31
+ export abstract class GModelCreateEdgeOperationHandler extends GModelOperationHandler implements CreateOperationHandler {
32
+ override readonly operationType: CreateOperationKind = CreateEdgeOperation.KIND;
33
+ abstract override label: string;
34
+ abstract elementTypeIds: string[];
33
35
 
34
- get operationType(): string {
35
- return CreateEdgeOperation.KIND;
36
+ override createCommand(operation: CreateEdgeOperation): MaybePromise<Command | undefined> {
37
+ return this.commandOf(() => this.executeCreation(operation));
36
38
  }
37
39
 
38
- execute(operation: CreateEdgeOperation): void {
40
+ getTriggerActions(): TriggerEdgeCreationAction[] {
41
+ return this.elementTypeIds.map(typeId => TriggerEdgeCreationAction.create(typeId));
42
+ }
43
+
44
+ executeCreation(operation: CreateEdgeOperation): void {
39
45
  const index = this.modelState.index;
40
46
 
41
47
  const source = index.find(operation.sourceElementId, element => element instanceof GNode || element instanceof GPort);
@@ -14,11 +14,14 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
 
17
- import { GNode } from '@eclipse-glsp/graph';
18
- import { CreateNodeOperation, Point, SelectAction } from '@eclipse-glsp/protocol';
17
+ import { GModelElement, GNode } from '@eclipse-glsp/graph';
18
+ import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCreationAction } from '@eclipse-glsp/protocol';
19
19
  import { inject, injectable } from 'inversify';
20
20
  import { ActionDispatcher } from '../actions/action-dispatcher';
21
- import { CreateNodeOperationHandler } from '../operations/create-operation-handler';
21
+ import { Command } from '../command/command';
22
+ import { CreateOperationHandler, CreateOperationKind } from '../operations/create-operation-handler';
23
+ import { getRelativeLocation } from '../utils/layout-util';
24
+ import { GModelOperationHandler } from './gmodel-operation-handler';
22
25
 
23
26
  /**
24
27
  * An abstract base implementation of {@link CreateNodeOperationHandler} for diagram implementations
@@ -26,13 +29,21 @@ import { CreateNodeOperationHandler } from '../operations/create-operation-handl
26
29
  * (i.e. all operation handlers directly modify the graphical model).
27
30
  */
28
31
  @injectable()
29
- export abstract class GModelCreateNodeOperationHandler extends CreateNodeOperationHandler {
32
+ export abstract class GModelCreateNodeOperationHandler extends GModelOperationHandler implements CreateOperationHandler {
30
33
  @inject(ActionDispatcher)
31
34
  protected actionDispatcher: ActionDispatcher;
32
35
 
33
- abstract override elementTypeIds: string[];
36
+ abstract elementTypeIds: string[];
34
37
 
35
- execute(operation: CreateNodeOperation): void {
38
+ abstract override label: string;
39
+
40
+ override operationType: CreateOperationKind = CreateNodeOperation.KIND;
41
+
42
+ override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined> {
43
+ return this.commandOf(() => this.executeCreation(operation));
44
+ }
45
+
46
+ executeCreation(operation: CreateNodeOperation): void {
36
47
  const container = this.getContainer(operation) ?? this.modelState.root;
37
48
  const relativeLocation = this.getRelativeLocation(operation);
38
49
  const element = this.createNode(operation, relativeLocation);
@@ -43,5 +54,42 @@ export abstract class GModelCreateNodeOperationHandler extends CreateNodeOperati
43
54
  }
44
55
  }
45
56
 
57
+ getTriggerActions(): TriggerNodeCreationAction[] {
58
+ return this.elementTypeIds.map(typeId => TriggerNodeCreationAction.create(typeId));
59
+ }
60
+
61
+ /**
62
+ * Return the GModelElement that will contain the newly created node. It is usually
63
+ * the target element ({@link CreateNodeOperation.containerId}), but could also
64
+ * be e.g. an intermediate compartment, or even a different Node.
65
+ *
66
+ * @param operation
67
+ * @return the GModelElement that will contain the newly created node.
68
+ */
69
+ getContainer(operation: CreateNodeOperation): GModelElement | undefined {
70
+ const index = this.modelState.index;
71
+ return operation.containerId ? index.get(operation.containerId) : undefined;
72
+ }
73
+
74
+ getLocation(operation: CreateNodeOperation): Point | undefined {
75
+ return operation.location;
76
+ }
77
+
78
+ /**
79
+ * Retrieves the diagram absolute location and the target container from the given {@link CreateNodeOperation}
80
+ * and converts the absolute location to coordinates relative to the given container.
81
+ * Relative coordinates can only be retrieved if the given container element is part of
82
+ * a hierarchy of {@link GBoundsAware} elements. This means each (recursive) parent element need to
83
+ * implement {@link GBoundsAware}. If that is not the case this method returns `undefined`.
84
+ * @param absoluteLocation The diagram absolute position.
85
+ * @param container The container element.
86
+ * @returns The relative position or `undefined`.
87
+ */
88
+ getRelativeLocation(operation: CreateNodeOperation): Point | undefined {
89
+ const container = this.getContainer(operation) ?? this.modelState.root;
90
+ const absoluteLocation = this.getLocation(operation) ?? Point.ORIGIN;
91
+ return getRelativeLocation(absoluteLocation, container);
92
+ }
93
+
46
94
  abstract createNode(operation: CreateNodeOperation, relativeLocation?: Point): GNode | undefined;
47
95
  }
@@ -19,19 +19,17 @@ import { BindingTarget } from '../di/binding-target';
19
19
  import { DiagramModule } from '../di/diagram-module';
20
20
  import { InstanceMultiBinding } from '../di/multi-binding';
21
21
  import { RequestClipboardDataActionHandler } from '../features/clipboard/request-clipboard-data-action-handler';
22
- import { LayoutOperationHandler } from '../features/layout/layout-operation-handler';
23
22
  import { GModelFactory, GModelFactoryNullImpl } from '../features/model/gmodel-factory';
24
23
  import { DefaultModelState, ModelState } from '../features/model/model-state';
25
- import { SaveModelActionHandler } from '../features/model/save-model-action-handler';
26
- import { CutOperationHandler } from '../operations/cut-operation-handler';
27
- import { OperationHandlerConstructor } from '../operations/operation-handler';
28
- import { ApplyLabelEditOperationHandler } from './apply-label-edit-operation-handler';
29
- import { ChangeBoundsOperationHandler } from './change-bounds-operation-handler';
30
- import { ChangeRoutingPointsOperationHandler } from './change-routing-points-operation-handler';
31
- import { ComputedBoundsActionHandler } from './computed-bounds-action-handler';
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ import { OperationHandler, OperationHandlerConstructor } from '../operations/operation-handler';
26
+ import { GModelApplyLabelEditOperationHandler } from './apply-label-edit-operation-handler';
27
+ import { GModelChangeBoundsOperationHandler } from './change-bounds-operation-handler';
28
+ import { GModelChangeRoutingPointsOperationHandler } from './change-routing-points-operation-handler';
29
+ import { GModelCutOperationHandler } from './cut-operation-handler';
32
30
  import { GModelDeleteOperationHandler } from './delete-operation-handler';
33
- import { PasteOperationHandler } from './paste-operation-handler';
34
- import { ReconnectEdgeOperationHandler } from './reconnect-edge-operation-handler';
31
+ import { GModelPasteOperationHandler } from './paste-operation-handler';
32
+ import { GModelReconnectEdgeOperationHandler } from './reconnect-edge-operation-handler';
35
33
 
36
34
  /**
37
35
  * Extension of the {@link DiagramModule} to provide GModel integration.
@@ -39,16 +37,16 @@ import { ReconnectEdgeOperationHandler } from './reconnect-edge-operation-handle
39
37
  * Contains all bindings of {@link DiagramModule}.
40
38
  *
41
39
  * Additionally binds:
42
- * - {@link CommandStack} to {@link DefaultCommandStack}
43
- * - {@link ModelState} to {@link ModelState}
44
40
  * - {@link GModelFactory} to {@link GModelFactoryNullImpl}
45
- * - {@link GModelIndex} to self
46
- * - {@link ComputedBoundsActionHandler} to {@link ActionHandler}
47
41
  * - {@link RequestClipboardDataActionHandler} to {@link ActionHandler}
48
- * - {@link ApplyLabelEditOperationHandler} to {@link OperationHandler}
49
- * - {@link ChangeBoundsOperationHandler} to {@link OperationHandler}
50
- * - {@link CutOperationHandler} to {@link OperationHandler}
51
- * - {@link PasteOperationHandler} to {@link OperationHandler}
42
+ * - {@link GModelApplyLabelEditOperationHandler} to {@link OperationHandler}
43
+ * - {@link GModelChangeBoundsOperationHandler} to {@link OperationHandler}
44
+ * - {@link GModelCutOperationHandler} to {@link OperationHandler}
45
+ * - {@link GModelDeleteOperationHandler} to {@link OperationHandler}
46
+ * - {@link GModelPasteOperationHandler} to {@link OperationHandler}
47
+ * - {@link GModelReconnectEdgeOperationHandler} to {@link OperationHandler}
48
+ * - {@link GModelChangeRoutingPointsOperationHandler} to {@link OperationHandler}
49
+
52
50
  */
53
51
  @injectable()
54
52
  export abstract class GModelDiagramModule extends DiagramModule {
@@ -62,20 +60,17 @@ export abstract class GModelDiagramModule extends DiagramModule {
62
60
 
63
61
  protected override configureActionHandlers(binding: InstanceMultiBinding<ActionHandlerConstructor>): void {
64
62
  super.configureActionHandlers(binding);
65
- binding.add(ComputedBoundsActionHandler);
66
- binding.add(SaveModelActionHandler);
67
63
  binding.add(RequestClipboardDataActionHandler);
68
64
  }
69
65
 
70
66
  protected override configureOperationHandlers(binding: InstanceMultiBinding<OperationHandlerConstructor>): void {
71
67
  super.configureOperationHandlers(binding);
72
- binding.add(ApplyLabelEditOperationHandler);
73
- binding.add(ChangeBoundsOperationHandler);
74
- binding.add(CutOperationHandler);
68
+ binding.add(GModelApplyLabelEditOperationHandler);
69
+ binding.add(GModelChangeBoundsOperationHandler);
70
+ binding.add(GModelCutOperationHandler);
75
71
  binding.add(GModelDeleteOperationHandler);
76
- binding.add(PasteOperationHandler);
77
- binding.add(ReconnectEdgeOperationHandler);
78
- binding.add(LayoutOperationHandler);
79
- binding.add(ChangeRoutingPointsOperationHandler);
72
+ binding.add(GModelPasteOperationHandler);
73
+ binding.add(GModelReconnectEdgeOperationHandler);
74
+ binding.add(GModelChangeRoutingPointsOperationHandler);
80
75
  }
81
76
  }
@@ -0,0 +1,31 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022-2023 EclipseSource 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
+
17
+ import { inject, injectable } from 'inversify';
18
+ import { Command } from '../command/command';
19
+ import { GModelRecordingCommand } from '../command/recording-command';
20
+ import { GModelSerializer } from '../features/model/gmodel-serializer';
21
+ import { OperationHandler } from '../operations/operation-handler';
22
+
23
+ injectable();
24
+ export abstract class GModelOperationHandler extends OperationHandler {
25
+ @inject(GModelSerializer)
26
+ protected serializer: GModelSerializer;
27
+
28
+ protected commandOf(runnable: () => void): Command {
29
+ return new GModelRecordingCommand(this.modelState, this.serializer, runnable);
30
+ }
31
+ }
@@ -17,10 +17,11 @@
17
17
  export * from './apply-label-edit-operation-handler';
18
18
  export * from './change-bounds-operation-handler';
19
19
  export * from './change-routing-points-operation-handler';
20
- export * from './computed-bounds-action-handler';
20
+ export * from './cut-operation-handler';
21
21
  export * from './delete-operation-handler';
22
22
  export * from './gmodel-create-edge-operation-handler';
23
23
  export * from './gmodel-create-node-operation-handler';
24
24
  export * from './gmodel-diagram-module';
25
+ export * from './gmodel-operation-handler';
25
26
  export * from './paste-operation-handler';
26
27
  export * from './reconnect-edge-operation-handler';
@@ -14,29 +14,37 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
  import { GBoundsAware, GEdge, GModelElement, isGBoundsAware } from '@eclipse-glsp/graph';
17
- import { MaybePromise, PasteOperation, Point, SModelElementSchema } from '@eclipse-glsp/protocol';
17
+ import { EditorContext, MaybePromise, PasteOperation, Point, SModelElementSchema } from '@eclipse-glsp/protocol';
18
18
  import { inject, injectable } from 'inversify';
19
19
  import * as uuid from 'uuid';
20
+ import { Command } from '../command/command';
20
21
  import { GModelSerializer } from '../features/model/gmodel-serializer';
21
- import { ModelState } from '../features/model/model-state';
22
- import { OperationHandler } from '../operations/operation-handler';
22
+ import { GModelOperationHandler } from './gmodel-operation-handler';
23
23
 
24
24
  @injectable()
25
- export class PasteOperationHandler implements OperationHandler {
25
+ export class GModelPasteOperationHandler extends GModelOperationHandler {
26
26
  operationType = PasteOperation.KIND;
27
27
 
28
28
  protected readonly DEFAULT_OFFSET = 20;
29
29
 
30
- @inject(ModelState)
31
- protected modelState: ModelState;
32
-
33
30
  @inject(GModelSerializer)
34
31
  protected modelSerializer: GModelSerializer;
35
32
 
36
- execute(operation: PasteOperation): MaybePromise<void> {
37
- const schemas: SModelElementSchema[] = JSON.parse(operation.clipboardData['application/json']);
38
- const elements = schemas.map(schema => this.modelSerializer.createElement(schema, this.modelState.root));
39
- shift(elements, this.computeOffset(elements, operation.editorContext.lastMousePosition));
33
+ createCommand(operation: PasteOperation): MaybePromise<Command | undefined> {
34
+ const elements = this.getCopiedElements(operation.clipboardData['application/json']);
35
+ return elements.length > 0 //
36
+ ? this.commandOf(() => this.executePaste(elements, operation.editorContext))
37
+ : undefined;
38
+ }
39
+
40
+ protected getCopiedElements(jsonString: string): GModelElement[] {
41
+ const schemas: SModelElementSchema[] = JSON.parse(jsonString);
42
+ return schemas.map(schema => this.modelSerializer.createElement(schema, this.modelState.root));
43
+ }
44
+
45
+ protected executePaste(elements: GModelElement[], context: EditorContext): MaybePromise<void> {
46
+ shift(elements, this.computeOffset(elements, context.lastMousePosition));
47
+
40
48
  const idMap = this.reassignIds(elements);
41
49
  this.filterElements(elements, idMap);
42
50
  this.rewireEdges(elements, idMap);
@@ -15,19 +15,20 @@
15
15
  ********************************************************************************/
16
16
  import { GEdge, GNode, GPort } from '@eclipse-glsp/graph';
17
17
  import { MaybePromise, ReconnectEdgeOperation } from '@eclipse-glsp/protocol';
18
- import { inject, injectable } from 'inversify';
19
- import { ModelState } from '../features/model/model-state';
20
- import { OperationHandler } from '../operations/operation-handler';
18
+ import { injectable } from 'inversify';
19
+ import { Command } from '../command/command';
21
20
  import { GLSPServerError } from '../utils/glsp-server-error';
21
+ import { GModelOperationHandler } from './gmodel-operation-handler';
22
22
 
23
23
  @injectable()
24
- export class ReconnectEdgeOperationHandler implements OperationHandler {
24
+ export class GModelReconnectEdgeOperationHandler extends GModelOperationHandler {
25
25
  operationType = ReconnectEdgeOperation.KIND;
26
26
 
27
- @inject(ModelState)
28
- protected readonly modelState: ModelState;
27
+ createCommand(operation: ReconnectEdgeOperation): MaybePromise<Command | undefined> {
28
+ return this.commandOf(() => this.executeReconnect(operation));
29
+ }
29
30
 
30
- execute(operation: ReconnectEdgeOperation): MaybePromise<void> {
31
+ executeReconnect(operation: ReconnectEdgeOperation): MaybePromise<void> {
31
32
  if (!operation.edgeElementId || !operation.sourceElementId || !operation.targetElementId) {
32
33
  throw new GLSPServerError('Incomplete reconnect connection action');
33
34
  }
@@ -43,6 +43,7 @@ export * from './features/directediting/context-edit-validator';
43
43
  export * from './features/directediting/context-edit-validator-registry';
44
44
  export * from './features/directediting/label-edit-validator';
45
45
  export * from './features/directediting/request-edit-validation-handler';
46
+ export * from './features/layout/computed-bounds-action-handler';
46
47
  export * from './features/layout/layout-engine';
47
48
  export * from './features/layout/layout-operation-handler';
48
49
  export * from './features/model/gmodel-factory';
@@ -64,11 +65,11 @@ export * from './features/popup/popup-model-factory';
64
65
  export * from './features/popup/request-popup-model-action-handler';
65
66
  export * from './features/validation/model-validator';
66
67
  export * from './features/validation/request-markers-handler';
68
+ export * from './gmodel/cut-operation-handler';
67
69
  export * from './gmodel/index';
68
70
  export * from './launch/glsp-server-launcher';
69
71
  export * from './operations/compound-operation-handler';
70
72
  export * from './operations/create-operation-handler';
71
- export * from './operations/cut-operation-handler';
72
73
  export * from './operations/operation-action-handler';
73
74
  export * from './operations/operation-handler';
74
75
  export * from './operations/operation-handler-registry';
@@ -13,26 +13,28 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { CompoundOperation, MaybePromise, Operation } from '@eclipse-glsp/protocol';
16
+ import { CompoundOperation } from '@eclipse-glsp/protocol';
17
17
  import { inject, injectable } from 'inversify';
18
- import { OperationActionHandler } from './operation-action-handler';
18
+ import { Command, CompoundCommand } from '../command/command';
19
19
  import { OperationHandler } from './operation-handler';
20
20
  import { OperationHandlerRegistry } from './operation-handler-registry';
21
21
 
22
22
  @injectable()
23
- export class CompoundOperationHandler implements OperationHandler {
24
- operationType = CompoundOperation.KIND;
23
+ export class CompoundOperationHandler extends OperationHandler {
24
+ @inject(OperationHandlerRegistry)
25
+ protected operationHandlerRegistry: OperationHandlerRegistry;
25
26
 
26
- @inject(OperationHandlerRegistry) protected operationHandlerRegistry: OperationHandlerRegistry;
27
+ operationType = CompoundOperation.KIND;
27
28
 
28
- execute(operation: CompoundOperation): void {
29
- operation.operationList.forEach(nestedOperation => this.executeNestedOperation(nestedOperation));
30
- }
29
+ async createCommand(operation: CompoundOperation): Promise<Command | undefined> {
30
+ const maybeCommands = operation.operationList.map(op => this.operationHandlerRegistry.getExecutableCommand(op));
31
+ const commands: Command[] = [];
31
32
 
32
- executeNestedOperation(operation: Operation): MaybePromise<void> {
33
- const operationHandler = OperationActionHandler.getOperationHandler(operation, this.operationHandlerRegistry);
34
- if (operationHandler) {
35
- operationHandler.execute(operation);
33
+ for await (const command of maybeCommands) {
34
+ if (command) {
35
+ commands.push(command);
36
+ }
36
37
  }
38
+ return new CompoundCommand(commands);
37
39
  }
38
40
  }