@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
174 lines • 6.14 kB
JavaScript
import { EShapeTableIds } from "./e-shape-table-ids";
import { UtilShapeSearch } from "../../util/util-shape-search";
export var EShapeTableRowSelectionType = {
NONE: 0,
SINGLE: 1,
MULTIPLE: 2
};
var EShapeTableRowSelection = /** @class */ (function () {
function EShapeTableRowSelection(parent) {
this.parent = parent;
this.type = EShapeTableRowSelectionType.NONE;
this.indices = [];
this.body = null;
}
Object.defineProperty(EShapeTableRowSelection.prototype, "values", {
get: function () {
var indices = this.indices;
var values = this.parent.data.values;
var result = (this._values = this._values || []);
if (values != null) {
result.length = 0;
for (var i = 0, imax = indices.length; i < imax; ++i) {
var index = indices[i];
if (0 <= index && index < values.length) {
result.push(values[index]);
}
}
}
return result;
},
enumerable: false,
configurable: true
});
EShapeTableRowSelection.prototype.size = function () {
return this.indices.length;
};
EShapeTableRowSelection.prototype.isEmpty = function () {
return this.indices.length <= 0;
};
EShapeTableRowSelection.prototype.toggle = function (index) {
var indices = this.indices;
var indexIndex = indices.indexOf(index);
if (indexIndex < 0) {
indices.push(index);
var body = this.getBody();
if (body != null) {
this.setRowActive(body, index, true);
}
}
else {
indices.splice(indexIndex, 1);
var body = this.getBody();
if (body != null) {
this.setRowActive(body, index, false);
}
}
};
EShapeTableRowSelection.prototype.add = function (index) {
var indices = this.indices;
var indexIndex = indices.indexOf(index);
if (indexIndex < 0) {
indices.push(index);
var body = this.getBody();
if (body != null) {
this.setRowActive(body, index, true);
}
}
};
EShapeTableRowSelection.prototype.addTo = function (index) {
var indices = this.indices;
var lastIndex = indices[indices.length - 1];
if (lastIndex < index) {
var body = this.getBody();
for (var i = lastIndex + 1; i <= index; ++i) {
if (indices.indexOf(i) < 0) {
indices.push(i);
if (body != null) {
this.setRowActive(body, i, true);
}
}
}
}
else if (index < lastIndex) {
var body = this.getBody();
for (var i = lastIndex - 1; index <= i; --i) {
if (indices.indexOf(i) < 0) {
indices.push(i);
if (body != null) {
this.setRowActive(body, i, true);
}
}
}
}
};
EShapeTableRowSelection.prototype.remove = function (index) {
var indices = this.indices;
var indexIndex = indices.indexOf(index);
if (0 <= indexIndex) {
indices.splice(indexIndex, 1);
var body = this.getBody();
if (body != null) {
this.setRowActive(body, index, false);
}
}
};
EShapeTableRowSelection.prototype.clear = function () {
var indices = this.indices;
var body = this.getBody();
if (body != null) {
for (var i = 0, imax = indices.length; i < imax; ++i) {
this.setRowActive(body, indices[i], false);
}
}
indices.length = 0;
};
EShapeTableRowSelection.prototype.clearAndAdd = function (index) {
var indices = this.indices;
var body = this.getBody();
if (body != null) {
for (var i = 0, imax = indices.length; i < imax; ++i) {
var target = indices[i];
if (target !== index) {
this.setRowActive(body, target, false);
}
}
this.setRowActive(body, index, true);
}
indices.length = 0;
indices.push(index);
};
EShapeTableRowSelection.prototype.getBody = function () {
var body = this.body;
if (body != null) {
return body;
}
return (this.body = UtilShapeSearch.findChildByType(this.parent, EShapeTableIds.BODY_ID));
};
EShapeTableRowSelection.prototype.getRow = function (body, index) {
var rows = body.children;
if (0 <= index && index < rows.length) {
return rows[index];
}
return null;
};
EShapeTableRowSelection.prototype.setRowActive = function (body, index, isActive) {
var row = this.getRow(body, index);
if (row != null) {
var cells = row.children;
for (var i = 0, imax = cells.length; i < imax; ++i) {
cells[i].state.isActive = isActive;
}
}
};
EShapeTableRowSelection.prototype.serialize = function (manager) {
return manager.addResource("[".concat(this.type, "]"));
};
EShapeTableRowSelection.prototype.deserialize = function (target, manager) {
var resources = manager.resources;
if (0 <= target && target < resources.length) {
var parsed = manager.getExtension(target);
if (parsed == null) {
parsed = JSON.parse(resources[target]);
manager.setExtension(target, parsed);
}
var type = parsed[0];
if (this.type !== type) {
this.type = type;
}
}
};
return EShapeTableRowSelection;
}());
export { EShapeTableRowSelection };
//# sourceMappingURL=e-shape-table-row-selection.js.map