Skip to content

Commit

Permalink
Add ghost elements to tool palette items through trigger actions (#65)
Browse files Browse the repository at this point in the history
* Add ghost elements to tool palette items through trigger actions

Relates to eclipse-glsp/glsp#1159

* PR Review: Add easier hooks for customization

* Update yarn lock

---------

Co-authored-by: Tobias Ortmayr <[email protected]>
  • Loading branch information
martin-fleck-at and tortmayr authored Nov 21, 2023
1 parent 1a0997e commit 6db8ac8
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 19 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 { CreateNodeOperation, GNode, Point } from '@eclipse-glsp/server';
import { CreateNodeOperation, GNode, GhostElement, Point } from '@eclipse-glsp/server';
import { injectable } from 'inversify';
import { ActivityNode, ActivityNodeBuilder } from '../graph-extension';
import { ModelTypes } from '../util/model-types';
Expand All @@ -25,10 +25,14 @@ export abstract class CreateActivityNodeHandler extends CreateWorkflowNodeOperat
return this.builder(relativeLocation).build();
}

protected builder(point: Point | undefined): ActivityNodeBuilder {
protected builder(point: Point = Point.ORIGIN, elementTypeId = this.elementTypeIds[0]): ActivityNodeBuilder {
return ActivityNode.builder()
.position(point ?? Point.ORIGIN)
.type(this.elementTypeIds[0])
.nodeType(ModelTypes.toNodeType(this.elementTypeIds[0]));
.position(point)
.type(elementTypeId)
.nodeType(ModelTypes.toNodeType(elementTypeId));
}

override createTriggerGhostElement(elementTypeId: string): GhostElement | undefined {
return { template: this.serializer.createSchema(this.builder(undefined, elementTypeId).build()) };
}
}
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 { ArgsUtil, CreateNodeOperation, GNode, Point } from '@eclipse-glsp/server';
import { ArgsUtil, CreateNodeOperation, GNode, GhostElement, Point } from '@eclipse-glsp/server';
import { Category, CategoryNodeBuilder } from '../graph-extension';
import { ModelTypes } from '../util/model-types';
import { CreateWorkflowNodeOperationHandler } from './create-workflow-node-operation-handler';
Expand All @@ -26,12 +26,16 @@ export class CreateCategoryHandler extends CreateWorkflowNodeOperationHandler {
return this.builder(relativeLocation).build();
}

protected builder(point: Point | undefined): CategoryNodeBuilder {
protected builder(point: Point = Point.ORIGIN, elementTypeId = this.elementTypeIds[0]): CategoryNodeBuilder {
return Category.builder()
.type(this.elementTypeIds[0])
.position(point ?? Point.ORIGIN)
.type(elementTypeId)
.position(point)
.name(this.label.replace(' ', '') + this.modelState.index.getAllByClass(Category).length)
.addArgs(ArgsUtil.cornerRadius(5))
.children();
}

override createTriggerGhostElement(elementTypeId: string): GhostElement | undefined {
return { template: this.serializer.createSchema(this.builder(undefined, elementTypeId).build()), dynamic: true };
}
}
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/protocol';
import { GhostElement, Point } from '@eclipse-glsp/protocol';
import { CreateNodeOperation, GNode } from '@eclipse-glsp/server';
import { injectable } from 'inversify';
import { TaskNode, TaskNodeBuilder } from '../graph-extension';
Expand All @@ -26,12 +26,16 @@ export abstract class CreateTaskHandler extends CreateWorkflowNodeOperationHandl
return this.builder(relativeLocation).build();
}

