@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
299 lines • 11.7 kB
JavaScript
import { __extends } from "tslib";
import { DBaseState, DButtonAmbient, DLayoutHorizontal, DLayoutVertical, DList, DListItem, DText, EShapeCapabilities, EShapeCapability } from "@wcardinal/wcardinal-ui";
import { EDialogDataMappingValue } from "./e-dialog-data-mapping-value";
var EEditorDataMapping = /** @class */ (function (_super) {
__extends(EEditorDataMapping, _super);
function EEditorDataMapping(options) {
var _this = _super.call(this, options) || this;
// Selection
var selection = options.selection;
_this._selection = selection;
// Icons
_this._icons = options.icons;
// Layout
_this.addChild(new DLayoutHorizontal({
x: "padding",
width: "padding",
height: "auto",
children: [
_this.newTextLabel(),
_this.buttonNew,
_this.buttonDelete,
_this.buttonBringForward,
_this.buttonSendBackward
]
}));
_this.addChild(_this.listDataMappingValue);
// Initialize
selection.on("change", function () {
_this.onSelectionChange(selection);
});
var listDataMappingValue = _this.listDataMappingValue;
listDataMappingValue.selection.on("change", function () {
_this.onListDataMappingValueSelectionChange(listDataMappingValue);
});
_this.onSelectionChange(selection);
return _this;
}
EEditorDataMapping.prototype.newTextLabel = function () {
return new DText({
weight: 1,
text: {
value: this.theme.getLabel()
}
});
};
Object.defineProperty(EEditorDataMapping.prototype, "buttonNew", {
get: function () {
var result = this._buttonNew;
if (result == null) {
result = this.newButtonNew();
this._buttonNew = result;
}
return result;
},
enumerable: false,
configurable: true
});
EEditorDataMapping.prototype.newButtonNew = function () {
var _this = this;
return new DButtonAmbient({
width: 30,
image: {
source: this._icons.new
},
title: this.theme.getButtonNewTitle(),
on: {
active: function (emitter) {
_this.onButtonNewActive(emitter);
}
}
});
};
EEditorDataMapping.prototype.onButtonNewActive = function (opener) {
var _this = this;
this.dialogDataMappingValue
.set(null, this._selection.last())
.open(opener)
.then(function (value) {
if (value != null) {
_this._selection.addDataMappingValue(value);
}
});
};
Object.defineProperty(EEditorDataMapping.prototype, "buttonDelete", {
get: function () {
var result = this._buttonDelete;
if (result == null) {
result = this.newButtonDelete();
this._buttonDelete = result;
}
return result;
},
enumerable: false,
configurable: true
});
EEditorDataMapping.prototype.newButtonDelete = function () {
var _this = this;
return new DButtonAmbient({
width: 30,
image: {
source: this._icons.delete
},
title: this.theme.getButtonDeleteTitle(),
state: DBaseState.DISABLED,
on: {
active: function () {
var first = _this.listDataMappingValue.selection.first;
if (first != null) {
_this._selection.removeDataMappingValue(first);
}
}
}
});
};
EEditorDataMapping.prototype.onListDataMappingValueSelectionChangeButtonDelete = function (listDataMappingValue) {
this.buttonDelete.state.isDisabled = listDataMappingValue.data.selection.isEmpty();
};
Object.defineProperty(EEditorDataMapping.prototype, "buttonBringForward", {
get: function () {
var result = this._buttonBringForward;
if (result == null) {
result = this.newButtonBringForward();
this._buttonBringForward = result;
}
return result;
},
enumerable: false,
configurable: true
});
EEditorDataMapping.prototype.newButtonBringForward = function () {
var _this = this;
return new DButtonAmbient({
width: 30,
image: {
source: this._icons.arrow_up
},
title: this.theme.getButtonBringForwardTitle(),
state: DBaseState.DISABLED,
on: {
active: function () {
var listDataMappingValue = _this.listDataMappingValue;
var first = listDataMappingValue.data.selection.first;
var items = listDataMappingValue.data.items;
if (first != null && items[0] !== first) {
_this._selection.bringDataMappingValueForward(first);
}
}
}
});
};
EEditorDataMapping.prototype.onListDataMappingValueSelectionChangeButtonBringForward = function (listDataMappingValue) {
var first = listDataMappingValue.data.selection.first;
var items = listDataMappingValue.data.items;
this.buttonBringForward.state.isDisabled = first == null || items[0] === first;
};
Object.defineProperty(EEditorDataMapping.prototype, "buttonSendBackward", {
get: function () {
var result = this._buttonSendBackward;
if (result == null) {
result = this.newButtonSendBackward();
this._buttonSendBackward = result;
}
return result;
},
enumerable: false,
configurable: true
});
EEditorDataMapping.prototype.newButtonSendBackward = function () {
var _this = this;
return new DButtonAmbient({
width: 30,
image: {
source: this._icons.arrow_down
},
title: this.theme.getButtonSendBackwardTitle(),
state: DBaseState.DISABLED,
on: {
active: function () {
var listDataMappingValue = _this.listDataMappingValue;
var first = listDataMappingValue.data.selection.first;
var items = listDataMappingValue.data.items;
if (first != null && items[items.length - 1] !== first) {
_this._selection.sendDataMappingValueBackward(first);
}
}
}
});
};
EEditorDataMapping.prototype.onListDataMappingValueSelectionChangeButtonSendBackward = function (listDataMappingValue) {
var first = listDataMappingValue.data.selection.first;
var items = listDataMappingValue.data.items;
this.buttonSendBackward.state.isDisabled =
first == null || items[items.length - 1] === first;
};
Object.defineProperty(EEditorDataMapping.prototype, "dialogDataMappingValue", {
get: function () {
var result = this._dialogDataMappingValue;
if (result == null) {
result = this.newDialogDataMappingValue();
this._dialogDataMappingValue = result;
}
return result;
},
enumerable: false,
configurable: true
});
EEditorDataMapping.prototype.newDialogDataMappingValue = function () {
return new EDialogDataMappingValue();
};
Object.defineProperty(EEditorDataMapping.prototype, "listDataMappingValue", {
get: function () {
var result = this._listDataMappingValue;
if (result == null) {
result = this.newListDataMappingValue();
this._listDataMappingValue = result;
}
return result;
},
enumerable: false,
configurable: true
});
EEditorDataMapping.prototype.newListDataMappingValue = function () {
var _this = this;
var result = new DList({
width: "padding",
weight: 1,
data: {
toLabel: function (value) {
var source = value[0];
var destination = value[1];
var initial = value[2];
if (0 < destination.length) {
if (0 < initial.length) {
return "".concat(source, " -> ").concat(destination, ", ").concat(initial);
}
else {
return "".concat(source, " -> ").concat(destination);
}
}
else {
if (0 < initial.length) {
return "".concat(source, " -> ").concat(initial);
}
else {
return "".concat(source);
}
}
}
},
updater: {
newItem: function (data) {
return new DListItem(data, {
on: {
dblclick: function (e, _, item) {
_this.onListDataMappingValueDblClick(e, _, item, result);
}
}
});
}
}
});
return result;
};
EEditorDataMapping.prototype.onListDataMappingValueDblClick = function (e, _, item, list) {
var _this = this;
var oldValue = item.value;
if (oldValue != null) {
this.dialogDataMappingValue
.set(oldValue, this._selection.last())
.open(item)
.then(function (newValue) {
if (newValue != null) {
_this._selection.replaceDataMappingValue(oldValue, newValue, list);
}
});
}
};
EEditorDataMapping.prototype.onSelectionChangeListDataMappingValue = function (selection) {
var _a, _b;
var listDataMappingValue = this.listDataMappingValue;
listDataMappingValue.data.items = ((_b = (_a = selection.last()) === null || _a === void 0 ? void 0 : _a.data.getMapping()) === null || _b === void 0 ? void 0 : _b.values) || [];
this.onListDataMappingValueSelectionChange(listDataMappingValue);
};
EEditorDataMapping.prototype.onSelectionChange = function (selection) {
this.state.isDisabled = !EShapeCapabilities.contains(selection.last(), EShapeCapability.DATA_MAPPING);
this.onSelectionChangeListDataMappingValue(selection);
};
EEditorDataMapping.prototype.onListDataMappingValueSelectionChange = function (listDataMappingValue) {
this.onListDataMappingValueSelectionChangeButtonDelete(listDataMappingValue);
this.onListDataMappingValueSelectionChangeButtonBringForward(listDataMappingValue);
this.onListDataMappingValueSelectionChangeButtonSendBackward(listDataMappingValue);
};
EEditorDataMapping.prototype.getType = function () {
return "EEditorDataMapping";
};
return EEditorDataMapping;
}(DLayoutVertical));
export { EEditorDataMapping };
//# sourceMappingURL=e-editor-data-mapping.js.map