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

110
LINES

< > BotCompany Repo | #1034944 // G22CRUDAndDetailPanel

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

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

// now a concept to allow for persistence of selected item
abstract concept G22CRUDAndDetailPanel<A extends ConceptWithChangeListeners> extends ConceptWithChangeListeners is Swingable, IUnstructured {
  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();
  }
  
  { _doneLoading2(); }
  
  public void _doneLoading2 :: after {
    // Save vertical space
    collapsiblePanel.wrappedSideComponent = -> centerAndEastWithMargin(collapsiblePanel.sideComponent(), vstack(collapsiblePanel.collapseButton()));
  }
  
  cachedVisualize {
    crud = makeCRUD();
    putCRUDButtonsNextToSearchBar(crud);
    
    scpDetail = singleComponentPanel();
    if (collapsiblePanel.expanded)
      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.defaultSplitPoint(0.3);
 
    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 appendPrefix(crud.entityName() + " " + item.id + ": ", str(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) {
    var searcher = crud().tableSearcher();
    searcher?.clearSearchField();
    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/52
Text MD5: 38868aac76663eedae6165357ba91e9f
Transpilation MD5: b9ff34b7211d2be4be43c830d921800b
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-11 15:01:22
Source code size: 2872 bytes / 110 lines
Pitched / IR pitched: No / No
Views / Downloads: 308 / 569
Version history: 51 change(s)
Referenced in: [show references]