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

94
LINES

< > BotCompany Repo | #1034944 // G22CRUDAndDetailPanel

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

Transpiled version (63199L) is out of date.

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

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

  abstract SimpleCRUD_v2<A> makeCRUD();
  
  // create detail view in background thread
  transient RSTVar<A> handleSelectionVar = new(l1 handleSelection_impl);
  
  // a is not null
  // override me
  JComponent makeDetailView(A a) {
    ret jTodo();
  }

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

    handleSelectionVar.forceUpdate();
    crud.onSelectionChanged(-> {
      var selected = crud.selected();
      this.selected.set(selected);
      handleSelectionVar.set(selected);
    });

    /*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_impl(A selected) {
    if (selected == null)
      scpDetail.set(emptyDetailView());
    else {
      var view = makeDetailView(selected);
      var lvTitle = liveValue_hasChangeListeners(
        selected,
        -> detailTitle(selected));
      scpDetail.set(jCenteredRaisedBoldLiveValueSection(lvTitle, view));
    }
  }
  
  // item is not null
  swappable S detailTitle(A item) {
    ret crud.entityName() + " " + item.id + ": " + item;
  }
  
  JComponent emptyDetailView() {
    ret jGazelleLogo();
  }
  
  // override me
  void crudVisualized {}
  
  void addCountToEnclosingTab(bool b) {
    crud.addCountToEnclosingTab(b);
  }
  
  void updateCount {
    crud.update();
  }
  
  void edit aka setSelected(A A) {
    crud().setSelected(A);
  }
  
  void selectAfterUpdate(A A) {
    crud.selectAfterUpdate(A);
  }
  
  SimpleCRUD_v2<A> crud() {
    visualize();
    ret crud;
  }
}

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/37
Text MD5: acf48ad1d833a5a21c9751dddfb25e2f
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-15 20:22:12
Source code size: 2329 bytes / 94 lines
Pitched / IR pitched: No / No
Views / Downloads: 125 / 289
Version history: 36 change(s)
Referenced in: [show references]