-
Notifications
You must be signed in to change notification settings - Fork 197
/
di.config.ts
126 lines (118 loc) · 4.91 KB
/
di.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import {ExampleWebsocketDiagramServer, VSCodeWebViewDiagramServer} from "./model";
console.log("Loading di.config");
import "reflect-metadata"
import { Container, ContainerModule } from "inversify";
import {
defaultModule,
TYPES,
configureViewerOptions,
ConsoleLogger,
LogLevel,
boundsModule,
hoverModule,
moveModule,
selectModule,
undoRedoModule,
viewportModule,
LocalModelSource,
exportModule,
CircularNode,
configureModelElement,
SGraph,
updateModule,
graphModule,
routingModule,
modelSourceModule,
edgeLayoutModule,
SLabel,
SLabelView,
SCompartment,
SCompartmentView,
SEdge,
RectangularNode,
HtmlRootView,
HtmlRoot,
PreRenderedView,
PreRenderedElement,
labelEditModule, edgeEditModule, RectangularPort, LayoutRegistry, VBoxLayouter, HBoxLayouter, boundsFeature
} from "sprotty";
import {
IntegrationNodeView,
CircleNodeView,
EdgeView,
ExampleGraphView,
ChannelNodeView,
PortView,
ErrorPortView
} from "./views";
import fadeModule from "sprotty/lib/features/fade/di.config";
import buttonModule from "sprotty/lib/features/button/di.config";
import expandModule from "sprotty/lib/features/expand/di.config";
import {MyHBoxLayouter, MyVBoxLayouter} from "./layout";
export enum TransportMedium {
None,
Websocket,
LSP
}
export default (transport: TransportMedium, clientId: string) => {
require("sprotty/css/sprotty.css");
require("../css/diagram.css");
const integrationGaphModule = new ContainerModule((bind, unbind, isBound, rebind) => {
switch (transport) {
case TransportMedium.Websocket:
bind(TYPES.ModelSource).to(ExampleWebsocketDiagramServer).inSingletonScope();
break;
case TransportMedium.LSP:
bind(TYPES.ModelSource).to(VSCodeWebViewDiagramServer).inSingletonScope();
break;
default:
bind(TYPES.ModelSource).to(LocalModelSource).inSingletonScope();
}
rebind(TYPES.ILogger).to(ConsoleLogger).inSingletonScope();
rebind(TYPES.LogLevel).toConstantValue(LogLevel.log);
const context = { bind, unbind, isBound, rebind };
configureModelElement(context, 'graph', SGraph, ExampleGraphView);
configureModelElement(context, 'node:circle', CircularNode, CircleNodeView);
configureModelElement(context, 'node:integration', RectangularNode, IntegrationNodeView, {disable: [boundsFeature]});
configureModelElement(context, 'node:channel', RectangularNode, ChannelNodeView);
configureModelElement(context, 'node:label', SLabel, SLabelView);
configureModelElement(context, 'compartment', SCompartment, SCompartmentView);
configureModelElement(context, 'edge:straight', /*OrthogonalEgde*/ SEdge, EdgeView);
configureModelElement(context, 'html', HtmlRoot, HtmlRootView);
configureModelElement(context, 'pre-rendered', PreRenderedElement, PreRenderedView);
configureModelElement(context, 'input-port', RectangularPort, PortView);
configureModelElement(context, 'output-port', RectangularPort, PortView);
configureModelElement(context, 'error-port', RectangularPort, ErrorPortView);
configureViewerOptions(context, {
needsClientLayout: true,
needsServerLayout: true,
baseDiv: clientId,
});
});
const container = new Container();
container.load(defaultModule, selectModule, moveModule, boundsModule, undoRedoModule,
viewportModule, fadeModule, hoverModule, exportModule, expandModule, buttonModule,
updateModule, graphModule, routingModule, edgeEditModule, edgeLayoutModule, labelEditModule,
modelSourceModule, integrationGaphModule);
const layoutRegistry = container.get<LayoutRegistry>(TYPES.LayoutRegistry);
layoutRegistry.deregister(VBoxLayouter.KIND);
layoutRegistry.register(VBoxLayouter.KIND, new MyVBoxLayouter());
layoutRegistry.deregister(HBoxLayouter.KIND);
layoutRegistry.register(HBoxLayouter.KIND, new MyHBoxLayouter());
return container;
};