Skip to content

Commit 8cdaaed

Browse files
committed
- implement thema autocompletion
1 parent 2e05fd6 commit 8cdaaed

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

src/main/java/mediathek/gui/tabs/tab_film/filter/SwingFilterDialog.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
import ca.odell.glazedlists.EventList;
2727
import ca.odell.glazedlists.FilterList;
2828
import ca.odell.glazedlists.swing.GlazedListsSwing;
29+
import com.jidesoft.swing.AutoCompletion;
2930
import com.jidesoft.swing.CheckBoxList;
31+
import com.jidesoft.swing.ComboBoxSearchable;
32+
import com.jidesoft.swing.Searchable;
33+
import com.jidesoft.swing.event.SearchableEvent;
3034
import mediathek.config.Daten;
3135
import mediathek.config.Konstanten;
3236
import mediathek.controller.SenderFilmlistLoadApprover;
@@ -77,6 +81,10 @@ public class SwingFilterDialog extends JDialog {
7781
* The "base" thema list
7882
*/
7983
private final EventList<String> sourceThemaList = new BasicEventList<>();
84+
/**
85+
* Indicates whether an autocompletion action is currently active.
86+
*/
87+
private boolean isAutoCompletionActive;
8088

8189
public SwingFilterDialog(@NotNull Window owner, @NotNull FilterSelectionComboBoxModel model,
8290
@NotNull JToggleButton filterToggleButton,
@@ -225,6 +233,30 @@ private void updateThemaComboBox() {
225233
jcbThema.setSelectedItem(aktuellesThema);
226234
}
227235

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+
228260
private void setupThemaComboBox() {
229261
var model = GlazedListsSwing.eventComboBoxModel(new EventListWithEmptyFirstEntry(sourceThemaList));
230262
jcbThema.setModel(model);
@@ -234,7 +266,15 @@ private void setupThemaComboBox() {
234266
sourceThemaList.add(thema);
235267
}
236268
jcbThema.setSelectedItem(thema);
269+
270+
//setup auto completion
271+
new AutoCompletion(jcbThema, getAutocompletionSearchable());
272+
237273
jcbThema.addActionListener(l -> {
274+
//don't fire when we are in autocompletion search
275+
if (isAutoCompletionActive)
276+
return;
277+
238278
var sel = (String) jcbThema.getSelectedItem();
239279
if (sel != null) {
240280
filterConfig.setThema(sel);
@@ -476,21 +516,22 @@ public void restoreFilterConfig() {
476516

477517
private class AddNewFilterAction extends AbstractAction {
478518
private static final String STR_ACTION_NAME = "Neuen Filter anlegen";
519+
479520
public AddNewFilterAction() {
480521
putValue(Action.SMALL_ICON, SVGIconUtilities.createSVGIcon("icons/fontawesome/plus.svg"));
481522
putValue(Action.SHORT_DESCRIPTION, STR_ACTION_NAME);
482523
}
483524

484525
@Override
485526
public void actionPerformed(ActionEvent e) {
486-
String newFilterName = (String)JOptionPane.showInputDialog(MediathekGui.ui(), "Filtername:",
527+
String newFilterName = (String) JOptionPane.showInputDialog(MediathekGui.ui(), "Filtername:",
487528
STR_ACTION_NAME, JOptionPane.PLAIN_MESSAGE, null, null,
488529
String.format("Filter %d", filterConfig.getAvailableFilters().size() + 1));
489530
if (newFilterName != null) {
490531
filterConfig.findFilterForName(newFilterName).ifPresentOrElse(f ->
491532
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), () -> {
494535
FilterDTO newFilter = new FilterDTO(UUID.randomUUID(), newFilterName);
495536
filterConfig.addNewFilter(newFilter);
496537
checkDeleteCurrentFilterButtonState();

0 commit comments

Comments
 (0)