modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/FlexSearchBar.java | 27 -- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/favorites/SavedSearchGrid.java | 3 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/suggest/SuggestTextBox_v3.java | 68 ++--- modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties | 3 modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties | 3 modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties | 3 modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties | 3 modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties | 3 modules/enterprise/gui/coregui/src/main/webapp/css/search.css | 7 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java | 121 ++++------ 10 files changed, 118 insertions(+), 123 deletions(-)
New commits: commit 0540bcd236373f420235c9e30a6ac3ae285728b7 Author: Jay Shaughnessy jshaughn@redhat.com Date: Thu Aug 25 14:31:21 2011 -0400
[BZ 695889 - Search Bar Saved Search issues] More SearchBar/SavedSearch Work, done for now. - simplify behavior of saved search name/update such that it requires a return to get applied. Change onBlur to just close the edit box, thus avoiding duplicate storage/update of the saved search. - remove some odd time-delay stuff joe had in there, it seeme to only confuse things and with the change to onBlur I don't think it's necessary. - More I18N, missing properties and migration of some messaging from server-side to client-side. - Change look of saved search entries, different colors/fonts/indent
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/FlexSearchBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/FlexSearchBar.java index 12df81d..1a99b85 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/FlexSearchBar.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/FlexSearchBar.java @@ -90,7 +90,6 @@ public class FlexSearchBar extends AbstractSearchBar { private SavedSearchGrid savedSearchesGrid;
private Integer currentSearchId = 0; - private long lastNameFieldBlurTime = 0;
private SearchSubsystem searchSubsystem; private String defaultSearchText; @@ -384,8 +383,16 @@ public class FlexSearchBar extends AbstractSearchBar { }
public void onBlur(BlurEvent event) { - lastNameFieldBlurTime = System.currentTimeMillis(); - turnNameFieldIntoLabel(true); + // If this is a name change update (star on) then return to displaying the unchanged label. + // otherwise, abort the creation of the new saved search. + if (starImage.getUrl().endsWith(STAR_ON_URL)) { + patternNameField.setVisible(false); + patternNameLabel.setVisible(true); + + } else { + patternNameField.setVisible(false); + patternNameLabel.setVisible(false); + } } }
@@ -397,20 +404,6 @@ public class FlexSearchBar extends AbstractSearchBar {
class StarImageEventHandler implements ClickHandler, MouseOverHandler, MouseOutHandler { public void onClick(ClickEvent event) { - long diff = System.currentTimeMillis() - lastNameFieldBlurTime; - if (Math.abs(diff) < 750) { - /* - * This event propagation is annoying. If the threshold is set too low, then both - * the name field blur event and this star image click event fire...but the blur - * event fires first, which turns the star white. Then a click on a white star - * triggers edit mode, re-enabling the name field. However, setting the threshold - * too high will prevent the click event from being handled when the user naturally - * wants to click on the star in rapid succession within the threshold time frame. - * It is hoped that 750ms will strike a nice balance, and that most users will never - * experienced any oddities from this trade-off. - */ - return; - }
// note - since hover changes off to active, we never have the star off case here if (starImage.getUrl().endsWith(STAR_ACTIVE_URL)) { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/favorites/SavedSearchGrid.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/favorites/SavedSearchGrid.java index f0e72c3..8965900 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/favorites/SavedSearchGrid.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/favorites/SavedSearchGrid.java @@ -167,7 +167,8 @@ public class SavedSearchGrid extends Grid {
@Override public void onFailure(Throwable caught) { - CoreGUI.getErrorHandler().handleError("Could not load saved searches", caught); + CoreGUI.getErrorHandler().handleError( + CoreGUI.getMessages().view_searchBar_savedSearch_failFind("*"), caught);
callback.onFailure(caught); } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/suggest/SuggestTextBox_v3.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/suggest/SuggestTextBox_v3.java index a2e2d5d..ee170a1 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/suggest/SuggestTextBox_v3.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/suggest/SuggestTextBox_v3.java @@ -30,7 +30,6 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.event.dom.client.HandlesAllKeyEvents; import com.google.gwt.event.dom.client.HasAllFocusHandlers; -import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.dom.client.KeyPressEvent; @@ -62,6 +61,8 @@ import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import org.rhq.core.domain.search.SearchSuggestion; import org.rhq.core.domain.search.SearchSuggestion.Kind; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.Messages; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.gwt.SearchGWTServiceAsync; import org.rhq.enterprise.gui.coregui.client.search.AbstractSearchBar; @@ -69,6 +70,8 @@ import org.rhq.enterprise.gui.coregui.client.search.AbstractSearchBar; public class SuggestTextBox_v3 extends Composite implements HasText, HasAllFocusHandlers, HasValue<String>, HasSelectionHandlers<Suggestion> {
+ private static final Messages MSG = CoreGUI.getMessages(); + private final AbstractSearchBar searchBar; private final SearchSuggestOracle oracle;
@@ -199,53 +202,33 @@ public class SuggestTextBox_v3 extends Composite implements HasText, HasAllFocus class TextBoxEvents extends HandlesAllKeyEvents implements ValueChangeHandler<String>, ClickHandler {
private boolean isInstructionalCommentSelected() { + if (!suggestionPopup.isAttached() || suggestionMenu.getSelectedItemIndex() < 0) { + return false; + } + SearchSuggestion searchSuggestion = suggestionMenu.getSearchSuggestion(); Kind kind = searchSuggestion.getKind(); return kind == Kind.InstructionalTextComment; }
+ // We used to allow clicking and keypress to select from the suggestion list. But this + // could be confusing because we keep focus in the text box. A return would likely mean + // the user wants to submit the current pattern in the text box for search. But if the mouse + // was hovering over a suggest menu item, which could be accidental as the menu can be large and + // pops up automatically, his pattern would get replaced by a random suggestion entry and then + // that would get submitted. So, we now only accept clicking to select from the suggest menu + // and we assume a return means the user wants to submit the current text box pattern. public void onClick(ClickEvent event) { + + // if the user clicked on one of our helpful little messages then just ignore it + if (isInstructionalCommentSelected()) { + return; + } + handleSuggestions(); }
public void onKeyDown(KeyDownEvent event) { - /* - * Make sure that the menu is actually showing. These - * keystrokes are only relevant when choosing a suggestion. - */ - if (suggestionPopup.isAttached()) { - switch (event.getNativeKeyCode()) { - case KeyCodes.KEY_DOWN: - suggestionMenu.moveSelectionDown(); - if (isInstructionalCommentSelected()) { - if (suggestionMenu.getNumItems() == 1) { - suggestionMenu.selectItem(null); - } else { - suggestionMenu.moveSelectionDown(); - } - } - event.preventDefault(); - break; - case KeyCodes.KEY_UP: - suggestionMenu.moveSelectionUp(); - if (isInstructionalCommentSelected()) { - if (suggestionMenu.getNumItems() == 1) { - suggestionMenu.selectItem(null); - } else { - suggestionMenu.moveSelectionUp(); - } - } - event.preventDefault(); - break; - case KeyCodes.KEY_ENTER: - if (suggestionMenu.getSelectedItemIndex() < 0) { - suggestionPopup.hide(); - } else { - suggestionMenu.doSelectedItemAction(); - } - break; - } - } delegateEvent(SuggestTextBox_v3.this, event); }
@@ -402,6 +385,7 @@ public class SuggestTextBox_v3 extends Composite implements HasText, HasAllFocus setStyleName(""); }
+ @SuppressWarnings("unused") public void doSelectedItemAction() { // In order to perform the action of the item that is currently // selected, the menu must be showing. @@ -684,8 +668,8 @@ public class SuggestTextBox_v3 extends Composite implements HasText, HasAllFocus }
public void onFailure(Throwable caught) { - SearchSuggestion errorInform = new SearchSuggestion(Kind.InstructionalTextComment, caught - .getMessage()); + SearchSuggestion errorInform = new SearchSuggestion(Kind.InstructionalTextComment, MSG + .view_searchBar_instructional_failSuggest()); adaptAndHandle(errorInform); }
@@ -694,6 +678,10 @@ public class SuggestTextBox_v3 extends Composite implements HasText, HasAllFocus for (SearchSuggestion next : searchSuggestionResults) { adaptedResults.add(new SearchSuggestionOracleAdapter(next)); } + if (adaptedResults.isEmpty()) { + adaptedResults.add(new SearchSuggestionOracleAdapter(new SearchSuggestion( + Kind.InstructionalTextComment, MSG.view_searchBar_instructional_noSuggest()))); + } SuggestOracle.Response response = new SuggestOracle.Response(adaptedResults); callback.onSuggestionsReady(request, response); } diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties index 4362b8f..beb105b 100644 --- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties +++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties @@ -1623,6 +1623,9 @@ view_resource_monitor_table_min = Minimum view_resource_title_component_errors_tooltip = Shows managed component errors. Click for details view_resource_title_tagUpdateFailed = Failed to update resource tags view_searchBar_defaultPattern = name your pattern +view_searchBar_instructional_failSuggest = Failed to generate suggestions, see server log for possible errors +view_searchBar_instructional_noSuggest = No matches, enter a different pattern +view_searchBar_instructional_refresh = Failed to retrieve saved searches, please refresh page view_searchBar_savedSearch_delete = Successfully deleted saved search [{0}] view_searchBar_savedSearch_failDelete = Failed to delete saved search with name [{0}] view_searchBar_savedSearch_failFind = Failed to find saved search with name [{0}] diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties index 581c8cb..5bb5a98 100644 --- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties +++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties @@ -1349,6 +1349,9 @@ view_resource_monitor_table_min = Minimum view_resource_title_component_errors_tooltip = Zeigt Fehler der gemanagten Ressource. Klicken für Details view_resource_title_tagUpdateFailed = Fehler beim Aktualisieren der Ressourcen-Tags view_searchBar_defaultPattern = name your pattern~ +##view_searchBar_instructional_failSuggest = Failed to generate suggestions, see server log for possible errors +view_searchBar_instructional_noSuggest = No matches, enter a different pattern +##view_searchBar_instructional_refresh = Failed to retrieve saved searches, please refresh page ##view_searchBar_savedSearch_delete = Successfully deleted saved search [{0}] ##view_searchBar_savedSearch_failDelete = Failed to delete saved search with name [{0}] ##view_searchBar_savedSearch_failFind = Failed to find saved search with name [{0}] diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties index 67762d3..98a20a4 100644 --- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties +++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties @@ -1590,6 +1590,9 @@ view_resource_monitor_table_min = 最小 view_resource_title_component_errors_tooltip = 管理コンポーネントエラーの表示。詳細はクリックしてください view_resource_title_tagUpdateFailed = リソースタグの更新に失敗しました view_searchBar_defaultPattern = パターンを名前を付けてください +##view_searchBar_instructional_failSuggest = Failed to generate suggestions, see server log for possible errors +view_searchBar_instructional_noSuggest = No matches, enter a different pattern +##view_searchBar_instructional_refresh = Failed to retrieve saved searches, please refresh page ##view_searchBar_savedSearch_delete = Successfully deleted saved search [{0}] ##view_searchBar_savedSearch_failDelete = Failed to delete saved search with name [{0}] ##view_searchBar_savedSearch_failFind = Failed to find saved search with name [{0}] diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties index 27312f7..48cae04 100644 --- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties +++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties @@ -1728,6 +1728,9 @@ view_resource_monitor_table_min = Minimum view_resource_title_component_errors_tooltip = Shows managed component errors. Click for details view_resource_title_tagUpdateFailed = Failed to update resource tags view_searchBar_defaultPattern = definir nome para o padr\u00E3o +##view_searchBar_instructional_failSuggest = Failed to generate suggestions, see server log for possible errors +view_searchBar_instructional_noSuggest = No matches, enter a different pattern +##view_searchBar_instructional_refresh = Failed to retrieve saved searches, please refresh page ##view_searchBar_savedSearch_delete = Successfully deleted saved search [{0}] ##view_searchBar_savedSearch_failDelete = Failed to delete saved search with name [{0}] ##view_searchBar_savedSearch_failFind = Failed to find saved search with name [{0}] diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties index 9b9fab0..77d3749 100644 --- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties +++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties @@ -1598,6 +1598,9 @@ view_resource_monitor_table_min = \u6700\u5c0f view_resource_title_component_errors_tooltip = \u663e\u793a\u88ab\u7ba1\u7ec4\u4ef6\u9519\u8bef.\u5355\u51fb\u67e5\u770b\u8be6\u60c5 view_resource_title_tagUpdateFailed = \u66f4\u65b0\u8d44\u6e90\u6807\u7b7e\u5931\u8d25 view_searchBar_defaultPattern = \u5b9a\u4e49\u81ea\u5df1\u7684\u6837\u5f0f +##view_searchBar_instructional_failSuggest = Failed to generate suggestions, see server log for possible errors +view_searchBar_instructional_noSuggest = No matches, enter a different pattern +##view_searchBar_instructional_refresh = Failed to retrieve saved searches, please refresh page ##view_searchBar_savedSearch_delete = Successfully deleted saved search [{0}] ##view_searchBar_savedSearch_failDelete = Failed to delete saved search with name [{0}] ##view_searchBar_savedSearch_failFind = Failed to find saved search with name [{0}] diff --git a/modules/enterprise/gui/coregui/src/main/webapp/css/search.css b/modules/enterprise/gui/coregui/src/main/webapp/css/search.css index f4c8390..81a6967 100644 --- a/modules/enterprise/gui/coregui/src/main/webapp/css/search.css +++ b/modules/enterprise/gui/coregui/src/main/webapp/css/search.css @@ -153,7 +153,8 @@ div { }
.savedSearchesPanel-top { - font-size: 12px; + color: green; + font-size: 12px; position: relative; padding: 0; margin: 0; @@ -161,10 +162,10 @@ div { }
.savedSearchesPanel-bottom { - color: green; + font-size: 10px; position: relative; padding: 0; - margin: 0; + margin: 3px; bottom: 1px; }
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java index 8d723d9..bfc2164 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java @@ -387,55 +387,34 @@ public class SearchAssistManager { public List<SearchSuggestion> getTabAwareSuggestions(String expression, int caretPos, String tab) { List<SearchSuggestion> results = new ArrayList<SearchSuggestion>();
- if (subject == null) { - // likely a client's misuse of the API, but gracefully return no saved searches if the user is not found - SearchSuggestion footerMessage = new SearchSuggestion(Kind.InstructionalTextComment, - "Error retrieving saved searches, please refresh page"); - results.add(footerMessage); - return results; + if (expression == null) { + expression = ""; }
- try { - if (expression == null) { - expression = ""; - } - - // make sure caretPos is at a valid index prior to parsing it for suggestions - if (caretPos > expression.length()) { - caretPos = expression.length(); - } + // make sure caretPos is at a valid index prior to parsing it for suggestions + if (caretPos > expression.length()) { + caretPos = expression.length(); + }
- List<SearchSuggestion> simple = getSimpleSuggestions(expression, caretPos, tab); - List<SearchSuggestion> advanced = getAdvancedSuggestions(expression, caretPos, tab); - List<SearchSuggestion> userSavedSearches = getUserSavedSearchSuggestions(expression); - //List<SearchSuggestion> globalSavedSearches = getGlobalSavedSearchSuggestions(expression); + List<SearchSuggestion> simple = getSimpleSuggestions(expression, caretPos, tab); + List<SearchSuggestion> advanced = getAdvancedSuggestions(expression, caretPos, tab); + List<SearchSuggestion> userSavedSearches = getUserSavedSearchSuggestions(expression); + //List<SearchSuggestion> globalSavedSearches = getGlobalSavedSearchSuggestions(expression);
- results.addAll(simple); - results.addAll(advanced); - results.addAll(userSavedSearches); - //results.addAll(globalSavedSearches); + results.addAll(simple); + results.addAll(advanced); + results.addAll(userSavedSearches); + //results.addAll(globalSavedSearches);
- if (results.isEmpty()) { - SearchSuggestion footerMessage = new SearchSuggestion(Kind.InstructionalTextComment, - "Start typing for more simple text matches"); - results.add(footerMessage); - } else { - Collections.sort(results); - } + Collections.sort(results);
- } catch (Throwable t) { - SearchSuggestion footerMessage = new SearchSuggestion(Kind.InstructionalTextComment, - "Error retrieving suggestions: " + t.getMessage() + ", see server log for more details"); - results.add(footerMessage); - LOG.info("Error retrieving suggestions", t); - } return results; }
public List<SearchSuggestion> getSimpleSuggestions(String expression, int caretPos, String tab) { SearchAssistant completor = getTabAwareSearchAssistant(tab);
- debug("getSimpleSuggestions: START"); + LOG.debug("getSimpleSuggestions: START");
SearchTermAssistant assistant = new SearchTermAssistant(expression, caretPos); String beforeCaret = assistant.getFragmentBeforeCaret(); @@ -451,7 +430,11 @@ public class SearchAssistManager { */ String parsedTerm = parsed.context; String primarySimpleContext = completor.getPrimarySimpleContext(); - debug("getSimpleSuggestions: suggesting value completions for a simple context [" + primarySimpleContext + "]"); + + if (LOG.isDebugEnabled()) { + LOG.debug("getSimpleSuggestions: suggesting value completions for a simple context [" + + primarySimpleContext + "]"); + }
List<String> valueSuggestions = padWithQuotes(beforeCaret, completor.getValues(primarySimpleContext, null, parsedTerm)); @@ -461,33 +444,47 @@ public class SearchAssistManager {
public List<SearchSuggestion> getAdvancedSuggestions(String expression, int caretPos, String tab) { SearchAssistant completor = getTabAwareSearchAssistant(tab); + boolean isDebugEnabled = LOG.isDebugEnabled();
- debug("getAdvancedSuggestions: START"); + LOG.debug("getAdvancedSuggestions: START"); SearchTermAssistant assistant = new SearchTermAssistant(expression, caretPos); String[] tokens = assistant.getTerms().toArray(new String[0]); - debug("" + tokens.length + " tokens are " + Arrays.asList(tokens)); + + if (isDebugEnabled) { + LOG.debug("" + tokens.length + " tokens are " + Arrays.asList(tokens)); + }
if (tokens.length == 0 || caretPos == 0) { - debug("getAdvancedSuggestions: no terms"); + LOG.debug("getAdvancedSuggestions: no terms"); return convert(getAllContexts()); // no terms yet defined }
String beforeCaret = assistant.getFragmentBeforeCaret(); - debug("getAdvancedSuggestions: beforeCaret is '" + beforeCaret + "'"); + + if (isDebugEnabled) { + LOG.debug("getAdvancedSuggestions: beforeCaret is '" + beforeCaret + "'"); + }
String pad = getQuotePadding(beforeCaret); - debug("getAdvancedSuggestions: padding is ~" + pad + "~"); + + if (isDebugEnabled) { + LOG.debug("getAdvancedSuggestions: padding is ~" + pad + "~"); + }
if (beforeCaret.startsWith("'") || beforeCaret.startsWith(""")) { return Collections.emptyList(); }
ParsedContext parsed = ParsedContext.get(beforeCaret); - debug("getAdvancedSuggestions: parsed is " + parsed); + + if (isDebugEnabled) { + LOG.debug("getAdvancedSuggestions: parsed is " + parsed); + } + switch (parsed.state) { case CONTEXT: if (parsed.context.equals("")) { - debug("getAdvancedSuggestions: empty term, suggesting all contexts"); + LOG.debug("getAdvancedSuggestions: empty term, suggesting all contexts"); return convert(getAllContexts()); /* if (tokens.length == 1) { @@ -502,22 +499,22 @@ public class SearchAssistManager { } */ } else if (isBooleanTerm(parsed.context)) { - debug("getAdvancedSuggestions: beforeCaret is whole boolean operator"); + LOG.debug("getAdvancedSuggestions: beforeCaret is whole boolean operator"); return convert(getAllContexts()); // TODO: should we tell user to type a space first? } else { // check if this context is complete or not if (completor.getSimpleContexts().contains(parsed.context)) { - debug("getAdvancedSuggestions: search term is simple context, wants operator"); + LOG.debug("getAdvancedSuggestions: search term is simple context, wants operator"); List<String> contextComparisonOperators = getComparisonOperatorsForContext(parsed.context, completor); return convert(pad(parsed.context, contextComparisonOperators, ""), parsed, parsed.context); } if (completor.getParameterizedContexts().contains(parsed.context)) { - debug("getAdvancedSuggestions: search term is parameterized context, wants open bracket"); + LOG.debug("getAdvancedSuggestions: search term is parameterized context, wants open bracket"); return convert(Arrays.asList(parsed.context + "["), parsed, parsed.context); }
- debug("getAdvancedSuggestions: search term wants context completion"); + LOG.debug("getAdvancedSuggestions: search term wants context completion"); List<String> startsWithContexts = new ArrayList<String>(); String lowerCaseParsedContext = parsed.context.toLowerCase(); // contexts should already be lower-cased for (String context : completor.getSimpleContexts()) { @@ -533,20 +530,20 @@ public class SearchAssistManager { return convert(startsWithContexts, parsed, parsed.context); } case PARAM: - debug("getAdvancedSuggestions: param state"); + LOG.debug("getAdvancedSuggestions: param state"); return convert(pad(parsed.context + "[", completor.getParameters(parsed.context, parsed.param), "]"), parsed, parsed.param); case OPERATOR: - debug("getAdvancedSuggestions: operator state"); + LOG.debug("getAdvancedSuggestions: operator state"); if (allComparisonOperators.contains(parsed.operator)) { - debug("search term is complete operator, suggesting values instead"); + LOG.debug("search term is complete operator, suggesting values instead"); List<String> valueSuggestions = padWithQuotes(beforeCaret, completor.getValues(parsed.context, parsed.param, "")); if (completor.getSimpleContexts().contains(parsed.context)) { - debug("getAdvancedSuggestions: suggesting value completions for a simple context"); + LOG.debug("getAdvancedSuggestions: suggesting value completions for a simple context"); return convert(pad(parsed.context + parsed.operator, valueSuggestions, "")); } else { - debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); + LOG.debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, "")); } @@ -560,21 +557,21 @@ public class SearchAssistManager { } }
- debug("getAdvancedSuggestions: providing suggestions for comparison operators"); + LOG.debug("getAdvancedSuggestions: providing suggestions for comparison operators"); if (completor.getSimpleContexts().contains(parsed.context)) { return convert(pad(parsed.context, operatorSuggestions, "")); } else { return convert(pad(parsed.context + "[" + parsed.param + "]", operatorSuggestions, "")); } case VALUE: - debug("getAdvancedSuggestions: value state"); + LOG.debug("getAdvancedSuggestions: value state"); List<String> valueSuggestions = padWithQuotes(beforeCaret, completor.getValues(parsed.context, parsed.param, parsed.value)); if (completor.getSimpleContexts().contains(parsed.context)) { - debug("getAdvancedSuggestions: suggesting value completions for a simple context"); + LOG.debug("getAdvancedSuggestions: suggesting value completions for a simple context"); return convert(pad(parsed.context + parsed.operator, valueSuggestions, ""), parsed, parsed.value); } else { - debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); + LOG.debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, ""), parsed, parsed.value); } @@ -594,6 +591,10 @@ public class SearchAssistManager { }
public List<SearchSuggestion> getUserSavedSearchSuggestions(String expression) { + if (null == subject) { + return new ArrayList<SearchSuggestion>(); + } + expression = expression.trim().toLowerCase().replaceAll("\s+", " ");
SavedSearchCriteria criteria = new SavedSearchCriteria(); @@ -772,8 +773,4 @@ public class SearchAssistManager { return """; } } - - private void debug(String message) { - LOG.debug(message); - } }