AbstractView.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import * as React from "react";
  2. import classes from '../../styles/RcsbFvStyle.module.scss';
  3. import {asyncScheduler, Subscription} from "rxjs";
  4. import {RcsbFvDOMConstants} from "../../RcsbFvConstants/RcsbFvConstants";
  5. import {
  6. SaguaroPluginInterface,
  7. SaguaroPluginModelMapType
  8. } from "../../RcsbFvStructure/SaguaroPluginInterface";
  9. import {RcsbFvSelectorManager} from "../../RcsbFvSelection/RcsbFvSelectorManager";
  10. import {SequenceViewInterface} from "./SequenceViewInterface";
  11. export interface AbstractViewInterface {
  12. componentId: string;
  13. title?: string;
  14. subtitle?: string;
  15. plugin: SaguaroPluginInterface;
  16. selectorManager: RcsbFvSelectorManager;
  17. unmount:(flag:boolean)=>void;
  18. }
  19. export abstract class AbstractView<P,S> extends React.Component <P & AbstractViewInterface, S> implements SequenceViewInterface {
  20. protected readonly componentDivId: string;
  21. protected readonly rcsbFvDivId: string;
  22. private updateDimTask: Subscription | null = null;
  23. constructor(props:P & AbstractViewInterface) {
  24. super(props);
  25. this.componentDivId = props.componentId+"_"+RcsbFvDOMConstants.PFV_DIV;
  26. this.rcsbFvDivId = props.componentId+"_"+RcsbFvDOMConstants.PFV_APP_ID;
  27. }
  28. render():JSX.Element {
  29. return (
  30. <div id={this.componentDivId} >
  31. <div style={{paddingLeft:10, position:"relative"}}>
  32. {this.createTitle()}
  33. {this.createSubtitle()}
  34. {this.additionalContent()}
  35. </div>
  36. <div id ={this.rcsbFvDivId} />
  37. </div>
  38. );
  39. }
  40. componentDidMount() {
  41. this.props.plugin.setSelectCallback(this.structureSelectionCallback.bind(this));
  42. this.props.plugin.setModelChangeCallback(this.modelChangeCallback.bind(this));
  43. this.props.plugin.setHoverCallback(this.structureHoverCallback.bind(this));
  44. this.props.plugin.setRepresentationChangeCallback(this.representationChangeCallback.bind(this));
  45. window.addEventListener('resize', this.resizeCallback);
  46. }
  47. componentWillUnmount() {
  48. this.props.plugin.unsetCallbacks();
  49. window.removeEventListener('resize', this.resizeCallback);
  50. }
  51. private resizeCallback: ()=>void = () => {
  52. if(this.updateDimTask)
  53. this.updateDimTask.unsubscribe();
  54. this.updateDimTask = asyncScheduler.schedule(()=> {
  55. this.updateDimensions();
  56. },300);
  57. };
  58. private createTitle(): JSX.Element | null{
  59. if(this.props.title)
  60. return (<div id={RcsbFvDOMConstants.TITLE_ID} className={classes.rcsbFvTitle}>{this.props.title}</div>)
  61. return null;
  62. }
  63. private createSubtitle(): JSX.Element | null{
  64. if(this.props.subtitle)
  65. return (<div id={RcsbFvDOMConstants.SUBTITLE_ID} className={classes.rcsbFvSubtitle}>{this.props.subtitle}</div>)
  66. return null;
  67. }
  68. abstract structureSelectionCallback(): void;
  69. abstract structureHoverCallback(): void;
  70. abstract representationChangeCallback(): void;
  71. abstract modelChangeCallback(modelMap:SaguaroPluginModelMapType): void;
  72. abstract updateDimensions(): void;
  73. abstract additionalContent(): JSX.Element | null;
  74. }