Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

82
LINES

< > BotCompany Repo | #1034944 // G22CRUDAndDetailPanel

JavaX fragment (include) [tags: use-pretranspiled]

Uses 2164K of libraries. Click here for Pure Java version (57980L/308K).

// now a concept to allow for persistence of selected item
abstract concept G22CRUDAndDetailPanel<A extends ConceptWithChangeListeners> {
  new Ref<A> selected;
  
  CollapsibleNorthPanel collapsiblePanel = new(true);

  transient settable G22Utils g22utils;
  
  transient gettable SimpleCRUD_v2<A> crud;
  transient SingleComponentPanel scpDetail;

  abstract SimpleCRUD_v2<A> makeCRUD();
  
  // a is not null
  abstract JComponent makeDetailView(A a);

  cachedVisualize {
    crud = makeCRUD();
    scpDetail = singleComponentPanel();
    handleSelection();
    selectAfterUpdate(selected!);
    var crudVis = crud.visualize();
    crudVisualized();

    crud.onSelectionChanged(-> {
      this.selected.set(crud.selected());
      handleSelection();
    });

    /*ret jvsplit(
      jCenteredSection(crud.entityNamePlural(), crudVis),
      scpDetail);*/
 
    collapsiblePanel.init(
      crud.entityName() + " List",
      jCenteredSection(crud.entityNamePlural(), crudVis),
      scpDetail);
      
    collapsiblePanel.onChange(l0 change);     
    ret collapsiblePanel.visualize();
  }
  
  void handleSelection {
    var selected = this.selected!;
    if (selected == null)
      scpDetail.set(emptyDetailView());
    else {
      var view = makeDetailView(selected);
      var lvTitle = liveValue_hasChangeListeners(
        selected,
        -> crud.entityName() + " " + selected.id + ": " + selected);
      scpDetail.set(jCenteredRaisedBoldLiveValueSection(lvTitle, view));
    }
  }
  
  JComponent emptyDetailView() {
    ret jGazelleLogo();
  }
  
  // override me
  void crudVisualized {}
  
  void addCountToEnclosingTab(bool b) {
    crud.addCountToEnclosingTab(b);
  }
  
  void updateCount {
    crud.update();
  }
  
  void edit(A A) {
    crud.setSelected(A);
  }
    
  void setSelected(A A) {
    crud.setSelected(A);
  }
  
  void selectAfterUpdate(A A) {
    crud.selectAfterUpdate(A);
  }
}

Author comment

Began life as a copy of #1034599

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034944
Snippet name: G22CRUDAndDetailPanel
Eternal ID of this version: #1034944/25
Text MD5: fa06c86eac8e0cb825bc7c6bd1034646
Transpilation MD5: 673f6a8e7b56ec46be76ba55f2644389
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-14 02:23:38
Source code size: 2003 bytes / 82 lines
Pitched / IR pitched: No / No
Views / Downloads: 85 / 227
Version history: 24 change(s)
Referenced in: [show references]