theia-sprotty
Version:
Glue code for sprotty diagrams in a Theia IDE
104 lines • 4.51 kB
JavaScript
"use strict";
/*
* 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 __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var lib_1 = require("sprotty/lib");
var widget_1 = require("@theia/core/lib/browser/widgets/widget");
exports.DiagramWidgetFactory = Symbol('DiagramWidgetFactory');
var DiagramWidget = /** @class */ (function (_super) {
__extends(DiagramWidget, _super);
function DiagramWidget(options) {
var _this = _super.call(this) || this;
_this.id = options.id;
_this.svgContainerId = options.svgContainerId;
_this.uri = options.uri;
_this.diagramType = options.diagramType;
_this.modelSource = options.modelSource;
_this.actionDispatcher = options.actionDispatcher;
return _this;
}
DiagramWidget.prototype.onAfterAttach = function (msg) {
_super.prototype.onAfterAttach.call(this, msg);
var svgContainer = document.createElement("div");
svgContainer.id = this.svgContainerId;
this.node.appendChild(svgContainer);
var statusDiv = document.createElement("div");
statusDiv.setAttribute('class', 'sprotty-status');
this.node.appendChild(statusDiv);
this.statusIconDiv = document.createElement("div");
this.statusIconDiv.setAttribute('class', 'fa');
statusDiv.appendChild(this.statusIconDiv);
this.statusMessageDiv = document.createElement("div");
this.statusMessageDiv.setAttribute('class', 'sprotty-status-message');
statusDiv.appendChild(this.statusMessageDiv);
this.modelSource.handle(new lib_1.RequestModelAction({
sourceUri: this.uri.toString(true),
diagramType: this.diagramType
}));
};
DiagramWidget.prototype.getBoundsInPage = function (element) {
var bounds = element.getBoundingClientRect();
return {
x: bounds.left,
y: bounds.top,
width: bounds.width,
height: bounds.height
};
};
DiagramWidget.prototype.onResize = function (msg) {
_super.prototype.onResize.call(this, msg);
var newBounds = this.getBoundsInPage(this.node);
this.actionDispatcher.dispatch(new lib_1.InitializeCanvasBoundsAction(newBounds));
this.actionDispatcher.dispatch(new lib_1.CenterAction([], false));
};
DiagramWidget.prototype.onActivateRequest = function (msg) {
_super.prototype.onActivateRequest.call(this, msg);
var svgElement = this.node.querySelector("#" + this.svgContainerId + " svg");
if (svgElement !== null)
svgElement.focus();
};
DiagramWidget.prototype.setStatus = function (status) {
this.statusMessageDiv.textContent = status.message;
this.removeClasses(this.statusMessageDiv, 1);
this.statusMessageDiv.classList.add(status.severity.toLowerCase());
this.removeClasses(this.statusIconDiv, 1);
var classes = this.statusIconDiv.classList;
classes.add(status.severity.toLowerCase());
switch (status.severity) {
case 'ERROR':
classes.add('fa-exclamation-circle');
break;
case 'WARNING':
classes.add('fa-warning');
break;
case 'INFO':
classes.add('fa-info-circle');
break;
}
};
DiagramWidget.prototype.removeClasses = function (element, keep) {
var classes = element.classList;
while (classes.length > keep) {
var item = classes.item(classes.length - 1);
if (item)
classes.remove(item);
}
};
return DiagramWidget;
}(widget_1.BaseWidget));
exports.DiagramWidget = DiagramWidget;
//# sourceMappingURL=diagram-widget.js.map