@eclipse-glsp/server 1.1.0-next.f0fc2cf.63 → 2.0.0
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.
- package/lib/browser/launch/worker-server-launcher.js +2 -1
- package/lib/browser/launch/worker-server-launcher.js.map +1 -1
- package/lib/common/actions/action-dispatcher.d.ts +2 -1
- package/lib/common/actions/action-dispatcher.d.ts.map +1 -1
- package/lib/common/actions/action-dispatcher.js +9 -6
- package/lib/common/actions/action-dispatcher.js.map +1 -1
- package/lib/common/actions/action-handler-registry.js +4 -2
- package/lib/common/actions/action-handler-registry.js.map +1 -1
- package/lib/common/actions/client-action-handler.d.ts +17 -8
- package/lib/common/actions/client-action-handler.d.ts.map +1 -1
- package/lib/common/actions/client-action-handler.js +32 -21
- package/lib/common/actions/client-action-handler.js.map +1 -1
- package/lib/common/actions/global-action-provider.d.ts +6 -21
- package/lib/common/actions/global-action-provider.d.ts.map +1 -1
- package/lib/common/actions/global-action-provider.js +17 -21
- package/lib/common/actions/global-action-provider.js.map +1 -1
- package/lib/common/command/command-stack.js +2 -1
- package/lib/common/command/command-stack.js.map +1 -1
- package/lib/common/command/recording-command.d.ts +9 -15
- package/lib/common/command/recording-command.d.ts.map +1 -1
- package/lib/common/command/recording-command.js +12 -26
- package/lib/common/command/recording-command.js.map +1 -1
- package/lib/common/command/undo-redo-action-handler.js +2 -1
- package/lib/common/command/undo-redo-action-handler.js.map +1 -1
- package/lib/common/di/client-session-module.d.ts +9 -1
- package/lib/common/di/client-session-module.d.ts.map +1 -1
- package/lib/common/di/client-session-module.js +9 -9
- package/lib/common/di/client-session-module.js.map +1 -1
- package/lib/common/di/diagram-module.d.ts +20 -1
- package/lib/common/di/diagram-module.d.ts.map +1 -1
- package/lib/common/di/diagram-module.js +17 -56
- package/lib/common/di/diagram-module.js.map +1 -1
- package/lib/common/di/glsp-module.js +2 -1
- package/lib/common/di/glsp-module.js.map +1 -1
- package/lib/common/di/server-module.d.ts +0 -1
- package/lib/common/di/server-module.d.ts.map +1 -1
- package/lib/common/di/server-module.js +0 -1
- package/lib/common/di/server-module.js.map +1 -1
- package/lib/common/features/clipboard/request-clipboard-data-action-handler.d.ts.map +1 -1
- package/lib/common/features/clipboard/request-clipboard-data-action-handler.js +2 -1
- package/lib/common/features/clipboard/request-clipboard-data-action-handler.js.map +1 -1
- package/lib/common/features/contextactions/command-palette-action-provider.js +2 -1
- package/lib/common/features/contextactions/command-palette-action-provider.js.map +1 -1
- package/lib/common/features/contextactions/context-actions-provider-registry.js +2 -1
- package/lib/common/features/contextactions/context-actions-provider-registry.js.map +1 -1
- package/lib/common/features/contextactions/context-menu-item-provider.js +2 -1
- package/lib/common/features/contextactions/context-menu-item-provider.js.map +1 -1
- package/lib/common/features/contextactions/request-context-actions-handler.js +2 -1
- package/lib/common/features/contextactions/request-context-actions-handler.js.map +1 -1
- package/lib/common/features/contextactions/tool-palette-item-provider.js +4 -2
- package/lib/common/features/contextactions/tool-palette-item-provider.js.map +1 -1
- package/lib/common/features/directediting/context-edit-validator-registry.js +2 -1
- package/lib/common/features/directediting/context-edit-validator-registry.js.map +1 -1
- package/lib/common/features/directediting/label-edit-validator.js +2 -1
- package/lib/common/features/directediting/label-edit-validator.js.map +1 -1
- package/lib/common/features/directediting/request-edit-validation-handler.js +2 -1
- package/lib/common/features/directediting/request-edit-validation-handler.js.map +1 -1
- package/lib/common/features/layout/computed-bounds-action-handler.js +2 -1
- package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -1
- package/lib/common/features/layout/layout-operation-handler.js +2 -1
- package/lib/common/features/layout/layout-operation-handler.js.map +1 -1
- package/lib/common/features/model/gmodel-factory.js +2 -1
- package/lib/common/features/model/gmodel-factory.js.map +1 -1
- package/lib/common/features/model/gmodel-index.js +2 -1
- package/lib/common/features/model/gmodel-index.js.map +1 -1
- package/lib/common/features/model/gmodel-serializer.d.ts +10 -10
- package/lib/common/features/model/gmodel-serializer.d.ts.map +1 -1
- package/lib/common/features/model/gmodel-serializer.js +2 -1
- package/lib/common/features/model/gmodel-serializer.js.map +1 -1
- package/lib/common/features/model/model-state.d.ts.map +1 -1
- package/lib/common/features/model/model-state.js +5 -1
- package/lib/common/features/model/model-state.js.map +1 -1
- package/lib/common/features/model/model-submission-handler.d.ts +28 -3
- package/lib/common/features/model/model-submission-handler.d.ts.map +1 -1
- package/lib/common/features/model/model-submission-handler.js +63 -8
- package/lib/common/features/model/model-submission-handler.js.map +1 -1
- package/lib/common/features/model/request-model-action-handler.d.ts.map +1 -1
- package/lib/common/features/model/request-model-action-handler.js +5 -4
- package/lib/common/features/model/request-model-action-handler.js.map +1 -1
- package/lib/common/features/model/save-model-action-handler.js +2 -1
- package/lib/common/features/model/save-model-action-handler.js.map +1 -1
- package/lib/common/features/navigation/navigation-target-provider-registry.js +2 -1
- package/lib/common/features/navigation/navigation-target-provider-registry.js.map +1 -1
- package/lib/common/features/navigation/navigation-target-resolver.js +2 -1
- package/lib/common/features/navigation/navigation-target-resolver.js.map +1 -1
- package/lib/common/features/navigation/request-navigation-targets-action-handler.js +2 -1
- package/lib/common/features/navigation/request-navigation-targets-action-handler.js.map +1 -1
- package/lib/common/features/navigation/resolve-navigation-targets-action-handler.js +2 -1
- package/lib/common/features/navigation/resolve-navigation-targets-action-handler.js.map +1 -1
- package/lib/common/features/popup/request-popup-model-action-handler.js +2 -1
- package/lib/common/features/popup/request-popup-model-action-handler.js.map +1 -1
- package/lib/common/features/progress/progress-service.js +2 -1
- package/lib/common/features/progress/progress-service.js.map +1 -1
- package/lib/common/features/type-hints/edge-creation-checker.d.ts +42 -0
- package/lib/common/features/type-hints/edge-creation-checker.d.ts.map +1 -0
- package/lib/common/features/type-hints/edge-creation-checker.js +20 -0
- package/lib/common/features/type-hints/edge-creation-checker.js.map +1 -0
- package/lib/common/features/type-hints/request-check-edge-action-handler.d.ts +29 -0
- package/lib/common/features/type-hints/request-check-edge-action-handler.d.ts.map +1 -0
- package/lib/common/features/type-hints/request-check-edge-action-handler.js +72 -0
- package/lib/common/features/type-hints/request-check-edge-action-handler.js.map +1 -0
- package/lib/common/{diagram → features/type-hints}/request-type-hints-action-handler.d.ts +2 -3
- package/lib/common/features/type-hints/request-type-hints-action-handler.d.ts.map +1 -0
- package/lib/common/{diagram → features/type-hints}/request-type-hints-action-handler.js +3 -3
- package/lib/common/features/type-hints/request-type-hints-action-handler.js.map +1 -0
- package/lib/common/features/validation/model-validator.js +2 -1
- package/lib/common/features/validation/model-validator.js.map +1 -1
- package/lib/common/features/validation/request-markers-handler.js +2 -1
- package/lib/common/features/validation/request-markers-handler.js.map +1 -1
- package/lib/common/gmodel/apply-label-edit-operation-handler.js +2 -1
- package/lib/common/gmodel/apply-label-edit-operation-handler.js.map +1 -1
- package/lib/common/gmodel/change-bounds-operation-handler.js +2 -1
- package/lib/common/gmodel/change-bounds-operation-handler.js.map +1 -1
- package/lib/common/gmodel/change-routing-points-operation-handler.js +2 -1
- package/lib/common/gmodel/change-routing-points-operation-handler.js.map +1 -1
- package/lib/common/gmodel/cut-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/cut-operation-handler.js +7 -4
- package/lib/common/gmodel/cut-operation-handler.js.map +1 -1
- package/lib/common/gmodel/delete-operation-handler.d.ts +1 -1
- package/lib/common/gmodel/delete-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/delete-operation-handler.js +7 -6
- package/lib/common/gmodel/delete-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts +3 -3
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.js +2 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts +3 -3
- package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js +2 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-diagram-module.js +2 -1
- package/lib/common/gmodel/gmodel-diagram-module.js.map +1 -1
- package/lib/common/gmodel/paste-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/paste-operation-handler.js +2 -1
- package/lib/common/gmodel/paste-operation-handler.js.map +1 -1
- package/lib/common/gmodel/reconnect-edge-operation-handler.js +2 -1
- package/lib/common/gmodel/reconnect-edge-operation-handler.js.map +1 -1
- package/lib/common/index.d.ts +3 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +3 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/launch/glsp-server-launcher.js +2 -1
- package/lib/common/launch/glsp-server-launcher.js.map +1 -1
- package/lib/common/launch/jsonrpc-server-launcher.js +2 -1
- package/lib/common/launch/jsonrpc-server-launcher.js.map +1 -1
- package/lib/common/operations/compound-operation-handler.d.ts +5 -0
- package/lib/common/operations/compound-operation-handler.d.ts.map +1 -1
- package/lib/common/operations/compound-operation-handler.js +8 -2
- package/lib/common/operations/compound-operation-handler.js.map +1 -1
- package/lib/common/operations/create-operation-handler.d.ts +19 -5
- package/lib/common/operations/create-operation-handler.d.ts.map +1 -1
- package/lib/common/operations/create-operation-handler.js +2 -1
- package/lib/common/operations/create-operation-handler.js.map +1 -1
- package/lib/common/operations/json-operation-handler.d.ts +94 -0
- package/lib/common/operations/json-operation-handler.d.ts.map +1 -0
- package/lib/common/operations/json-operation-handler.js +120 -0
- package/lib/common/operations/json-operation-handler.js.map +1 -0
- package/lib/common/operations/operation-action-handler.d.ts.map +1 -1
- package/lib/common/operations/operation-action-handler.js +3 -2
- package/lib/common/operations/operation-action-handler.js.map +1 -1
- package/lib/common/operations/operation-handler-registry.d.ts +1 -9
- package/lib/common/operations/operation-handler-registry.d.ts.map +1 -1
- package/lib/common/operations/operation-handler-registry.js +4 -12
- package/lib/common/operations/operation-handler-registry.js.map +1 -1
- package/lib/common/operations/operation-handler.d.ts +2 -2
- package/lib/common/operations/operation-handler.d.ts.map +1 -1
- package/lib/common/operations/operation-handler.js +2 -1
- package/lib/common/operations/operation-handler.js.map +1 -1
- package/lib/common/protocol/client-action.d.ts +31 -0
- package/lib/common/protocol/client-action.d.ts.map +1 -0
- package/lib/common/protocol/client-action.js +35 -0
- package/lib/common/protocol/client-action.js.map +1 -0
- package/lib/common/protocol/glsp-server.d.ts +1 -1
- package/lib/common/protocol/glsp-server.d.ts.map +1 -1
- package/lib/common/protocol/glsp-server.js +9 -10
- package/lib/common/protocol/glsp-server.js.map +1 -1
- package/lib/common/session/client-session-factory.js +5 -4
- package/lib/common/session/client-session-factory.js.map +1 -1
- package/lib/common/session/client-session-manager.js +2 -1
- package/lib/common/session/client-session-manager.js.map +1 -1
- package/lib/common/utils/console-logger.js +2 -1
- package/lib/common/utils/console-logger.js.map +1 -1
- package/lib/common/utils/logger.js +2 -1
- package/lib/common/utils/logger.js.map +1 -1
- package/lib/common/utils/promise-queue.d.ts.map +1 -1
- package/lib/common/utils/promise-queue.js +3 -6
- package/lib/common/utils/promise-queue.js.map +1 -1
- package/lib/common/utils/registry.d.ts +3 -1
- package/lib/common/utils/registry.d.ts.map +1 -1
- package/lib/common/utils/registry.js +15 -4
- package/lib/common/utils/registry.js.map +1 -1
- package/lib/node/abstract-json-model-storage.js +2 -1
- package/lib/node/abstract-json-model-storage.js.map +1 -1
- package/lib/node/gmodel/gmodel-storage.d.ts.map +1 -1
- package/lib/node/gmodel/gmodel-storage.js +4 -2
- package/lib/node/gmodel/gmodel-storage.js.map +1 -1
- package/lib/node/launch/socket-server-launcher.js +2 -1
- package/lib/node/launch/socket-server-launcher.js.map +1 -1
- package/lib/node/launch/websocket-server-launcher.js +2 -1
- package/lib/node/launch/websocket-server-launcher.js.map +1 -1
- package/package.json +4 -4
- package/src/common/actions/action-dispatcher.spec.ts +3 -2
- package/src/common/actions/action-dispatcher.ts +8 -5
- package/src/common/actions/client-action-handler.ts +28 -18
- package/src/common/actions/global-action-provider.spec.ts +4 -15
- package/src/common/actions/global-action-provider.ts +21 -25
- package/src/common/command/recording-command.spec.ts +15 -5
- package/src/common/command/recording-command.ts +16 -27
- package/src/common/di/client-session-module.ts +17 -10
- package/src/common/di/diagram-module.ts +23 -75
- package/src/common/di/server-module.ts +0 -1
- package/src/common/features/clipboard/request-clipboard-data-action-handler.ts +3 -3
- package/src/common/features/model/gmodel-serializer.ts +11 -11
- package/src/common/features/model/model-state.ts +3 -0
- package/src/common/features/model/model-submission-handler.ts +52 -7
- package/src/common/features/model/request-model-action-handler.ts +4 -4
- package/src/common/features/type-hints/edge-creation-checker.ts +44 -0
- package/src/common/features/type-hints/request-check-edge-action-handler.ts +62 -0
- package/src/common/{diagram → features/type-hints}/request-type-hints-action-handler.spec.ts +2 -2
- package/src/common/{diagram → features/type-hints}/request-type-hints-action-handler.ts +2 -3
- package/src/common/gmodel/cut-operation-handler.ts +5 -3
- package/src/common/gmodel/delete-operation-handler.ts +6 -5
- package/src/common/gmodel/gmodel-create-edge-operation-handler.ts +3 -3
- package/src/common/gmodel/gmodel-create-node-operation-handler.ts +3 -3
- package/src/common/gmodel/paste-operation-handler.ts +2 -2
- package/src/common/index.ts +3 -1
- package/src/common/operations/compound-operation-handler.ts +6 -1
- package/src/common/operations/create-operation-handler.ts +22 -5
- package/src/common/operations/json-operation-handler.ts +147 -0
- package/src/common/operations/operation-action-handler.ts +2 -2
- package/src/common/operations/operation-handler-registry.ts +1 -12
- package/src/common/operations/operation-handler.ts +2 -2
- package/src/common/protocol/client-action.ts +38 -0
- package/src/common/protocol/glsp-server.spec.ts +11 -10
- package/src/common/protocol/glsp-server.ts +11 -14
- package/src/common/session/client-session-factory.spec.ts +2 -2
- package/src/common/session/client-session-factory.ts +3 -3
- package/src/common/session/client-session-manager.spec.ts +4 -3
- package/src/common/utils/promise-queue.ts +4 -5
- package/src/common/utils/registry.spec.ts +3 -1
- package/src/common/utils/registry.ts +8 -3
- package/src/node/gmodel/gmodel-storage.ts +3 -3
- package/lib/common/diagram/request-type-hints-action-handler.d.ts.map +0 -1
- package/lib/common/diagram/request-type-hints-action-handler.js.map +0 -1
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import { GModelRootSchema } from '@eclipse-glsp/graph';
|
|
17
16
|
import {
|
|
18
17
|
Action,
|
|
19
18
|
DirtyStateChangeReason,
|
|
19
|
+
GModelRootSchema,
|
|
20
20
|
MarkersReason,
|
|
21
21
|
MaybePromise,
|
|
22
22
|
RequestBoundsAction,
|
|
23
|
+
RequestModelAction,
|
|
23
24
|
SetDirtyStateAction,
|
|
24
25
|
SetMarkersAction,
|
|
25
26
|
SetModelAction,
|
|
@@ -35,6 +36,15 @@ import { GModelFactory } from './gmodel-factory';
|
|
|
35
36
|
import { GModelSerializer } from './gmodel-serializer';
|
|
36
37
|
import { ModelState } from './model-state';
|
|
37
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Helper class that provides utility methods to handle model updates i.e.
|
|
41
|
+
* submit a new model to the client. In addition, to the core model update action this class
|
|
42
|
+
* also takes care of related behavior like dirty state handling, validation and client/server side layouting.
|
|
43
|
+
* Note that the submissions handler is only responsible for deriving the set of actions that comprise a model update
|
|
44
|
+
* but does not actually dispatch them. The returned actions should be either manually dispatched
|
|
45
|
+
* to the `ActionDispatcher`, or simply returned as the result of an
|
|
46
|
+
* `ActionHandler.execute` method.
|
|
47
|
+
*/
|
|
38
48
|
@injectable()
|
|
39
49
|
export class ModelSubmissionHandler {
|
|
40
50
|
@inject(DiagramConfiguration)
|
|
@@ -60,8 +70,34 @@ export class ModelSubmissionHandler {
|
|
|
60
70
|
@optional()
|
|
61
71
|
protected validator?: ModelValidator;
|
|
62
72
|
|
|
73
|
+
protected requestModelAction?: RequestModelAction;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns a list of actions to submit the initial revision of the client-side model, based on the injected
|
|
77
|
+
* {@link GModelState}. Typically this method is invoked by the {@link RequestModelActionHandler} when the diagram
|
|
78
|
+
* is (re)loaded.
|
|
79
|
+
* <p>
|
|
80
|
+
* These actions are not processed by this {@link ModelSubmissionHandler}, but should be either manually dispatched
|
|
81
|
+
* to the {@link ActionDispatcher}, or simply returned as the result of an
|
|
82
|
+
* {@link ActionHandler#execute(Action)} method.
|
|
83
|
+
* </p>
|
|
84
|
+
*
|
|
85
|
+
* @param requestAction The {@link RequestModelAction} that triggere the initial model update
|
|
86
|
+
* @return A list of actions to be processed in order to submit the intial model.
|
|
87
|
+
*
|
|
88
|
+
*/
|
|
89
|
+
submitInitialModel(requestAction: RequestModelAction): MaybePromise<Action[]> {
|
|
90
|
+
/*
|
|
91
|
+
* In the default update action flow a `RequestModelAction` does not directly trigger a `SetModelAction` response
|
|
92
|
+
* (RequestModelAction (C) -> RequestBoundsAction (S) -> ComputedBoundsAction (C) -> SetModelACtion (S)
|
|
93
|
+
* Therefore we temporarily store the action later retrival
|
|
94
|
+
*/
|
|
95
|
+
this.requestModelAction = requestAction;
|
|
96
|
+
return this.submitModel();
|
|
97
|
+
}
|
|
98
|
+
|
|
63
99
|
/**
|
|
64
|
-
* Returns a list of actions to update the client-side model, based on the
|
|
100
|
+
* Returns a list of actions to update the client-side model, based on the injected {@link ModelState}
|
|
65
101
|
*
|
|
66
102
|
* These actions are not processed by this {@link ModelSubmissionHandler}, but should be either manually dispatched
|
|
67
103
|
* to the `ActionDispatcher`, or simply returned as the result of an `ActionHandler.execute()` method.
|
|
@@ -71,13 +107,15 @@ export class ModelSubmissionHandler {
|
|
|
71
107
|
*/
|
|
72
108
|
submitModel(reason?: DirtyStateChangeReason): MaybePromise<Action[]> {
|
|
73
109
|
this.modelFactory.createModel();
|
|
74
|
-
|
|
75
|
-
const
|
|
110
|
+
|
|
111
|
+
const revision = this.requestModelAction ? 0 : this.modelState.root.revision! + 1;
|
|
112
|
+
this.modelState.root.revision = revision;
|
|
76
113
|
|
|
77
114
|
if (this.diagramConfiguration.needsClientLayout) {
|
|
115
|
+
const root = this.serializeGModel();
|
|
78
116
|
return [RequestBoundsAction.create(root), SetDirtyStateAction.create(this.commandStack.isDirty, { reason })];
|
|
79
117
|
}
|
|
80
|
-
return
|
|
118
|
+
return this.submitModelDirectly(reason);
|
|
81
119
|
}
|
|
82
120
|
|
|
83
121
|
/**
|
|
@@ -102,8 +140,8 @@ export class ModelSubmissionHandler {
|
|
|
102
140
|
}
|
|
103
141
|
const result: Action[] = [];
|
|
104
142
|
result.push(
|
|
105
|
-
|
|
106
|
-
?
|
|
143
|
+
this.requestModelAction
|
|
144
|
+
? this.createSetModeAction(root)
|
|
107
145
|
: UpdateModelAction.create(root, { animate: this.diagramConfiguration.animatedUpdate })
|
|
108
146
|
);
|
|
109
147
|
if (!this.diagramConfiguration.needsClientLayout) {
|
|
@@ -116,6 +154,13 @@ export class ModelSubmissionHandler {
|
|
|
116
154
|
return result;
|
|
117
155
|
}
|
|
118
156
|
|
|
157
|
+
protected createSetModeAction(newRoot: GModelRootSchema): SetModelAction {
|
|
158
|
+
const responseId = this.requestModelAction?.requestId ?? '';
|
|
159
|
+
const response = SetModelAction.create(newRoot, { responseId });
|
|
160
|
+
this.requestModelAction = undefined;
|
|
161
|
+
return response;
|
|
162
|
+
}
|
|
163
|
+
|
|
119
164
|
protected serializeGModel(): GModelRootSchema {
|
|
120
165
|
return this.serializer.createSchema(this.modelState.root);
|
|
121
166
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import { Action, RequestModelAction,
|
|
16
|
+
import { Action, RequestModelAction, StatusAction } from '@eclipse-glsp/protocol';
|
|
17
17
|
import { inject, injectable } from 'inversify';
|
|
18
18
|
import { ActionDispatcher } from '../../actions/action-dispatcher';
|
|
19
19
|
import { ActionHandler } from '../../actions/action-handler';
|
|
@@ -61,7 +61,7 @@ export class RequestModelActionHandler implements ActionHandler {
|
|
|
61
61
|
}
|
|
62
62
|
this.reportModelLoadingFinished(progress);
|
|
63
63
|
|
|
64
|
-
return this.submissionHandler.
|
|
64
|
+
return this.submissionHandler.submitInitialModel(action);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
protected async handleReconnect(action: RequestModelAction): Promise<void> {
|
|
@@ -76,12 +76,12 @@ export class RequestModelActionHandler implements ActionHandler {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
protected reportModelLoading(message: string): ProgressMonitor {
|
|
79
|
-
this.actionDispatcher.dispatch(
|
|
79
|
+
this.actionDispatcher.dispatch(StatusAction.create(message, { severity: 'INFO' }));
|
|
80
80
|
return this.progressService.start(message);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
protected reportModelLoadingFinished(monitor: ProgressMonitor): void {
|
|
84
|
-
this.actionDispatcher.dispatch(
|
|
84
|
+
this.actionDispatcher.dispatch(StatusAction.create('', { severity: 'NONE' }));
|
|
85
85
|
monitor.end();
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 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 { GModelElement } from '@eclipse-glsp/graph';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Optional service used to check the validity of an edge being created. Used in combination with `dynamic`
|
|
21
|
+
* `EdgeTypeHints`.
|
|
22
|
+
* A dynamic edge type hint is used for cases where a plain list of allowed source and target element ids is not enough
|
|
23
|
+
* to determine wether an edge being created is valid. In this cases the client will query the server to determine wether the edge
|
|
24
|
+
* is valid. The `EdgeCreationChecker` then checks the given edge information and returns wether the edge being created is
|
|
25
|
+
* valid.
|
|
26
|
+
*/
|
|
27
|
+
export interface EdgeCreationChecker {
|
|
28
|
+
/**
|
|
29
|
+
* Checks wether the given source element for an edge being created is valid i.e. if the
|
|
30
|
+
* given source is and allowed source element for the given edge type.
|
|
31
|
+
*
|
|
32
|
+
* @returns `true` if the edge source is valid, `false` otherwise
|
|
33
|
+
*/
|
|
34
|
+
isValidSource(edgeType: string, sourceElement: GModelElement): boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks wether the given information for an edge being created is valid i.e. if the
|
|
38
|
+
* given target is an allowed target for the given source and edge type.
|
|
39
|
+
*
|
|
40
|
+
* @return `true` if the edge target is valid, `false` otherwise
|
|
41
|
+
*/
|
|
42
|
+
isValidTarget(edgeType: string, sourceElement: GModelElement, targetElement: GModelElement): boolean;
|
|
43
|
+
}
|
|
44
|
+
export const EdgeCreationChecker = Symbol('EdgeCreationChecker');
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 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
|
+
import { Action, CheckEdgeResultAction, MaybePromise, RequestCheckEdgeAction } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { inject, injectable, optional } from 'inversify';
|
|
18
|
+
import { ActionHandler } from '../../actions/action-handler';
|
|
19
|
+
import { DiagramConfiguration } from '../../diagram/diagram-configuration';
|
|
20
|
+
import { GLSPServerError, getOrThrow } from '../../utils/glsp-server-error';
|
|
21
|
+
import { ModelState } from '../model/model-state';
|
|
22
|
+
import { EdgeCreationChecker } from './edge-creation-checker';
|
|
23
|
+
|
|
24
|
+
@injectable()
|
|
25
|
+
export class RequestCheckEdgeActionHandler implements ActionHandler {
|
|
26
|
+
@inject(ModelState)
|
|
27
|
+
protected modelState: ModelState;
|
|
28
|
+
|
|
29
|
+
@inject(DiagramConfiguration)
|
|
30
|
+
protected diagramConfiguration: DiagramConfiguration;
|
|
31
|
+
|
|
32
|
+
@inject(EdgeCreationChecker)
|
|
33
|
+
@optional()
|
|
34
|
+
protected edgeCreationChecker?: EdgeCreationChecker;
|
|
35
|
+
|
|
36
|
+
readonly actionKinds: string[] = [RequestCheckEdgeAction.KIND];
|
|
37
|
+
|
|
38
|
+
execute(action: RequestCheckEdgeAction): MaybePromise<Action[]> {
|
|
39
|
+
const hasDynamicHint = this.diagramConfiguration.edgeTypeHints.some(hint => hint.elementTypeId === action.edgeType && hint.dynamic);
|
|
40
|
+
const { edgeType, sourceElementId, targetElementId } = action;
|
|
41
|
+
const isValid = this.edgeCreationChecker && hasDynamicHint ? this.validate(action) : true;
|
|
42
|
+
|
|
43
|
+
return [CheckEdgeResultAction.create({ edgeType, isValid, sourceElementId, targetElementId })];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected validate(action: RequestCheckEdgeAction): boolean {
|
|
47
|
+
const sourceElement = getOrThrow(
|
|
48
|
+
this.modelState.index.get(action.sourceElementId),
|
|
49
|
+
'Invalid `RequestCheckEdgeTargetAction`!. Could not find a source element with id: ' + action.sourceElementId
|
|
50
|
+
);
|
|
51
|
+
const targetElement = action.targetElementId ? this.modelState.index.get(action.targetElementId) : undefined;
|
|
52
|
+
|
|
53
|
+
if (action.targetElementId && !targetElement) {
|
|
54
|
+
throw new GLSPServerError(
|
|
55
|
+
'Invalid `RequestCheckEdgeTargetAction`! Could not find a target element with id: ' + action.targetElementId
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return targetElement
|
|
59
|
+
? this.edgeCreationChecker!.isValidTarget(action.edgeType, sourceElement, targetElement)
|
|
60
|
+
: this.edgeCreationChecker!.isValidSource(action.edgeType, sourceElement);
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/common/{diagram → features/type-hints}/request-type-hints-action-handler.spec.ts
RENAMED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
import { EdgeTypeHint, RequestTypeHintsAction, SetTypeHintsAction, ShapeTypeHint } from '@eclipse-glsp/protocol';
|
|
17
17
|
import { expect } from 'chai';
|
|
18
18
|
import { Container, ContainerModule } from 'inversify';
|
|
19
|
-
import
|
|
20
|
-
import
|
|
19
|
+
import { DiagramConfiguration } from '../../diagram/diagram-configuration';
|
|
20
|
+
import * as mock from '../../test/mock-util';
|
|
21
21
|
import { RequestTypeHintsActionHandler } from './request-type-hints-action-handler';
|
|
22
22
|
|
|
23
23
|
describe('test RequestTypeHintsActionHandler', () => {
|
|
@@ -15,13 +15,12 @@
|
|
|
15
15
|
********************************************************************************/
|
|
16
16
|
import { Action, MaybePromise, RequestTypeHintsAction, SetTypeHintsAction } from '@eclipse-glsp/protocol';
|
|
17
17
|
import { inject, injectable } from 'inversify';
|
|
18
|
-
import { ActionHandler } from '
|
|
19
|
-
import { DiagramConfiguration } from '
|
|
18
|
+
import { ActionHandler } from '../../actions/action-handler';
|
|
19
|
+
import { DiagramConfiguration } from '../../diagram/diagram-configuration';
|
|
20
20
|
|
|
21
21
|
@injectable()
|
|
22
22
|
export class RequestTypeHintsActionHandler implements ActionHandler {
|
|
23
23
|
@inject(DiagramConfiguration) protected diagramConfiguration: DiagramConfiguration;
|
|
24
|
-
static KINDS = [RequestTypeHintsAction.KIND];
|
|
25
24
|
|
|
26
25
|
execute(action: RequestTypeHintsAction): MaybePromise<Action[]> {
|
|
27
26
|
return [
|
|
@@ -28,9 +28,11 @@ export class GModelCutOperationHandler extends GModelOperationHandler {
|
|
|
28
28
|
|
|
29
29
|
createCommand(operation: CutOperation): MaybePromise<Command | undefined> {
|
|
30
30
|
const cuttableElementIds = this.getElementToCut(operation);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// If we have cuttable elements we dispatch a DeleteElementOperation otherwise do nothing
|
|
32
|
+
if (cuttableElementIds.length > 0) {
|
|
33
|
+
this.actionDispatcher.dispatch(DeleteElementOperation.create(cuttableElementIds));
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
protected getElementToCut(cutOperation: CutOperation): string[] {
|
|
@@ -72,7 +72,7 @@ export class GModelDeleteOperationHandler extends GModelOperationHandler {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
const dependents = new Set<GModelElement>();
|
|
75
|
-
this.collectDependents(dependents, nodeToDelete);
|
|
75
|
+
this.collectDependents(dependents, nodeToDelete, false);
|
|
76
76
|
|
|
77
77
|
dependents.forEach(dependant => {
|
|
78
78
|
const index = this.modelState.root.children.findIndex(element => element === dependant);
|
|
@@ -85,22 +85,23 @@ export class GModelDeleteOperationHandler extends GModelOperationHandler {
|
|
|
85
85
|
return true;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
protected collectDependents(dependents: Set<GModelElement>, nodeToDelete: GModelElement): void {
|
|
88
|
+
protected collectDependents(dependents: Set<GModelElement>, nodeToDelete: GModelElement, isChild: boolean): void {
|
|
89
89
|
if (dependents.has(nodeToDelete)) {
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
if (nodeToDelete.children.length > 0) {
|
|
94
|
-
nodeToDelete.children.forEach(child => this.collectDependents(dependents, child));
|
|
94
|
+
nodeToDelete.children.forEach(child => this.collectDependents(dependents, child, true));
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
if (nodeToDelete instanceof GNode) {
|
|
98
98
|
const index = this.modelState.index;
|
|
99
|
+
|
|
99
100
|
index.getIncomingEdges(nodeToDelete).forEach(incoming => {
|
|
100
|
-
|
|
101
|
+
dependents.add(incoming);
|
|
101
102
|
});
|
|
102
103
|
index.getOutgoingEdges(nodeToDelete).forEach(outgoing => {
|
|
103
|
-
|
|
104
|
+
dependents.add(outgoing);
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
107
|
|
|
@@ -19,7 +19,7 @@ import { GNode } from '@eclipse-glsp/graph/lib/gnode';
|
|
|
19
19
|
import { CreateEdgeOperation, MaybePromise, TriggerEdgeCreationAction } from '@eclipse-glsp/protocol';
|
|
20
20
|
import { injectable } from 'inversify';
|
|
21
21
|
import { Command } from '../command/command';
|
|
22
|
-
import {
|
|
22
|
+
import { CreateEdgeOperationHandler } from '../operations/create-operation-handler';
|
|
23
23
|
import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -28,8 +28,8 @@ import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
|
28
28
|
* (i.e. all operation handlers directly modify the graphical model).
|
|
29
29
|
*/
|
|
30
30
|
@injectable()
|
|
31
|
-
export abstract class GModelCreateEdgeOperationHandler extends GModelOperationHandler implements
|
|
32
|
-
override readonly operationType
|
|
31
|
+
export abstract class GModelCreateEdgeOperationHandler extends GModelOperationHandler implements CreateEdgeOperationHandler {
|
|
32
|
+
override readonly operationType = CreateEdgeOperation.KIND;
|
|
33
33
|
abstract override label: string;
|
|
34
34
|
abstract elementTypeIds: string[];
|
|
35
35
|
|
|
@@ -19,7 +19,7 @@ import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCrea
|
|
|
19
19
|
import { inject, injectable } from 'inversify';
|
|
20
20
|
import { ActionDispatcher } from '../actions/action-dispatcher';
|
|
21
21
|
import { Command } from '../command/command';
|
|
22
|
-
import {
|
|
22
|
+
import { CreateNodeOperationHandler } from '../operations/create-operation-handler';
|
|
23
23
|
import { getRelativeLocation } from '../utils/layout-util';
|
|
24
24
|
import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
25
25
|
|
|
@@ -29,7 +29,7 @@ import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
|
29
29
|
* (i.e. all operation handlers directly modify the graphical model).
|
|
30
30
|
*/
|
|
31
31
|
@injectable()
|
|
32
|
-
export abstract class GModelCreateNodeOperationHandler extends GModelOperationHandler implements
|
|
32
|
+
export abstract class GModelCreateNodeOperationHandler extends GModelOperationHandler implements CreateNodeOperationHandler {
|
|
33
33
|
@inject(ActionDispatcher)
|
|
34
34
|
protected actionDispatcher: ActionDispatcher;
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ export abstract class GModelCreateNodeOperationHandler extends GModelOperationHa
|
|
|
37
37
|
|
|
38
38
|
abstract override label: string;
|
|
39
39
|
|
|
40
|
-
override operationType
|
|
40
|
+
override readonly operationType = CreateNodeOperation.KIND;
|
|
41
41
|
|
|
42
42
|
override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined> {
|
|
43
43
|
return this.commandOf(() => this.executeCreation(operation));
|
|
@@ -14,7 +14,7 @@
|
|
|
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 { EditorContext, MaybePromise, PasteOperation, Point
|
|
17
|
+
import { EditorContext, GModelElementSchema, MaybePromise, PasteOperation, Point } from '@eclipse-glsp/protocol';
|
|
18
18
|
import { inject, injectable } from 'inversify';
|
|
19
19
|
import * as uuid from 'uuid';
|
|
20
20
|
import { Command } from '../command/command';
|
|
@@ -38,7 +38,7 @@ export class GModelPasteOperationHandler extends GModelOperationHandler {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
protected getCopiedElements(jsonString: string): GModelElement[] {
|
|
41
|
-
const schemas:
|
|
41
|
+
const schemas: GModelElementSchema[] = JSON.parse(jsonString);
|
|
42
42
|
return schemas.map(schema => this.modelSerializer.createElement(schema, this.modelState.root));
|
|
43
43
|
}
|
|
44
44
|
|
package/src/common/index.ts
CHANGED
|
@@ -33,7 +33,6 @@ export * from './di/multi-binding';
|
|
|
33
33
|
export * from './di/server-module';
|
|
34
34
|
export * from './di/service-identifiers';
|
|
35
35
|
export * from './diagram/diagram-configuration';
|
|
36
|
-
export * from './diagram/request-type-hints-action-handler';
|
|
37
36
|
export * from './features/clipboard/request-clipboard-data-action-handler';
|
|
38
37
|
export * from './features/contextactions/command-palette-action-provider';
|
|
39
38
|
export * from './features/contextactions/context-actions-provider';
|
|
@@ -65,12 +64,15 @@ export * from './features/navigation/request-navigation-targets-action-handler';
|
|
|
65
64
|
export * from './features/navigation/resolve-navigation-targets-action-handler';
|
|
66
65
|
export * from './features/popup/popup-model-factory';
|
|
67
66
|
export * from './features/popup/request-popup-model-action-handler';
|
|
67
|
+
export * from './features/type-hints/edge-creation-checker';
|
|
68
|
+
export * from './features/type-hints/request-type-hints-action-handler';
|
|
68
69
|
export * from './features/validation/model-validator';
|
|
69
70
|
export * from './features/validation/request-markers-handler';
|
|
70
71
|
export * from './gmodel/index';
|
|
71
72
|
export * from './launch/glsp-server-launcher';
|
|
72
73
|
export * from './operations/compound-operation-handler';
|
|
73
74
|
export * from './operations/create-operation-handler';
|
|
75
|
+
export * from './operations/json-operation-handler';
|
|
74
76
|
export * from './operations/operation-action-handler';
|
|
75
77
|
export * from './operations/operation-handler';
|
|
76
78
|
export * from './operations/operation-handler-registry';
|
|
@@ -19,6 +19,11 @@ import { Command, CompoundCommand } from '../command/command';
|
|
|
19
19
|
import { OperationHandler } from './operation-handler';
|
|
20
20
|
import { OperationHandlerRegistry } from './operation-handler-registry';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Generic {@link OperationHandler} from {@link CompoundOperations}.
|
|
24
|
+
* Retrieves the corresponding execution commands for the list of (sub) operations
|
|
25
|
+
* and constructs a {@link CompoundCommand} for them.
|
|
26
|
+
*/
|
|
22
27
|
@injectable()
|
|
23
28
|
export class CompoundOperationHandler extends OperationHandler {
|
|
24
29
|
@inject(OperationHandlerRegistry)
|
|
@@ -27,7 +32,7 @@ export class CompoundOperationHandler extends OperationHandler {
|
|
|
27
32
|
operationType = CompoundOperation.KIND;
|
|
28
33
|
|
|
29
34
|
async createCommand(operation: CompoundOperation): Promise<Command | undefined> {
|
|
30
|
-
const maybeCommands = operation.operationList.map(op => this.operationHandlerRegistry.
|
|
35
|
+
const maybeCommands = operation.operationList.map(op => this.operationHandlerRegistry.getOperationHandler(op)?.execute(op));
|
|
31
36
|
const commands: Command[] = [];
|
|
32
37
|
|
|
33
38
|
for await (const command of maybeCommands) {
|
|
@@ -19,21 +19,37 @@ import {
|
|
|
19
19
|
hasArrayProp,
|
|
20
20
|
hasFunctionProp,
|
|
21
21
|
hasStringProp,
|
|
22
|
+
MaybePromise,
|
|
22
23
|
TriggerEdgeCreationAction,
|
|
23
24
|
TriggerNodeCreationAction
|
|
24
25
|
} from '@eclipse-glsp/protocol';
|
|
26
|
+
import { Command } from '../command/command';
|
|
25
27
|
import { OperationHandler } from './operation-handler';
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
|
-
* A special {@link OperationHandler} that is responsible for the handling of {@link
|
|
30
|
+
* A special {@link OperationHandler} that is responsible for the handling of (a subset of) {@link CreateEdgeOperation}s. Depending on its
|
|
29
31
|
* operation type the triggered actions are {@link TriggerNodeCreationAction} or {@link TriggerEdgeCreationAction}s.
|
|
30
32
|
*/
|
|
31
|
-
export interface
|
|
33
|
+
export interface CreateEdgeOperationHandler extends OperationHandler {
|
|
34
|
+
label: string;
|
|
35
|
+
elementTypeIds: string[];
|
|
36
|
+
operationType: typeof CreateEdgeOperation.KIND;
|
|
37
|
+
getTriggerActions(): TriggerEdgeCreationAction[];
|
|
38
|
+
createCommand(operation: CreateEdgeOperation): MaybePromise<Command | undefined>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CreateNodeOperationHandler extends OperationHandler {
|
|
32
42
|
readonly label: string;
|
|
33
43
|
elementTypeIds: string[];
|
|
34
|
-
operationType:
|
|
35
|
-
getTriggerActions():
|
|
44
|
+
operationType: typeof CreateNodeOperation.KIND;
|
|
45
|
+
getTriggerActions(): TriggerNodeCreationAction[];
|
|
46
|
+
createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined>;
|
|
36
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* A special {@link OperationHandler} that is responsible for the handling of a node or edge creation operation. Depending on its
|
|
50
|
+
* operation type the triggered actions are {@link TriggerNodeCreationAction} or {@link TriggerEdgeCreationAction}s.
|
|
51
|
+
*/
|
|
52
|
+
export type CreateOperationHandler = CreateNodeOperationHandler | CreateEdgeOperationHandler;
|
|
37
53
|
|
|
38
54
|
export type CreateOperationKind = typeof CreateNodeOperation.KIND | typeof CreateEdgeOperation.KIND;
|
|
39
55
|
|
|
@@ -41,9 +57,10 @@ export namespace CreateOperationHandler {
|
|
|
41
57
|
export function is(object: unknown): object is CreateOperationHandler {
|
|
42
58
|
return (
|
|
43
59
|
object instanceof OperationHandler &&
|
|
60
|
+
hasStringProp(object, 'operationType') &&
|
|
44
61
|
hasStringProp(object, 'label') &&
|
|
45
62
|
hasArrayProp(object, 'elementTypeIds') &&
|
|
46
|
-
hasFunctionProp(object, 'getTriggerActions')
|
|
63
|
+
hasFunctionProp(object, 'getTriggerActions', true)
|
|
47
64
|
);
|
|
48
65
|
}
|
|
49
66
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 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
|
+
import { GModelElement } from '@eclipse-glsp/graph';
|
|
17
|
+
import {
|
|
18
|
+
AnyObject,
|
|
19
|
+
CreateEdgeOperation,
|
|
20
|
+
CreateNodeOperation,
|
|
21
|
+
MaybePromise,
|
|
22
|
+
Point,
|
|
23
|
+
TriggerEdgeCreationAction,
|
|
24
|
+
TriggerNodeCreationAction,
|
|
25
|
+
hasFunctionProp,
|
|
26
|
+
hasObjectProp
|
|
27
|
+
} from '@eclipse-glsp/protocol';
|
|
28
|
+
import { injectable } from 'inversify';
|
|
29
|
+
import { Command } from '../command/command';
|
|
30
|
+
import { AbstractRecordingCommand } from '../command/recording-command';
|
|
31
|
+
import { ModelState } from '../features/model/model-state';
|
|
32
|
+
import { getRelativeLocation } from '../utils/layout-util';
|
|
33
|
+
import { CreateEdgeOperationHandler, CreateNodeOperationHandler } from './create-operation-handler';
|
|
34
|
+
import { OperationHandler } from './operation-handler';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Helper interface for {@link ModelState} implementations of diagram languages that use a (serializable) JSON-based source model.
|
|
38
|
+
* Has to be implemented in order to reuse the {@link JsonOperationHandler} API.
|
|
39
|
+
*/
|
|
40
|
+
export interface JsonModelState<JsonObject extends AnyObject = AnyObject> extends ModelState {
|
|
41
|
+
readonly sourceModel: JsonObject;
|
|
42
|
+
updateSourceModel(sourceModel: JsonObject): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export namespace JsonModelState {
|
|
46
|
+
export function is(modelState: ModelState): modelState is JsonModelState {
|
|
47
|
+
return hasObjectProp(modelState, 'sourceModel') && hasFunctionProp(modelState, 'updateSourceModel');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Simple base implementation of {@link AbstractRecordingCommand} that allows recording of changes made
|
|
53
|
+
* to the `sourceModel` of the given {@link JsonModelState} during the given `doExecute` function
|
|
54
|
+
*/
|
|
55
|
+
export class JsonRecordingCommand<JsonObject extends AnyObject = AnyObject> extends AbstractRecordingCommand<JsonObject> {
|
|
56
|
+
constructor(protected modelState: JsonModelState<JsonObject>, protected doExecute: () => MaybePromise<void>) {
|
|
57
|
+
super();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
protected override getJsonObject(): MaybePromise<JsonObject> {
|
|
61
|
+
return this.modelState.sourceModel;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected override postChange(newModel: JsonObject): MaybePromise<void> {
|
|
65
|
+
this.modelState.updateSourceModel(newModel);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Reusable {@link OperationHandler} base implementation for diagram languages that use a (serializable) JSON-based source model.
|
|
71
|
+
* To use this class (or its subclasses) the injected {@link ModelState} has to implement the {@link JsonModelState} interface.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
@injectable()
|
|
75
|
+
export abstract class JsonOperationHandler extends OperationHandler {
|
|
76
|
+
protected commandOf(runnable: () => void): Command {
|
|
77
|
+
if (!JsonModelState.is(this.modelState)) {
|
|
78
|
+
throw new Error('Cannot create command. The underlying model state does not implement the `JsonModelState` interface');
|
|
79
|
+
}
|
|
80
|
+
return new JsonRecordingCommand(this.modelState, runnable);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Reusable {@link CreateNodeOperationHandler} base implementation for diagram languages that use a (serializable) JSON-based source model.
|
|
86
|
+
*/
|
|
87
|
+
@injectable()
|
|
88
|
+
export abstract class JsonCreateNodeOperationHandler extends JsonOperationHandler implements CreateNodeOperationHandler {
|
|
89
|
+
abstract elementTypeIds: string[];
|
|
90
|
+
abstract override label: string;
|
|
91
|
+
override readonly operationType = CreateNodeOperation.KIND;
|
|
92
|
+
|
|
93
|
+
abstract override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined>;
|
|
94
|
+
|
|
95
|
+
getTriggerActions(): TriggerNodeCreationAction[] {
|
|
96
|
+
return this.elementTypeIds.map(typeId => TriggerNodeCreationAction.create(typeId));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Return the GModelElement that will contain the newly created node. It is usually
|
|
101
|
+
* the target element ({@link CreateNodeOperation.containerId}), but could also
|
|
102
|
+
* be e.g. an intermediate compartment, or even a different Node.
|
|
103
|
+
*
|
|
104
|
+
* @param operation
|
|
105
|
+
* @return the GModelElement that will contain the newly created node.
|
|
106
|
+
*/
|
|
107
|
+
getContainer(operation: CreateNodeOperation): GModelElement | undefined {
|
|
108
|
+
const index = this.modelState.index;
|
|
109
|
+
return operation.containerId ? index.get(operation.containerId) : undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getLocation(operation: CreateNodeOperation): Point | undefined {
|
|
113
|
+
return operation.location;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves the diagram absolute location and the target container from the given {@link CreateNodeOperation}
|
|
118
|
+
* and converts the absolute location to coordinates relative to the given container.
|
|
119
|
+
* Relative coordinates can only be retrieved if the given container element is part of
|
|
120
|
+
* a hierarchy of {@link GBoundsAware} elements. This means each (recursive) parent element need to
|
|
121
|
+
* implement {@link GBoundsAware}. If that is not the case this method returns `undefined`.
|
|
122
|
+
* @param absoluteLocation The diagram absolute position.
|
|
123
|
+
* @param container The container element.
|
|
124
|
+
* @returns The relative position or `undefined`.
|
|
125
|
+
*/
|
|
126
|
+
getRelativeLocation(operation: CreateNodeOperation): Point | undefined {
|
|
127
|
+
const container = this.getContainer(operation) ?? this.modelState.root;
|
|
128
|
+
const absoluteLocation = this.getLocation(operation) ?? Point.ORIGIN;
|
|
129
|
+
return getRelativeLocation(absoluteLocation, container);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Reusable {@link CreateEdgeOperationHandler} base implementation for diagram languages that use a (serializable) JSON-based source model.
|
|
135
|
+
*/
|
|
136
|
+
@injectable()
|
|
137
|
+
export abstract class JsonCreateEdgeOperationHandler extends JsonOperationHandler implements CreateEdgeOperationHandler {
|
|
138
|
+
abstract elementTypeIds: string[];
|
|
139
|
+
abstract override label: string;
|
|
140
|
+
override readonly operationType = CreateEdgeOperation.KIND;
|
|
141
|
+
|
|
142
|
+
abstract override createCommand(operation: CreateEdgeOperation): MaybePromise<Command | undefined>;
|
|
143
|
+
|
|
144
|
+
getTriggerActions(): TriggerEdgeCreationAction[] {
|
|
145
|
+
return this.elementTypeIds.map(typeId => TriggerEdgeCreationAction.create(typeId));
|
|
146
|
+
}
|
|
147
|
+
}
|