Skip to content

Commit

Permalink
#258 Refactor theia integration code base (#84)
Browse files Browse the repository at this point in the history
* #258 Refactor theia integration code base

Reactor the theia integration code base to reduce boilerplate configuration code and make the setup of a new GLSP theia diagram editor easier

Major changes:
- Rename `GLSPTheiaSprottyConnector` to `TheiaGLSPConnector` and refactor the implementation to enable injecton of connectors (instead of the previous constructor-based approach). The connector is injected into the corresponding diagram container in the diagram configuration.
- Implement  a reusable and easy reconfigurable convenience container module ('GLSPTheiaFrontendModule') that setups the necessary module configuration for a GLSP theia diagram implementation and serves as a documented entry point for users. Similar to how the `GLSPModule` is implemented on server side
- Introduced `GLSPDiagramLanguage` interface to capture configuration constants for a diagram integration. The 'GLSPTheiaFrontendModule' uses this for configuration. This replaces the previous best-practice approach of keeping a namespace with configuration constants in the common-package.
- The 'GLSPDiagramClient' API is no longer needed and for the base use case it's no longer necessary to explicitly bind a diagram manager glsp client contribution or theia-glsp connector. 

Additional changes:
- Remove redundant `name` property in GLSPClient and GLSPServer contribution
- Refactor TheiaJsonrpcClient
- Remove unused `fileExtensions` property form glsp-client-contribution.ts
- Rename files so that the file name is aligned with the name of the central component in the .ts file (Theia Coding Convention)
- Defined lib/browser as main entry point  for `@eclipse-glsp/theia-integration`. 

Requires eclipse-glsp/glsp-client/pull/130
Fixes eclipse-glsp/glsp/issues/258

* Apply suggestions from code review

Co-authored-by: Philip Langer <planger@users.noreply.github.com>

Co-authored-by: Philip Langer <planger@users.noreply.github.com>
  • Loading branch information
tortmayr and planger authored Aug 10, 2021
1 parent c71a8a7 commit 2e2816c
Show file tree
Hide file tree
Showing 39 changed files with 2,045 additions and 1,680 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019 EclipseSource and others.
* Copyright (c) 2019-2021 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
Expand All @@ -16,17 +16,15 @@
import 'sprotty-theia/css/theia-sprotty.css';

import { createWorkflowDiagramContainer } from '@eclipse-glsp-examples/workflow-glsp/lib';
import {
GLSPTheiaDiagramConfiguration
} from '@eclipse-glsp/theia-integration/lib/browser/diagram/glsp-theia-diagram-configuration';
import { GLSPDiagramConfiguration } from '@eclipse-glsp/theia-integration';
import { Container, injectable } from '@theia/core/shared/inversify';

import { WorkflowLanguage } from '../../common/workflow-language';
import { WorkflowDiagramServer } from './workflow-diagram-server';

