UNPKG

sprotty-theia

Version:

Glue code for Sprotty diagrams in a Theia IDE

114 lines 4.88 kB
"use strict"; /******************************************************************************** * 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 ********************************************************************************/ 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TheiaDiagramServer = exports.IRootPopupModelProvider = void 0; const inversify_1 = require("inversify"); const sprotty_1 = require("sprotty"); const sprotty_protocol_1 = require("sprotty-protocol"); exports.IRootPopupModelProvider = Symbol('IRootPopupModelProvider'); /** * A sprotty DiagramServer that integrates with the Theia workbench. * * 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. */ let TheiaDiagramServer = /** @class */ (() => { let TheiaDiagramServer = class TheiaDiagramServer extends sprotty_1.DiagramServerProxy { connect(connector) { this._connector = connector; } disconnect() { } get connector() { if (!this._connector) { throw Error("TheiaDiagramServer is not connected."); } return this._connector; } get sourceUri() { return this._sourceUri; } initialize(registry) { super.initialize(registry); registry.register(sprotty_protocol_1.SelectAction.KIND, this); } handle(action) { if (action.kind === sprotty_protocol_1.RequestModelAction.KIND && action.options !== undefined) { this._sourceUri = action.options.sourceUri; } return super.handle(action); } handleLocally(action) { if (action.kind === sprotty_protocol_1.RequestPopupModelAction.KIND) { return this.handleRequestPopupModel(action); } else { return super.handleLocally(action); } } handleExportSvgAction(action) { this.connector.save(this.sourceUri, action); return true; } handleRequestPopupModel(action) { if (action.elementId === this.currentRoot.id) { this.rootPopupModelProvider.getPopupModel(action, this.currentRoot).then(model => { if (model) this.actionDispatcher.dispatch(sprotty_protocol_1.SetPopupModelAction.create(model)); }); return false; } else { return true; } } handleServerStateAction(status) { this.connector.showStatus(this.clientId, status); return false; } sendMessage(message) { this.connector.sendMessage(message); } /** * made public */ messageReceived(message) { super.messageReceived(message); } }; __decorate([ inversify_1.inject(exports.IRootPopupModelProvider), inversify_1.optional(), __metadata("design:type", Object) ], TheiaDiagramServer.prototype, "rootPopupModelProvider", void 0); TheiaDiagramServer = __decorate([ inversify_1.injectable() ], TheiaDiagramServer); return TheiaDiagramServer; })(); exports.TheiaDiagramServer = TheiaDiagramServer; //# sourceMappingURL=theia-diagram-server.js.map