forked from equinor/webviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5e83ec
commit 976a0e2
Showing
24 changed files
with
508 additions
and
238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,57 @@ | ||
import { WorkbenchServices } from "@framework/WorkbenchServices"; | ||
import { WorkbenchSession } from "@framework/WorkbenchSession"; | ||
import { Message, MessageDirection } from "./Message"; | ||
|
||
export class Broker { | ||
private _workbenchServices: WorkbenchServices; | ||
private _workbenchSession: WorkbenchSession; | ||
private _parentBroker: Broker | null = null; | ||
private _childrenBrokers: Broker[] = []; | ||
private _messageCallback: ((message: Message) => void) | null = null; | ||
|
||
constructor(workbenchServices: WorkbenchServices, workbenchSession: WorkbenchSession) { | ||
this._workbenchServices = workbenchServices; | ||
this._workbenchSession = workbenchSession; | ||
constructor(parent: Broker | null) { | ||
this._parentBroker = parent; | ||
} | ||
|
||
getWorkbenchServices(): WorkbenchServices { | ||
return this._workbenchServices; | ||
setParent(parent: Broker | null) { | ||
this._parentBroker = parent; | ||
} | ||
|
||
getWorkbenchSession(): WorkbenchSession { | ||
return this._workbenchSession; | ||
setChildren(children: Broker[]) { | ||
this._childrenBrokers = children; | ||
} | ||
|
||
addChild(child: Broker) { | ||
this._childrenBrokers.push(child); | ||
} | ||
|
||
removeChild(child: Broker) { | ||
this._childrenBrokers = this._childrenBrokers.filter((broker) => broker !== child); | ||
} | ||
|
||
emit(message: Message) { | ||
this.callCallback(message); | ||
|
||
if (message.isPropagationStopped()) { | ||
return; | ||
} | ||
|
||
if (message.getDirection() === MessageDirection.UP && this._parentBroker) { | ||
this._parentBroker.emit(message); | ||
return; | ||
} | ||
|
||
if (message.getDirection() === MessageDirection.DOWN) { | ||
for (const child of this._childrenBrokers) { | ||
child.emit(message); | ||
} | ||
} | ||
} | ||
|
||
onMessage(callback: (message: Message) => void) { | ||
this._messageCallback = callback; | ||
} | ||
|
||
callCallback(message: Message): void { | ||
const callback = this._messageCallback; | ||
if (callback) { | ||
callback(message); | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,53 @@ | ||
import { v4 } from "uuid"; | ||
|
||
import { Broker } from "./Broker"; | ||
import { LayerManager } from "./LayerManager"; | ||
import { Message, MessageDirection, MessageType } from "./Message"; | ||
import { SettingsContextDelegateTopic } from "./SettingsContextDelegate"; | ||
import { Item, Settings, SettingsContext } from "./interfaces"; | ||
|
||
export class LayerDelegate<TSettings extends Settings> implements Item { | ||
private _name: string; | ||
private _id: string; | ||
private _broker: Broker = new Broker(null); | ||
private _settingsContext: SettingsContext<TSettings>; | ||
private _layerManager: LayerManager | null = null; | ||
|
||
constructor(name: string, settingsContext: SettingsContext<TSettings>) { | ||
this._id = v4(); | ||
this._name = name; | ||
this._settingsContext = settingsContext; | ||
this._settingsContext.getDelegate().makeSubscriberFunction(SettingsContextDelegateTopic.SETTINGS_CHANGED)( | ||
() => { | ||
this._broker.emit(new Message(MessageType.SETTINGS_CHANGED, MessageDirection.UP)); | ||
} | ||
); | ||
} | ||
|
||
getBroker(): Broker { | ||
return this._broker; | ||
} | ||
|
||
getId(): string { | ||
return this._id; | ||
} | ||
|
||
getName(): string { | ||
return this._name; | ||
} | ||
|
||
getSettingsContext(): SettingsContext<TSettings> { | ||
return this._settingsContext; | ||
} | ||
|
||
setLayerManager(layerManager: LayerManager | null): void { | ||
this._layerManager = layerManager; | ||
} | ||
|
||
getLayerManager(): LayerManager { | ||
if (this._layerManager === null) { | ||
throw new Error("LayerManager not set"); | ||
} | ||
return this._layerManager; | ||
} | ||
} |
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,33 @@ | ||
import { WorkbenchSession } from "@framework/WorkbenchSession"; | ||
import { WorkbenchSettings } from "@framework/WorkbenchSettings"; | ||
|
||
import { GroupDelegate } from "./GroupDelegate"; | ||
import { View } from "./View"; | ||
|
||
export class LayerManager { | ||
private _workbenchSession: WorkbenchSession; | ||
private _workbenchSettings: WorkbenchSettings; | ||
private _groupDelegate: GroupDelegate; | ||
|
||
constructor(workbenchSession: WorkbenchSession, workbenchSettings: WorkbenchSettings) { | ||
this._workbenchSession = workbenchSession; | ||
this._workbenchSettings = workbenchSettings; | ||
this._groupDelegate = new GroupDelegate(this); | ||
} | ||
|
||
getWorkbenchSession(): WorkbenchSession { | ||
return this._workbenchSession; | ||
} | ||
|
||
getWorkbenchSettings(): WorkbenchSettings { | ||
return this._workbenchSettings; | ||
} | ||
|
||
getGroupDelegate(): GroupDelegate { | ||
return this._groupDelegate; | ||
} | ||
|
||
makeView(name: string): View { | ||
return new View(this, name); | ||
} | ||
} |
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,36 @@ | ||
export enum MessageDirection { | ||
UP = "UP", | ||
DOWN = "DOWN", | ||
} | ||
|
||
export enum MessageType { | ||
SETTINGS_CHANGED = "SETTINGS_CHANGED", | ||
AVAILABLE_SETTINGS_CHANGED = "AVAILABLE_SETTINGS_CHANGED", | ||
} | ||
|
||
export class Message { | ||
private _direction: MessageDirection; | ||
private _type: MessageType; | ||
private _propagationStopped: boolean = false; | ||
|
||
constructor(type: MessageType, direction: MessageDirection) { | ||
this._type = type; | ||
this._direction = direction; | ||
} | ||
|
||
getType() { | ||
return this._type; | ||
} | ||
|
||
getDirection() { | ||
return this._direction; | ||
} | ||
|
||
stopPropagation() { | ||
this._propagationStopped = true; | ||
} | ||
|
||
isPropagationStopped() { | ||
return this._propagationStopped; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.