@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
70 lines • 4.04 kB
TypeScript
/********************************************************************************
* Copyright (c) 2019-2025 EclipseSource 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
********************************************************************************/
import { GModelElement, GNode, Point } from '@eclipse-glsp/sprotty';
import { ModifyCSSFeedbackAction } from '../../base/feedback/css-feedback';
import { BoundsAwareModelElement } from '../../utils/gmodel-util';
import { ContainerElement } from '../hints/model';
/**
* A `MovementRestrictor` is an optional service that can be used by tools to validate
* whether a certain move operation (e.g. `ChangeBoundsOperation`) in the diagram is valid.
*/
export interface IMovementRestrictor {
/**
* Validate whether moving the given element to a new given location is allowed.
* @param element The element that should be moved.
* @param newLocation The new location of the element.
* @returns `true` if the the element is movable and moving to the given location is allowed, `false` otherwise.
* Should also return `false` if the newLocation is `undefined`:
*/
validate(element: GModelElement, newLocation?: Point): boolean;
/**
* Feedback css-classes. Can be applied to elements that did fail the validation.
*/
cssClasses?: string[];
}
export interface MoveElementContext {
element: GModelElement;
elementAtNewLocation: BoundsAwareModelElement;
parentContainers: ContainerElement[];
childNodes: GNode[];
}
/**
* A `IMovementRestrictor` that checks for overlapping elements. Move operations
* are only valid if the element does not collide with another element/node after moving.
*/
export declare class NoOverlapMovementRestrictor implements IMovementRestrictor {
cssClasses: string[];
validate(element: GModelElement, newLocation?: Point): boolean;
protected createMoveElementContext(element: GModelElement, newLocation: Point): MoveElementContext;
protected isBoundsRelevant(element: GModelElement, moveContext: MoveElementContext): element is BoundsAwareModelElement;
protected areOverlapping(element1: BoundsAwareModelElement, element2: BoundsAwareModelElement): boolean;
}
/**
* Utility function to create an action that applies the given {@link IMovementRestrictor.cssClasses} to the given element.
* @param element The element on which the css classes should be applied.
* @param movementRestrictor The movement restrictor whose cssClasses should be applied.
* @returns The corresponding {@link ModifyCSSFeedbackAction}
*/
export declare function createMovementRestrictionFeedback(element: GModelElement, movementRestrictor: IMovementRestrictor): ModifyCSSFeedbackAction;
/**
* Utility function to create an action that removes the given {@link IMovementRestrictor.cssClasses} from the given element.
* @param element The element from which the css classes should be removed.
* @param movementRestrictor The movement restrictor whose cssClasses should be removed.
* @returns The corresponding {@link ModifyCSSFeedbackAction}
*/
export declare function removeMovementRestrictionFeedback(element: GModelElement, movementRestrictor: IMovementRestrictor): ModifyCSSFeedbackAction;
export declare function movementRestrictionFeedback(element: GModelElement, movementRestrictor: IMovementRestrictor, valid: boolean): ModifyCSSFeedbackAction;
//# sourceMappingURL=movement-restrictor.d.ts.map