-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handlers for Smart Connector UIExtension #70
Open
yentelmanero
wants to merge
14
commits into
eclipse-glsp:main
Choose a base branch
from
yentelmanero:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+296
−3
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
32ceb71
added server components (handler, item provider) for smart connector
yentelmanero ca2e9b1
added possibility to set position for smart connector containers (lef…
yentelmanero 510c9f7
Merge remote-tracking branch 'upstream/main'
yentelmanero 85cb92c
added customization options and workflow example for smart connector
yentelmanero b79650e
Merge remote-tracking branch 'upstream/main'
yentelmanero 8b77069
addressed lint issues
yentelmanero 0edc62d
Merge branch 'main' of https://github.com/yentelmanero/glsp-server-node
yentelmanero cb71c3b
Implemented suggested changes from PR
yentelmanero 1f8cb5a
Merge pull request #1 from eclipse-glsp/main
yentelmanero 6a88438
Implemented suggested changes from PR #2
yentelmanero 19d6020
Merge branch 'eclipse-glsp:main' into main
yentelmanero c6ba7bd
applied prettier formatting
yentelmanero 6b01139
renamed smart connector to selection palette, removed related action …
yentelmanero c97bc4b
renamed createSelectionPaletteItems to createSelectionPaletteItem
yentelmanero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
examples/workflow-server/src/common/provider/workflow-selection-palette-item-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************** | ||
* 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 { | ||
DefaultSelectionPaletteItemProvider, SelectionPaletteSettings | ||
} from '@eclipse-glsp/server'; | ||
import { | ||
SelectionPalettePosition, | ||
SelectionPaletteGroupUIType, | ||
DefaultTypes | ||
} from '@eclipse-glsp/protocol'; | ||
import { injectable } from 'inversify'; | ||
import { ModelTypes } from '../util/model-types'; | ||
|
||
@injectable() | ||
export class WorkflowSelectionPaletteItemProvider extends DefaultSelectionPaletteItemProvider { | ||
|
||
protected override selectionPaletteNodeSettings: SelectionPaletteSettings = { | ||
position: SelectionPalettePosition.Top, | ||
showTitle: true, | ||
submenu: false, | ||
showOnlyForChildren: SelectionPaletteGroupUIType.Labels | ||
}; | ||
|
||
protected override selectionPaletteEdgeSettings: SelectionPaletteSettings = { | ||
position: SelectionPalettePosition.Right, | ||
showTitle: true, | ||
submenu: true | ||
}; | ||
|
||
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], | ||
[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] | ||
}; | ||
|
||
protected override defaultEdge = DefaultTypes.EDGE; | ||
|
||
protected override edgeTypes = { | ||
[ModelTypes.AUTOMATED_TASK]: DefaultTypes.EDGE, | ||
[ModelTypes.MERGE_NODE]: DefaultTypes.EDGE | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
packages/server/src/common/features/contextactions/selection-palette-item-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
/******************************************************************************** | ||
* 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 { | ||
Args, | ||
CreateEdgeOperation, | ||
CreateNodeOperation, | ||
PaletteItem, | ||
SelectionPaletteGroupItem, | ||
EditorContext, | ||
LabeledAction, | ||
MaybePromise, | ||
SelectionPalettePosition, | ||
SelectionPaletteGroupUIType, | ||
SelectionPaletteNodeItem, | ||
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 { Logger } from '../../utils/logger'; | ||
|
||
/** | ||
* A {@link ContextActionsProvider} for {@link PaletteItem}s in the Selection palette which appears when a node is selected. | ||
*/ | ||
@injectable() | ||
export abstract class SelectionPaletteItemProvider implements ContextActionsProvider { | ||
/** | ||
* Returns the context id of the provider. | ||
*/ | ||
get contextId(): string { | ||
return 'selection-palette'; | ||
} | ||
|
||
/** | ||
* 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<LabeledAction[]> { | ||
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<SelectionPaletteGroupItem[]>; | ||
} | ||
|
||
export type SelectionPaletteSettings = | ||
| { | ||
position: SelectionPalettePosition; | ||
showTitle: true; | ||
submenu: boolean; | ||
showOnlyForChildren?: SelectionPaletteGroupUIType; | ||
} | ||
| { | ||
position: SelectionPalettePosition; | ||
showTitle: false; | ||
showOnlyForChildren?: SelectionPaletteGroupUIType; | ||
}; | ||
|
||
@injectable() | ||
export class DefaultSelectionPaletteItemProvider extends SelectionPaletteItemProvider { | ||
@inject(OperationHandlerRegistry) protected operationHandlerRegistry: OperationHandlerRegistry; | ||
@inject(Logger) | ||
protected logger: Logger; | ||
|
||
protected counter: number; | ||
|
||
protected selectionPaletteNodeSettings: SelectionPaletteSettings = { | ||
position: SelectionPalettePosition.Right, | ||
showTitle: true, | ||
submenu: true, | ||
showOnlyForChildren: SelectionPaletteGroupUIType.Icons | ||
}; | ||
|
||
protected selectionPaletteEdgeSettings: SelectionPaletteSettings = { | ||
position: SelectionPalettePosition.Right, | ||
showTitle: true, | ||
submenu: false | ||
}; | ||
/** filter that excludes nodes/edges from options, given a node ID as key */ | ||
protected nodeOperationFilter: Record<string, string[] | undefined> = {}; | ||
|
||
/** 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<string, string | undefined>; | ||
|
||
getItems(args?: Args): SelectionPaletteGroupItem[] { | ||
const handlers = this.operationHandlerRegistry.getAll().filter(CreateOperationHandler.is) as CreateOperationHandler[]; | ||
this.counter = 0; | ||
const nodes = this.createSelectionPaletteGroupItem( | ||
handlers, | ||
CreateNodeOperation.KIND, | ||
args?.nodeType as string, | ||
this.selectionPaletteNodeSettings.showOnlyForChildren | ||
); | ||
const edges = this.createSelectionPaletteGroupItem( | ||
handlers, | ||
CreateEdgeOperation.KIND, | ||
args?.nodeType as string, | ||
this.selectionPaletteEdgeSettings.showOnlyForChildren | ||
); | ||
return [ | ||
{ | ||
id: 'selection-palette-node-group', | ||
label: 'Nodes', | ||
actions: [], | ||
children: nodes, | ||
icon: 'symbol-property', | ||
sortString: 'A', | ||
...this.selectionPaletteNodeSettings | ||
}, | ||
{ | ||
id: 'selection-palette-edge-group', | ||
label: 'Edges', | ||
actions: [], | ||
children: edges, | ||
icon: 'symbol-property', | ||
sortString: 'B', | ||
...this.selectionPaletteEdgeSettings | ||
} | ||
]; | ||
} | ||
|
||
protected createSelectionPaletteGroupItem( | ||
handlers: CreateOperationHandler[], | ||
kind: string, | ||
selectedNodeType: string, | ||
showOnly?: SelectionPaletteGroupUIType | ||
): 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.createSelectionPaletteItem(action, handler.label, selectedNodeType)) | ||
) | ||
.reduce((accumulator, value) => accumulator.concat(value), []) | ||
.sort((a, b) => a.sortString.localeCompare(b.sortString)); | ||
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 selection palette.'); | ||
return paletteItems; | ||
} | ||
paletteItems.forEach(paletteItem => (paletteItem.label = '')); | ||
} else if (showOnly === SelectionPaletteGroupUIType.Labels) { | ||
paletteItems.forEach(paletteItem => (paletteItem.icon = '')); | ||
} | ||
return paletteItems; | ||
} | ||
|
||
protected createSelectionPaletteItem( | ||
action: PaletteItem.TriggerElementCreationAction, | ||
label: string, | ||
nodeType: string | ||
): PaletteItem | SelectionPaletteNodeItem { | ||
if (TriggerNodeCreationAction.is(action)) { | ||
let edgeType = this.edgeTypes[nodeType]; | ||
if (!edgeType) { | ||
edgeType = this.defaultEdge; | ||
} | ||
return { | ||
id: `selection-palette-palette-item${this.counter++}`, | ||
sortString: label.charAt(0), | ||
label, | ||
actions: [action], | ||
edgeType: edgeType | ||
}; | ||
} | ||
return { | ||
id: `selection-palette-palette-item${this.counter++}`, | ||
sortString: label.charAt(0), | ||
label, | ||
actions: [action] | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why this is done this way, but we should find a more generic solution here.
Ideally we would dispatch a
CompoundOperation
on the client-side that contains theCreateNode
andCreateEdge
operations. Currently the API does not support this, because we need context-specific information. i.e. theCreateEdge
operation needs to know the id of the newly created node it should connect to.We should create a follow-up for that.