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

40
LINES

< > BotCompany Repo | #1033913 // ConceptsComboBox

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

Libraryless. Click here for Pure Java version (23135L/141K).

sclass ConceptsComboBox<A extends Concept> extends JComboBox<A> {
  Concepts concepts;
  Class<A> conceptClass;
  AWTOnConceptChanges updater;
  settable bool allowNull;
  settable IPred<A> itemFilter;

  *(Concepts *concepts, Class<A> *conceptClass) {
    updateItems();
    
    updater = new AWTOnConceptChanges(concepts, this, l0 updateItems);
    updater.install();
  }
  
  void updateItems {
    var l = sortTheList(filterTheList(freshList()));
    if (allowNull) l = nullPlus(l);
    setComboBoxItems_notifyListeners(this, l);
  }
  
  swappable Cl<A> freshList() {
    ret main list(concepts, conceptClass);
  }
  
  L<A> filterTheList(Cl<A> l) {
    ret itemFilter == null ? asList(l) : filter(itemFilter, l);
  }
  
  swappable L<A> sortTheList(L<A> l) {
    ret sortConceptsByID(l);
  }
  
  selfType sorter(IF1<L<A>> sorter) { sortTheList = sorter; this; }
  
  A get() { ret getSelectedItem_typed(this); }
  
  void select(long conceptID) {
    main setSelectedItem(this, getConcept(concepts, conceptClass, conceptID));
  }
}

Author comment

Began life as a copy of #1006615

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1033913
Snippet name: ConceptsComboBox
Eternal ID of this version: #1033913/22
Text MD5: c0e3f2c70708ff6d0a429636c69a6a21
Transpilation MD5: 347cba42374f2705c3ce1e07b930c238
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-10-17 16:48:22
Source code size: 1078 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 228 / 447
Version history: 21 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)