Skip to content

Commit

Permalink
implement new preference to change between client and server layout
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasRentzCAU committed Nov 5, 2024
1 parent 402df1a commit c848768
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/klighd-core/src/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ export default function createContainer(widgetId: string): Container {
)
// FIXME: bookmarkModule is currently broken due to wrong usage of Sprotty commands. action handling needs to be reimplemented for this to work.
overrideViewerOptions(container, {
// TODO: need some configuration switch to enable/disable client layout
needsClientLayout: true, // client layout = micro layout (Sprotty/Sprotty+KLighD)
needsServerLayout: false, // server layout = macro layout (ELK/elkjs). false here to not forward it to the Java server (the model source), but keep and handle it directly on the diagram server proxy manually
// These are ignored ignored and overwritten by the current needsClientLayout preference during model request.
needsClientLayout: false, // client layout = micro layout (Sprotty/Sprotty+KLighD)
needsServerLayout: true, // server layout = macro layout (ELK/elkjs). false here to not forward it to the Java server (the model source), but keep and handle it directly on the diagram server proxy manually
baseDiv: widgetId,
hiddenDiv: `${widgetId}_hidden`,
// TODO: We should be able to completely deactivate Sprotty's zoom limits to not limit top down layout.
Expand Down
22 changes: 20 additions & 2 deletions packages/klighd-core/src/diagram-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import {
import { RequestKlighdPopupModelAction } from './hover/hover'
import { PopupModelProvider } from './hover/popup-provider'
import { RenderOptionsRegistry, ResizeToFit } from './options/render-options-registry'
import { IncrementalDiagramGeneratorOption, PreferencesRegistry } from './preferences-registry'
import { ClientLayoutOption, IncrementalDiagramGeneratorOption, PreferencesRegistry } from './preferences-registry'
import { Connection, ServiceTypes, SessionStorage } from './services'
import { SetSynthesisAction } from './syntheses/actions'
import { UpdateDepthMapModelAction } from './update/update-depthmap-model'
Expand Down Expand Up @@ -308,9 +308,27 @@ export class KlighdDiagramServer extends DiagramServerProxy {
return false
}

// Super class behavior, except taking the needsClientLayout preference into account instead of the client option.
override handleRequestModel(action: RequestModelAction): boolean {
const needsClientLayout = !!this.preferencesRegistry.getValue(ClientLayoutOption)
const needsServerLayout = !needsClientLayout

const newOptions = {
needsClientLayout,
needsServerLayout,
...action.options,
}
const newAction = {
...action,
options: newOptions,
}
this.forwardToServer(newAction)
return false
}

// Behavior adapted from the super class and modified to the behavior of the DiagramServer to allow this proxy to the Java diagram server to still be able to perform the layout locally.
handleComputedBounds(action: ComputedBoundsAction): boolean {
if (this.viewerOptions.needsServerLayout) {
if (!this.preferencesRegistry.getValue(ClientLayoutOption)) {
return false
}
const root = this.currentRoot
Expand Down
20 changes: 20 additions & 0 deletions packages/klighd-core/src/options/general-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import { inject, injectable, postConstruct } from 'inversify'
import { VNode } from 'snabbdom'
import { html } from 'sprotty' // eslint-disable-line @typescript-eslint/no-unused-vars
import { RefreshDiagramAction } from '@kieler/klighd-interactive/lib/actions'
import { DISymbol } from '../di.symbols'
import { FeatherIcon } from '../feather-icons-snabbdom/feather-icons-snabbdom'
import {
ClientLayoutOption,
IncrementalDiagramGeneratorOption,
PreferencesRegistry,
ShouldSelectDiagramOption,
Expand Down Expand Up @@ -123,6 +125,16 @@ export class GeneralPanel extends SidebarPanel {
) : (
''
)}
{(this.renderOptionsRegistry.getValue(DebugOptions) as boolean) ? (
<CheckOption
id={ClientLayoutOption.ID}
name={ClientLayoutOption.NAME}
value={this.preferencesRegistry.getValue(ClientLayoutOption)}
onChange={this.handlePreferenceChange.bind(this, ClientLayoutOption.ID)}
/>
) : (
''
)}
</div>
</div>
)
Expand All @@ -134,6 +146,14 @@ export class GeneralPanel extends SidebarPanel {

private handlePreferenceChange(key: string, newValue: any) {
this.actionDispatcher.dispatch(SetPreferencesAction.create([{ id: key, value: newValue }]))
if (key === ClientLayoutOption.ID) {
this.actionDispatcher.dispatch(
RefreshDiagramAction.create({
needsClientLayout: newValue,
needsServerLayout: !newValue,
})
)
}
}

get icon(): VNode {
Expand Down
4 changes: 1 addition & 3 deletions packages/klighd-core/src/options/render-options-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2021-2022 by
* Copyright 2021-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand Down Expand Up @@ -509,8 +509,6 @@ export class DebugOptions implements RenderOption {
readonly description = 'Whether debug options should be shown.'

currentValue = false

debug = true
}

export interface RenderOptionType {
Expand Down
29 changes: 28 additions & 1 deletion packages/klighd-core/src/preferences-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2021 by
* Copyright 2021-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand Down Expand Up @@ -87,6 +87,31 @@ export class IncrementalDiagramGeneratorOption implements Preference {
debug = true
}

/**
* Switch between client-only and server-only layout.
*/
export class ClientLayoutOption implements Preference {
static readonly ID: string = 'diagram.clientLayout'

static readonly NAME: string = 'Client Layout'

readonly description: string | undefined = 'Switch between client-only and server-only layout.'

readonly id: string = ClientLayoutOption.ID

readonly name: string = ClientLayoutOption.NAME

readonly type: TransformationOptionType = TransformationOptionType.CHECK

readonly initialValue: boolean = false

currentValue = false

notifyServer = true

debug = true
}

export interface PreferenceType {
readonly ID: string
readonly NAME: string
Expand Down Expand Up @@ -116,6 +141,7 @@ export class PreferencesRegistry extends Registry {
this.register(ShouldSelectDiagramOption)
this.register(ShouldSelectTextOption)
this.register(IncrementalDiagramGeneratorOption)
this.register(ClientLayoutOption)
}

@postConstruct()
Expand Down Expand Up @@ -184,6 +210,7 @@ export class PreferencesRegistry extends Registry {
'diagram.shouldSelectDiagram': this.getValue(ShouldSelectDiagramOption),
'diagram.shouldSelectText': this.getValue(ShouldSelectTextOption),
'diagram.incrementalDiagramGenerator': this.getValue(IncrementalDiagramGeneratorOption),
'diagram.clientLayout': this.getValue(ClientLayoutOption),
}
this.connection.sendNotification(NotificationType.SetPreferences, obj)
})
Expand Down
8 changes: 5 additions & 3 deletions packages/klighd-interactive/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2020-2021 by
* Copyright 2020-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand All @@ -17,22 +17,24 @@
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file.
/* eslint-disable no-redeclare */

import { Action } from 'sprotty-protocol'
import { Action, JsonMap } from 'sprotty-protocol'
import { DeleteConstraint } from './layered/constraint-types'

/**
* A sprotty action to refresh the diagram. Sent from client to server.
*/
export interface RefreshDiagramAction extends Action {
kind: typeof RefreshDiagramAction.KIND
options?: JsonMap
}

export namespace RefreshDiagramAction {
export const KIND = 'refreshDiagram'

export function create(): RefreshDiagramAction {
export function create(options?: JsonMap): RefreshDiagramAction {
return {
kind: KIND,
options,
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions schema/klighd/actions/refreshDiagram.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "refreshDiagram",
"type": "object",
"allOf": [{"$ref": "/kieler/klighd-vscode/tree/main/schema/sprotty/action.json"}],
"allOf": [{ "$ref": "/kieler/klighd-vscode/tree/main/schema/sprotty/action.json" }],
"required": ["kind"],
"properties": {
"kind": {
"type": "string",
"enum": ["refreshDiagram"]
},
"options": {
"type": "object",
"properties": {
"needsClientLayout": {
"type": "boolean"
},
"needsServerLayout": {
"type": "boolean"
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions schema/klighd/messages/preferencesSetPreferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
"diagram.incrementalDiagramGenerator": {
"type": "boolean"
},
"diagram.clientLayout": {
"type": "boolean"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions schema/sprotty/actions/requestModel.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"$id": "https://github.com/kieler/klighd-vscode/tree/main/schema/sprotty/actions/requestModel.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "requestBounds",
"title": "requestModel",
"type": "object",
"allOf": [{"$ref": "/kieler/klighd-vscode/tree/main/schema/sprotty/actions/action.json"}],
"allOf": [{ "$ref": "/kieler/klighd-vscode/tree/main/schema/sprotty/actions/action.json" }],
"required": ["kind", "options", "requestId"],
"properties": {
"kind": {
Expand Down Expand Up @@ -32,4 +32,4 @@
"type": "string"
}
}
}
}

0 comments on commit c848768

Please sign in to comment.