protected builder(point: Point | undefined): TaskNodeBuilder {
protected builder(point: Point = Point.ORIGIN, elementTypeId = this.elementTypeIds[0]): TaskNodeBuilder {
return TaskNode.builder()
.position(point ?? Point.ORIGIN)
.name(this.label.replace(' ', '') + this.modelState.index.getAllByClass(TaskNode).length)
.type(this.elementTypeIds[0])
.taskType(ModelTypes.toNodeType(this.elementTypeIds[0]))
.type(elementTypeId)
.taskType(ModelTypes.toNodeType(elementTypeId))
.children();
}

override createTriggerGhostElement(elementTypeId: string): GhostElement | undefined {
return { template: this.serializer.createSchema(this.builder(undefined, elementTypeId).build()), dynamic: true };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
********************************************************************************/

import { GModelElement, GNode } from '@eclipse-glsp/graph';
import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCreationAction } from '@eclipse-glsp/protocol';
import {
Args, CreateNodeOperation, GhostElement, MaybePromise, Point, SelectAction,
TriggerNodeCreationAction
} from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ActionDispatcher } from '../actions/action-dispatcher';
import { Command } from '../command/command';
Expand Down Expand Up @@ -55,7 +58,20 @@ export abstract class GModelCreateNodeOperationHandler extends GModelOperationHa
}

getTriggerActions(): TriggerNodeCreationAction[] {
return this.elementTypeIds.map(typeId => TriggerNodeCreationAction.create(typeId));
return this.elementTypeIds.map(elementTypeId => this.createTriggerNodeCreationAction(elementTypeId));
}

protected createTriggerNodeCreationAction(elementTypeId: string): TriggerNodeCreationAction {
return TriggerNodeCreationAction.create(elementTypeId,
{ ghostElement: this.createTriggerGhostElement(elementTypeId), args: this.createTriggerArgs(elementTypeId) } );
}

protected createTriggerGhostElement(elementTypeId: string): GhostElement | undefined {
return undefined;
}

protected createTriggerArgs(elementTypeId: string): Args | undefined {
return undefined;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion packages/server/src/common/operations/json-operation-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import { GModelElement } from '@eclipse-glsp/graph';
import {
AnyObject,
Args,
CreateEdgeOperation,
CreateNodeOperation,
GhostElement,
MaybePromise,
Point,
TriggerEdgeCreationAction,
Expand Down Expand Up @@ -93,7 +95,20 @@ export abstract class JsonCreateNodeOperationHandler extends JsonOperationHandle
abstract override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined>;

getTriggerActions(): TriggerNodeCreationAction[] {
return this.elementTypeIds.map(typeId => TriggerNodeCreationAction.create(typeId));
return this.elementTypeIds.map(elementTypeId => this.createTriggerNodeCreationAction(elementTypeId));
}

protected createTriggerNodeCreationAction(elementTypeId: string): TriggerNodeCreationAction {
return TriggerNodeCreationAction.create(elementTypeId,
{ ghostElement: this.createTriggerGhostElement(elementTypeId), args: this.createTriggerArgs(elementTypeId) } );
}

protected createTriggerGhostElement(elementTypeId: string): GhostElement | undefined {
return undefined;
}

protected createTriggerArgs(elementTypeId: string): Args | undefined {
return undefined;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@
prettier-plugin-packagejson "~2.4.6"

"@eclipse-glsp/protocol@next":
version "2.1.0-alpha.290"
resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-2.1.0-alpha.290.tgz#0b874cb344e5b741f2a4be43a824121f2913aab6"
integrity sha512-e49InCT4rgW33wY7Y15RA5jvC34qHdMfxIE/vmxZQApOQEdmdHw7fg8CtJ4hXDVeSXOuUN0On5InaMIpg07xKQ==
version "2.1.0-next.297"
resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-2.1.0-next.297.tgz#4d178d5286c44b293b58b614fd84d0a0653052a6"
integrity sha512-WmV/ZAHusldwrXFof5oF68peBo0EpmVAb0N/v7LeYaTUiwnz4eFARm/p0KxL2QlcPBuKgLvi0xgGDzDGvbeNcw==
dependencies:
sprotty-protocol "0.15.0-next.044bba2.13"
uuid "7.0.3"
Expand Down Expand Up @@ -7563,6 +7563,7 @@ [email protected]:
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down

0 comments on commit 6db8ac8

Please sign in to comment.