CallbackManagerFactoryInterface.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {RcsbFvTrackDataElementInterface} from "@rcsb/rcsb-saguaro";
  2. import {
  3. ViewerCallbackManagerInterface, ViewerActionManagerInterface
  4. } from "../../../RcsbFvStructure/StructureViewerInterface";
  5. import {DataContainer} from "../../../Utils/DataContainer";
  6. import {
  7. RcsbFvModulePublicInterface
  8. } from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvModule/RcsbFvModuleInterface";
  9. import {PfvManagerInterface} from "./PfvManagerFactoryInterface";
  10. import {RcsbFvStateInterface} from "../../../RcsbFvState/RcsbFvStateInterface";
  11. export interface CallbackManagerInterface<U> {
  12. structureViewerSelectionCallback(mode:'select'|'hover'): Promise<void>;
  13. featureClickCallback(e:RcsbFvTrackDataElementInterface): void;
  14. highlightHoverCallback(selection: RcsbFvTrackDataElementInterface[]): void;
  15. pfvSelectionChangeCallback(selection: Array<RcsbFvTrackDataElementInterface>): void;
  16. modelChangeCallback(defaultAuthId?: string, defaultOperatorName?:string): Promise<void>;
  17. pfvChangeCallback(args:U): Promise<void>;
  18. }
  19. export interface CallbackManagerFactoryInterface<U> {
  20. getCallbackManager(config: CallbackConfigInterface): CallbackManagerInterface<U>;
  21. }
  22. export interface CallbackConfigInterface {
  23. rcsbFvContainer: DataContainer<RcsbFvModulePublicInterface>;
  24. stateManager: RcsbFvStateInterface;
  25. pfvFactory: PfvManagerInterface;
  26. }
  27. export abstract class AbstractCallbackManager<U> implements CallbackManagerInterface<U> {
  28. protected readonly rcsbFvContainer: DataContainer<RcsbFvModulePublicInterface>;
  29. protected readonly stateManager: RcsbFvStateInterface;
  30. protected pfvFactory: PfvManagerInterface;
  31. private readonly isInnerSelection: DataContainer<boolean> = new DataContainer<boolean>();
  32. constructor(config: CallbackConfigInterface) {
  33. this.rcsbFvContainer = config.rcsbFvContainer;
  34. this.stateManager = config.stateManager;
  35. this.pfvFactory = config.pfvFactory;
  36. }
  37. public async structureViewerSelectionCallback(mode:'select'|'hover'): Promise<void> {
  38. if(this.rcsbFvContainer.get() == null)
  39. return;
  40. this.isInnerSelection.set(true);
  41. await this.innerStructureViewerSelectionChange(mode);
  42. this.isInnerSelection.set(false);
  43. }
  44. public pfvSelectionChangeCallback(selection: Array<RcsbFvTrackDataElementInterface>): void {
  45. if(this.isInnerSelection.get())
  46. return;
  47. this.innerPfvSelectionChange(selection);
  48. }
  49. public abstract featureClickCallback(e:RcsbFvTrackDataElementInterface): void;
  50. public abstract highlightHoverCallback(selection: RcsbFvTrackDataElementInterface[]): void;
  51. public abstract modelChangeCallback(defaultAuthId?: string, defaultOperatorName?:string): Promise<void>;
  52. public abstract pfvChangeCallback(args: U): Promise<void>;
  53. protected abstract innerStructureViewerSelectionChange(mode: "select" | "hover"): Promise<void> ;
  54. protected abstract innerPfvSelectionChange(selection: Array<RcsbFvTrackDataElementInterface>): void;
  55. }