From 32ceb7125e0c0413824ad96733eb175cc4e19f86 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 30 Oct 2023 23:06:27 +0100 Subject: [PATCH 1/9] added server components (handler, item provider) for smart connector --- .../server/src/common/di/diagram-module.ts | 7 ++ .../context-actions-provider-registry.ts | 7 +- .../smart-connector-action-handler.ts | 35 +++++++++ .../smart-connector-item-provider.ts | 76 +++++++++++++++++++ .../gmodel-create-node-operation-handler.ts | 11 ++- 5 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 packages/server/src/common/features/contextactions/smart-connector-action-handler.ts create mode 100644 packages/server/src/common/features/contextactions/smart-connector-item-provider.ts diff --git a/packages/server/src/common/di/diagram-module.ts b/packages/server/src/common/di/diagram-module.ts index b85d224..d6706dc 100644 --- a/packages/server/src/common/di/diagram-module.ts +++ b/packages/server/src/common/di/diagram-module.ts @@ -75,6 +75,8 @@ import { NavigationTargetProviders, Operations } from './service-identifiers'; +import { DefaultSmartConnectorItemProvider, SmartConnectorItemProvider } from '../features/contextactions/smart-connector-item-provider'; +import { OpenSmartConnectorActionHandler } from '../features/contextactions/smart-connector-action-handler'; /** * The diagram module is the central configuration artifact for configuring a client session specific injector. For each @@ -151,6 +153,7 @@ export abstract class DiagramModule extends GLSPModule { applyOptionalBindingTarget(context, ToolPaletteItemProvider, this.bindToolPaletteItemProvider()); applyOptionalBindingTarget(context, CommandPaletteActionProvider, this.bindCommandPaletteActionProvider()); applyOptionalBindingTarget(context, ContextMenuItemProvider, this.bindContextMenuItemProvider()); + applyOptionalBindingTarget(context, SmartConnectorItemProvider, this.bindSmartConnectorPaletteActionProvider()); this.configureMultiBinding(new MultiBinding(ContextActionsProviders), binding => this.configureContextActionProviders(binding) ); @@ -211,6 +214,7 @@ export abstract class DiagramModule extends GLSPModule { binding.add(SaveModelActionHandler); binding.add(UndoRedoActionHandler); binding.add(ComputedBoundsActionHandler); + binding.add(OpenSmartConnectorActionHandler); } protected bindDiagramType(): BindingTarget { @@ -338,6 +342,9 @@ export abstract class DiagramModule extends GLSPModule { protected bindToolPaletteItemProvider(): BindingTarget | undefined { return DefaultToolPaletteItemProvider; } + protected bindSmartConnectorPaletteActionProvider(): BindingTarget | undefined { + return DefaultSmartConnectorItemProvider; + } protected bindCommandPaletteActionProvider(): BindingTarget | undefined { return undefined; } diff --git a/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts b/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts index 7a2c71c..9f776c5 100644 --- a/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts +++ b/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts @@ -20,6 +20,7 @@ import { CommandPaletteActionProvider } from './command-palette-action-provider' import { ContextActionsProvider } from './context-actions-provider'; import { ContextMenuItemProvider } from './context-menu-item-provider'; import { ToolPaletteItemProvider } from './tool-palette-item-provider'; +import { SmartConnectorItemProvider } from './smart-connector-item-provider'; /** * A registry that keeps track of all registered {@link ContextActionsProvider}s. @@ -30,7 +31,8 @@ export class ContextActionsProviderRegistry extends Registry this.register(provider.contextId, provider)); @@ -43,5 +45,8 @@ export class ContextActionsProviderRegistry extends Registry { + if (SelectAction.is(action)) { + const selectedElement = this.modelState.index.find(action.selectedElementsIDs[0]); + if (selectedElement && selectedElement instanceof GNode) { + var bounds: Bounds = { + x: selectedElement.position.x, + y: selectedElement.position.y, + width: selectedElement.size.width, + height: selectedElement.size.height + } + return [OpenSmartConnectorAction.create(action.selectedElementsIDs[0], bounds)]; + } + } + return [CloseSmartConnectorAction.create()]; + } +} \ No newline at end of file diff --git a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts new file mode 100644 index 0000000..4d35493 --- /dev/null +++ b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts @@ -0,0 +1,76 @@ +import { + Args, + CreateEdgeOperation, + CreateNodeOperation, + PaletteItem, + EditorContext, + LabeledAction, + MaybePromise, +} from '@eclipse-glsp/protocol'; +import { inject, injectable } from 'inversify'; +import { CreateOperationHandler } from '../../operations/create-operation-handler'; +import { OperationHandlerRegistry } from '../../operations/operation-handler-registry'; +import { ContextActionsProvider } from './context-actions-provider'; + + + +/** + * A {@link ContextActionsProvider} for {@link PaletteItem}s in the Smart Connector which appears when a node is selected. + */ +@injectable() +export abstract class SmartConnectorItemProvider implements ContextActionsProvider { + /** + * Returns the context id of the provider. + */ + get contextId(): string { + return 'smart-connector'; + } + + /** + * Returns a list of {@link LabeledAction}s for a given {@link EditorContext}. + * + * @param editorContext The editorContext for which the actions are returned. + * @returns A list of {@link LabeledAction}s for a given {@link EditorContext}. + */ + async getActions(editorContext: EditorContext): Promise { + return this.getItems(editorContext.args); + } + + /** + * Constructs a list of {@link PaletteItem}s for a given map of string arguments. + * + * @param args A map of string arguments. + * @returns A list of {@link PaletteItem}s for a given map of string arguments. + */ + abstract getItems(args?: Args): MaybePromise; +} + +@injectable() +export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvider { + @inject(OperationHandlerRegistry) operationHandlerRegistry: OperationHandlerRegistry; + protected counter: number; + + getItems(_args?: Args): PaletteItem[] { + const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; + this.counter = 0; + const nodes = this.createPaletteItem(handlers, CreateNodeOperation.KIND); + const edges = this.createPaletteItem(handlers, CreateEdgeOperation.KIND); + return [ + { id: 'node-group', label: 'Nodes', actions: [], children: nodes, icon: 'symbol-property', sortString: 'A' }, + { id: 'edge-group', label: 'Edges', actions: [], children: edges, icon: 'symbol-property', sortString: 'B' } + ]; + } + + createPaletteItem(handlers: CreateOperationHandler[], kind: string): PaletteItem[] { + return handlers + .filter(handler => handler.operationType === kind) + .map(handler => handler.getTriggerActions().map(action => this.create(action, handler.label))) + .reduce((accumulator, value) => accumulator.concat(value), []) + .sort((a, b) => a.sortString.localeCompare(b.sortString)); + } + + create(action: PaletteItem.TriggerElementCreationAction, label: string): PaletteItem { + return { id: `smart-connector-palette-item${this.counter}`, sortString: label.charAt(0), label, actions: [action] }; + } + +} diff --git a/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts b/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts index 112bec4..59a89f1 100644 --- a/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts +++ b/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts @@ -15,7 +15,7 @@ ********************************************************************************/ import { GModelElement, GNode } from '@eclipse-glsp/graph'; -import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCreationAction } from '@eclipse-glsp/protocol'; +import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCreationAction, CreateEdgeOperation } from '@eclipse-glsp/protocol'; import { inject, injectable } from 'inversify'; import { ActionDispatcher } from '../actions/action-dispatcher'; import { Command } from '../command/command'; @@ -51,6 +51,15 @@ export abstract class GModelCreateNodeOperationHandler extends GModelOperationHa container.children.push(element); element.parent = container; this.actionDispatcher.dispatchAfterNextUpdate(SelectAction.create({ selectedElementsIDs: [element.id] })); + // Creates default edge on node creation when a source ID is given in the CreateNodeOperation + if (operation.args?.createEdge) { + this.actionDispatcher.dispatchAfterNextUpdate(CreateEdgeOperation.create({ + //TODO: change to default edge type + elementTypeId: 'edge', + sourceElementId: operation.args?.source as string, + targetElementId: element.id + })) + } } } From ca2e9b105091bb09a1922c3eac75107065bb9d3c Mon Sep 17 00:00:00 2001 From: Tobias Date: Tue, 14 Nov 2023 15:07:35 +0100 Subject: [PATCH 2/9] added possibility to set position for smart connector containers (left, right, up, down) --- .../smart-connector-action-handler.ts | 10 +---- .../smart-connector-item-provider.ts | 45 +++++++++++++++---- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts index 4936688..b7f4a1d 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts @@ -1,6 +1,5 @@ import { Action, - Bounds, CloseSmartConnectorAction, OpenSmartConnectorAction, SelectAction, @@ -21,14 +20,9 @@ export class OpenSmartConnectorActionHandler implements ActionHandler { if (SelectAction.is(action)) { const selectedElement = this.modelState.index.find(action.selectedElementsIDs[0]); if (selectedElement && selectedElement instanceof GNode) { - var bounds: Bounds = { - x: selectedElement.position.x, - y: selectedElement.position.y, - width: selectedElement.size.width, - height: selectedElement.size.height - } - return [OpenSmartConnectorAction.create(action.selectedElementsIDs[0], bounds)]; + return [OpenSmartConnectorAction.create(action.selectedElementsIDs[0])]; } + else return [] } return [CloseSmartConnectorAction.create()]; } diff --git a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts index 4d35493..ece54ab 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts @@ -3,14 +3,18 @@ import { CreateEdgeOperation, CreateNodeOperation, PaletteItem, + SmartConnectorGroupItem, EditorContext, LabeledAction, MaybePromise, + SmartConnectorPosition, + SmartConnectorGroupUIType } from '@eclipse-glsp/protocol'; import { inject, injectable } from 'inversify'; import { CreateOperationHandler } from '../../operations/create-operation-handler'; import { OperationHandlerRegistry } from '../../operations/operation-handler-registry'; import { ContextActionsProvider } from './context-actions-provider'; +import { GLSPServerError } from '../../utils/glsp-server-error'; @@ -50,23 +54,48 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide @inject(OperationHandlerRegistry) operationHandlerRegistry: OperationHandlerRegistry; protected counter: number; - getItems(_args?: Args): PaletteItem[] { + // TODO + protected defaultSmartConnectorNodeSettings = { + position: SmartConnectorPosition.Top, + showTitle: true, + submenu: false, + showOnlyForChildren: SmartConnectorGroupUIType.Icons + } + + protected defaultSmartConnectorEdgeSettings = { + position: SmartConnectorPosition.Right, + showTitle: true, + submenu: false + } + + getItems(args?: Args): SmartConnectorGroupItem[] { + if (args?.iconOnly && args?.labelOnly) throw new GLSPServerError('Settings for smart connector cannot contain iconOnly and labelOnly at the same time!'); const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; - this.counter = 0; - const nodes = this.createPaletteItem(handlers, CreateNodeOperation.KIND); - const edges = this.createPaletteItem(handlers, CreateEdgeOperation.KIND); + this.counter = 0; + var maxNodes = args?.maxNodes as number; + var maxEdges = args?.maxEdges as number; + var iconOnly = args?.iconOnly as boolean; + var labelOnly = args?.labelOnly as boolean; + const nodes = this.createPaletteItem(handlers, CreateNodeOperation.KIND, maxNodes, iconOnly, labelOnly); + const edges = this.createPaletteItem(handlers, CreateEdgeOperation.KIND, maxEdges, iconOnly, labelOnly); return [ - { id: 'node-group', label: 'Nodes', actions: [], children: nodes, icon: 'symbol-property', sortString: 'A' }, - { id: 'edge-group', label: 'Edges', actions: [], children: edges, icon: 'symbol-property', sortString: 'B' } + { id: 'node-group', label: 'Nodes', actions: [], children: nodes, icon: 'symbol-property', sortString: 'A', ...this.defaultSmartConnectorNodeSettings }, + { id: 'edge-group', label: 'Edges', actions: [], children: edges, icon: 'symbol-property', sortString: 'B', ...this.defaultSmartConnectorEdgeSettings } ]; } - createPaletteItem(handlers: CreateOperationHandler[], kind: string): PaletteItem[] { - return handlers + createPaletteItem(handlers: CreateOperationHandler[], kind: string, maxElements?: number, iconOnly?: boolean, labelOnly?: boolean): PaletteItem[] { + var paletteItems = handlers .filter(handler => handler.operationType === kind) .map(handler => handler.getTriggerActions().map(action => this.create(action, handler.label))) .reduce((accumulator, value) => accumulator.concat(value), []) .sort((a, b) => a.sortString.localeCompare(b.sortString)); + paletteItems.forEach(paletteItem => paletteItem.icon = !iconOnly ? paletteItem.icon : '') + paletteItems.forEach(paletteItem => paletteItem.label = !labelOnly ? paletteItem.label : '') + if (maxElements) + return paletteItems.slice(0, maxElements); + else + return paletteItems; } create(action: PaletteItem.TriggerElementCreationAction, label: string): PaletteItem { From 85cb92c3104104d7f7a35b5f8a2502e26223440f Mon Sep 17 00:00:00 2001 From: yentelmanero Date: Thu, 30 Nov 2023 01:32:17 +0100 Subject: [PATCH 3/9] added customization options and workflow example for smart connector --- .../workflow-smart-connector-item-provider.ts | 58 ++++++++++++ .../src/common/workflow-diagram-module.ts | 8 +- .../server/src/common/di/diagram-module.ts | 4 +- .../smart-connector-item-provider.ts | 94 +++++++++++++------ .../gmodel-create-node-operation-handler.ts | 4 +- packages/server/src/common/index.ts | 2 + 6 files changed, 134 insertions(+), 36 deletions(-) create mode 100644 examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts diff --git a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts new file mode 100644 index 0000000..537d16c --- /dev/null +++ b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts @@ -0,0 +1,58 @@ +/******************************************************************************** + * Copyright (c) 2022-2023 STMicroelectronics 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 { + DefaultSmartConnectorItemProvider, SmartConnectorSettings, +} from '@eclipse-glsp/server'; +import { + SmartConnectorPosition, + SmartConnectorGroupUIType, + DefaultTypes, +} from '@eclipse-glsp/protocol'; +import { injectable } from 'inversify'; +import { ModelTypes } from '../util/model-types'; + + +@injectable() +export class WorkflowSmartConnectorItemProvider extends DefaultSmartConnectorItemProvider { + + protected override smartConnectorNodeSettings: SmartConnectorSettings = { + position: SmartConnectorPosition.Top, + showTitle: true, + submenu: false, + showOnlyForChildren: SmartConnectorGroupUIType.Labels + } + + protected override smartConnectorEdgeSettings: SmartConnectorSettings = { + position: SmartConnectorPosition.Right, + showTitle: true, + submenu: true + } + + override nodeOperationFilter = { + [ModelTypes.AUTOMATED_TASK]: [ModelTypes.WEIGHTED_EDGE, ModelTypes.AUTOMATED_TASK, ModelTypes.MANUAL_TASK, ModelTypes.ACTIVITY_NODE], + [ModelTypes.MERGE_NODE]: [DefaultTypes.EDGE, ModelTypes.MERGE_NODE, ModelTypes.CATEGORY], + [ModelTypes.FORK_NODE]: [DefaultTypes.EDGE, ModelTypes.FORK_NODE], + [ModelTypes.CATEGORY]: [ModelTypes.WEIGHTED_EDGE, ModelTypes.FORK_NODE], + [ModelTypes.JOIN_NODE]: [ModelTypes.AUTOMATED_TASK, ModelTypes.FORK_NODE, ModelTypes.JOIN_NODE], + } + + override defaultEdge = DefaultTypes.EDGE; + + override edgeTypes = { + [ModelTypes.AUTOMATED_TASK]: DefaultTypes.EDGE, + [ModelTypes.MERGE_NODE]: DefaultTypes.EDGE, + } +} diff --git a/examples/workflow-server/src/common/workflow-diagram-module.ts b/examples/workflow-server/src/common/workflow-diagram-module.ts index 8cfdc82..45e2310 100644 --- a/examples/workflow-server/src/common/workflow-diagram-module.ts +++ b/examples/workflow-server/src/common/workflow-diagram-module.ts @@ -32,7 +32,8 @@ import { OperationHandlerConstructor, PopupModelFactory, ServerModule, - SourceModelStorage + SourceModelStorage, + SmartConnectorItemProvider } from '@eclipse-glsp/server'; import { injectable } from 'inversify'; import { CreateAutomatedTaskHandler } from './handler/create-automated-task-handler'; @@ -52,6 +53,7 @@ import { NodeDocumentationNavigationTargetProvider } from './provider/node-docum import { PreviousNodeNavigationTargetProvider } from './provider/previous-node-navigation-target-provider'; import { WorkflowCommandPaletteActionProvider } from './provider/workflow-command-palette-action-provider'; import { WorkflowContextMenuItemProvider } from './provider/workflow-context-menu-item-provider'; +import { WorkflowSmartConnectorItemProvider } from './provider/workflow-smart-connector-item-provider'; import { EditTaskOperationHandler } from './taskedit/edit-task-operation-handler'; import { TaskEditContextActionProvider } from './taskedit/task-edit-context-provider'; import { TaskEditValidator } from './taskedit/task-edit-validator'; @@ -107,6 +109,10 @@ export class WorkflowDiagramModule extends GModelDiagramModule { return WorkflowCommandPaletteActionProvider; } + protected override bindSmartConnectorItemProvider(): BindingTarget | undefined { + return WorkflowSmartConnectorItemProvider; + } + protected override bindLabelEditValidator(): BindingTarget | undefined { return WorkflowLabelEditValidator; } diff --git a/packages/server/src/common/di/diagram-module.ts b/packages/server/src/common/di/diagram-module.ts index 260dbd3..bff3bd1 100644 --- a/packages/server/src/common/di/diagram-module.ts +++ b/packages/server/src/common/di/diagram-module.ts @@ -156,7 +156,7 @@ export abstract class DiagramModule extends GLSPModule { applyOptionalBindingTarget(context, ToolPaletteItemProvider, this.bindToolPaletteItemProvider()); applyOptionalBindingTarget(context, CommandPaletteActionProvider, this.bindCommandPaletteActionProvider()); applyOptionalBindingTarget(context, ContextMenuItemProvider, this.bindContextMenuItemProvider()); - applyOptionalBindingTarget(context, SmartConnectorItemProvider, this.bindSmartConnectorPaletteActionProvider()); + applyOptionalBindingTarget(context, SmartConnectorItemProvider, this.bindSmartConnectorItemProvider()); this.configureMultiBinding(new MultiBinding(ContextActionsProviders), binding => this.configureContextActionProviders(binding) ); @@ -348,7 +348,7 @@ export abstract class DiagramModule extends GLSPModule { protected bindToolPaletteItemProvider(): BindingTarget | undefined { return DefaultToolPaletteItemProvider; } - protected bindSmartConnectorPaletteActionProvider(): BindingTarget | undefined { + protected bindSmartConnectorItemProvider(): BindingTarget | undefined { return DefaultSmartConnectorItemProvider; } protected bindCommandPaletteActionProvider(): BindingTarget | undefined { diff --git a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts index ece54ab..e9577f9 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts @@ -8,14 +8,14 @@ import { LabeledAction, MaybePromise, SmartConnectorPosition, - SmartConnectorGroupUIType + SmartConnectorGroupUIType, + SmartConnectorNodeItem, + TriggerNodeCreationAction } from '@eclipse-glsp/protocol'; import { inject, injectable } from 'inversify'; import { CreateOperationHandler } from '../../operations/create-operation-handler'; import { OperationHandlerRegistry } from '../../operations/operation-handler-registry'; import { ContextActionsProvider } from './context-actions-provider'; -import { GLSPServerError } from '../../utils/glsp-server-error'; - /** @@ -46,60 +46,92 @@ export abstract class SmartConnectorItemProvider implements ContextActionsProvid * @param args A map of string arguments. * @returns A list of {@link PaletteItem}s for a given map of string arguments. */ - abstract getItems(args?: Args): MaybePromise; + abstract getItems(args?: Args): MaybePromise; + + /** filter that excludes nodes/edges from options, given a node ID as key */ + abstract nodeOperationFilter: Record; + + /** edge that is used between source and destination by default when a new node is created + * (if not given, no edge will be created when creating new node) */ + abstract defaultEdge: string; + + /** list of edges where the key is a node ID and the value is a edge ID + * the edge to a new node when the source node has the ID of the key + * otherwise, the default edge will be used */ + abstract edgeTypes: Record; } +export type SmartConnectorSettings = { + position: SmartConnectorPosition + showTitle: true; + submenu: boolean; + showOnlyForChildren?: SmartConnectorGroupUIType + } | { + position: SmartConnectorPosition + showTitle: false; + showOnlyForChildren?: SmartConnectorGroupUIType + } + @injectable() export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvider { + @inject(OperationHandlerRegistry) operationHandlerRegistry: OperationHandlerRegistry; + protected counter: number; - // TODO - protected defaultSmartConnectorNodeSettings = { - position: SmartConnectorPosition.Top, + protected smartConnectorNodeSettings: SmartConnectorSettings = { + position: SmartConnectorPosition.Right, showTitle: true, - submenu: false, - showOnlyForChildren: SmartConnectorGroupUIType.Icons + submenu: true, + showOnlyForChildren: SmartConnectorGroupUIType.Icons } - protected defaultSmartConnectorEdgeSettings = { + protected smartConnectorEdgeSettings: SmartConnectorSettings = { position: SmartConnectorPosition.Right, showTitle: true, submenu: false } + override nodeOperationFilter: Record; + override defaultEdge: string; + override edgeTypes: Record; + getItems(args?: Args): SmartConnectorGroupItem[] { - if (args?.iconOnly && args?.labelOnly) throw new GLSPServerError('Settings for smart connector cannot contain iconOnly and labelOnly at the same time!'); const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; - this.counter = 0; - var maxNodes = args?.maxNodes as number; - var maxEdges = args?.maxEdges as number; - var iconOnly = args?.iconOnly as boolean; - var labelOnly = args?.labelOnly as boolean; - const nodes = this.createPaletteItem(handlers, CreateNodeOperation.KIND, maxNodes, iconOnly, labelOnly); - const edges = this.createPaletteItem(handlers, CreateEdgeOperation.KIND, maxEdges, iconOnly, labelOnly); + this.counter = 0; + const nodes = this.createSmartConnectorGroupItem(handlers, CreateNodeOperation.KIND, args?.nodeType as string, this.smartConnectorNodeSettings.showOnlyForChildren); + const edges = this.createSmartConnectorGroupItem(handlers, CreateEdgeOperation.KIND, args?.nodeType as string, this.smartConnectorEdgeSettings.showOnlyForChildren); return [ - { id: 'node-group', label: 'Nodes', actions: [], children: nodes, icon: 'symbol-property', sortString: 'A', ...this.defaultSmartConnectorNodeSettings }, - { id: 'edge-group', label: 'Edges', actions: [], children: edges, icon: 'symbol-property', sortString: 'B', ...this.defaultSmartConnectorEdgeSettings } + { id: 'smart-connector-node-group', label: 'Nodes', actions: [], children: nodes, icon: 'symbol-property', sortString: 'A', ...this.smartConnectorNodeSettings }, + { id: 'smart-connector-edge-group', label: 'Edges', actions: [], children: edges, icon: 'symbol-property', sortString: 'B', ...this.smartConnectorEdgeSettings } ]; } - createPaletteItem(handlers: CreateOperationHandler[], kind: string, maxElements?: number, iconOnly?: boolean, labelOnly?: boolean): PaletteItem[] { + createSmartConnectorGroupItem(handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, showOnly?: SmartConnectorGroupUIType): PaletteItem[] { + var includedInNodeFilter = (e: string) => this.nodeOperationFilter[selectedNodeType].includes(e) var paletteItems = handlers - .filter(handler => handler.operationType === kind) - .map(handler => handler.getTriggerActions().map(action => this.create(action, handler.label))) + .filter(handler => handler.operationType === kind && (selectedNodeType && this.nodeOperationFilter[selectedNodeType] ? !handler.elementTypeIds.some(includedInNodeFilter) : true)) + .map(handler => handler.getTriggerActions().map(action => this.create(action, handler.label, selectedNodeType))) .reduce((accumulator, value) => accumulator.concat(value), []) .sort((a, b) => a.sortString.localeCompare(b.sortString)); - paletteItems.forEach(paletteItem => paletteItem.icon = !iconOnly ? paletteItem.icon : '') - paletteItems.forEach(paletteItem => paletteItem.label = !labelOnly ? paletteItem.label : '') - if (maxElements) - return paletteItems.slice(0, maxElements); - else - return paletteItems; + if (showOnly === SmartConnectorGroupUIType.Icons) { + if (paletteItems.every(paletteItem => paletteItem.icon != '')) { + console.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.') + return paletteItems; + } + paletteItems.forEach(paletteItem => paletteItem.label = '') + } + if (showOnly === SmartConnectorGroupUIType.Labels) paletteItems.forEach(paletteItem => paletteItem.icon = '') + return paletteItems; } - create(action: PaletteItem.TriggerElementCreationAction, label: string): PaletteItem { - return { id: `smart-connector-palette-item${this.counter}`, sortString: label.charAt(0), label, actions: [action] }; + create(action: PaletteItem.TriggerElementCreationAction, label: string, nodeType: string): PaletteItem | SmartConnectorNodeItem { + if (TriggerNodeCreationAction.is(action)) { + var edgeType = this.edgeTypes[nodeType] + if (!edgeType) edgeType = this.defaultEdge; + return { id: `smart-connector-palette-item${this.counter++}`, sortString: label.charAt(0), label, actions: [action], edgeType: edgeType }; + } + return { id: `smart-connector-palette-item${this.counter++}`, sortString: label.charAt(0), label, actions: [action] }; } } diff --git a/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts b/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts index 3bb11ec..6fb3651 100644 --- a/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts +++ b/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts @@ -52,10 +52,10 @@ export abstract class GModelCreateNodeOperationHandler extends GModelOperationHa element.parent = container; this.actionDispatcher.dispatchAfterNextUpdate(SelectAction.create({ selectedElementsIDs: [element.id] })); // Creates default edge on node creation when a source ID is given in the CreateNodeOperation - if (operation.args?.createEdge) { + if (operation.args?.createEdge && operation.args?.edgeType) { this.actionDispatcher.dispatchAfterNextUpdate(CreateEdgeOperation.create({ //TODO: change to default edge type - elementTypeId: 'edge', + elementTypeId: operation.args?.edgeType as string, sourceElementId: operation.args?.source as string, targetElementId: element.id })) diff --git a/packages/server/src/common/index.ts b/packages/server/src/common/index.ts index a2e84b4..a74be13 100644 --- a/packages/server/src/common/index.ts +++ b/packages/server/src/common/index.ts @@ -39,6 +39,8 @@ export * from './features/contextactions/context-actions-provider'; export * from './features/contextactions/context-actions-provider-registry'; export * from './features/contextactions/context-menu-item-provider'; export * from './features/contextactions/request-context-actions-handler'; +export * from './features/contextactions/smart-connector-action-handler'; +export * from './features/contextactions/smart-connector-item-provider'; export * from './features/contextactions/tool-palette-item-provider'; export * from './features/directediting/context-edit-validator'; export * from './features/directediting/context-edit-validator-registry'; From 8b770695d00dcd4de8f23ebb1fbde2d0c63b592c Mon Sep 17 00:00:00 2001 From: yentelmanero Date: Thu, 30 Nov 2023 15:51:24 +0100 Subject: [PATCH 4/9] addressed lint issues --- .../workflow-smart-connector-item-provider.ts | 28 +++--- .../smart-connector-action-handler.ts | 33 +++++-- .../smart-connector-item-provider.ts | 96 ++++++++++++++----- .../gmodel-create-node-operation-handler.ts | 8 +- 4 files changed, 112 insertions(+), 53 deletions(-) diff --git a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts index 537d16c..a78cd8d 100644 --- a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts +++ b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts @@ -14,45 +14,45 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { - DefaultSmartConnectorItemProvider, SmartConnectorSettings, + DefaultSmartConnectorItemProvider, SmartConnectorSettings } from '@eclipse-glsp/server'; -import { +import { SmartConnectorPosition, SmartConnectorGroupUIType, - DefaultTypes, -} from '@eclipse-glsp/protocol'; + DefaultTypes +} from '@eclipse-glsp/protocol'; import { injectable } from 'inversify'; import { ModelTypes } from '../util/model-types'; - @injectable() export class WorkflowSmartConnectorItemProvider extends DefaultSmartConnectorItemProvider { - + protected override smartConnectorNodeSettings: SmartConnectorSettings = { position: SmartConnectorPosition.Top, showTitle: true, submenu: false, - showOnlyForChildren: SmartConnectorGroupUIType.Labels - } + showOnlyForChildren: SmartConnectorGroupUIType.Labels + }; protected override smartConnectorEdgeSettings: SmartConnectorSettings = { position: SmartConnectorPosition.Right, showTitle: true, submenu: true - } + }; override nodeOperationFilter = { - [ModelTypes.AUTOMATED_TASK]: [ModelTypes.WEIGHTED_EDGE, ModelTypes.AUTOMATED_TASK, ModelTypes.MANUAL_TASK, ModelTypes.ACTIVITY_NODE], + [ModelTypes.AUTOMATED_TASK]: [ModelTypes.WEIGHTED_EDGE, ModelTypes.AUTOMATED_TASK, ModelTypes.MANUAL_TASK, + ModelTypes.ACTIVITY_NODE], [ModelTypes.MERGE_NODE]: [DefaultTypes.EDGE, ModelTypes.MERGE_NODE, ModelTypes.CATEGORY], [ModelTypes.FORK_NODE]: [DefaultTypes.EDGE, ModelTypes.FORK_NODE], [ModelTypes.CATEGORY]: [ModelTypes.WEIGHTED_EDGE, ModelTypes.FORK_NODE], - [ModelTypes.JOIN_NODE]: [ModelTypes.AUTOMATED_TASK, ModelTypes.FORK_NODE, ModelTypes.JOIN_NODE], - } + [ModelTypes.JOIN_NODE]: [ModelTypes.AUTOMATED_TASK, ModelTypes.FORK_NODE, ModelTypes.JOIN_NODE] + }; override defaultEdge = DefaultTypes.EDGE; override edgeTypes = { [ModelTypes.AUTOMATED_TASK]: DefaultTypes.EDGE, - [ModelTypes.MERGE_NODE]: DefaultTypes.EDGE, - } + [ModelTypes.MERGE_NODE]: DefaultTypes.EDGE + }; } diff --git a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts index b7f4a1d..51f34bb 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts @@ -1,9 +1,24 @@ -import { - Action, - CloseSmartConnectorAction, - OpenSmartConnectorAction, - SelectAction, - MaybePromise, } from '@eclipse-glsp/protocol'; +/******************************************************************************** + * Copyright (c) 2022-2023 STMicroelectronics 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 { + Action, + CloseSmartConnectorAction, + OpenSmartConnectorAction, + SelectAction, + MaybePromise} from '@eclipse-glsp/protocol'; import { inject, injectable } from 'inversify'; import { ActionHandler } from '../../actions/action-handler'; import { ModelState } from '../model/model-state'; @@ -20,10 +35,10 @@ export class OpenSmartConnectorActionHandler implements ActionHandler { if (SelectAction.is(action)) { const selectedElement = this.modelState.index.find(action.selectedElementsIDs[0]); if (selectedElement && selectedElement instanceof GNode) { - return [OpenSmartConnectorAction.create(action.selectedElementsIDs[0])]; + return [OpenSmartConnectorAction.create(action.selectedElementsIDs[0])]; } - else return [] + else {return [];} } return [CloseSmartConnectorAction.create()]; } -} \ No newline at end of file +} diff --git a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts index e9577f9..ce6531f 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts @@ -1,3 +1,18 @@ +/******************************************************************************** + * Copyright (c) 2022-2023 STMicroelectronics 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 { Args, CreateEdgeOperation, @@ -17,7 +32,6 @@ import { CreateOperationHandler } from '../../operations/create-operation-handle import { OperationHandlerRegistry } from '../../operations/operation-handler-registry'; import { ContextActionsProvider } from './context-actions-provider'; - /** * A {@link ContextActionsProvider} for {@link PaletteItem}s in the Smart Connector which appears when a node is selected. */ @@ -48,11 +62,11 @@ export abstract class SmartConnectorItemProvider implements ContextActionsProvid */ abstract getItems(args?: Args): MaybePromise; - /** filter that excludes nodes/edges from options, given a node ID as key */ + /** filter that excludes nodes/edges from options, given a node ID as key */ abstract nodeOperationFilter: Record; /** edge that is used between source and destination by default when a new node is created - * (if not given, no edge will be created when creating new node) */ + * (if not given, no edge will be created when creating new node) */ abstract defaultEdge: string; /** list of edges where the key is a node ID and the value is a edge ID @@ -70,11 +84,11 @@ export type SmartConnectorSettings = { position: SmartConnectorPosition showTitle: false; showOnlyForChildren?: SmartConnectorGroupUIType - } + }; @injectable() export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvider { - + @inject(OperationHandlerRegistry) operationHandlerRegistry: OperationHandlerRegistry; protected counter: number; @@ -83,55 +97,85 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide position: SmartConnectorPosition.Right, showTitle: true, submenu: true, - showOnlyForChildren: SmartConnectorGroupUIType.Icons - } + showOnlyForChildren: SmartConnectorGroupUIType.Icons + }; protected smartConnectorEdgeSettings: SmartConnectorSettings = { position: SmartConnectorPosition.Right, showTitle: true, submenu: false - } + }; override nodeOperationFilter: Record; override defaultEdge: string; override edgeTypes: Record; - getItems(args?: Args): SmartConnectorGroupItem[] { const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; this.counter = 0; - const nodes = this.createSmartConnectorGroupItem(handlers, CreateNodeOperation.KIND, args?.nodeType as string, this.smartConnectorNodeSettings.showOnlyForChildren); - const edges = this.createSmartConnectorGroupItem(handlers, CreateEdgeOperation.KIND, args?.nodeType as string, this.smartConnectorEdgeSettings.showOnlyForChildren); + const nodes = this.createSmartConnectorGroupItem(handlers, CreateNodeOperation.KIND, args?.nodeType as string, + this.smartConnectorNodeSettings.showOnlyForChildren); + const edges = this.createSmartConnectorGroupItem(handlers, CreateEdgeOperation.KIND, args?.nodeType as string, + this.smartConnectorEdgeSettings.showOnlyForChildren); return [ - { id: 'smart-connector-node-group', label: 'Nodes', actions: [], children: nodes, icon: 'symbol-property', sortString: 'A', ...this.smartConnectorNodeSettings }, - { id: 'smart-connector-edge-group', label: 'Edges', actions: [], children: edges, icon: 'symbol-property', sortString: 'B', ...this.smartConnectorEdgeSettings } + { + id: 'smart-connector-node-group', + label: 'Nodes', + actions: [], + children: nodes, + icon: 'symbol-property', + sortString: 'A', + ...this.smartConnectorNodeSettings + }, + { + id: 'smart-connector-edge-group', + label: 'Edges', + actions: [], + children: edges, + icon: 'symbol-property', + sortString: 'B', + ...this.smartConnectorEdgeSettings + } ]; } - createSmartConnectorGroupItem(handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, showOnly?: SmartConnectorGroupUIType): PaletteItem[] { - var includedInNodeFilter = (e: string) => this.nodeOperationFilter[selectedNodeType].includes(e) - var paletteItems = handlers - .filter(handler => handler.operationType === kind && (selectedNodeType && this.nodeOperationFilter[selectedNodeType] ? !handler.elementTypeIds.some(includedInNodeFilter) : true)) + createSmartConnectorGroupItem(handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, + showOnly?: SmartConnectorGroupUIType): PaletteItem[] { + const includedInNodeFilter = (e: string): boolean => this.nodeOperationFilter[selectedNodeType].includes(e); + const paletteItems = handlers + .filter(handler => handler.operationType === kind && (selectedNodeType && + this.nodeOperationFilter[selectedNodeType] ? !handler.elementTypeIds.some(includedInNodeFilter) : true)) .map(handler => handler.getTriggerActions().map(action => this.create(action, handler.label, selectedNodeType))) .reduce((accumulator, value) => accumulator.concat(value), []) .sort((a, b) => a.sortString.localeCompare(b.sortString)); if (showOnly === SmartConnectorGroupUIType.Icons) { - if (paletteItems.every(paletteItem => paletteItem.icon != '')) { - console.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.') + if (paletteItems.every(paletteItem => paletteItem.icon !== '')) { + console.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.'); return paletteItems; } - paletteItems.forEach(paletteItem => paletteItem.label = '') - } - if (showOnly === SmartConnectorGroupUIType.Labels) paletteItems.forEach(paletteItem => paletteItem.icon = '') + paletteItems.forEach(paletteItem => paletteItem.label = ''); + } + if (showOnly === SmartConnectorGroupUIType.Labels) {paletteItems.forEach(paletteItem => paletteItem.icon = '');} return paletteItems; } create(action: PaletteItem.TriggerElementCreationAction, label: string, nodeType: string): PaletteItem | SmartConnectorNodeItem { if (TriggerNodeCreationAction.is(action)) { - var edgeType = this.edgeTypes[nodeType] - if (!edgeType) edgeType = this.defaultEdge; - return { id: `smart-connector-palette-item${this.counter++}`, sortString: label.charAt(0), label, actions: [action], edgeType: edgeType }; + let edgeType = this.edgeTypes[nodeType]; + if (!edgeType) {edgeType = this.defaultEdge;} + return { + id: `smart-connector-palette-item${this.counter++}`, + sortString: label.charAt(0), + label, + actions: [action], + edgeType: edgeType + }; } - return { id: `smart-connector-palette-item${this.counter++}`, sortString: label.charAt(0), label, actions: [action] }; + return { + id: `smart-connector-palette-item${this.counter++}`, + sortString: label.charAt(0), + label, + actions: [action] + }; } } diff --git a/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts b/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts index 6fb3651..d25112e 100644 --- a/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts +++ b/packages/server/src/common/gmodel/gmodel-create-node-operation-handler.ts @@ -15,7 +15,8 @@ ********************************************************************************/ import { GModelElement, GNode } from '@eclipse-glsp/graph'; -import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCreationAction, CreateEdgeOperation } from '@eclipse-glsp/protocol'; +import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCreationAction, + CreateEdgeOperation } from '@eclipse-glsp/protocol'; import { inject, injectable } from 'inversify'; import { ActionDispatcher } from '../actions/action-dispatcher'; import { Command } from '../command/command'; @@ -54,11 +55,10 @@ export abstract class GModelCreateNodeOperationHandler extends GModelOperationHa // Creates default edge on node creation when a source ID is given in the CreateNodeOperation if (operation.args?.createEdge && operation.args?.edgeType) { this.actionDispatcher.dispatchAfterNextUpdate(CreateEdgeOperation.create({ - //TODO: change to default edge type elementTypeId: operation.args?.edgeType as string, - sourceElementId: operation.args?.source as string, + sourceElementId: operation.args?.source as string, targetElementId: element.id - })) + })); } } } From cb71c3b40c73f6df30c9ea85cbd30a86d394a5d9 Mon Sep 17 00:00:00 2001 From: yentelmanero Date: Wed, 27 Dec 2023 15:08:30 +0100 Subject: [PATCH 5/9] Implemented suggested changes from PR --- .../workflow-smart-connector-item-provider.ts | 2 +- .../server/src/common/di/diagram-module.ts | 2 + .../smart-connector-action-handler.ts | 2 +- .../smart-connector-item-provider.ts | 39 ++++++++++--------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts index a78cd8d..baec783 100644 --- a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts +++ b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022-2023 STMicroelectronics and others. + * Copyright (c) 2023 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 diff --git a/packages/server/src/common/di/diagram-module.ts b/packages/server/src/common/di/diagram-module.ts index bff3bd1..1b74f65 100644 --- a/packages/server/src/common/di/diagram-module.ts +++ b/packages/server/src/common/di/diagram-module.ts @@ -348,9 +348,11 @@ export abstract class DiagramModule extends GLSPModule { protected bindToolPaletteItemProvider(): BindingTarget | undefined { return DefaultToolPaletteItemProvider; } + protected bindSmartConnectorItemProvider(): BindingTarget | undefined { return DefaultSmartConnectorItemProvider; } + protected bindCommandPaletteActionProvider(): BindingTarget | undefined { return undefined; } diff --git a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts index 51f34bb..b17cfd3 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022-2023 STMicroelectronics and others. + * Copyright (c) 2023 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 diff --git a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts index ce6531f..a139529 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022-2023 STMicroelectronics and others. + * Copyright (c) 2023 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 @@ -31,6 +31,7 @@ import { inject, injectable } from 'inversify'; import { CreateOperationHandler } from '../../operations/create-operation-handler'; import { OperationHandlerRegistry } from '../../operations/operation-handler-registry'; import { ContextActionsProvider } from './context-actions-provider'; +import { Logger } from '../../utils/logger'; /** * A {@link ContextActionsProvider} for {@link PaletteItem}s in the Smart Connector which appears when a node is selected. @@ -61,18 +62,6 @@ export abstract class SmartConnectorItemProvider implements ContextActionsProvid * @returns A list of {@link PaletteItem}s for a given map of string arguments. */ abstract getItems(args?: Args): MaybePromise; - - /** filter that excludes nodes/edges from options, given a node ID as key */ - abstract nodeOperationFilter: Record; - - /** edge that is used between source and destination by default when a new node is created - * (if not given, no edge will be created when creating new node) */ - abstract defaultEdge: string; - - /** list of edges where the key is a node ID and the value is a edge ID - * the edge to a new node when the source node has the ID of the key - * otherwise, the default edge will be used */ - abstract edgeTypes: Record; } export type SmartConnectorSettings = { @@ -90,6 +79,8 @@ export type SmartConnectorSettings = { export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvider { @inject(OperationHandlerRegistry) operationHandlerRegistry: OperationHandlerRegistry; + @inject(Logger) + protected logger: Logger; protected counter: number; @@ -105,9 +96,17 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide showTitle: true, submenu: false }; - override nodeOperationFilter: Record; - override defaultEdge: string; - override edgeTypes: Record; + /** filter that excludes nodes/edges from options, given a node ID as key */ + protected nodeOperationFilter: Record = {}; + + /** edge that is used between source and destination by default when a new node is created + * (if not given, no edge will be created when creating new node) */ + protected defaultEdge?: string; + + /** list of edges where the key is a node ID and the value is a edge ID + * the edge to a new node when the source node has the ID of the key + * otherwise, the default edge will be used */ + protected edgeTypes: Record; getItems(args?: Args): SmartConnectorGroupItem[] { const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; @@ -140,7 +139,7 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide createSmartConnectorGroupItem(handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, showOnly?: SmartConnectorGroupUIType): PaletteItem[] { - const includedInNodeFilter = (e: string): boolean => this.nodeOperationFilter[selectedNodeType].includes(e); + const includedInNodeFilter = (e: string): boolean => !!this.nodeOperationFilter[selectedNodeType]?.includes(e); const paletteItems = handlers .filter(handler => handler.operationType === kind && (selectedNodeType && this.nodeOperationFilter[selectedNodeType] ? !handler.elementTypeIds.some(includedInNodeFilter) : true)) @@ -149,12 +148,14 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide .sort((a, b) => a.sortString.localeCompare(b.sortString)); if (showOnly === SmartConnectorGroupUIType.Icons) { if (paletteItems.every(paletteItem => paletteItem.icon !== '')) { - console.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.'); + this.logger.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.') return paletteItems; } paletteItems.forEach(paletteItem => paletteItem.label = ''); } - if (showOnly === SmartConnectorGroupUIType.Labels) {paletteItems.forEach(paletteItem => paletteItem.icon = '');} + else if (showOnly === SmartConnectorGroupUIType.Labels) { + paletteItems.forEach(paletteItem => paletteItem.icon = ''); + } return paletteItems; } From 6a884389253c6e04308cb1d48d0c8578ee1525c4 Mon Sep 17 00:00:00 2001 From: Tobias Pellkvist Date: Thu, 1 Feb 2024 22:40:51 +0100 Subject: [PATCH 6/9] Implemented suggested changes from PR #2 --- .../workflow-smart-connector-item-provider.ts | 6 +++--- packages/server/src/common/di/diagram-module.ts | 2 +- .../contextactions/smart-connector-item-provider.ts | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts index baec783..a61bf33 100644 --- a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts +++ b/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts @@ -40,7 +40,7 @@ export class WorkflowSmartConnectorItemProvider extends DefaultSmartConnectorIte submenu: true }; - override nodeOperationFilter = { + protected override nodeOperationFilter = { [ModelTypes.AUTOMATED_TASK]: [ModelTypes.WEIGHTED_EDGE, ModelTypes.AUTOMATED_TASK, ModelTypes.MANUAL_TASK, ModelTypes.ACTIVITY_NODE], [ModelTypes.MERGE_NODE]: [DefaultTypes.EDGE, ModelTypes.MERGE_NODE, ModelTypes.CATEGORY], @@ -49,9 +49,9 @@ export class WorkflowSmartConnectorItemProvider extends DefaultSmartConnectorIte [ModelTypes.JOIN_NODE]: [ModelTypes.AUTOMATED_TASK, ModelTypes.FORK_NODE, ModelTypes.JOIN_NODE] }; - override defaultEdge = DefaultTypes.EDGE; + protected override defaultEdge = DefaultTypes.EDGE; - override edgeTypes = { + protected override edgeTypes = { [ModelTypes.AUTOMATED_TASK]: DefaultTypes.EDGE, [ModelTypes.MERGE_NODE]: DefaultTypes.EDGE }; diff --git a/packages/server/src/common/di/diagram-module.ts b/packages/server/src/common/di/diagram-module.ts index 1b74f65..4faf7a5 100644 --- a/packages/server/src/common/di/diagram-module.ts +++ b/packages/server/src/common/di/diagram-module.ts @@ -348,7 +348,7 @@ export abstract class DiagramModule extends GLSPModule { protected bindToolPaletteItemProvider(): BindingTarget | undefined { return DefaultToolPaletteItemProvider; } - + protected bindSmartConnectorItemProvider(): BindingTarget | undefined { return DefaultSmartConnectorItemProvider; } diff --git a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts index a139529..5221118 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts @@ -78,7 +78,7 @@ export type SmartConnectorSettings = { @injectable() export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvider { - @inject(OperationHandlerRegistry) operationHandlerRegistry: OperationHandlerRegistry; + @inject(OperationHandlerRegistry) protected operationHandlerRegistry: OperationHandlerRegistry; @inject(Logger) protected logger: Logger; @@ -137,18 +137,19 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide ]; } - createSmartConnectorGroupItem(handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, + protected createSmartConnectorGroupItem(handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, showOnly?: SmartConnectorGroupUIType): PaletteItem[] { const includedInNodeFilter = (e: string): boolean => !!this.nodeOperationFilter[selectedNodeType]?.includes(e); const paletteItems = handlers .filter(handler => handler.operationType === kind && (selectedNodeType && this.nodeOperationFilter[selectedNodeType] ? !handler.elementTypeIds.some(includedInNodeFilter) : true)) - .map(handler => handler.getTriggerActions().map(action => this.create(action, handler.label, selectedNodeType))) + .map(handler => handler.getTriggerActions().map( + action => this.createSmartConnectorItems(action, handler.label, selectedNodeType))) .reduce((accumulator, value) => accumulator.concat(value), []) .sort((a, b) => a.sortString.localeCompare(b.sortString)); if (showOnly === SmartConnectorGroupUIType.Icons) { if (paletteItems.every(paletteItem => paletteItem.icon !== '')) { - this.logger.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.') + this.logger.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.'); return paletteItems; } paletteItems.forEach(paletteItem => paletteItem.label = ''); @@ -159,7 +160,8 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide return paletteItems; } - create(action: PaletteItem.TriggerElementCreationAction, label: string, nodeType: string): PaletteItem | SmartConnectorNodeItem { + protected createSmartConnectorItems(action: PaletteItem.TriggerElementCreationAction, + label: string, nodeType: string): PaletteItem | SmartConnectorNodeItem { if (TriggerNodeCreationAction.is(action)) { let edgeType = this.edgeTypes[nodeType]; if (!edgeType) {edgeType = this.defaultEdge;} From c6ba7bd28c6d8a19faea4db45af61aff36aa20b8 Mon Sep 17 00:00:00 2001 From: Tobias Pellkvist Date: Mon, 12 Feb 2024 01:28:30 +0100 Subject: [PATCH 7/9] applied prettier formatting --- .../smart-connector-action-handler.ts | 10 +-- .../smart-connector-item-provider.ts | 80 ++++++++++++------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts index b17cfd3..218a653 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts @@ -13,12 +13,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { - Action, - CloseSmartConnectorAction, - OpenSmartConnectorAction, - SelectAction, - MaybePromise} from '@eclipse-glsp/protocol'; +import { Action, CloseSmartConnectorAction, OpenSmartConnectorAction, SelectAction, MaybePromise } from '@eclipse-glsp/protocol'; import { inject, injectable } from 'inversify'; import { ActionHandler } from '../../actions/action-handler'; import { ModelState } from '../model/model-state'; @@ -36,8 +31,9 @@ export class OpenSmartConnectorActionHandler implements ActionHandler { const selectedElement = this.modelState.index.find(action.selectedElementsIDs[0]); if (selectedElement && selectedElement instanceof GNode) { return [OpenSmartConnectorAction.create(action.selectedElementsIDs[0])]; + } else { + return []; } - else {return [];} } return [CloseSmartConnectorAction.create()]; } diff --git a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts index 5221118..672f974 100644 --- a/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts +++ b/packages/server/src/common/features/contextactions/smart-connector-item-provider.ts @@ -64,20 +64,21 @@ export abstract class SmartConnectorItemProvider implements ContextActionsProvid abstract getItems(args?: Args): MaybePromise; } -export type SmartConnectorSettings = { - position: SmartConnectorPosition - showTitle: true; - submenu: boolean; - showOnlyForChildren?: SmartConnectorGroupUIType - } | { - position: SmartConnectorPosition - showTitle: false; - showOnlyForChildren?: SmartConnectorGroupUIType - }; +export type SmartConnectorSettings = + | { + position: SmartConnectorPosition; + showTitle: true; + submenu: boolean; + showOnlyForChildren?: SmartConnectorGroupUIType; + } + | { + position: SmartConnectorPosition; + showTitle: false; + showOnlyForChildren?: SmartConnectorGroupUIType; + }; @injectable() export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvider { - @inject(OperationHandlerRegistry) protected operationHandlerRegistry: OperationHandlerRegistry; @inject(Logger) protected logger: Logger; @@ -111,10 +112,18 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide getItems(args?: Args): SmartConnectorGroupItem[] { const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; this.counter = 0; - const nodes = this.createSmartConnectorGroupItem(handlers, CreateNodeOperation.KIND, args?.nodeType as string, - this.smartConnectorNodeSettings.showOnlyForChildren); - const edges = this.createSmartConnectorGroupItem(handlers, CreateEdgeOperation.KIND, args?.nodeType as string, - this.smartConnectorEdgeSettings.showOnlyForChildren); + const nodes = this.createSmartConnectorGroupItem( + handlers, + CreateNodeOperation.KIND, + args?.nodeType as string, + this.smartConnectorNodeSettings.showOnlyForChildren + ); + const edges = this.createSmartConnectorGroupItem( + handlers, + CreateEdgeOperation.KIND, + args?.nodeType as string, + this.smartConnectorEdgeSettings.showOnlyForChildren + ); return [ { id: 'smart-connector-node-group', @@ -137,14 +146,24 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide ]; } - protected createSmartConnectorGroupItem(handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, - showOnly?: SmartConnectorGroupUIType): PaletteItem[] { + protected createSmartConnectorGroupItem( + handlers: CreateOperationHandler[], + kind: string, + selectedNodeType: string, + showOnly?: SmartConnectorGroupUIType + ): PaletteItem[] { const includedInNodeFilter = (e: string): boolean => !!this.nodeOperationFilter[selectedNodeType]?.includes(e); const paletteItems = handlers - .filter(handler => handler.operationType === kind && (selectedNodeType && - this.nodeOperationFilter[selectedNodeType] ? !handler.elementTypeIds.some(includedInNodeFilter) : true)) - .map(handler => handler.getTriggerActions().map( - action => this.createSmartConnectorItems(action, handler.label, selectedNodeType))) + .filter( + handler => + handler.operationType === kind && + (selectedNodeType && this.nodeOperationFilter[selectedNodeType] + ? !handler.elementTypeIds.some(includedInNodeFilter) + : true) + ) + .map(handler => + handler.getTriggerActions().map(action => this.createSmartConnectorItems(action, handler.label, selectedNodeType)) + ) .reduce((accumulator, value) => accumulator.concat(value), []) .sort((a, b) => a.sortString.localeCompare(b.sortString)); if (showOnly === SmartConnectorGroupUIType.Icons) { @@ -152,19 +171,23 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide this.logger.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.'); return paletteItems; } - paletteItems.forEach(paletteItem => paletteItem.label = ''); - } - else if (showOnly === SmartConnectorGroupUIType.Labels) { - paletteItems.forEach(paletteItem => paletteItem.icon = ''); + paletteItems.forEach(paletteItem => (paletteItem.label = '')); + } else if (showOnly === SmartConnectorGroupUIType.Labels) { + paletteItems.forEach(paletteItem => (paletteItem.icon = '')); } return paletteItems; } - protected createSmartConnectorItems(action: PaletteItem.TriggerElementCreationAction, - label: string, nodeType: string): PaletteItem | SmartConnectorNodeItem { + protected createSmartConnectorItems( + action: PaletteItem.TriggerElementCreationAction, + label: string, + nodeType: string + ): PaletteItem | SmartConnectorNodeItem { if (TriggerNodeCreationAction.is(action)) { let edgeType = this.edgeTypes[nodeType]; - if (!edgeType) {edgeType = this.defaultEdge;} + if (!edgeType) { + edgeType = this.defaultEdge; + } return { id: `smart-connector-palette-item${this.counter++}`, sortString: label.charAt(0), @@ -180,5 +203,4 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide actions: [action] }; } - } From 6b01139a6cc76861adbaa93be97e11e072d550e3 Mon Sep 17 00:00:00 2001 From: Tobias Pellkvist Date: Mon, 1 Apr 2024 18:02:12 +0200 Subject: [PATCH 8/9] renamed smart connector to selection palette, removed related action handler, is now handled client side --- ...rkflow-selection-palette-item-provider.ts} | 18 ++--- .../src/common/workflow-diagram-module.ts | 8 +- .../server/src/common/di/diagram-module.ts | 13 ++-- .../context-actions-provider-registry.ts | 8 +- ....ts => selection-palette-item-provider.ts} | 76 +++++++++---------- .../smart-connector-action-handler.ts | 40 ---------- packages/server/src/common/index.ts | 3 +- 7 files changed, 63 insertions(+), 103 deletions(-) rename examples/workflow-server/src/common/provider/{workflow-smart-connector-item-provider.ts => workflow-selection-palette-item-provider.ts} (77%) rename packages/server/src/common/features/contextactions/{smart-connector-item-provider.ts => selection-palette-item-provider.ts} (73%) delete mode 100644 packages/server/src/common/features/contextactions/smart-connector-action-handler.ts diff --git a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts b/examples/workflow-server/src/common/provider/workflow-selection-palette-item-provider.ts similarity index 77% rename from examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts rename to examples/workflow-server/src/common/provider/workflow-selection-palette-item-provider.ts index a61bf33..8dbf0c7 100644 --- a/examples/workflow-server/src/common/provider/workflow-smart-connector-item-provider.ts +++ b/examples/workflow-server/src/common/provider/workflow-selection-palette-item-provider.ts @@ -14,28 +14,28 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { - DefaultSmartConnectorItemProvider, SmartConnectorSettings + DefaultSelectionPaletteItemProvider, SelectionPaletteSettings } from '@eclipse-glsp/server'; import { - SmartConnectorPosition, - SmartConnectorGroupUIType, + SelectionPalettePosition, + SelectionPaletteGroupUIType, DefaultTypes } from '@eclipse-glsp/protocol'; import { injectable } from 'inversify'; import { ModelTypes } from '../util/model-types'; @injectable() -export class WorkflowSmartConnectorItemProvider extends DefaultSmartConnectorItemProvider { +export class WorkflowSelectionPaletteItemProvider extends DefaultSelectionPaletteItemProvider { - protected override smartConnectorNodeSettings: SmartConnectorSettings = { - position: SmartConnectorPosition.Top, + protected override selectionPaletteNodeSettings: SelectionPaletteSettings = { + position: SelectionPalettePosition.Top, showTitle: true, submenu: false, - showOnlyForChildren: SmartConnectorGroupUIType.Labels + showOnlyForChildren: SelectionPaletteGroupUIType.Labels }; - protected override smartConnectorEdgeSettings: SmartConnectorSettings = { - position: SmartConnectorPosition.Right, + protected override selectionPaletteEdgeSettings: SelectionPaletteSettings = { + position: SelectionPalettePosition.Right, showTitle: true, submenu: true }; diff --git a/examples/workflow-server/src/common/workflow-diagram-module.ts b/examples/workflow-server/src/common/workflow-diagram-module.ts index 45e2310..b71f1f5 100644 --- a/examples/workflow-server/src/common/workflow-diagram-module.ts +++ b/examples/workflow-server/src/common/workflow-diagram-module.ts @@ -33,7 +33,7 @@ import { PopupModelFactory, ServerModule, SourceModelStorage, - SmartConnectorItemProvider + SelectionPaletteItemProvider } from '@eclipse-glsp/server'; import { injectable } from 'inversify'; import { CreateAutomatedTaskHandler } from './handler/create-automated-task-handler'; @@ -53,7 +53,7 @@ import { NodeDocumentationNavigationTargetProvider } from './provider/node-docum import { PreviousNodeNavigationTargetProvider } from './provider/previous-node-navigation-target-provider'; import { WorkflowCommandPaletteActionProvider } from './provider/workflow-command-palette-action-provider'; import { WorkflowContextMenuItemProvider } from './provider/workflow-context-menu-item-provider'; -import { WorkflowSmartConnectorItemProvider } from './provider/workflow-smart-connector-item-provider'; +import { WorkflowSelectionPaletteItemProvider } from './provider/workflow-selection-palette-item-provider'; import { EditTaskOperationHandler } from './taskedit/edit-task-operation-handler'; import { TaskEditContextActionProvider } from './taskedit/task-edit-context-provider'; import { TaskEditValidator } from './taskedit/task-edit-validator'; @@ -109,8 +109,8 @@ export class WorkflowDiagramModule extends GModelDiagramModule { return WorkflowCommandPaletteActionProvider; } - protected override bindSmartConnectorItemProvider(): BindingTarget | undefined { - return WorkflowSmartConnectorItemProvider; + protected override bindSelectionPaletteItemProvider(): BindingTarget | undefined { + return WorkflowSelectionPaletteItemProvider; } protected override bindLabelEditValidator(): BindingTarget | undefined { diff --git a/packages/server/src/common/di/diagram-module.ts b/packages/server/src/common/di/diagram-module.ts index 4faf7a5..d6f0348 100644 --- a/packages/server/src/common/di/diagram-module.ts +++ b/packages/server/src/common/di/diagram-module.ts @@ -77,8 +77,10 @@ import { NavigationTargetProviders, Operations } from './service-identifiers'; -import { DefaultSmartConnectorItemProvider, SmartConnectorItemProvider } from '../features/contextactions/smart-connector-item-provider'; -import { OpenSmartConnectorActionHandler } from '../features/contextactions/smart-connector-action-handler'; +import { + DefaultSelectionPaletteItemProvider, + SelectionPaletteItemProvider +} from '../features/contextactions/selection-palette-item-provider'; /** * The diagram module is the central configuration artifact for configuring a client session specific injector. For each @@ -156,7 +158,7 @@ export abstract class DiagramModule extends GLSPModule { applyOptionalBindingTarget(context, ToolPaletteItemProvider, this.bindToolPaletteItemProvider()); applyOptionalBindingTarget(context, CommandPaletteActionProvider, this.bindCommandPaletteActionProvider()); applyOptionalBindingTarget(context, ContextMenuItemProvider, this.bindContextMenuItemProvider()); - applyOptionalBindingTarget(context, SmartConnectorItemProvider, this.bindSmartConnectorItemProvider()); + applyOptionalBindingTarget(context, SelectionPaletteItemProvider, this.bindSelectionPaletteItemProvider()); this.configureMultiBinding(new MultiBinding(ContextActionsProviders), binding => this.configureContextActionProviders(binding) ); @@ -219,7 +221,6 @@ export abstract class DiagramModule extends GLSPModule { binding.add(SaveModelActionHandler); binding.add(UndoRedoActionHandler); binding.add(ComputedBoundsActionHandler); - binding.add(OpenSmartConnectorActionHandler); } protected bindDiagramType(): BindingTarget { @@ -349,8 +350,8 @@ export abstract class DiagramModule extends GLSPModule { return DefaultToolPaletteItemProvider; } - protected bindSmartConnectorItemProvider(): BindingTarget | undefined { - return DefaultSmartConnectorItemProvider; + protected bindSelectionPaletteItemProvider(): BindingTarget | undefined { + return DefaultSelectionPaletteItemProvider; } protected bindCommandPaletteActionProvider(): BindingTarget | undefined { diff --git a/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts b/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts index 9f776c5..c0f2147 100644 --- a/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts +++ b/packages/server/src/common/features/contextactions/context-actions-provider-registry.ts @@ -20,7 +20,7 @@ import { CommandPaletteActionProvider } from './command-palette-action-provider' import { ContextActionsProvider } from './context-actions-provider'; import { ContextMenuItemProvider } from './context-menu-item-provider'; import { ToolPaletteItemProvider } from './tool-palette-item-provider'; -import { SmartConnectorItemProvider } from './smart-connector-item-provider'; +import { SelectionPaletteItemProvider } from './selection-palette-item-provider'; /** * A registry that keeps track of all registered {@link ContextActionsProvider}s. @@ -32,7 +32,7 @@ export class ContextActionsProviderRegistry extends Registry this.register(provider.contextId, provider)); @@ -45,8 +45,8 @@ export class ContextActionsProviderRegistry extends Registry; + abstract getItems(args?: Args): MaybePromise; } -export type SmartConnectorSettings = +export type SelectionPaletteSettings = | { - position: SmartConnectorPosition; + position: SelectionPalettePosition; showTitle: true; submenu: boolean; - showOnlyForChildren?: SmartConnectorGroupUIType; + showOnlyForChildren?: SelectionPaletteGroupUIType; } | { - position: SmartConnectorPosition; + position: SelectionPalettePosition; showTitle: false; - showOnlyForChildren?: SmartConnectorGroupUIType; + showOnlyForChildren?: SelectionPaletteGroupUIType; }; @injectable() -export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvider { +export class DefaultSelectionPaletteItemProvider extends SelectionPaletteItemProvider { @inject(OperationHandlerRegistry) protected operationHandlerRegistry: OperationHandlerRegistry; @inject(Logger) protected logger: Logger; protected counter: number; - protected smartConnectorNodeSettings: SmartConnectorSettings = { - position: SmartConnectorPosition.Right, + protected selectionPaletteNodeSettings: SelectionPaletteSettings = { + position: SelectionPalettePosition.Right, showTitle: true, submenu: true, - showOnlyForChildren: SmartConnectorGroupUIType.Icons + showOnlyForChildren: SelectionPaletteGroupUIType.Icons }; - protected smartConnectorEdgeSettings: SmartConnectorSettings = { - position: SmartConnectorPosition.Right, + protected selectionPaletteEdgeSettings: SelectionPaletteSettings = { + position: SelectionPalettePosition.Right, showTitle: true, submenu: false }; @@ -109,48 +109,48 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide * otherwise, the default edge will be used */ protected edgeTypes: Record; - getItems(args?: Args): SmartConnectorGroupItem[] { + getItems(args?: Args): SelectionPaletteGroupItem[] { const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; this.counter = 0; - const nodes = this.createSmartConnectorGroupItem( + const nodes = this.createSelectionPaletteGroupItem( handlers, CreateNodeOperation.KIND, args?.nodeType as string, - this.smartConnectorNodeSettings.showOnlyForChildren + this.selectionPaletteNodeSettings.showOnlyForChildren ); - const edges = this.createSmartConnectorGroupItem( + const edges = this.createSelectionPaletteGroupItem( handlers, CreateEdgeOperation.KIND, args?.nodeType as string, - this.smartConnectorEdgeSettings.showOnlyForChildren + this.selectionPaletteEdgeSettings.showOnlyForChildren ); return [ { - id: 'smart-connector-node-group', + id: 'selection-palette-node-group', label: 'Nodes', actions: [], children: nodes, icon: 'symbol-property', sortString: 'A', - ...this.smartConnectorNodeSettings + ...this.selectionPaletteNodeSettings }, { - id: 'smart-connector-edge-group', + id: 'selection-palette-edge-group', label: 'Edges', actions: [], children: edges, icon: 'symbol-property', sortString: 'B', - ...this.smartConnectorEdgeSettings + ...this.selectionPaletteEdgeSettings } ]; } - protected createSmartConnectorGroupItem( + protected createSelectionPaletteGroupItem( handlers: CreateOperationHandler[], kind: string, selectedNodeType: string, - showOnly?: SmartConnectorGroupUIType + showOnly?: SelectionPaletteGroupUIType ): PaletteItem[] { const includedInNodeFilter = (e: string): boolean => !!this.nodeOperationFilter[selectedNodeType]?.includes(e); const paletteItems = handlers @@ -162,34 +162,34 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide : true) ) .map(handler => - handler.getTriggerActions().map(action => this.createSmartConnectorItems(action, handler.label, selectedNodeType)) + handler.getTriggerActions().map(action => this.createSelectionPaletteItems(action, handler.label, selectedNodeType)) ) .reduce((accumulator, value) => accumulator.concat(value), []) .sort((a, b) => a.sortString.localeCompare(b.sortString)); - if (showOnly === SmartConnectorGroupUIType.Icons) { + if (showOnly === SelectionPaletteGroupUIType.Icons) { if (paletteItems.every(paletteItem => paletteItem.icon !== '')) { - this.logger.warn('Not all elements have icons. Labels will be shown, check settings for smart connector.'); + this.logger.warn('Not all elements have icons. Labels will be shown, check settings for selection palette.'); return paletteItems; } paletteItems.forEach(paletteItem => (paletteItem.label = '')); - } else if (showOnly === SmartConnectorGroupUIType.Labels) { + } else if (showOnly === SelectionPaletteGroupUIType.Labels) { paletteItems.forEach(paletteItem => (paletteItem.icon = '')); } return paletteItems; } - protected createSmartConnectorItems( + protected createSelectionPaletteItems( action: PaletteItem.TriggerElementCreationAction, label: string, nodeType: string - ): PaletteItem | SmartConnectorNodeItem { + ): PaletteItem | SelectionPaletteNodeItem { if (TriggerNodeCreationAction.is(action)) { let edgeType = this.edgeTypes[nodeType]; if (!edgeType) { edgeType = this.defaultEdge; } return { - id: `smart-connector-palette-item${this.counter++}`, + id: `selection-palette-palette-item${this.counter++}`, sortString: label.charAt(0), label, actions: [action], @@ -197,7 +197,7 @@ export class DefaultSmartConnectorItemProvider extends SmartConnectorItemProvide }; } return { - id: `smart-connector-palette-item${this.counter++}`, + id: `selection-palette-palette-item${this.counter++}`, sortString: label.charAt(0), label, actions: [action] diff --git a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts b/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts deleted file mode 100644 index 218a653..0000000 --- a/packages/server/src/common/features/contextactions/smart-connector-action-handler.ts +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 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 - ********************************************************************************/ -import { Action, CloseSmartConnectorAction, OpenSmartConnectorAction, SelectAction, MaybePromise } from '@eclipse-glsp/protocol'; -import { inject, injectable } from 'inversify'; -import { ActionHandler } from '../../actions/action-handler'; -import { ModelState } from '../model/model-state'; -import { GNode } from '@eclipse-glsp/graph'; - -@injectable() -export class OpenSmartConnectorActionHandler implements ActionHandler { - actionKinds = [SelectAction.KIND]; - - @inject(ModelState) - protected modelState: ModelState; - - execute(action: Action): MaybePromise { - if (SelectAction.is(action)) { - const selectedElement = this.modelState.index.find(action.selectedElementsIDs[0]); - if (selectedElement && selectedElement instanceof GNode) { - return [OpenSmartConnectorAction.create(action.selectedElementsIDs[0])]; - } else { - return []; - } - } - return [CloseSmartConnectorAction.create()]; - } -} diff --git a/packages/server/src/common/index.ts b/packages/server/src/common/index.ts index a74be13..6752d91 100644 --- a/packages/server/src/common/index.ts +++ b/packages/server/src/common/index.ts @@ -39,8 +39,7 @@ export * from './features/contextactions/context-actions-provider'; export * from './features/contextactions/context-actions-provider-registry'; export * from './features/contextactions/context-menu-item-provider'; export * from './features/contextactions/request-context-actions-handler'; -export * from './features/contextactions/smart-connector-action-handler'; -export * from './features/contextactions/smart-connector-item-provider'; +export * from './features/contextactions/selection-palette-item-provider'; export * from './features/contextactions/tool-palette-item-provider'; export * from './features/directediting/context-edit-validator'; export * from './features/directediting/context-edit-validator-registry'; From c97bc4bbaa62dc60a754e385e519acb85c33fdf4 Mon Sep 17 00:00:00 2001 From: Tobias Pellkvist Date: Mon, 1 Apr 2024 18:21:10 +0200 Subject: [PATCH 9/9] renamed createSelectionPaletteItems to createSelectionPaletteItem --- .../contextactions/selection-palette-item-provider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/common/features/contextactions/selection-palette-item-provider.ts b/packages/server/src/common/features/contextactions/selection-palette-item-provider.ts index 58909fa..09fa7f1 100644 --- a/packages/server/src/common/features/contextactions/selection-palette-item-provider.ts +++ b/packages/server/src/common/features/contextactions/selection-palette-item-provider.ts @@ -162,7 +162,7 @@ export class DefaultSelectionPaletteItemProvider extends SelectionPaletteItemPro : true) ) .map(handler => - handler.getTriggerActions().map(action => this.createSelectionPaletteItems(action, handler.label, selectedNodeType)) + handler.getTriggerActions().map(action => this.createSelectionPaletteItem(action, handler.label, selectedNodeType)) ) .reduce((accumulator, value) => accumulator.concat(value), []) .sort((a, b) => a.sortString.localeCompare(b.sortString)); @@ -178,7 +178,7 @@ export class DefaultSelectionPaletteItemProvider extends SelectionPaletteItemPro return paletteItems; } - protected createSelectionPaletteItems( + protected createSelectionPaletteItem( action: PaletteItem.TriggerElementCreationAction, label: string, nodeType: string