diff --git a/open-bpmn.glsp-client/open-bpmn-glsp/src/bpmn-property-actions.tsx b/open-bpmn.glsp-client/open-bpmn-glsp/src/bpmn-property-actions.tsx new file mode 100644 index 00000000..baa7b92c --- /dev/null +++ b/open-bpmn.glsp-client/open-bpmn-glsp/src/bpmn-property-actions.tsx @@ -0,0 +1,50 @@ +/******************************************************************************** + * Copyright (c) 2022 Imixs Software Solutions GmbH 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 } from '@eclipse-glsp/protocol'; +import { injectable } from 'inversify'; +import { + IActionHandler +} from 'sprotty'; + +/**************************************************************************** + * This module provides BPMN action listeners for custom behavior. + * + ****************************************************************************/ + +export interface BPMNPropertyAction extends Action { + kind: typeof BPMNPropertyAction.KIND; +} + +export namespace BPMNPropertyAction { + export const KIND = 'properties'; + + export function is(object: any): object is BPMNPropertyAction { + return Action.hasKind(object, KIND); + } + + export function create(): BPMNPropertyAction { + return { kind: KIND }; + } +} + +@injectable() +export class BPMNPropertyActionHandler implements IActionHandler { + handle(action: BPMNPropertyAction): void | BPMNPropertyAction { + console.log('--------> custom action arrived'); + // implement your custom logic to handle the action + // Optionally issue a response action + } +} diff --git a/open-bpmn.glsp-client/open-bpmn-glsp/src/di.config.ts b/open-bpmn.glsp-client/open-bpmn-glsp/src/di.config.ts index 3372c09c..d35ac6e1 100644 --- a/open-bpmn.glsp-client/open-bpmn-glsp/src/di.config.ts +++ b/open-bpmn.glsp-client/open-bpmn-glsp/src/di.config.ts @@ -14,8 +14,8 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { - boundsFeature, CircularNodeView, configureCommand, configureDefaultModelElements, - configureModelElement, configureView, ConsoleLogger, + boundsFeature, CircularNodeView, configureActionHandler, configureCommand, + configureDefaultModelElements, configureModelElement, configureView, ConsoleLogger, createDiagramContainer, DeleteElementContextMenuItemProvider, DiamondNodeView, @@ -51,6 +51,8 @@ import { import bpmnPropertyModule from '@open-bpmn/open-bpmn-properties'; +import { BPMNPropertyAction, BPMNPropertyActionHandler } from './bpmn-property-actions'; + const bpmnDiagramModule = new ContainerModule((bind, unbind, isBound, rebind) => { const context = { bind, unbind, isBound, rebind }; @@ -121,6 +123,9 @@ const bpmnDiagramModule = new ContainerModule((bind, unbind, isBound, rebind) => configureModelElement(context, 'messageFlow', BPMNEdge, BPMNEdgeView); configureModelElement(context, 'association', BPMNEdge, BPMNEdgeView); + // Action BPMN Property Action Handler + configureActionHandler(context, BPMNPropertyAction.KIND, BPMNPropertyActionHandler); + }); /* diff --git a/open-bpmn.glsp-client/open-bpmn-glsp/src/index.ts b/open-bpmn.glsp-client/open-bpmn-glsp/src/index.ts index e97fe785..dec7a06a 100644 --- a/open-bpmn.glsp-client/open-bpmn-glsp/src/index.ts +++ b/open-bpmn.glsp-client/open-bpmn-glsp/src/index.ts @@ -16,6 +16,8 @@ import createBPMNDiagramContainer from './di.config'; export * from './bpmn-element-views'; +export * from './bpmn-property-actions'; export * from './bpmn-routing-views'; - export { createBPMNDiagramContainer }; + + diff --git a/open-bpmn.glsp-client/open-bpmn-theia/src/browser/bpmn-frontend-module.ts b/open-bpmn.glsp-client/open-bpmn-theia/src/browser/bpmn-frontend-module.ts index 725bc927..8fbb1ddd 100644 --- a/open-bpmn.glsp-client/open-bpmn-theia/src/browser/bpmn-frontend-module.ts +++ b/open-bpmn.glsp-client/open-bpmn-theia/src/browser/bpmn-frontend-module.ts @@ -14,10 +14,12 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { ContainerContext, GLSPClientContribution, GLSPTheiaFrontendModule } from '@eclipse-glsp/theia-integration'; +import { CommandContribution, MenuContribution } from '@theia/core'; import { DiagramConfiguration } from 'sprotty-theia'; import { BPMNLanguage } from '../common/bpmn-language'; -import { BPMNDiagramConfiguration } from './diagram/bpmn-diagram-configuration'; import { BPMNGLSPClientContribution } from './bpmn-glsp-client-contribution'; +import { BPMNPropertiesCommandContribution, BPMNPropertiesMenuContribution } from './bpmn-property-commands'; +import { BPMNDiagramConfiguration } from './diagram/bpmn-diagram-configuration'; export class BPMNTheiaFrontendModule extends GLSPTheiaFrontendModule { protected override enableCopyPaste = true; @@ -26,44 +28,18 @@ export class BPMNTheiaFrontendModule extends GLSPTheiaFrontendModule { bindDiagramConfiguration(context: ContainerContext): void { context.bind(DiagramConfiguration).to(BPMNDiagramConfiguration); } - override bindGLSPClientContribution(context: ContainerContext): void { - context.bind(GLSPClientContribution).to(BPMNGLSPClientContribution); - } -} - -export default new BPMNTheiaFrontendModule(); - -// -- -/* -export class WorkflowTheiaFrontendModule extends GLSPTheiaFrontendModule { - protected override enableCopyPaste = true; - - bindDiagramConfiguration(context: ContainerContext): void { - context.bind(DiagramConfiguration).to(WorkflowDiagramConfiguration); - } - readonly diagramLanguage = WorkflowLanguage; override configure(context: ContainerContext): void { // Custom workflow commands and menus - context.bind(CommandContribution).to(WorkflowTaskEditCommandContribution); - context.bind(MenuContribution).to(WorkflowTaskEditMenuContribution); - context.bind(CommandContribution).to(WorkflowNavigationCommandContribution); - context.bind(MenuContribution).to(WorkflowNavigationMenuContribution); - context.bind(KeybindingContext).to(WorkflowDiagramKeybindingContext); - context.bind(KeybindingContribution).to(WorkflowKeybindingContribution); + context.bind(CommandContribution).to(BPMNPropertiesCommandContribution); + context.bind(MenuContribution).to(BPMNPropertiesMenuContribution); - // Example for a command that navigates to an element in a diagram with a query resolved by the server - context.bind(CommandContribution).to(ExampleNavigationCommandContribution).inSingletonScope(); - - // Readonly workflow diagram view - context.bind(WorkflowDiagramReadonlyViewContribution).toSelf().inSingletonScope(); - context.bind(MenuContribution).toService(WorkflowDiagramReadonlyViewContribution); - context.bind(CommandContribution).toService(WorkflowDiagramReadonlyViewContribution); } override bindGLSPClientContribution(context: ContainerContext): void { - context.bind(GLSPClientContribution).to(WorkflowGLSPClientContribution); + context.bind(GLSPClientContribution).to(BPMNGLSPClientContribution); } } -*/ + +export default new BPMNTheiaFrontendModule(); diff --git a/open-bpmn.glsp-client/open-bpmn-theia/src/browser/bpmn-property-commands.tsx b/open-bpmn.glsp-client/open-bpmn-theia/src/browser/bpmn-property-commands.tsx new file mode 100644 index 00000000..272543fd --- /dev/null +++ b/open-bpmn.glsp-client/open-bpmn-theia/src/browser/bpmn-property-commands.tsx @@ -0,0 +1,76 @@ +/******************************************************************************** + * Copyright (c) 2020-2022 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 { NavigateAction } from '@eclipse-glsp/client'; +import { GLSPCommandHandler, GLSPContextMenu } from '@eclipse-glsp/theia-integration'; +import { + BPMNPropertyAction +} from '@open-bpmn/open-bpmn-glsp'; +import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core'; +import { ApplicationShell } from '@theia/core/lib/browser'; +import { inject, injectable } from '@theia/core/shared/inversify'; +/** + * This module defines different commands and menu actions that fire a specific action. + * These actions can be handled by the server or client part. + * + * Note! the command contributions must be registered in the BPMNTheiaFrontendModule + * + */ +export namespace PropertyPanelCommands { + export const PROPERTIES_CLOSE = 'glsp-bpmn-properties-close'; + export const PROPERTIES_OPEN = 'glsp-bpmn-properties-open'; +} + +@injectable() +export class BPMNPropertiesCommandContribution implements CommandContribution { + @inject(ApplicationShell) protected readonly shell: ApplicationShell; + registerCommands(commands: CommandRegistry): void { + // register commands... + commands.registerCommand( + { id: PropertyPanelCommands.PROPERTIES_OPEN, label: 'Open Properties' }, + new GLSPCommandHandler(this.shell, { + actions: () => [BPMNPropertyAction.create()], + isEnabled: context => context.selectedElements.length === 1 + }) + ); + + commands.registerCommand( + { id: PropertyPanelCommands.PROPERTIES_CLOSE, label: 'Close Properties' }, + new GLSPCommandHandler(this.shell, { + actions: () => [NavigateAction.create('properties')], + isEnabled: context => context.selectedElements.length === 1 + }) + ); + } +} + +@injectable() +export class BPMNPropertiesMenuContribution implements MenuContribution { + // static readonly NAVIGATION = GLSPContextMenu.MENU_PATH.concat('navigate'); + // static readonly NIX = GLSPContextMenu.MENU_PATH; + registerMenus(menus: MenuModelRegistry): void { + + menus.registerMenuAction(GLSPContextMenu.MENU_PATH.concat('z'), { + commandId: PropertyPanelCommands.PROPERTIES_OPEN, + label: 'Open Properties' + }); + menus.registerMenuAction(GLSPContextMenu.MENU_PATH.concat('z'), { + commandId: PropertyPanelCommands.PROPERTIES_CLOSE, + label: 'Close Properties' + }); + + } +}