Skip to content

Commit

Permalink
Add Resizable with 'resizeLocations' to shape elements
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fleck-at committed May 27, 2024
1 parent cfd67f9 commit d4535d1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Point } from '@eclipse-glsp/server';
import { GResizeLocation, Point } from '@eclipse-glsp/server';
import { injectable } from 'inversify';
import { ActivityNodeBuilder } from '../graph-extension';
import { ModelTypes } from '../util/model-types';
Expand All @@ -25,6 +25,6 @@ export class CreateDecisionNodeHandler extends CreateActivityNodeHandler {
label = 'Decision Node';

protected override builder(point?: Point): ActivityNodeBuilder {
return super.builder(point).addCssClass('decision');
return super.builder(point).addCssClass('decision').resizeLocations(GResizeLocation.CROSS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Point } from '@eclipse-glsp/server';
import { GResizeLocation, Point } from '@eclipse-glsp/server';
import { injectable } from 'inversify';
import { ActivityNodeBuilder } from '../graph-extension';
import { ModelTypes } from '../util/model-types';
Expand All @@ -25,6 +25,6 @@ export class CreateMergeNodeHandler extends CreateActivityNodeHandler {
label = 'Merge Node';

protected override builder(point: Point | undefined): ActivityNodeBuilder {
return super.builder(point).addCssClass('merge');
return super.builder(point).addCssClass('merge').resizeLocations(GResizeLocation.CROSS);
}
}
60 changes: 60 additions & 0 deletions packages/graph/src/gresizable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/********************************************************************************
* Copyright (c) 2024 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, GModelElementBuilder } from './gmodel-element';

export const GResizable = Symbol('GResizable');

export interface GResizable {
resizeLocations?: GResizeLocation[];
[GResizable]: boolean;
}

export function isGResizable<G extends GModelElement>(element: G): element is G & GResizable {
return GResizable in element && element[GResizable] === true;
}

export type GResizableBuilder<G extends GModelElement = GModelElement> = GModelElementBuilder<G & GResizable>;

export namespace GResizableBuilder {
export function resizeLocations<B extends GResizableBuilder>(builder: B, resizeLocations?: GResizeLocation[]): B {
const proxy = builder['proxy'];
proxy.resizeLocations = resizeLocations;
return builder;
}
}

export enum GResizeLocation {
TopLeft = 'top-left',
Top = 'top',
TopRight = 'top-right',
Right = 'right',
BottomRight = 'bottom-right',
Bottom = 'bottom',
BottomLeft = 'bottom-left',
Left = 'left'
}

export namespace GResizeLocation {
export const CORNERS: GResizeLocation[] = [
GResizeLocation.TopLeft,
GResizeLocation.TopRight,
GResizeLocation.BottomRight,
GResizeLocation.BottomLeft
];
export const CROSS: GResizeLocation[] = [GResizeLocation.Top, GResizeLocation.Right, GResizeLocation.Bottom, GResizeLocation.Left];
export const ALL: GResizeLocation[] = [...GResizeLocation.CORNERS, ...GResizeLocation.CROSS];
}
9 changes: 8 additions & 1 deletion packages/graph/src/gshape-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import { Args, Dimension, JsonPrimitive, Point } from '@eclipse-glsp/protocol';
import { GBoundsAware, GBoundsAwareBuilder } from './gbounds-aware';
import { GLayoutable, GLayoutableBuilder } from './glayoutable';
import { GModelElement, GModelElementBuilder } from './gmodel-element';
import { GResizable, GResizableBuilder, GResizeLocation } from './gresizable';

export abstract class GShapeElement extends GModelElement implements GBoundsAware, GLayoutable {
export abstract class GShapeElement extends GModelElement implements GBoundsAware, GLayoutable, GResizable {
layoutOptions?: Args;
position: Point;
size: Dimension;
resizeLocations?: GResizeLocation[];
[GBoundsAware] = true;
[GLayoutable] = true;
[GResizable] = true;
}

export class GShapeElementBuilder<G extends GShapeElement> extends GModelElementBuilder<G> {
Expand All @@ -48,4 +51,8 @@ export class GShapeElementBuilder<G extends GShapeElement> extends GModelElement
addLayoutOptions(layoutOptions: Args | Map<string, JsonPrimitive>): this {
return GLayoutableBuilder.addLayoutOptions(this, layoutOptions);
}

resizeLocations(resizeLocations?: GResizeLocation[]): this {
return GResizableBuilder.resizeLocations(this, resizeLocations);
}
}
1 change: 1 addition & 0 deletions packages/graph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export * from './gmodel-util';
export * from './gnode';
export * from './gport';
export * from './gpre-rendered-element';
export * from './gresizable';
export * from './gshape-element';
export * from './gshaped-prerendered-element';

0 comments on commit d4535d1

Please sign in to comment.