UNPKG

@wcardinal/wcardinal-geditor

Version:

WebGL-based graphic editor, tester and viewer for supervisory systems

211 lines 7.27 kB
import { __extends } from "tslib"; import { DButtonAmbient, DControllers, DDialogMessage, DDialogProcessing, DLayoutHorizontal, DLayoutVertical, DList, DListItem, DText, isArray } from "@wcardinal/wcardinal-ui"; import { ECommandShapeSelect } from "../command/e-command-shape-select"; var EEditorValidation = /** @class */ (function (_super) { __extends(EEditorValidation, _super); function EEditorValidation(options) { var _this = _super.call(this, options) || this; // Selection var selection = options.selection; _this._selection = selection; // Icons _this._icons = options.icons; // Verifier _this._validator = options.validator; // Diagram var diagram = options.diagram; _this._diagram = diagram; _this.state.isDisabled = diagram.canvas == null; diagram.on("unset", function () { _this.list.data.clear(); _this.state.isDisabled = true; }); diagram.on("set", function () { _this.state.isDisabled = false; }); // Layout _this.addChild(new DLayoutHorizontal({ x: "padding", width: "padding", height: "auto", children: [_this.newTextLabel(), _this.buttonRevalidate] })); _this.addChild(_this.list); return _this; } EEditorValidation.prototype.newTextLabel = function () { return new DText({ weight: 1, text: { value: this.theme.getLabel() } }); }; Object.defineProperty(EEditorValidation.prototype, "buttonRevalidate", { get: function () { var result = this._buttonRevalidate; if (result == null) { result = this.newButtonRevalidate(); this._buttonRevalidate = result; } return result; }, enumerable: false, configurable: true }); EEditorValidation.prototype.newButtonRevalidate = function () { var _this = this; return new DButtonAmbient({ width: 30, image: { source: this._icons.refresh }, title: this.theme.getButtonRevalidateTitle(), on: { active: function (emitter) { _this.onButtonValidateActive(emitter); } } }); }; EEditorValidation.prototype.onButtonValidateActive = function (opener) { var validator = this._validator; if (validator != null) { var canvas = this._diagram.canvas; if (canvas != null) { var dialogProcessing_1 = this.dialogProcessing; dialogProcessing_1.open(opener); var data_1 = this.list.data; try { var result = validator(canvas); if (isArray(result)) { data_1.clearAndAddAll(result); dialogProcessing_1.resolve(); } else { result.then(function (results) { data_1.clearAndAddAll(results); dialogProcessing_1.resolve(); }, function () { data_1.clear(); dialogProcessing_1.reject(); }); } } catch (_a) { data_1.clear(); dialogProcessing_1.reject(); } } } }; Object.defineProperty(EEditorValidation.prototype, "list", { get: function () { var result = this._list; if (result == null) { result = this.newList(); this._list = result; } return result; }, enumerable: false, configurable: true }); EEditorValidation.prototype.newList = function () { var _this = this; var result = new DList({ width: "padding", weight: 1, data: { toLabel: function (value) { return value.message; } }, updater: { newItem: function (data) { return new DListItem(data, { on: { select: function (value, item) { _this.onListItemDown(value, item); } } }); } } }); return result; }; EEditorValidation.prototype.onListItemDown = function (value, item) { var shape = value.shape; if (shape != null) { var canvas = this._diagram.canvas; var layer = shape.root.parent; if (canvas != null && layer != null) { // Selection var selection = this._selection; var before = selection.store(); if (selection.set(shape)) { selection.focus(); var after = selection.store(); DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection)); } else { selection.focus(); } // Change the active layer var layerActive = canvas.layer.active; if (layerActive !== layer) { canvas.layer.active = layer; } } else { this.dialogError.open(item); } } }; Object.defineProperty(EEditorValidation.prototype, "dialogError", { get: function () { var result = this._dialogError; if (result == null) { result = this.newDialogError(); this._dialogError = result; } return result; }, enumerable: false, configurable: true }); EEditorValidation.prototype.newDialogError = function () { return new DDialogMessage({ message: "No shapes found." }); }; Object.defineProperty(EEditorValidation.prototype, "dialogProcessing", { get: function () { var result = this._dialogProcessing; if (result == null) { result = this.newDialogProcessing(); this._dialogProcessing = result; } return result; }, enumerable: false, configurable: true }); EEditorValidation.prototype.newDialogProcessing = function () { return new DDialogProcessing({ footer: { button: { ok: "OK", cancel: null } } }); }; EEditorValidation.prototype.getType = function () { return "EEditorValidation"; }; return EEditorValidation; }(DLayoutVertical)); export { EEditorValidation }; //# sourceMappingURL=e-editor-validation.js.map