AbstractView.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as React from "react";
  2. import * as classes from '../../styles/RcsbFvStyle.module.scss';
  3. import {RcsbFvDOMConstants} from "../../RcsbFvConstants/RcsbFvConstants";
  4. import {SaguaroPluginInterface} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
  5. import { RcsbFvSelection} from "../../RcsbFvSelection/RcsbFvSelection";
  6. export interface AbstractViewInterface {
  7. componentId: string;
  8. title?: string;
  9. subtitle?: string;
  10. plugin: SaguaroPluginInterface;
  11. selection: RcsbFvSelection;
  12. }
  13. export abstract class AbstractView<P,S> extends React.Component <P & AbstractViewInterface, S & AbstractViewInterface> {
  14. protected componentDivId: string;
  15. protected pfvDivId: string;
  16. constructor(props:P & AbstractViewInterface) {
  17. super(props);
  18. this.componentDivId = props.componentId+"_"+RcsbFvDOMConstants.PFV_DIV;
  19. this.pfvDivId = props.componentId+"_"+RcsbFvDOMConstants.PFV_APP_ID;
  20. }
  21. render():JSX.Element {
  22. return (
  23. <div id={this.componentDivId} style={{width: "100%", height:"100%"}} >
  24. {this.createTitle()}
  25. {this.createSubtitle()}
  26. {this.additionalContent()}
  27. <div id ={this.pfvDivId} />
  28. </div>
  29. );
  30. }
  31. componentDidMount() {
  32. this.props.plugin.selectCallback(this.structureSelectionCallback.bind(this));
  33. this.props.plugin.setObjectChangeCallback(this.objectChangeCallback.bind(this));
  34. window.addEventListener('resize', this.updatePfvDimensions.bind(this));
  35. }
  36. private createTitle(): JSX.Element | null{
  37. if(this.props.title)
  38. return (<div id={RcsbFvDOMConstants.TITLE_ID} className={classes.rcsbFvTitle}>{this.props.title}</div>)
  39. return null;
  40. }
  41. private createSubtitle(): JSX.Element | null{
  42. if(this.props.subtitle)
  43. return (<div id={RcsbFvDOMConstants.SUBTITLE_ID} className={classes.rcsbFvSubtitle}>{this.props.subtitle}</div>)
  44. return null;
  45. }
  46. protected structureSelectionCallback(): void{}
  47. protected objectChangeCallback(): void{}
  48. protected updatePfvDimensions(): void{}
  49. protected additionalContent(): JSX.Element | null {
  50. return null;
  51. }
  52. }