26
26
import ca .odell .glazedlists .EventList ;
27
27
import ca .odell .glazedlists .FilterList ;
28
28
import ca .odell .glazedlists .swing .GlazedListsSwing ;
29
+ import com .jidesoft .swing .AutoCompletion ;
29
30
import com .jidesoft .swing .CheckBoxList ;
31
+ import com .jidesoft .swing .ComboBoxSearchable ;
32
+ import com .jidesoft .swing .Searchable ;
33
+ import com .jidesoft .swing .event .SearchableEvent ;
30
34
import mediathek .config .Daten ;
31
35
import mediathek .config .Konstanten ;
32
36
import mediathek .controller .SenderFilmlistLoadApprover ;
@@ -77,6 +81,10 @@ public class SwingFilterDialog extends JDialog {
77
81
* The "base" thema list
78
82
*/
79
83
private final EventList <String > sourceThemaList = new BasicEventList <>();
84
+ /**
85
+ * Indicates whether an autocompletion action is currently active.
86
+ */
87
+ private boolean isAutoCompletionActive ;
80
88
81
89
public SwingFilterDialog (@ NotNull Window owner , @ NotNull FilterSelectionComboBoxModel model ,
82
90
@ NotNull JToggleButton filterToggleButton ,
@@ -225,6 +233,30 @@ private void updateThemaComboBox() {
225
233
jcbThema .setSelectedItem (aktuellesThema );
226
234
}
227
235
236
+ private Searchable getAutocompletionSearchable () {
237
+ Searchable searchable = new ComboBoxSearchable (jcbThema );
238
+ searchable .setSearchingDelay (500 );
239
+ searchable .setSearchLabel ("Suchtext:" );
240
+ searchable .setFromStart (false );
241
+ searchable .setRepeats (true );
242
+ searchable .addSearchableListener (l -> {
243
+ //System.out.println(l.paramString());
244
+ switch (l .getID ()) {
245
+ case SearchableEvent .SEARCHABLE_START -> isAutoCompletionActive = true ;
246
+ case SearchableEvent .SEARCHABLE_END -> {
247
+ isAutoCompletionActive = false ;
248
+
249
+ var sel = (String ) jcbThema .getSelectedItem ();
250
+ if (sel != null ) {
251
+ filterConfig .setThema (sel );
252
+ }
253
+ MessageBus .getMessageBus ().publish (new ReloadTableDataEvent ());
254
+ }
255
+ }
256
+ });
257
+ return searchable ;
258
+ }
259
+
228
260
private void setupThemaComboBox () {
229
261
var model = GlazedListsSwing .eventComboBoxModel (new EventListWithEmptyFirstEntry (sourceThemaList ));
230
262
jcbThema .setModel (model );
@@ -234,7 +266,15 @@ private void setupThemaComboBox() {
234
266
sourceThemaList .add (thema );
235
267
}
236
268
jcbThema .setSelectedItem (thema );
269
+
270
+ //setup auto completion
271
+ new AutoCompletion (jcbThema , getAutocompletionSearchable ());
272
+
237
273
jcbThema .addActionListener (l -> {
274
+ //don't fire when we are in autocompletion search
275
+ if (isAutoCompletionActive )
276
+ return ;
277
+
238
278
var sel = (String ) jcbThema .getSelectedItem ();
239
279
if (sel != null ) {
240
280
filterConfig .setThema (sel );
@@ -476,21 +516,22 @@ public void restoreFilterConfig() {
476
516
477
517
private class AddNewFilterAction extends AbstractAction {
478
518
private static final String STR_ACTION_NAME = "Neuen Filter anlegen" ;
519
+
479
520
public AddNewFilterAction () {
480
521
putValue (Action .SMALL_ICON , SVGIconUtilities .createSVGIcon ("icons/fontawesome/plus.svg" ));
481
522
putValue (Action .SHORT_DESCRIPTION , STR_ACTION_NAME );
482
523
}
483
524
484
525
@ Override
485
526
public void actionPerformed (ActionEvent e ) {
486
- String newFilterName = (String )JOptionPane .showInputDialog (MediathekGui .ui (), "Filtername:" ,
527
+ String newFilterName = (String ) JOptionPane .showInputDialog (MediathekGui .ui (), "Filtername:" ,
487
528
STR_ACTION_NAME , JOptionPane .PLAIN_MESSAGE , null , null ,
488
529
String .format ("Filter %d" , filterConfig .getAvailableFilters ().size () + 1 ));
489
530
if (newFilterName != null ) {
490
531
filterConfig .findFilterForName (newFilterName ).ifPresentOrElse (f ->
491
532
JOptionPane .showMessageDialog (MediathekGui .ui (),
492
- "Ein Filter mit dem gewählten Namen existiert bereits!" ,
493
- STR_ACTION_NAME , JOptionPane .ERROR_MESSAGE ), () -> {
533
+ "Ein Filter mit dem gewählten Namen existiert bereits!" ,
534
+ STR_ACTION_NAME , JOptionPane .ERROR_MESSAGE ), () -> {
494
535
FilterDTO newFilter = new FilterDTO (UUID .randomUUID (), newFilterName );
495
536
filterConfig .addNewFilter (newFilter );
496
537
checkDeleteCurrentFilterButtonState ();
0 commit comments