theia-sprotty
Version:
Glue code for sprotty diagrams in a Theia IDE
138 lines • 6.44 kB
JavaScript
;
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License") you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
var lib_1 = require("sprotty/lib");
var inversify_1 = require("inversify");
exports.TheiaDiagramServerProvider = Symbol('TheiaDiagramServerProvider');
exports.IRootPopupModelProvider = Symbol('IRootPopupModelProvider');
/**
* A sprotty DiagramServer that can be connected to a Theia language
* server.
*
* This class is the sprotty side of the Theia/sprotty integration. It
* is instantiated with the DI container of the sprotty diagram. Theia
* services are available via the TheiaDiagramServerConnector.
*/
var TheiaDiagramServer = /** @class */ (function (_super) {
__extends(TheiaDiagramServer, _super);
function TheiaDiagramServer(actionDispatcher, actionHandlerRegistry, viewerOptions, storage, logger) {
var _this = _super.call(this, actionDispatcher, actionHandlerRegistry, viewerOptions, storage, logger) || this;
_this.actionDispatcher = actionDispatcher;
_this.waitForConnector();
return _this;
}
TheiaDiagramServer.prototype.connect = function (connector) {
this.resolveConnector(connector);
this.workspace = connector.workspace;
};
TheiaDiagramServer.prototype.disconnect = function () {
this.waitForConnector();
};
TheiaDiagramServer.prototype.waitForConnector = function () {
var _this = this;
this.connector = new Promise(function (resolve) {
return _this.resolveConnector = resolve;
});
};
TheiaDiagramServer.prototype.getConnector = function () {
return this.connector;
};
TheiaDiagramServer.prototype.getSourceUri = function () {
return this.sourceUri;
};
TheiaDiagramServer.prototype.getWorkspace = function () {
return this.workspace;
};
TheiaDiagramServer.prototype.initialize = function (registry) {
_super.prototype.initialize.call(this, registry);
registry.register(lib_1.SelectCommand.KIND, this);
};
TheiaDiagramServer.prototype.handle = function (action) {
if (action instanceof lib_1.RequestModelAction && action.options !== undefined)
this.sourceUri = action.options.sourceUri;
return _super.prototype.handle.call(this, action);
};
TheiaDiagramServer.prototype.handleLocally = function (action) {
if (action instanceof lib_1.RequestPopupModelAction) {
return this.handleRequestPopupModel(action);
}
else {
return _super.prototype.handleLocally.call(this, action);
}
};
TheiaDiagramServer.prototype.handleExportSvgAction = function (action) {
var _this = this;
this.connector.then(function (c) { return c.save(_this.sourceUri, action); });
return true;
};
TheiaDiagramServer.prototype.handleRequestPopupModel = function (action) {
var _this = this;
if (action.elementId === this.currentRoot.id) {
this.rootPopupModelProvider.getPopupModel(action, this.currentRoot).then(function (model) {
if (model)
_this.actionDispatcher.dispatch(new lib_1.SetPopupModelAction(model));
});
return false;
}
else {
return true;
}
};
TheiaDiagramServer.prototype.handleServerStateAction = function (status) {
var _this = this;
this.connector.then(function (c) { return c.showStatus(_this.clientId, status); });
return false;
};
TheiaDiagramServer.prototype.sendMessage = function (message) {
this.connector.then(function (c) { return c.sendThroughLsp(message); });
};
/**
* made public
*/
TheiaDiagramServer.prototype.messageReceived = function (message) {
_super.prototype.messageReceived.call(this, message);
};
__decorate([
inversify_1.inject(exports.IRootPopupModelProvider), inversify_1.optional(),
__metadata("design:type", Object)
], TheiaDiagramServer.prototype, "rootPopupModelProvider", void 0);
TheiaDiagramServer = __decorate([
inversify_1.injectable(),
__param(0, inversify_1.inject(lib_1.TYPES.IActionDispatcher)),
__param(1, inversify_1.inject(lib_1.TYPES.ActionHandlerRegistry)),
__param(2, inversify_1.inject(lib_1.TYPES.ViewerOptions)),
__param(3, inversify_1.inject(lib_1.TYPES.SModelStorage)),
__param(4, inversify_1.inject(lib_1.TYPES.ILogger)),
__metadata("design:paramtypes", [Object, lib_1.ActionHandlerRegistry, Object, lib_1.SModelStorage, Object])
], TheiaDiagramServer);
return TheiaDiagramServer;
}(lib_1.DiagramServer));
exports.TheiaDiagramServer = TheiaDiagramServer;
//# sourceMappingURL=theia-diagram-server.js.map