modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/AbstractSearchBar.java | 36
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/FlexSearchBar.java | 550 -------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/favorites/SavedSearchGrid.java | 196 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/suggest/SuggestTextBox_v3.java | 762 ----------
4 files changed, 1544 deletions(-)
New commits:
commit 7880800def42dbcd7dfa3d51309fd7fcc5cffef1
Author: Mike Thompson <mithomps(a)redhat.com>
Date: Mon Sep 17 12:09:35 2012 -0700
Remove deprecated GWT Search classes that are no longer used as they were replaced by smartGWT search classes. Deprecated classes can be retrieved from history.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/AbstractSearchBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/AbstractSearchBar.java
deleted file mode 100644
index d26913a..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/AbstractSearchBar.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.search;
-
-import com.google.gwt.user.client.ui.Composite;
-import org.rhq.core.domain.search.SearchSubsystem;
-
-/**
- * Abstract class for SearchBar, so that a separate implementation can be written alongside the original.
- * @author Joseph Marques
- */
-@Deprecated
-public abstract class AbstractSearchBar extends Composite {
-
- public abstract SearchSubsystem getSearchSubsystem();
-
- public abstract String getSelectedTab();
-
- public abstract void activateSavedSearch(String savedSearchName);
-}
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
deleted file mode 100644
index 4875c92..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/FlexSearchBar.java
+++ /dev/null
@@ -1,550 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.search;
-
-import com.google.gwt.event.dom.client.*;
-import com.google.gwt.event.logical.shared.CloseEvent;
-import com.google.gwt.event.logical.shared.CloseHandler;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.*;
-import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.criteria.SavedSearchCriteria;
-import org.rhq.core.domain.search.SavedSearch;
-import org.rhq.core.domain.search.SearchSubsystem;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.Messages;
-import org.rhq.enterprise.gui.coregui.client.UserSessionManager;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.search.favorites.SavedSearchGrid;
-import org.rhq.enterprise.gui.coregui.client.search.favorites.SavedSearchGrid.SavedSearchSelectionHandler;
-import org.rhq.enterprise.gui.coregui.client.search.suggest.SuggestTextBox_v3;
-import org.rhq.enterprise.gui.coregui.client.util.Log;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
-
-import java.util.List;
-
-/**
- * @author Joseph Marques
- */
-@Deprecated
-public class FlexSearchBar extends AbstractSearchBar {
-
- private static final Messages MSG = CoreGUI.getMessages();
-
- public static final String DEFAULT_PATTERN_NAME = MSG.view_searchBar_defaultPattern();
-
- private static final String IMAGE_DIR = "/coregui/images/search/";
-
- private static final String STAR_OFF_URL = IMAGE_DIR + "star1.png";
- private static final String STAR_ACTIVE_URL = IMAGE_DIR + "star2.png";
- private static final String STAR_ON_URL = IMAGE_DIR + "star3.png";
-
- private static final String ARROW_WHITE_URL = IMAGE_DIR + "menu_arrow.png";
- private static final String ARROW_GRAY_URL = IMAGE_DIR + "menu_arrow_down.png";
-
- public static final String TRASH = IMAGE_DIR + "trash.png";
-
- private final TextBox patternField = new TextBox();
- private final SuggestTextBox_v3 autoCompletePatternField = new SuggestTextBox_v3(this, patternField);
- private final TextBox patternNameField = new TextBox();
- private final Label patternNameLabel = new Label();
-
- private final Image starImage = new Image(STAR_OFF_URL);
- private final Image arrowImage = new Image(ARROW_WHITE_URL);
-
- private final PopupPanel savedSearchesPanel = new PopupPanel(true);
- private SavedSearchGrid savedSearchesGrid;
-
- private int currentSearchId = 0;
-
- private SearchSubsystem searchSubsystem;
- private String defaultSearchText;
- private String defaultSavedSearchPatternId;
-
- HorizontalPanel sbc;
- HorizontalPanel sbc_sbbgc;
- HorizontalPanel sbc_sbbgc_sbcc;
- HorizontalPanel sbc_sbbgc_sbcc_sbclhs_pfc;
- HorizontalPanel sbc_sbbgc_sbcc_sbcrhs_aic;
- HorizontalPanel sbc_sbbgc_sbcc_sbcrhs_sic;
- HorizontalPanel sbc_sbbgc_sbcc_sbcrhs_pnfc;
- HorizontalPanel sbc_sbbgc_sbcc_sbcrhs_pnlc;
- HorizontalPanel sbc_sbbc;
- HorizontalPanel sbc_pfsc;
- HorizontalPanel sbc_ssc;
-
- private HorizontalPanel createHPanel(Panel parent, String className, String id) {
- HorizontalPanel panel = new HorizontalPanel();
- if (parent != null) {
- parent.add(panel);
- }
- if (className != null) {
- panel.setStyleName(className);
- }
- if (id != null) {
- panel.getElement().setId(id);
- }
- return panel;
- }
-
- public FlexSearchBar(SearchSubsystem searchSubsystem) {
- this(searchSubsystem, null);
- }
-
- public FlexSearchBar(SearchSubsystem searchSubsystem, String initialSearchText) {
- Log.info("Loading SearchBar...");
-
- this.searchSubsystem = searchSubsystem;
- this.savedSearchesGrid = new SavedSearchGrid(searchSubsystem);
- // TODO: load default saved search pattern, if user has selected one
- // populate default search text
- // ensure that search subsystem is selected, probably want to force it to be a ctor argument
-
- sbc = createHPanel(null, "searchBarContainer", null);
- sbc_sbbgc = createHPanel(sbc, "searchBarBackgroundContainer", null);
- sbc_sbbgc_sbcc = createHPanel(sbc_sbbgc, "searchBarComponentsContainer", null);
- sbc_sbbgc_sbcc_sbclhs_pfc = createHPanel(sbc_sbbgc_sbcc, "searchBarComponentLHS", "patternFieldContainer");
- sbc_sbbgc_sbcc_sbcrhs_aic = createHPanel(sbc_sbbgc_sbcc, "searchBarComponentRHS", "arrowImageContainer");
- sbc_sbbgc_sbcc_sbcrhs_sic = createHPanel(sbc_sbbgc_sbcc, "searchBarComponentRHS", "starImageContainer");
- sbc_sbbgc_sbcc_sbcrhs_pnfc = createHPanel(sbc_sbbgc_sbcc, "searchBarComponentRHS", "patternNameFieldContainer");
- sbc_sbbgc_sbcc_sbcrhs_pnlc = createHPanel(sbc_sbbgc_sbcc, "searchBarComponentRHS", "patternNameLabelContainer");
- sbc_pfsc = createHPanel(sbc, null, "patternFieldSuggestionsContainer");
- sbc_ssc = createHPanel(sbc, null, "savedSearchesContainer");
-
- sbc_sbbgc_sbcc_sbclhs_pfc.add(autoCompletePatternField);
- sbc_sbbgc_sbcc_sbcrhs_sic.add(starImage);
- sbc_sbbgc_sbcc_sbcrhs_aic.add(arrowImage);
- sbc_sbbgc_sbcc_sbcrhs_pnfc.add(patternNameField);
- sbc_sbbgc_sbcc_sbcrhs_pnlc.add(patternNameLabel);
- sbc_ssc.add(savedSearchesPanel);
-
- initWidget(sbc);
-
- setupAutoCompletingPatternField();
- setupPatternNameField();
- setupPatternNameLabel();
- setupStarImage();
- setupArrowImage();
- setupSavedSearches();
-
- setDefaultSearchText(initialSearchText);
- if (getDefaultSearchText() != null) {
- this.autoCompletePatternField.setText(getDefaultSearchText());
- } else if (getDefaultSavedSearchPatternId() != null) {
- try {
- Integer savedSearchId = Integer.valueOf(getDefaultSavedSearchPatternId());
- activateSavedSearch(savedSearchId);
- } catch (Exception e) {
- this.autoCompletePatternField.setText(MSG
- .view_searchBar_savedSearch_failFind(getDefaultSavedSearchPatternId()));
- }
- }
- }
-
- public SearchSubsystem getSearchSubsystem() {
- return searchSubsystem;
- }
-
- public void setDefaultSearchText(String defaultSearchText) {
- if (defaultSearchText == null || defaultSearchText.trim().equals("")) {
- return; // do nothing
- }
-
- this.defaultSearchText = defaultSearchText;
- }
-
- public String getDefaultSearchText() {
- return defaultSearchText;
- }
-
- public void setDefaultSavedSearchPatternId(String defaultSavedSearchPatternId) {
- if (defaultSavedSearchPatternId == null || defaultSavedSearchPatternId.trim().equals("")) {
- return; // do nothing
- }
-
- this.defaultSavedSearchPatternId = defaultSavedSearchPatternId;
- }
-
- public String getDefaultSavedSearchPatternId() {
- return defaultSavedSearchPatternId;
- }
-
- private void setupAutoCompletingPatternField() {
- autoCompletePatternField.getElement().setId("patternField");
- autoCompletePatternField.setStyleName("patternField");
-
- AutoCompletePatternFieldEventHandler handler = new AutoCompletePatternFieldEventHandler();
- autoCompletePatternField.getTextBox().addFocusHandler(handler);
- autoCompletePatternField.getTextBox().addBlurHandler(handler);
- autoCompletePatternField.addKeyPressHandler(handler);
- }
-
- private void setupPatternNameField() {
- patternNameField.setStyleName("patternNameField");
- patternNameField.setVisible(false);
-
- PatternNameFieldEventHandler handler = new PatternNameFieldEventHandler();
- patternNameField.addKeyPressHandler(handler);
- patternNameField.addClickHandler(handler);
- patternNameField.addBlurHandler(handler);
- }
-
- private void setupPatternNameLabel() {
- patternNameLabel.setStyleName("patternNameLabel");
- patternNameLabel.setVisible(false);
-
- PatternNameLabelEventHandler handler = new PatternNameLabelEventHandler();
- patternNameLabel.addClickHandler(handler);
- }
-
- private void setupStarImage() {
- StarImageEventHandler handler = new StarImageEventHandler();
- starImage.addClickHandler(handler);
- starImage.addMouseOverHandler(handler);
- starImage.addMouseOutHandler(handler);
- }
-
- private void setupArrowImage() {
- ArrowImageEventHandler handler = new ArrowImageEventHandler();
- arrowImage.addClickHandler(handler);
- }
-
- private void setupSavedSearches() {
- savedSearchesPanel.add(savedSearchesGrid);
- savedSearchesPanel.setStyleName("savedSearchesPanel");
- savedSearchesGrid.addStyleName("savedSearchesPanel");
-
- // panel position will be re-calculated on down-arrow click
- //savedSearchesPanel.show();
- savedSearchesPanel.hide();
-
- SavedSearchesEventHandler handler = new SavedSearchesEventHandler();
- savedSearchesPanel.addCloseHandler(handler);
- savedSearchesGrid.setSavedSearchSelectionHandler(handler);
- }
-
- private void turnNameFieldIntoLabel(boolean nameJustUpdated) {
- String name = patternNameField.getText();
-
- if (name.equalsIgnoreCase(DEFAULT_PATTERN_NAME)) {
- name = "";
- }
-
- arrowImage.setVisible(true);
- patternNameField.setVisible(false);
-
- if ("".equals(name)) {
- starImage.setUrl(STAR_OFF_URL);
- } else {
- // NOTE: currently do not support updated a saved search pattern
- if (0 == currentSearchId) {
- String pattern = autoCompletePatternField.getText();
- createSavedSearch(name, pattern);
- } else if (nameJustUpdated) {
- updateSavedSearchName(currentSearchId, name);
- }
-
- starImage.setUrl(STAR_ON_URL);
- patternNameLabel.setText(elipse(name));
- patternNameLabel.setVisible(true);
- autoCompletePatternField.setFocus(true);
- }
- }
-
- private void turnNameLabelIntoField() {
- patternNameField.setText(patternNameLabel.getText());
- patternNameField.setVisible(true);
- patternNameLabel.setVisible(false);
- patternNameField.setFocus(true);
- }
-
- private String elipse(String data) {
- if (data.length() > 14) {
- return data.substring(0, 20) + "...";
- }
- return data;
- }
-
- private void createSavedSearch(final String name, final String pattern) {
- Subject subject = UserSessionManager.getSessionSubject();
- SavedSearch newSavedSearch = new SavedSearch(searchSubsystem, name, pattern, subject);
- GWTServiceLookup.getSearchService().createSavedSearch(newSavedSearch, new AsyncCallback<Integer>() {
- @Override
- public void onSuccess(Integer newSavedSearchId) {
- CoreGUI.getMessageCenter()
- .notify(new Message(MSG.view_searchBar_savedSearch_save(name), Severity.Info));
- currentSearchId = newSavedSearchId;
- }
-
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_searchBar_savedSearch_failSave(name), caught);
- }
- });
- }
-
- private void updateSavedSearchName(final int savedSearchId, final String newName) {
- GWTServiceLookup.getSearchService().updateSavedSearchName(savedSearchId, newName, new AsyncCallback<Boolean>() {
- @Override
- public void onSuccess(Boolean hadUpdates) {
- if (hadUpdates) {
- CoreGUI.getMessageCenter().notify(
- new Message(MSG.view_searchBar_savedSearch_rename(newName), Severity.Info));
- }
- }
-
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_searchBar_savedSearch_failRename(newName), caught);
- }
- });
- }
-
- /*
- * Event Handlers
- */
- class AutoCompletePatternFieldEventHandler implements KeyPressHandler, FocusHandler, BlurHandler {
- public void onKeyPress(KeyPressEvent event) {
- // hide pattern field/label, turn off star
- if (event.getCharCode() == KeyCodes.KEY_ENTER) {
- return;
- }
-
- patternNameLabel.setText("");
- patternNameLabel.setVisible(false);
- patternNameField.setValue("", true);
- patternNameField.setVisible(false);
- currentSearchId = 0;
- starImage.setUrl(STAR_OFF_URL);
-
- if (event.getCharCode() == KeyCodes.KEY_ESCAPE) {
- autoCompletePatternField.hideSuggestionList();
- event.preventDefault();
- event.stopPropagation();
- }
- }
-
- public void onFocus(FocusEvent event) {
- autoCompletePatternField.showSuggestionList();
- savedSearchesPanel.hide();
- }
-
- public void onBlur(BlurEvent event) {
- savedSearchesPanel.hide();
- }
- }
-
- class PatternNameFieldEventHandler implements KeyPressHandler, ClickHandler, BlurHandler {
- public void onKeyPress(KeyPressEvent event) {
- if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
- Log.debug("key press pattern name field");
- turnNameFieldIntoLabel(true);
- }
- }
-
- public void onClick(ClickEvent event) {
- if (patternNameField.getText().equals(DEFAULT_PATTERN_NAME)) {
- patternNameField.setValue("", false);
- }
- }
-
- public void onBlur(BlurEvent event) {
- // 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);
- }
- }
- }
-
- class PatternNameLabelEventHandler implements ClickHandler {
- public void onClick(ClickEvent event) {
- turnNameLabelIntoField();
- }
- }
-
- class StarImageEventHandler implements ClickHandler, MouseOverHandler, MouseOutHandler {
- public void onClick(ClickEvent event) {
-
- // note - since hover changes off to active, we never have the star off case here
- if (starImage.getUrl().endsWith(STAR_ACTIVE_URL)) {
- if (patternNameField.isVisible()) {
- patternNameField.setVisible(false);
-
- } else {
- patternNameField.setText(DEFAULT_PATTERN_NAME);
- patternNameField.setVisible(true);
- patternNameField.selectAll();
- patternNameField.setFocus(true);
- patternNameLabel.setVisible(false);
-
- }
- } else if (starImage.getUrl().endsWith(STAR_ON_URL)) {
- starImage.setUrl(STAR_ACTIVE_URL);
- patternNameField.setVisible(false);
- patternNameLabel.setVisible(false);
- }
- }
-
- public void onMouseOver(MouseOverEvent event) {
- if (starImage.getUrl().endsWith(STAR_OFF_URL) && !"".equals(getValue().trim())) {
-
- starImage.setUrl(STAR_ACTIVE_URL);
- }
- }
-
- public void onMouseOut(MouseOutEvent event) {
- if (starImage.getUrl().endsWith(STAR_ACTIVE_URL) && !patternNameField.isVisible()) {
- starImage.setUrl(STAR_OFF_URL);
- }
- }
- }
-
- class ArrowImageEventHandler implements ClickHandler {
- public void onClick(ClickEvent event) {
- savedSearchesGrid.updateModel(new AsyncCallback<List<SavedSearch>>() {
- @Override
- public void onFailure(Throwable caught) {
- // nothing needs to be done
- }
-
- @Override
- public void onSuccess(List<SavedSearch> updatedGridData) {
- int left = autoCompletePatternField.getAbsoluteLeft();
- int top = autoCompletePatternField.getAbsoluteTop() + autoCompletePatternField.getOffsetHeight();
- savedSearchesPanel.setPopupPosition(left, top + 5);
- savedSearchesPanel.show();
- arrowImage.setUrl(ARROW_GRAY_URL);
- }
- });
- }
- }
-
- class SavedSearchesEventHandler implements CloseHandler<PopupPanel>, SavedSearchSelectionHandler {
- public void onClose(CloseEvent<PopupPanel> event) {
- arrowImage.setUrl(ARROW_WHITE_URL);
- }
-
- public void handleSelection(final int rowIndex, final int columnIndex, final SavedSearch savedSearch) {
- Log.debug("SavedSearchesEventHandler.handleSelection(" + rowIndex + "," + columnIndex + "," + savedSearch
- + ")");
- if (columnIndex == 1) {
- GWTServiceLookup.getSearchService().deleteSavedSearch(savedSearch.getId(), new AsyncCallback<Void>() {
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
- MSG.view_searchBar_savedSearch_failDelete(savedSearch.getName()), caught);
- }
-
- @Override
- public void onSuccess(Void result) {
- // handle deletion of current saved search
- if (currentSearchId == savedSearch.getId()) {
- currentSearchId = 0;
- patternNameField.setValue("", true);
- patternNameField.setVisible(false);
- patternNameLabel.setText("");
- patternNameLabel.setVisible(false);
- autoCompletePatternField.setFocus(true);
- starImage.setUrl(STAR_OFF_URL);
- savedSearchesPanel.hide();
- }
-
- // handle deletion of the one and only element in the list
- if (savedSearchesGrid.size() == 1) {
- savedSearchesPanel.hide();
- }
-
- savedSearchesGrid.removeRow(rowIndex);
-
- CoreGUI.getMessageCenter().notify(
- new Message(MSG.view_searchBar_savedSearch_delete(savedSearch.getName()), Severity.Info));
- }
- });
- } else {
- activateSavedSearch(savedSearch); // activating the saved search also clicks the button
- }
- }
- }
-
- public void activateSavedSearch(Integer savedSearchId) {
- activeSavedSearchByIdOrName(savedSearchId, null);
- }
-
- public void activateSavedSearch(String savedSearchName) {
- activeSavedSearchByIdOrName(null, savedSearchName);
- }
-
- private void activeSavedSearchByIdOrName(Integer savedSearchId, final String savedSearchName) {
- Subject subject = UserSessionManager.getSessionSubject();
- SavedSearchCriteria criteria = new SavedSearchCriteria();
- criteria.addFilterSubjectId(subject.getId());
- criteria.addFilterId(savedSearchId); // null OK
- criteria.addFilterName(savedSearchName); // null OK
- criteria.setStrict(true);
-
- GWTServiceLookup.getSearchService().findSavedSearchesByCriteria(criteria,
- new AsyncCallback<List<SavedSearch>>() {
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_searchBar_savedSearch_failFind(savedSearchName),
- caught);
- }
-
- @Override
- public void onSuccess(List<SavedSearch> results) {
- if (results.size() == 0) {
- CoreGUI.getMessageCenter().notify(
- new Message(MSG.view_searchBar_savedSearch_failFind(savedSearchName), Severity.Error));
- } else {
- SavedSearch savedSearch = results.get(0);
- activateSavedSearch(savedSearch);
- }
- }
- });
- }
-
- public void activateSavedSearch(SavedSearch savedSearch) {
- currentSearchId = savedSearch.getId();
- autoCompletePatternField.setValue(savedSearch.getPattern(), true);
- patternNameField.setValue(savedSearch.getName(), true);
- Log.debug("search results change: [" + savedSearch.getName() + "," + savedSearch.getPattern() + "]");
- turnNameFieldIntoLabel(false);
- savedSearchesPanel.hide();
- }
-
- public String getSelectedTab() {
- return null;
- }
-
- public void addKeyPressHandler(KeyPressHandler handler) {
- autoCompletePatternField.addKeyPressHandler(handler);
- }
-
- public String getValue() {
- return autoCompletePatternField.getText();
- }
-
-}
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
deleted file mode 100644
index 3845a27..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/favorites/SavedSearchGrid.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.search.favorites;
-
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.Grid;
-import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.criteria.SavedSearchCriteria;
-import org.rhq.core.domain.search.SavedSearch;
-import org.rhq.core.domain.search.SearchSubsystem;
-import org.rhq.core.domain.util.PageOrdering;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.UserSessionManager;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Joseph Marques
- */
-@Deprecated
-public class SavedSearchGrid extends Grid {
-
- private SavedSearchSelectionHandler patternSelectionHandler;
- private SearchSubsystem searchSubsystem;
- private List<SavedSearch> data = new ArrayList<SavedSearch>();
-
- public interface SavedSearchSelectionHandler {
- public void handleSelection(int rowIndex, int columnIndex, SavedSearch savedSearch);
- }
-
- public void setSavedSearchSelectionHandler(SavedSearchSelectionHandler handler) {
- this.patternSelectionHandler = handler;
- }
-
- class SavedSearchRowFormatter extends RowFormatter {
- private int savedSearchCount;
-
- public SavedSearchRowFormatter() {
- this(0);
- }
-
- public SavedSearchRowFormatter(int savedSearchCount) {
- this.savedSearchCount = savedSearchCount;
- }
-
- @Override
- public String getStyleName(int row) {
- // add -bottom decoration for all rows except last
- if (row < savedSearchCount) {
- return " savedSearchesPanel-row";
- }
- return "";
- }
-
- @Override
- public String getStylePrimaryName(int row) {
- return getStyleName(row);
- }
- }
-
- public SavedSearchGrid(SearchSubsystem searchSubsystem) {
- super(0, 2); // assume no rows to start, but we'll always have 2 columns
-
- setRowFormatter(new SavedSearchRowFormatter());
- sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONCLICK);
- setCellSpacing(0);
- setCellPadding(5);
- setStyleName("savedSearchesGrid");
-
- this.searchSubsystem = searchSubsystem;
- }
-
- @Override
- public void onBrowserEvent(Event event) {
- Element td = getEventTargetCell(event);
- if (td == null) {
- return;
- }
- Element tr = DOM.getParent(td);
- Element table = DOM.getParent(tr);
- switch (DOM.eventGetType(event)) {
- case Event.ONCLICK: {
- int columnIndex = DOM.getChildIndex(tr, td);
- int rowIndex = DOM.getChildIndex(table, tr);
- SavedSearch savedSearch = data.get(rowIndex); // get request-cached element that should be in that row
- patternSelectionHandler.handleSelection(rowIndex, columnIndex, savedSearch);
- if (columnIndex == 0) {
- onRowOut(tr);
- }
- break;
- }
- case Event.ONMOUSEOVER: {
- onRowOver(tr);
- break;
- }
- case Event.ONMOUSEOUT: {
- onRowOut(tr);
- break;
- }
- }
- }
-
- protected void onRowOut(Element row) {
- Element actionCell = DOM.getChild(row, 1);
- DOM.setStyleAttribute(actionCell, "background", "");
- DOM.setStyleAttribute(row, "backgroundColor", "white");
- }
-
- protected void onRowOver(Element row) {
- Element actionCell = DOM.getChild(row, 1);
- //DOM.setStyleAttribute(actionCell, "backgroundImage", "url(" + SearchBar.TRASH + ")");
- DOM.setStyleAttribute(actionCell, "backgroundRepeat", "no-repeat");
- DOM.setStyleAttribute(actionCell, "backgroundPosition", "center");
- DOM.setStyleAttribute(actionCell, "width", "24px");
- DOM.setStyleAttribute(actionCell, "height", "24px");
- DOM.setStyleAttribute(row, "backgroundColor", "rgb(222,222,222)");
- }
-
- public void updateModel(final AsyncCallback<List<SavedSearch>> callback) {
- Subject subject = UserSessionManager.getSessionSubject();
- SavedSearchCriteria criteria = new SavedSearchCriteria();
- criteria.addFilterSubjectId(subject.getId());
- criteria.addFilterSearchSubsystem(searchSubsystem);
- criteria.addSortName(PageOrdering.ASC);
-
- GWTServiceLookup.getSearchService().findSavedSearchesByCriteria(criteria,
- new AsyncCallback<List<SavedSearch>>() {
- @Override
- public void onSuccess(List<SavedSearch> userSavedSearches) {
- data = userSavedSearches; // cache for correct client-side lookup on selection event
- clear(true);
- resizeRows(userSavedSearches.size());
-
- int i = 0;
- SavedSearchRowFormatter rowFormatter = new SavedSearchRowFormatter(data.size());
- for (SavedSearch nextSavedSearch : userSavedSearches) {
- setHTML(i, 0, stylize(nextSavedSearch));
- setHTML(i, 1, trashify());
- i++;
- }
- setRowFormatter(rowFormatter);
-
- callback.onSuccess(userSavedSearches);
- }
-
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
- CoreGUI.getMessages().view_searchBar_savedSearch_failFind("*"), caught);
-
- callback.onFailure(caught);
- }
- });
- }
-
- private static String stylize(SavedSearch savedSearch) {
- String name = savedSearch.getName();
- String pattern = savedSearch.getPattern();
- String count = savedSearch.getResultCount() == null ? "" : "(" + savedSearch.getResultCount() + ")";
- return "<span class=\"savedSearchesPanel-top\">" + name + "</span> " + count + "<br/>" //
- + "<span class=\"savedSearchesPanel-bottom\">" + pattern + "</span>";
- }
-
- private static String trashify() {
- return "<div name=\"action\"></div>";
- }
-
- public String getSelectedItem() {
- return "";
- }
-
- public int size() {
- return data.size();
- }
-}
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
deleted file mode 100644
index c4b91c5..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/suggest/SuggestTextBox_v3.java
+++ /dev/null
@@ -1,762 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.search.suggest;
-
-import com.google.gwt.event.dom.client.*;
-import com.google.gwt.event.logical.shared.*;
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.*;
-import com.google.gwt.user.client.ui.SuggestOracle.Callback;
-import com.google.gwt.user.client.ui.SuggestOracle.Request;
-import com.google.gwt.user.client.ui.SuggestOracle.Response;
-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;
-import org.rhq.enterprise.gui.coregui.client.util.Log;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-@Deprecated
-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;
-
- private int limit = 20;
- private int currentCursorPosition = 0;
- private final SuggestionMenu suggestionMenu;
- private final PopupPanel suggestionPopup;
- private final TextBoxBase box;
- private final Callback callback = new Callback() {
- public void onSuggestionsReady(Request request, Response response) {
- showSuggestions(response.getSuggestions());
- }
- };
-
- private final String STYLE_NAME_TEXT_BOX = "patternField";
- private final String STYLE_NAME_POPUP_PANEL = "suggestPanel";
-
- public SuggestTextBox_v3(AbstractSearchBar searchBar, TextBoxBase box) {
- super();
-
- this.searchBar = searchBar;
- this.oracle = new SearchSuggestOracle();
-
- this.box = box;
- this.box.setName("SearchPatternField");
- initWidget(box);
-
- getElement().setAttribute("autocomplete", "off"); // we're producing completion suggestions, not the browser
-
- // suggestionMenu must be created before suggestionPopup, because
- // suggestionMenu is suggestionPopup's widget
- suggestionMenu = new SuggestionMenu(true);
- // let the text box maintain focus when navigating the menu
- suggestionMenu.setFocusOnHoverEnabled(false);
- suggestionPopup = createPopup();
-
- // need to fork PopupPanel to access the animation type
- //suggestionPopup.setAnimationType(PopupPanel.AnimationType.ROLL_DOWN);
-
- addEventsToTextBox();
- setStyleName(STYLE_NAME_TEXT_BOX);
- }
-
- private PopupPanel createPopup() {
- PopupPanel p = new PopupPanel(true, false);
- p.setWidget(suggestionMenu);
- p.setStyleName(STYLE_NAME_POPUP_PANEL);
- p.setPreviewingAllNativeEvents(true);
- p.addAutoHidePartner(getTextBox().getElement());
- return p;
- }
-
- class SuggestionCompletionCommand implements Command {
-
- private Suggestion suggestion;
-
- public SuggestionCompletionCommand(Suggestion suggestion) {
- this.suggestion = suggestion;
- }
-
- public void execute() {
- complete(suggestion, currentCursorPosition);
- }
- }
-
- private void showSuggestions(Collection<? extends Suggestion> suggestions) {
- if (suggestions.size() > 0) {
-
- // Hide the popup before we manipulate the menu within it. If we do not
- // do this, some browsers will redraw the popup as items are removed
- // and added to the menu.
- boolean isAnimationEnabled = suggestionPopup.isAnimationEnabled();
- if (suggestionPopup.isAttached()) {
- suggestionPopup.hide();
- }
-
- suggestionMenu.clearItems();
-
- for (Suggestion curSuggestion : suggestions) {
- final SuggestionMenuItem menuItem = new SuggestionMenuItem(curSuggestion, oracle.isDisplayStringHTML(),
- new SuggestionCompletionCommand(curSuggestion));
-
- suggestionMenu.addItem(menuItem);
- }
-
- class TextBoxSkewWrapper extends TextBox {
- private TextBoxBase wrapped;
- private int skewWidth;
- private int skewHeight;
-
- public TextBoxSkewWrapper(TextBoxBase textBoxBase, int skewWidth, int skewHeight) {
- this.wrapped = textBoxBase;
- this.skewWidth = skewWidth;
- this.skewHeight = skewHeight;
- }
-
- @Override
- public int getOffsetWidth() {
- return wrapped.getOffsetWidth();
- }
-
- @Override
- public int getOffsetHeight() {
- return wrapped.getOffsetHeight();
- }
-
- @Override
- public int getAbsoluteLeft() {
- return wrapped.getAbsoluteLeft() + skewWidth;
- }
-
- @Override
- public int getAbsoluteTop() {
- return wrapped.getAbsoluteTop() + skewHeight;
- }
- }
-
- suggestionPopup.showRelativeTo(new TextBoxSkewWrapper(getTextBox(), 0, 5));
- suggestionPopup.setAnimationEnabled(isAnimationEnabled);
- } else {
- suggestionPopup.hide();
- }
-
- setFocus(true);
- }
-
- private void addEventsToTextBox() {
- 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) {
- delegateEvent(SuggestTextBox_v3.this, event);
- }
-
- public void onKeyPress(KeyPressEvent event) {
- if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
- Log.debug("****** Pressed Enter in SearchBar");
- hideSuggestionList();
- }
-
- delegateEvent(SuggestTextBox_v3.this, event);
- }
-
- public void onKeyUp(KeyUpEvent event) {
- handleSuggestions();
-
- delegateEvent(SuggestTextBox_v3.this, event);
- }
-
- public void onValueChange(ValueChangeEvent<String> event) {
- Log.debug("OnValueChange in SearchBar: "+event.getValue());
- delegateEvent(SuggestTextBox_v3.this, event);
- }
-
- private void handleSuggestions() {
- int nextCursorPosition = getTextBox().getCursorPos();
- if (nextCursorPosition != -1) {
- // refresh suggestions if cursor moved, meaning users want suggestions from a different context
- if (currentCursorPosition != nextCursorPosition) {
- currentCursorPosition = nextCursorPosition;
- showSuggestions();
- }
- }
- }
- }
-
- TextBoxEvents events = new TextBoxEvents();
- events.addKeyHandlersTo(box);
- box.addClickHandler(events);
- box.addValueChangeHandler(events);
- }
-
- /*
- * Composite methods
- */
- public void setLimit(int limit) {
- this.limit = limit;
- }
-
- /*
- * Handler methods
- */
- public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
- return addDomHandler(handler, KeyDownEvent.getType());
- }
-
- public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
- return addDomHandler(handler, KeyPressEvent.getType());
- }
-
- public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
- return addDomHandler(handler, KeyUpEvent.getType());
- }
-
- public HandlerRegistration addSelectionHandler(SelectionHandler<Suggestion> handler) {
- return addHandler(handler, SelectionEvent.getType());
- }
-
- public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) {
- return addHandler(handler, ValueChangeEvent.getType());
- }
-
- public int getLimit() {
- return limit;
- }
-
- /*
- * TextBox methods
- */
- public void setText(String text) {
- box.setText(text);
- }
-
- public void setValue(String newValue) {
- box.setValue(newValue);
- }
-
- public void setValue(String value, boolean fireEvents) {
- box.setValue(value, fireEvents);
- }
-
- public String getText() {
- return box.getText();
- }
-
- public String getValue() {
- return box.getValue();
- }
-
- public TextBoxBase getTextBox() {
- return box;
- }
-
- public void setFocus(boolean focused) {
- box.setFocus(focused);
- }
-
- /*
- * SuggestBox methods
- */
- public void showSuggestionList() {
- if (isAttached()) {
- showSuggestions();
- }
- }
-
- public void hideSuggestionList() {
- this.suggestionPopup.hide();
- }
-
- public boolean isSuggestionListShowing() {
- return suggestionPopup.isShowing();
- }
-
- /**
- * Get the number of suggestions that are currently showing.
- *
- * @return the number of suggestions currently showing, 0 if there are none
- */
- int getSuggestionCount() {
- return isSuggestionListShowing() ? suggestionMenu.getNumItems() : 0;
- }
-
- void showSuggestions() {
- String query = box.getText();
- int cursorPos = currentCursorPosition;
- if (query.length() == 0) {
- oracle.requestDefaultSuggestions(new SearchSuggestionRequest(null, cursorPos, limit), callback);
- } else {
- oracle.requestSuggestions(new SearchSuggestionRequest(query, cursorPos, limit), callback);
- }
- }
-
- /**
- * The SuggestionMenu class is used for the display and selection of
- * suggestions in the SuggestBox widget. SuggestionMenu differs from MenuBar
- * in that it always has a vertical orientation, and it has no submenus. It
- * also allows for programmatic selection of items in the menu, and
- * programmatically performing the action associated with the selected item.
- * In the MenuBar class, items cannot be selected programatically - they can
- * only be selected when the user places the mouse over a particlar item.
- * Additional methods in SuggestionMenu provide information about the number
- * of items in the menu, and the index of the currently selected item.
- */
- private static class SuggestionMenu extends MenuBar {
-
- public SuggestionMenu(boolean vertical) {
- super(vertical);
- // Make sure that CSS styles specified for the default Menu classes
- // do not affect this menu
- setStyleName("");
- }
-
- @SuppressWarnings("unused")
- public void doSelectedItemAction() {
- // In order to perform the action of the item that is currently
- // selected, the menu must be showing.
- MenuItem selectedItem = getSelectedItem();
- if (selectedItem != null) {
- selectedItem.getCommand().execute();
- //doItemAction(selectedSuggestItem, true);
- }
- }
-
- public int getNumItems() {
- return getItems().size();
- }
-
- /**
- * Returns the index of the menu item that is currently selected.
- *
- * @return returns the selected item
- */
- public int getSelectedItemIndex() {
- // The index of the currently selected item can only be
- // obtained if the menu is showing.
- MenuItem selectedItem = getSelectedItem();
- if (selectedItem != null) {
- return getItems().indexOf(selectedItem);
- }
- return -1;
- }
-
- public SearchSuggestion getSearchSuggestion() {
- SuggestionMenuItem menuItem = (SuggestionMenuItem) getSelectedItem();
- Suggestion suggestion = menuItem.getSuggestion();
- SearchSuggestion searchSuggestion = extraSearchSuggestion(suggestion);
- return searchSuggestion;
- }
- }
-
- private static SearchSuggestion extraSearchSuggestion(Suggestion suggestion) {
- SearchSuggestionOracleAdapter adapter = (SearchSuggestionOracleAdapter) suggestion;
- SearchSuggestion searchSuggestion = adapter.getSearchSuggestion();
- return searchSuggestion;
- }
-
- /**
- * Class for menu items in a SuggestionMenu. A SuggestionMenuItem differs from
- * a MenuItem in that each item is backed by a Suggestion object. The text of
- * each menu item is derived from the display string of a Suggestion object,
- * and each item stores a reference to its Suggestion object.
- */
- private static class SuggestionMenuItem extends MenuItem {
-
- private static final String STYLENAME_DEFAULT = "suggestData";
-
- private Suggestion suggestion;
-
- public SuggestionMenuItem(Suggestion suggestion, boolean asHTML, SuggestionCompletionCommand command) {
- super(getFormattedLabel(suggestion), asHTML, command);
- // Each suggestion should be placed in a single row in the suggestion
- // menu. If the window is resized and the suggestion cannot fit on a
- // single row, it should be clipped (instead of wrapping around and
- // taking up a second row).
- DOM.setStyleAttribute(getElement(), "whiteSpace", "nowrap");
- setStyleName(STYLENAME_DEFAULT);
- setSuggestion(suggestion);
- }
-
- public Suggestion getSuggestion() {
- return suggestion;
- }
-
- public void setSuggestion(Suggestion suggestion) {
- this.suggestion = suggestion;
- }
-
- private static String getFormattedLabel(Suggestion suggestion) {
- return getFormattedLabel(extraSearchSuggestion(suggestion));
- }
-
- private static String getFormattedLabel(SearchSuggestion item) {
- String className = "suggestData ";
- String prefix = "";
-
- if (item.getKind() == SearchSuggestion.Kind.Simple) {
- className += "suggestDataSimple";
- prefix = "text";
- } else if (item.getKind() == SearchSuggestion.Kind.Advanced) {
- className += "suggestDataAdvanced";
- prefix = "query";
- } else if (item.getKind() == SearchSuggestion.Kind.GlobalSavedSearch
- || item.getKind() == SearchSuggestion.Kind.UserSavedSearch) {
- className += "suggestDataSavedSearch";
- prefix = "saved";
- } else {
- }
-
- String style = "font-variant: small-caps; font-weight: bold; font-size: 11px; float: left; margin-left: 2px; width: 50px;";
- int marginOffset = 20;
- if (className.endsWith("suggestDataSavedSearch")) {
- style += " color: green;";
- marginOffset += 2;
- } else {
- style += " color: gray;";
- if (className.endsWith("suggestDataSimple")) {
- marginOffset += 8;
- }
- }
-
- String decoratedPrefix = wrap(prefix, style);
- String formattedItemLabel = chopWithEvery(item.getLabel(), "<br/>", 100);
- String decoratedItemLabel = decorate(formattedItemLabel, "background-color: yellow;", item.getStartIndex(),
- item.getEndIndex());
- String highlightedSuggestion = colorOperator(decoratedItemLabel);
- String decoratedSuffix = wrap(highlightedSuggestion, "float: left; ");
- String floatClear = "<br style=\"clear: both;\" />";
-
- String innerHTML = decoratedPrefix + decoratedSuffix + floatClear;
- return innerHTML;
- }
-
- private static String chopWithEvery(String toChop, String with, int every) {
- //String[] words = toChop.split("\\s");
- List<String> words = chop(toChop, "\\/- \t\r\n");
- StringBuilder results = new StringBuilder();
- int currentLineLength = 0;
- for (String next : words) {
- results.append(next);
- currentLineLength += next.length();
- if (currentLineLength + next.length() > every) {
- results.append(with);
- currentLineLength = 0;
- }
- }
-
- return results.toString();
- }
-
- // StringTokenzier doesn't exist in GWT, so have to write my own
- private static List<String> chop(String dataToChop, String chopTokens) {
- List<String> words = new ArrayList<String>();
-
- StringBuilder builder = new StringBuilder();
- for (char next : dataToChop.toCharArray()) {
- if (chopTokens.indexOf(next) != -1) {
- if (builder.length() > 0) {
- words.add(builder.toString());
- builder = new StringBuilder();
- }
- }
- builder.append(next);
- }
-
- if (builder.length() > 0) {
- words.add(builder.toString());
- }
-
- return words;
- }
-
- private static final List<String> OPERATORS = Arrays.asList("!==", "!=", "==", "=");
-
- // TODO: fixing coloring strategy
- private static String colorOperator(String data) {
- for (String operator : OPERATORS) {
- int index = -1;
- while ((index = data.indexOf(operator, index + 1)) != -1) {
- if ((index - 5 >= 0) && data.substring(index - 5, index).equals("style") == false) {
- break;
- }
- }
- if (index != -1) {
- return decorate(data, "color: blue;", index, index + operator.length());
- }
- }
- return data;
- }
-
- private static String wrap(String data, String style) {
- return "<span style=\"" + style + "\">" + data + "</span>";
- }
-
- /*
- private static String decorate(String data, String style, int startIndex, int endIndex) {
- if (startIndex == -1) {
- return data; // no match
- }
- String before = data.substring(0, startIndex);
- String highlight = data.substring(startIndex, endIndex);
- String after = data.substring(endIndex);
- return before + "<span style=\"" + style + "\">" + highlight + "</span>" + after;
- }
- */
-
- private static String decorate(String data, String style, int startIndex, int endIndex) {
- if (startIndex == -1 || (startIndex == endIndex)) {
- return data; // no match or zero-width match
- }
-
- String[] words = data.split("<br/>");
- int counter = 0;
- int wordIndex = 0;
- int letterIndex = 0;
-
- StringBuilder results = new StringBuilder();
- while (counter < startIndex) {
- if (wordIndex == words.length) {
- break;
- }
-
- if (letterIndex < words[wordIndex].length()) { // more letters left in the current word?
- results.append(words[wordIndex].charAt(letterIndex)); // append the next char of the current word
- letterIndex++; // move to the next char in the current word
- counter++; // only move counter forward when we've added non-BR chars to the results
- } else { // next word
- results.append("<br/>"); // put the break point back in between words
- letterIndex = 0; // point to the first char
- wordIndex++; // of the next word
- }
- }
-
- // we're at start index, wrap all words and word fragments in the specified style up to endIndex
- results.append("<span style=\"" + style + "\">"); // seed action
- while (counter < endIndex) {
- if (wordIndex == words.length) {
- break;
- }
-
- if (letterIndex < words[wordIndex].length()) { // more letters left in the current word?
- results.append(words[wordIndex].charAt(letterIndex)); // append the next char of the current word
- letterIndex++; // move to the next char in the current word
- counter++; // only move counter forward when we've added non-BR chars to the results
- } else { // next word
- results.append("</span>"); // close the previous word, we don't highlight breaks
- results.append("<br/>"); // put the break point back in between words
- letterIndex = 0; // point to the first char
- wordIndex++; // of the next word
- results.append("<span style=\"" + style + "\">"); // prepare for next word
- }
- }
- results.append("</span>"); // end last dangling span
-
- // append the rest of the current word fragment, if any
- if (wordIndex != words.length) {
- results.append(words[wordIndex].substring(letterIndex));
- }
-
- // append the rest of the words
- while (++wordIndex < words.length) {
- results.append("<br/>"); // put the break point back in between words
- results.append(words[wordIndex]);
- }
-
- return results.toString();
- }
- }
-
- @Deprecated
- class SearchSuggestOracle extends SuggestOracle {
- private SearchGWTServiceAsync searchService = GWTServiceLookup.getSearchService();
-
- @Override
- public boolean isDisplayStringHTML() {
- return true;
- }
-
- @Override
- public void requestDefaultSuggestions(Request request, Callback callback) {
- requestSuggestions(request, callback);
- }
-
- @Override
- public void requestSuggestions(final Request request, final Callback callback) {
- SearchSuggestionRequest suggestionRequest = (SearchSuggestionRequest) request;
- String expression = suggestionRequest.getQuery();
- int caretPosition = suggestionRequest.getCursorPosition();
-
- searchService.getTabAwareSuggestions(searchBar.getSearchSubsystem(), expression, caretPosition,
- searchBar.getSelectedTab(), new AsyncCallback<List<SearchSuggestion>>() {
-
- public void onSuccess(List<SearchSuggestion> results) {
- adaptAndHandle(results.toArray(new SearchSuggestion[results.size()]));
- }
-
- public void onFailure(Throwable caught) {
- SearchSuggestion errorInform = new SearchSuggestion(Kind.InstructionalTextComment, MSG
- .view_searchBar_instructional_failSuggest());
- adaptAndHandle(errorInform);
- }
-
- private void adaptAndHandle(SearchSuggestion... searchSuggestionResults) {
- List<SearchSuggestionOracleAdapter> adaptedResults = new java.util.ArrayList<SearchSuggestionOracleAdapter>();
- 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);
- }
- });
- }
- }
-
- protected void complete(Suggestion suggestion, int cursorPosition) {
- SearchSuggestion searchSuggestion = extraSearchSuggestion(suggestion);
- String currentText = getText().toLowerCase();
-
- if (searchSuggestion.getKind() == SearchSuggestion.Kind.GlobalSavedSearch
- || searchSuggestion.getKind() == SearchSuggestion.Kind.UserSavedSearch) {
- // execute saved searches immediately, since they presumably constitute complete expressions
- Log.debug("selected '" + searchSuggestion.getLabel() + "' saved search suggestion");
- searchBar.activateSavedSearch(searchSuggestion.getValue());
- } else {
- // selecting a simple suggestion or advanced suggestion
-
- int previousWhitespaceIndex = cursorPosition;
- if (cursorPosition != 0) {
- while (--previousWhitespaceIndex > 0) {
- if (currentText.charAt(previousWhitespaceIndex) == ' ') {
- previousWhitespaceIndex++; // put index right after found whitespace
- break;
- }
- }
- }
-
- int futureWhitespaceIndex = cursorPosition;
- while (futureWhitespaceIndex < currentText.length()) {
- if (currentText.charAt(futureWhitespaceIndex) == ' ') {
- break;
- }
- futureWhitespaceIndex++;
- }
-
- String before = getText().substring(0, previousWhitespaceIndex);
- String completion = suggestion.getReplacementString();
- String after = getText().substring(futureWhitespaceIndex);
-
- setValue(before + completion + after, true);
- currentCursorPosition = before.length() + completion.length();
- getTextBox().setCursorPos(currentCursorPosition);
-
- showSuggestions();
- }
- }
-
- @Deprecated
- class SearchSuggestionRequest extends SuggestOracle.Request {
- private int cursorPosition;
-
- public SearchSuggestionRequest(String query, int cursorPosition, int limit) {
- super(query, limit);
- this.cursorPosition = cursorPosition;
- }
-
- public int getCursorPosition() {
- return cursorPosition;
- }
- }
-
- class SearchSuggestionOracleAdapter implements SuggestOracle.Suggestion {
- private final SearchSuggestion suggestion;
-
- public SearchSuggestionOracleAdapter(SearchSuggestion suggestion) {
- this.suggestion = suggestion;
- }
-
- public String getDisplayString() {
- return suggestion.getLabel();
- }
-
- public String getReplacementString() {
- return suggestion.getValue();
- }
-
- public SearchSuggestion getSearchSuggestion() {
- return suggestion;
- }
- }
-
- public HandlerRegistration addFocusHandler(FocusHandler handler) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public HandlerRegistration addBlurHandler(BlurHandler handler) {
- // TODO Auto-generated method stub
- return null;
- }
-}