-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement command API & Undo/Redo support - implement a generic Command/Commandstack API similar to the EMF Api - Provide default implementations for Commandstack & Compound command - Provide a RecordingCommand API for arbitary JSON models using json patches - Add testscases for the new command API Fixes eclipse-glsp/glsp#791 - Refactor OperationHandler API to return optional executable commands (similar to how it has been done for the Java API) - Unfortunately this introduces hard breaks and maintaining a compatibility/deprecation layer is not easily feasible. - Most prominent changes: Refactor `OperationHandler` from interface to class and refactor `CreateOperationHandler` to interface to facilitate multi-inheritance Fixes eclipse-glsp/glsp#889 Ensure that all components of the direct gmodel library are correctly prefixed. Fixes eclipse-glsp/glsp#826
- Loading branch information
Showing
44 changed files
with
1,462 additions
and
368 deletions.
There are no files selected for viewing
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
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
118 changes: 118 additions & 0 deletions
118
examples/workflow-server/src/common/taskedit/edit-task-operation-handler.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,118 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { Action, Command, getOrThrow, GModelOperationHandler, hasStringProp, MaybePromise, Operation } from '@eclipse-glsp/server'; | ||
import { injectable } from 'inversify'; | ||
import { TaskNode } from '../graph-extension'; | ||
import { ModelTypes } from '../util/model-types'; | ||
/** | ||
* Is send from the {@link TaskEditor} to the GLSP server | ||
* to update a feature from a specified task. | ||
*/ | ||
export interface EditTaskOperation extends Operation { | ||
kind: typeof EditTaskOperation.KIND; | ||
|
||
/** | ||
* Id of the task that should be edited | ||
*/ | ||
taskId: string; | ||
|
||
/** | ||
* The feature that is to be updated | ||
*/ | ||
feature: 'duration' | 'taskType'; | ||
|
||
/** | ||
* The new feature value | ||
*/ | ||
value: string; | ||
} | ||
|
||
export namespace EditTaskOperation { | ||
export const KIND = 'editTask'; | ||
|
||
export function is(object: any): object is EditTaskOperation { | ||
return ( | ||
Action.hasKind(object, KIND) && | ||
hasStringProp(object, 'taskId') && | ||
hasStringProp(object, 'feature') && | ||
hasStringProp(object, 'value') | ||
); | ||
} | ||
|
||
export function create(options: { taskId: string; feature: 'duration' | 'taskType'; value: string }): EditTaskOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
...options | ||
}; | ||
} | ||
} | ||
|
||
@injectable() | ||
export class EditTaskOperationHandler extends GModelOperationHandler { | ||
readonly operationType = EditTaskOperation.KIND; | ||
|
||
createCommand(operation: EditTaskOperation): MaybePromise<Command | undefined> { | ||
const task = getOrThrow( | ||
this.modelState.index.findByClass(operation.taskId, TaskNode), | ||
`Cannot find task with id '${operation.taskId}'` | ||
); | ||
switch (operation.feature) { | ||
case 'duration': { | ||
const duration = Number.parseInt(operation.value, 10); | ||
return duration !== task.duration // | ||
? this.commandOf(() => this.editDuration(task, duration)) | ||
: undefined; | ||
} | ||
case 'taskType': { | ||
return task.taskType !== operation.value // | ||
? this.commandOf(() => this.editTaskType(task, operation.value)) | ||
: undefined; | ||
} | ||
} | ||
} | ||
|
||
protected editDuration(task: TaskNode, duration: number): void { | ||
task.duration = duration; | ||
} | ||
|
||
protected editTaskType(task: TaskNode, type: string): void { | ||
task.taskType = type; | ||
if (type === 'manual' || type === 'automated') { | ||
const temp = this.createTempTask(type, task); | ||
const toAssign: Partial<TaskNode> = { | ||
taskType: temp.taskType, | ||
type: temp.type, | ||
children: temp.children, | ||
cssClasses: temp.cssClasses | ||
}; | ||
Object.assign(task, toAssign); | ||
return; | ||
} | ||
throw new Error(`Could not edit task '${task.id}'. Invalid type: ${type}`); | ||
} | ||
|
||
protected createTempTask(type: 'automated' | 'manual', task: TaskNode): TaskNode { | ||
return TaskNode.builder() // | ||
.type(type === 'automated' ? ModelTypes.AUTOMATED_TASK : ModelTypes.MANUAL_TASK) | ||
.taskType(type) | ||
.name(task.name) | ||
.addCssClass(type) | ||
.children() | ||
.build(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
examples/workflow-server/src/common/taskedit/task-edit-context-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,66 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { ContextActionsProvider, EditorContext, LabeledAction, MaybePromise, ModelState, toTypeGuard } from '@eclipse-glsp/server'; | ||
import { inject, injectable } from 'inversify'; | ||
import { TaskNode } from '../graph-extension'; | ||
import { EditTaskOperation } from './edit-task-operation-handler'; | ||
|
||
@injectable() | ||
export class TaskEditContextActionProvider implements ContextActionsProvider { | ||
static readonly DURATION_PREFIX = 'duration:'; | ||
static readonly TYPE_PREFIX = 'type:'; | ||
static readonly TASK_PREFIX = 'task:'; | ||
|
||
readonly contextId = 'task-editor'; | ||
|
||
@inject(ModelState) | ||
protected modelState: ModelState; | ||
|
||
getActions(editorContext: EditorContext): MaybePromise<LabeledAction[]> { | ||
const text = editorContext.args?.['text'].toString() ?? ''; | ||
const taskNode = this.modelState.index.findParentElement(editorContext.selectedElementIds[0], toTypeGuard(TaskNode)); | ||
if (!taskNode) { | ||
return []; | ||
} | ||
|
||
if (text.startsWith(TaskEditContextActionProvider.TYPE_PREFIX)) { | ||
const taskId = taskNode.id; | ||
return [ | ||
{ label: 'type:automated', actions: [EditTaskOperation.create({ taskId, feature: 'taskType', value: 'automated' })] }, | ||
{ label: 'type:manual', actions: [EditTaskOperation.create({ taskId, feature: 'taskType', value: 'manual' })] } | ||
]; | ||
} | ||
|
||
if (text.startsWith(TaskEditContextActionProvider.DURATION_PREFIX)) { | ||
return []; | ||
} | ||
|
||
const taskType = taskNode.type.substring(TaskEditContextActionProvider.TASK_PREFIX.length); | ||
const duration = taskNode.duration; | ||
return [ | ||
<SetAutocompleteValueAction>{ label: 'type:', actions: [], text: `${TaskEditContextActionProvider.TYPE_PREFIX}${taskType}` }, | ||
<SetAutocompleteValueAction>{ | ||
label: 'duration:', | ||
actions: [], | ||
text: `${TaskEditContextActionProvider.DURATION_PREFIX}${duration ?? 0}` | ||
} | ||
]; | ||
} | ||
} | ||
|
||
interface SetAutocompleteValueAction extends LabeledAction { | ||
text: string; | ||
} |
45 changes: 45 additions & 0 deletions
45
examples/workflow-server/src/common/taskedit/task-edit-validator.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,45 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { ContextEditValidator, RequestEditValidationAction, ValidationStatus } from '@eclipse-glsp/server'; | ||
import { injectable } from 'inversify'; | ||
import { TaskEditContextActionProvider } from './task-edit-context-provider'; | ||
|
||
@injectable() | ||
export class TaskEditValidator implements ContextEditValidator { | ||
readonly contextId = 'task-editor'; | ||
|
||
validate(action: RequestEditValidationAction): ValidationStatus { | ||
const text = action.text; | ||
if (text.startsWith(TaskEditContextActionProvider.DURATION_PREFIX)) { | ||
const durationString = text.substring(TaskEditContextActionProvider.DURATION_PREFIX.length); | ||
const duration = Number.parseInt(durationString, 10); | ||
if (Number.isNaN(duration)) { | ||
return { severity: ValidationStatus.Severity.ERROR, message: `'${durationString}' is not a valid number.` }; | ||
} else if (duration < 0 || duration > 100) { | ||
return { severity: ValidationStatus.Severity.WARNING, message: `'${durationString}' should be between 0 and 100` }; | ||
} | ||
} else if (text.startsWith(TaskEditContextActionProvider.TYPE_PREFIX)) { | ||
const typeString = text.substring(TaskEditContextActionProvider.TYPE_PREFIX.length); | ||
if (typeString !== 'automated' && typeString !== 'manual') { | ||
return { | ||
severity: ValidationStatus.Severity.ERROR, | ||
message: `'Type of task can only be manual or automatic. You entered '${typeString}'.` | ||
}; | ||
} | ||
} | ||
return ValidationStatus.NONE; | ||
} | ||
} |
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
Oops, something went wrong.