theia-sprotty
Version:
Glue code for sprotty diagrams in a Theia IDE
189 lines • 9.71 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 __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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var theia_diagram_server_1 = require("../sprotty/theia-diagram-server");
var diagram_configuration_1 = require("./diagram-configuration");
var inversify_1 = require("inversify");
var browser_1 = require("@theia/core/lib/browser");
var diagram_widget_1 = require("./diagram-widget");
var diagram_widget_registry_1 = require("./diagram-widget-registry");
var common_1 = require("@theia/core/lib/common");
var lib_1 = require("sprotty/lib");
var browser_2 = require("@theia/editor/lib/browser");
exports.DiagramManagerProvider = Symbol('DiagramManagerProvider');
var DiagramManagerImpl = /** @class */ (function () {
function DiagramManagerImpl() {
this.onDiagramOpenedEmitter = new common_1.Emitter();
}
Object.defineProperty(DiagramManagerImpl.prototype, "id", {
get: function () {
return this.diagramType + "-diagram-opener";
},
enumerable: true,
configurable: true
});
Object.defineProperty(DiagramManagerImpl.prototype, "onDiagramOpened", {
get: function () {
return this.onDiagramOpenedEmitter.event;
},
enumerable: true,
configurable: true
});
DiagramManagerImpl.prototype.canHandle = function (uri, options) {
return 10;
};
DiagramManagerImpl.prototype.open = function (uri, input) {
var _this = this;
var promiseDiagramWidget = this.getOrCreateDiagramWidget(uri);
promiseDiagramWidget.then(function (diagramWidget) {
window.requestAnimationFrame(function () {
_this.shell.activateWidget(diagramWidget.id);
_this.onDiagramOpenedEmitter.fire(uri);
});
});
return promiseDiagramWidget;
};
DiagramManagerImpl.prototype.getOrCreateDiagramWidget = function (uri) {
return __awaiter(this, void 0, void 0, function () {
var widget, newWidget;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.widgetRegistry.getWidget(uri, this.diagramType)];
case 1:
widget = _a.sent();
if (widget !== undefined)
return [2 /*return*/, widget];
newWidget = this.createDiagramWidget(uri);
this.addToShell(newWidget);
return [2 /*return*/, Promise.resolve(newWidget)];
}
});
});
};
DiagramManagerImpl.prototype.createDiagramWidget = function (uri) {
var _this = this;
var widgetId = this.widgetRegistry.nextId();
var svgContainerId = widgetId + '_sprotty';
var diagramConfiguration = this.diagramConfigurationRegistry.get(this.diagramType);
var diContainer = diagramConfiguration.createContainer(svgContainerId);
var modelSource = diContainer.get(lib_1.TYPES.ModelSource);
if (modelSource instanceof lib_1.DiagramServer)
modelSource.clientId = widgetId;
if (modelSource instanceof theia_diagram_server_1.TheiaDiagramServer && this.diagramConnector)
this.diagramConnector.connect(modelSource);
var newWidget = this.diagramWidgetFactory({
id: widgetId, svgContainerId: svgContainerId, uri: uri, diagramType: this.diagramType, modelSource: modelSource,
actionDispatcher: diContainer.get(lib_1.TYPES.IActionDispatcher)
});
newWidget.title.closable = true;
newWidget.title.label = uri.path.base;
newWidget.title.icon = this.iconClass;
this.widgetRegistry.addWidget(uri, this.diagramType, newWidget);
newWidget.disposed.connect(function () {
_this.widgetRegistry.removeWidget(uri, _this.diagramType);
if (modelSource instanceof theia_diagram_server_1.TheiaDiagramServer && _this.diagramConnector)
_this.diagramConnector.disconnect(modelSource);
});
return newWidget;
};
DiagramManagerImpl.prototype.addToShell = function (widget) {
var currentEditor = this.editorManager.currentEditor;
var options = {
area: 'main'
};
if (!!currentEditor && currentEditor.editor.uri.toString(true) === widget.uri.toString(true)) {
options.ref = currentEditor;
options.mode = 'split-right';
}
this.shell.addWidget(widget, options);
};
Object.defineProperty(DiagramManagerImpl.prototype, "diagramWidgetFactory", {
get: function () {
return function (options) { return new diagram_widget_1.DiagramWidget(options); };
},
enumerable: true,
configurable: true
});
Object.defineProperty(DiagramManagerImpl.prototype, "diagramConnector", {
get: function () {
return undefined;
},
enumerable: true,
configurable: true
});
__decorate([
inversify_1.inject(browser_1.ApplicationShell),
__metadata("design:type", browser_1.ApplicationShell)
], DiagramManagerImpl.prototype, "shell", void 0);
__decorate([
inversify_1.inject(diagram_widget_registry_1.DiagramWidgetRegistry),
__metadata("design:type", diagram_widget_registry_1.DiagramWidgetRegistry)
], DiagramManagerImpl.prototype, "widgetRegistry", void 0);
__decorate([
inversify_1.inject(common_1.SelectionService),
__metadata("design:type", common_1.SelectionService)
], DiagramManagerImpl.prototype, "selectionService", void 0);
__decorate([
inversify_1.inject(diagram_configuration_1.DiagramConfigurationRegistry),
__metadata("design:type", diagram_configuration_1.DiagramConfigurationRegistry)
], DiagramManagerImpl.prototype, "diagramConfigurationRegistry", void 0);
__decorate([
inversify_1.inject(browser_2.EditorManager),
__metadata("design:type", browser_2.EditorManager)
], DiagramManagerImpl.prototype, "editorManager", void 0);
DiagramManagerImpl = __decorate([
inversify_1.injectable()
], DiagramManagerImpl);
return DiagramManagerImpl;
}());
exports.DiagramManagerImpl = DiagramManagerImpl;
//# sourceMappingURL=diagram-manager.js.map