From f9e9916048898f8f100955f17519d73298d6554a Mon Sep 17 00:00:00 2001 From: marmoure Date: Fri, 5 Jan 2024 16:19:03 +0100 Subject: [PATCH] [feature] set button to loading when fetching results --- .../oxygen/tei/completer/GUI/newSuggestionForm.java | 11 ++++++++--- .../oxygen/tei/completer/TeiCompleter.java | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/humanistika/oxygen/tei/completer/GUI/newSuggestionForm.java b/src/main/java/org/humanistika/oxygen/tei/completer/GUI/newSuggestionForm.java index ac5b61e..a2cec28 100644 --- a/src/main/java/org/humanistika/oxygen/tei/completer/GUI/newSuggestionForm.java +++ b/src/main/java/org/humanistika/oxygen/tei/completer/GUI/newSuggestionForm.java @@ -355,11 +355,11 @@ private void restultsJTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FI private void textChanged() { // GATE Keeper - // reject if either fields have less than 4 chars + // reject if either fields have less than 3 chars // this correspond to requestAutoComplete function as well //TODO USE a constant for this value - if(selectionJTextField.getText().length() < 4) return; - if(this.teiCompleter.getConfiguration().getAutoCompletes().get(0).getDependent() != null && dependentJTextField.getText().length() < 4) return; + if(selectionJTextField.getText().length() < 3) return; + if(this.teiCompleter.getConfiguration().getAutoCompletes().get(0).getDependent() != null && dependentJTextField.getText().length() < 3) return; // if we are already fetching results no need to do it again if(runningState.compareAndSet(false, true)) { @@ -395,6 +395,9 @@ public class LiveAutoComplete extends SwingWorker { @Override protected Object doInBackground() throws Exception { + fetchjButton.setText("Loading..."); + fetchjButton.setEnabled(false); + DefaultTableModel model = (DefaultTableModel) restultsJTable.getModel(); // clear the old results model.setRowCount(0); @@ -441,6 +444,8 @@ protected Object doInBackground() throws Exception { @Override protected void done() { // Update UI on EDT when the task is complete + fetchjButton.setText("Search..."); + fetchjButton.setEnabled(true); DefaultTableModel model = (DefaultTableModel) restultsJTable.getModel(); //populate with the new results diff --git a/src/main/java/org/humanistika/oxygen/tei/completer/TeiCompleter.java b/src/main/java/org/humanistika/oxygen/tei/completer/TeiCompleter.java index 32feeff..f159ed3 100755 --- a/src/main/java/org/humanistika/oxygen/tei/completer/TeiCompleter.java +++ b/src/main/java/org/humanistika/oxygen/tei/completer/TeiCompleter.java @@ -158,7 +158,7 @@ protected final AutoCompleteSuggestions getAutoCompleteSuggestions public List requestAutoComplete(final AutoComplete autoComplete, final String selection, @Nullable final String dependent) { final Authentication.AuthenticationType authenticationType = autoComplete.getRequestInfo().getAuthentication() == null ? null : autoComplete.getRequestInfo().getAuthentication().getAuthenticationType(); //TODO USE a constant for this value - if(selection.length() > 3) { + if(selection.length() >= 3) { final Suggestions suggestions = getClient(authenticationType).getSuggestions(autoComplete.getRequestInfo(), selection, dependent, autoComplete.getResponseAction()); final List results = new ArrayList<>(); for(final Suggestion suggestion : suggestions.getSuggestion()) {