@injectable()
export class WorkflowDiagramConfiguration extends GLSPTheiaDiagramConfiguration {
diagramType: string = WorkflowLanguage.DiagramType;
export class WorkflowDiagramConfiguration extends GLSPDiagramConfiguration {
diagramType: string = WorkflowLanguage.diagramType;

doCreateContainer(widgetId: string): Container {
const container = createWorkflowDiagramContainer(widgetId);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
* Copyright (c) 2020-2021 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
Expand All @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { EditMode } from '@eclipse-glsp/client';
import { GLSPWidgetOpenerOptions } from '@eclipse-glsp/theia-integration/lib/browser';
import { GLSPWidgetOpenerOptions } from '@eclipse-glsp/theia-integration';
import {
Command,
CommandContribution,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
* Copyright (c) 2020-2021 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
Expand All @@ -15,7 +15,7 @@
********************************************************************************/
import { ApplyTaskEditOperation } from '@eclipse-glsp-examples/workflow-glsp/lib/direct-task-editing/direct-task-editor';
import { ActionHandlerRegistry } from '@eclipse-glsp/client';
import { GLSPTheiaDiagramServer } from '@eclipse-glsp/theia-integration/lib/browser';
import { GLSPTheiaDiagramServer } from '@eclipse-glsp/theia-integration';
import { injectable } from '@theia/core/shared/inversify';

@injectable()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
* Copyright (c) 2020-2021 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
Expand All @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { GLSPDiagramWidget } from '@eclipse-glsp/theia-integration/lib/browser';
import { GLSPDiagramWidget } from '@eclipse-glsp/theia-integration';
import { ApplicationShell, KeybindingContext, KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
import { inject, injectable } from '@theia/core/shared/inversify';

Expand All @@ -27,7 +27,7 @@ export class WorkflowDiagramKeybindingContext implements KeybindingContext {
@inject(ApplicationShell) protected readonly shell: ApplicationShell;
isEnabled(): boolean {
return this.shell.activeWidget instanceof GLSPDiagramWidget
&& this.shell.activeWidget.diagramType === WorkflowLanguage.DiagramType;
&& this.shell.activeWidget.diagramType === WorkflowLanguage.diagramType;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
* Copyright (c) 2020-2021 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
Expand All @@ -15,7 +15,7 @@
********************************************************************************/
import { isTaskNode } from '@eclipse-glsp-examples/workflow-glsp/lib/model';
import { NavigateAction } from '@eclipse-glsp/client';
import { GLSPCommandHandler, GLSPContextMenu } from '@eclipse-glsp/theia-integration/lib/browser';
import { GLSPCommandHandler, GLSPContextMenu } from '@eclipse-glsp/theia-integration';
import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core';
import { ApplicationShell } from '@theia/core/lib/browser';
import { inject, injectable } from '@theia/core/shared/inversify';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
* Copyright (c) 2020-2021 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
Expand All @@ -16,7 +16,7 @@
import { TaskEditor } from '@eclipse-glsp-examples/workflow-glsp/lib/direct-task-editing/direct-task-editor';
import { isTaskNode } from '@eclipse-glsp-examples/workflow-glsp/lib/model';
import { SetUIExtensionVisibilityAction } from '@eclipse-glsp/client';
import { GLSPCommandHandler, GLSPContextMenu } from '@eclipse-glsp/theia-integration/lib/browser';
import { GLSPCommandHandler, GLSPContextMenu } from '@eclipse-glsp/theia-integration';
import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core';
import { ApplicationShell } from '@theia/core/lib/browser';
import { inject, injectable } from '@theia/core/shared/inversify';
Expand Down

This file was deleted.

65 changes: 29 additions & 36 deletions examples/workflow-theia/src/browser/workflow-frontend-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2020 EclipseSource and others.
* Copyright (c) 2019-2021 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
Expand All @@ -13,22 +13,14 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import {
GLSPClientContribution,
registerCopyPasteContextMenu,
registerDiagramLayoutCommands,
registerDiagramManager,
registerMarkerNavigationCommands
} from '@eclipse-glsp/theia-integration/lib/browser';
import { ContainerContext, GLSPTheiaFrontendModule } from '@eclipse-glsp/theia-integration';
import { CommandContribution, MenuContribution } from '@theia/core';
import { KeybindingContext, KeybindingContribution } from '@theia/core/lib/browser';
import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
import { DiagramConfiguration } from 'sprotty-theia';

import { WorkflowLanguage } from '../common/workflow-language';
import { WorkflowDiagramConfiguration } from './diagram/workflow-diagram-configuration';
import { WorkflowDiagramManager } from './diagram/workflow-diagram-manager';
import { WorkflowDiagramReadonlyViewContribution } from './diagram/workflow-diagram-readonly-view';
import { WorkflowGLSPDiagramClient } from './diagram/workflow-glsp-diagram-client';
import {
WorkflowDiagramKeybindingContext,
WorkflowKeybindingContribution
Expand All @@ -42,33 +34,34 @@ import {
WorkflowTaskEditMenuContribution
} from './diagram/workflow-task-editing-context-menu';
import { ExampleNavigationCommandContribution } from './external-navigation-example/external-navigation-example';
import { WorkflowGLSPClientContribution } from './language/workflow-glsp-client-contribution';

export default new ContainerModule((bind: interfaces.Bind) => {
bind(WorkflowGLSPClientContribution).toSelf().inSingletonScope();
bind(GLSPClientContribution).toService(WorkflowGLSPClientContribution);
bind(DiagramConfiguration).to(WorkflowDiagramConfiguration).inSingletonScope();
bind(WorkflowGLSPDiagramClient).toSelf().inSingletonScope();
registerDiagramManager(bind, WorkflowDiagramManager);
export class WorkflowTheiaFrontendModule extends GLSPTheiaFrontendModule {
protected enableCopyPaste = true;

bindDiagramConfiguration(context: ContainerContext): void {
context.bind(DiagramConfiguration).to(WorkflowDiagramConfiguration);
}
readonly diagramLanguage = WorkflowLanguage;

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);

// 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();

// Optional default commands and menus
registerDiagramLayoutCommands(bind);
registerCopyPasteContextMenu(bind);
registerMarkerNavigationCommands(bind);
// Readonly workflow diagram view
context.bind(WorkflowDiagramReadonlyViewContribution).toSelf().inSingletonScope();
context.bind(MenuContribution).toService(WorkflowDiagramReadonlyViewContribution);
context.bind(CommandContribution).toService(WorkflowDiagramReadonlyViewContribution);
}

// Custom workflow commands and menus
bind(CommandContribution).to(WorkflowTaskEditCommandContribution).inSingletonScope();
bind(MenuContribution).to(WorkflowTaskEditMenuContribution).inSingletonScope();
bind(CommandContribution).to(WorkflowNavigationCommandContribution).inSingletonScope();
bind(MenuContribution).to(WorkflowNavigationMenuContribution).inSingletonScope();
bind(KeybindingContext).to(WorkflowDiagramKeybindingContext).inSingletonScope();
bind(KeybindingContribution).to(WorkflowKeybindingContribution).inSingletonScope();
}

// Example for a command that navigates to an element in a diagram with a query resolved by the server
bind(CommandContribution).to(ExampleNavigationCommandContribution).inSingletonScope();
export default new WorkflowTheiaFrontendModule();

// Readonly workflow diagram view
bind(WorkflowDiagramReadonlyViewContribution).toSelf().inSingletonScope();
bind(MenuContribution).toService(WorkflowDiagramReadonlyViewContribution);
bind(CommandContribution).toService(WorkflowDiagramReadonlyViewContribution);
});
18 changes: 10 additions & 8 deletions examples/workflow-theia/src/common/workflow-language.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019 EclipseSource and others.
* Copyright (c) 2019-2021 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
Expand All @@ -13,10 +13,12 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
export namespace WorkflowLanguage {
export const Id = 'Workflow';
export const Name = 'Workflow';
export const Label = 'Workflow diagram';
export const DiagramType = 'workflow-diagram';
export const FileExtension = '.wf';
}
import { GLSPDiagramLanguage } from '@eclipse-glsp/theia-integration/lib/common';

export const WorkflowLanguage: GLSPDiagramLanguage = {
contributionId: 'workflow',
label: 'Workflow diagram',
diagramType: 'workflow-diagram',
fileExtensions: ['.wf'],
iconClass: 'fa fa-project-diagram'
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2020 EclipseSource and others.
* Copyright (c) 2019-2021 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
Expand Down Expand Up @@ -27,8 +27,7 @@ export const JAR_FILE = resolve(join(SERVER_DIR, 'org.eclipse.glsp.example.workf

@injectable()
export class WorkflowGLServerContribution extends JavaSocketServerContribution {
readonly id = WorkflowLanguage.Id;
readonly name = WorkflowLanguage.Name;
readonly id = WorkflowLanguage.contributionId;

createLaunchOptions(): Partial<JavaSocketServerLaunchOptions> {
return {
Expand Down
7 changes: 3 additions & 4 deletions packages/theia-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@
},
"theiaExtensions": [
{
"frontend": "lib/browser/glsp-frontend-module",
"backend": "lib/node/glsp-backend-module"
"frontend": "lib/browser/theia-integration-frontend-module",
"backend": "lib/node/theia-integration-backend-module"
}
],
"publishConfig": {
"access": "public"
},
"main": "lib/index",
"types": "lib/index"
"main": "lib/browser/index"
}
Loading

0 comments on commit 2e2816c

Please sign in to comment.