UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

118 lines 5.78 kB
"use strict"; 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocalElementNavigator = void 0; /******************************************************************************** * Copyright (c) 2023-2024 Business Informatics Group (TU Wien) and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ const sprotty_1 = require("@eclipse-glsp/sprotty"); const inversify_1 = require("inversify"); const css_feedback_1 = require("../../../base/feedback/css-feedback"); const model_1 = require("../../../model"); let LocalElementNavigator = class LocalElementNavigator { constructor() { this.navigableElementCSS = 'navigable-element'; } previous(root, current, previousCurrent, predicate) { return this.getPreviousElement(current, predicate); } next(root, current, previousCurrent, predicate) { return this.getNextElement(current, predicate); } up(root, current, previousCurrent, predicate) { return this.getIterable(current, previousCurrent, predicate); } down(root, current, previousCurrent, predicate) { return this.getIterable(current, previousCurrent, predicate); } process(root, current, target, previousCurrent, predicate) { let elements = []; // Mark only edges if (target instanceof model_1.GEdge) { // If current is a edge, we have to check the source and target if (current instanceof model_1.GEdge) { elements = this.getIterables(target, current.source === target.source ? current.source : current.target, predicate); } else { // Otherwise take the current as it is elements = this.getIterables(target, current, predicate); } } elements.filter(e => e.id !== target.id).forEach(e => this.actionDispatcher.dispatch((0, css_feedback_1.applyCssClasses)(e, this.navigableElementCSS))); } clean(root, current, previousCurrent) { root.index.all().forEach(e => this.actionDispatcher.dispatch((0, css_feedback_1.deleteCssClasses)(e, this.navigableElementCSS))); } getIterables(current, previousCurrent, predicate = () => true) { var _a, _b; const elements = []; if (current instanceof model_1.GEdge) { if (current.target === previousCurrent) { (_a = current.target) === null || _a === void 0 ? void 0 : _a.incomingEdges.forEach(e => elements.push(e)); } else { (_b = current.source) === null || _b === void 0 ? void 0 : _b.outgoingEdges.forEach(e => elements.push(e)); } } return elements.filter(predicate); } getIterable(current, previousCurrent, predicate = () => true) { return this.getIterables(current, previousCurrent, predicate).filter(e => e.id !== current.id)[0]; } getNextElement(current, predicate = () => true) { const elements = []; if (current instanceof sprotty_1.GConnectableElement) { current.outgoingEdges.forEach(e => elements.push(e)); } else if (current instanceof model_1.GEdge) { const target = current.target; elements.push(target); } return elements.filter(predicate)[0]; } getPreviousElement(current, predicate = () => true) { const elements = []; if (current instanceof sprotty_1.GConnectableElement) { current.incomingEdges.forEach(e => elements.push(e)); } else if (current instanceof model_1.GEdge) { const source = current.source; elements.push(source); } return elements.filter(predicate)[0]; } }; exports.LocalElementNavigator = LocalElementNavigator; __decorate([ (0, inversify_1.inject)(sprotty_1.EdgeRouterRegistry), (0, inversify_1.optional)(), __metadata("design:type", sprotty_1.EdgeRouterRegistry) ], LocalElementNavigator.prototype, "edgeRouterRegistry", void 0); __decorate([ (0, inversify_1.inject)(sprotty_1.TYPES.IActionDispatcher), __metadata("design:type", Object) ], LocalElementNavigator.prototype, "actionDispatcher", void 0); exports.LocalElementNavigator = LocalElementNavigator = __decorate([ (0, inversify_1.injectable)() ], LocalElementNavigator); //# sourceMappingURL=local-element-navigator.js.map