Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2011-03-16 17:09:16 +0000
committerChris Goldthorpe2011-03-16 17:09:16 +0000
commit9b1f0d643df70f76a92c7860c028a1df7c2bda44 (patch)
treebc8811750532e63726e6ca55676889a2b9e61460
parent8514876fca454c78866f2f7d7ccc792ba1075eab (diff)
downloadeclipse.platform.ua-9b1f0d643df70f76a92c7860c028a1df7c2bda44.tar.gz
eclipse.platform.ua-9b1f0d643df70f76a92c7860c028a1df7c2bda44.tar.xz
eclipse.platform.ua-9b1f0d643df70f76a92c7860c028a1df7c2bda44.zip
Bug 340096 - [Help][Search] Add preference for show description and show result categories in the search view
-rw-r--r--org.eclipse.help.base/preferences.ini8
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java4
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/SearchResultsPart.java35
-rw-r--r--org.eclipse.help.webapp/advanced/searchView.jsp24
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/RequestScope.java43
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/SearchData.java36
6 files changed, 105 insertions, 45 deletions
diff --git a/org.eclipse.help.base/preferences.ini b/org.eclipse.help.base/preferences.ini
index 195e7dc9f..a353eb870 100644
--- a/org.eclipse.help.base/preferences.ini
+++ b/org.eclipse.help.base/preferences.ini
@@ -213,4 +213,10 @@ maxConnections=10
# Assign a value no greater than Integer.MAX_VALUE
# Assign nothing to accept the default settings of the application
# Example: maxTopics=
-maxTopics=500 \ No newline at end of file
+maxTopics=500
+
+#########################
+# Search Results
+#########################
+showSearchDescription=true
+showSearchCategories=false \ No newline at end of file
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java
index 7bd701e0b..aa8d05119 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -33,6 +33,8 @@ public interface IHelpBaseConstants {
String P_KEY_REMOTE_HELP_DEFAULT_PORT = "remoteHelpUseDefaultPort"; //$NON-NLS-1$
String P_KEY_REMOTE_HELP_PORT = "remoteHelpPort"; //$NON-NLS-1$
String P_KEY_REMOTE_HELP_ICEnabled = "remoteHelpICEnabled"; //$NON-NLS-1$
+ String P_KEY_SHOW_SEARCH_DESCRIPTION = "showSearchDescription"; //$NON-NLS-1$
+ String P_KEY_SHOW_SEARCH_CATEGORIES = "showSearchCategories"; //$NON-NLS-1$
String P_SHOW_BREADCRUMBS = "showBreadcrumbs"; //$NON-NLS-1$
String P_PAGE_NOT_FOUND = "page_not_found"; //$NON-NLS-1$
}
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/SearchResultsPart.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/SearchResultsPart.java
index b69c543aa..717e18f1b 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/SearchResultsPart.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/SearchResultsPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,11 +13,15 @@ package org.eclipse.help.ui.internal.views;
import java.util.ArrayList;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.help.HelpSystem;
import org.eclipse.help.IHelpResource;
import org.eclipse.help.IToc;
+import org.eclipse.help.internal.base.HelpBasePlugin;
+import org.eclipse.help.internal.base.IHelpBaseConstants;
import org.eclipse.help.search.ISearchEngineResult;
-import org.eclipse.help.ui.internal.HelpUIPlugin;
import org.eclipse.help.ui.internal.HelpUIResources;
import org.eclipse.help.ui.internal.IHelpUIConstants;
import org.eclipse.help.ui.internal.Messages;
@@ -26,7 +30,6 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -44,10 +47,9 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
+import org.osgi.service.prefs.BackingStoreException;
public class SearchResultsPart extends AbstractFormPart implements IHelpPart {
- private static final String S_DESCRIPTION_OFF = "no-description"; //$NON-NLS-1$
- private static final String S_SHOW_CATEGORIES = "show-categories"; //$NON-NLS-1$
ReusableHelpPart parent;
private Composite separator;
@@ -122,13 +124,19 @@ public class SearchResultsPart extends AbstractFormPart implements IHelpPart {
* removeAllAction); tbm.insertAfter("removeAll", new Separator());
*/
- IDialogSettings settings = HelpUIPlugin.getDefault().getDialogSettings();
- boolean descOff = settings.getBoolean(S_DESCRIPTION_OFF);
- boolean showCategories = settings.getBoolean(S_SHOW_CATEGORIES);
+ boolean descOn = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_SHOW_SEARCH_DESCRIPTION, false, null);
+ boolean showCategories = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_SHOW_SEARCH_CATEGORIES, false, null);
showCategoriesAction = new Action() {
public void run() {
updateResultSections();
- HelpUIPlugin.getDefault().getDialogSettings().put(S_SHOW_CATEGORIES, showCategoriesAction.isChecked());
+ IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
+ pref.putBoolean(IHelpBaseConstants.P_KEY_SHOW_SEARCH_CATEGORIES, showCategoriesAction.isChecked());
+ try {
+ pref.flush();
+ } catch (BackingStoreException e) {
+ }
}
};
showCategoriesAction.setImageDescriptor(HelpUIResources
@@ -141,12 +149,17 @@ public class SearchResultsPart extends AbstractFormPart implements IHelpPart {
showDescriptionAction = new Action() {
public void run() {
updateResultSections();
- HelpUIPlugin.getDefault().getDialogSettings().put(S_DESCRIPTION_OFF, !showDescriptionAction.isChecked());
+ IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
+ pref.putBoolean(IHelpBaseConstants.P_KEY_SHOW_SEARCH_DESCRIPTION, showDescriptionAction.isChecked());
+ try {
+ pref.flush();
+ } catch (BackingStoreException e) {
+ }
}
};
showDescriptionAction.setImageDescriptor(HelpUIResources
.getImageDescriptor(IHelpUIConstants.IMAGE_SHOW_DESC));
- showDescriptionAction.setChecked(!descOff);
+ showDescriptionAction.setChecked(descOn);
showDescriptionAction.setToolTipText(Messages.SearchResultsPart_showDescriptionAction_tooltip);
showDescriptionAction.setId("description"); //$NON-NLS-1$
tbm.insertAfter("categories", showDescriptionAction); //$NON-NLS-1$
diff --git a/org.eclipse.help.webapp/advanced/searchView.jsp b/org.eclipse.help.webapp/advanced/searchView.jsp
index 51644a2ca..3a7090305 100644
--- a/org.eclipse.help.webapp/advanced/searchView.jsp
+++ b/org.eclipse.help.webapp/advanced/searchView.jsp
@@ -35,30 +35,24 @@
<script language="JavaScript">
var cookiesRequired = "<%=UrlUtil.JavaScriptEncode(ServletResources.getString("cookiesRequired", request))%>";
+var showCategories = <%=data.isShowCategories()%>;
+var scope ="<%=UrlUtil.JavaScriptEncode(data.getScope())%>";
function refresh() {
window.location.replace("searchView.jsp?<%=UrlUtil.JavaScriptEncode(request.getQueryString())%>");
}
-function isShowCategories() {
- var value = getCookie("showCategories");
- return value ? value == "true" : false;
-}
-
function isShowDescriptions() {
var value = getCookie("showDescriptions");
return value ? value == "true" : true;
}
-function setShowCategories(value) {
- setCookie("showCategories", value);
- var newValue = isShowCategories();
- parent.searchToolbarFrame.setButtonState("show_categories", newValue);
- if (value != newValue) {
- alert(cookiesRequired);
- } else {
- window.location.reload();
- }
+function setShowCategories(value) {
+ parent.searchToolbarFrame.setButtonState("show_categories", value);
+ var searchWord = "<%=UrlUtil.JavaScriptEncode(data.getSearchWord())%>";
+ window.location="searchView.jsp?searchWord=" + encodeURIComponent(searchWord)
+ + "&showSearchCategories=" + value +
+ "&scope=" + encodeURIComponent(scope);
}
function setShowDescriptions(value) {
@@ -73,7 +67,7 @@ function setShowDescriptions(value) {
}
function toggleShowCategories() {
- setShowCategories(!isShowCategories());
+ setShowCategories(!showCategories);
}
function toggleShowDescriptions() {
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/RequestScope.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/RequestScope.java
index ea8762846..8a2754605 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/RequestScope.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/RequestScope.java
@@ -140,9 +140,8 @@ public class RequestScope {
CookieUtil.setCookieValue(SCOPE_COOKIE_NAME, URLCoder.compactEncode(scope), request, response);
}
} else {
- InstanceScope instanceScope = new InstanceScope();
- IEclipsePreferences pref = instanceScope.getNode(HelpBasePlugin.PLUGIN_ID);
- pref.put(IHelpBaseConstants.P_KEY_HELP_SCOPE, scope);
+ IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
+ pref.put(IHelpBaseConstants.P_KEY_HELP_SCOPE, scope);
try {
pref.flush();
} catch (BackingStoreException e) {
@@ -151,11 +150,15 @@ public class RequestScope {
}
private static String getScopeFromCookies(HttpServletRequest request) {
+ return getValueFromCookies(request, SCOPE_COOKIE_NAME);
+ }
+
+ private static String getValueFromCookies(HttpServletRequest request, String cookieName) {
// check if scope was passed earlier in this session
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int c = 0; c < cookies.length; c++) {
- if (SCOPE_COOKIE_NAME.equals(cookies[c].getName())) {
+ if (cookieName.equals(cookies[c].getName())) {
return URLCoder.decode(cookies[c].getValue());
}
}
@@ -172,5 +175,37 @@ public class RequestScope {
public static boolean filterBySearchScope(HttpServletRequest request) {
return true;
}
+
+ public static boolean getFlag(HttpServletRequest request, String flagName ) {
+ String value;
+ if (HelpSystem.isShared()) {
+ value = getValueFromCookies(request, flagName);
+ } else {
+ value = Platform.getPreferencesService().getString
+ (HelpBasePlugin.PLUGIN_ID, flagName + "Webapp", null, null); //$NON-NLS-1$
+ }
+ if (value == null) {
+ return Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, flagName, false, null);
+ }
+ return "true".equalsIgnoreCase(value); //$NON-NLS-1$
+ }
+
+ public static void setFlag(HttpServletRequest request,
+ HttpServletResponse response,
+ String flagName,
+ boolean value)
+ {
+ if (HelpSystem.isShared()) {
+ CookieUtil.setCookieValue(flagName, Boolean.toString(value), request, response);
+ } else {
+ IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
+ pref.putBoolean(flagName + "Webapp", value ); //$NON-NLS-1$
+ try {
+ pref.flush();
+ } catch (BackingStoreException e) {
+ }
+ }
+ }
}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/SearchData.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/SearchData.java
index f7a1c123f..fe4413c6f 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/SearchData.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/SearchData.java
@@ -22,6 +22,7 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.help.HelpSystem;
import org.eclipse.help.IHelpResource;
import org.eclipse.help.IToc;
@@ -30,6 +31,7 @@ import org.eclipse.help.base.AbstractHelpScope;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
+import org.eclipse.help.internal.base.IHelpBaseConstants;
import org.eclipse.help.internal.search.ISearchQuery;
import org.eclipse.help.internal.search.QueryTooComplexException;
import org.eclipse.help.internal.search.SearchHit;
@@ -55,6 +57,8 @@ import org.eclipse.osgi.util.NLS;
* Helper class for searchView.jsp initialization
*/
public class SearchData extends ActivitiesData {
+ private static final String SHOW_CATEGORIES = "showSearchCategories"; //$NON-NLS-1$
+
private WebappWorkingSetManager wsmgr;
// Request parameters
@@ -78,6 +82,8 @@ public class SearchData extends ActivitiesData {
// List of alternate search terms
private List altList = new ArrayList();
+ private boolean showCategories = false;
+
/**
* Constructs the xml data for the search results page.
*
@@ -93,6 +99,7 @@ public class SearchData extends ActivitiesData {
topicHref = null;
searchWord = request.getParameter("searchWord"); //$NON-NLS-1$
+ readDisplayFlags(request, response);
if (isScopeRequest()) {
workingSetName = request.getParameter("workingSet"); //$NON-NLS-1$
@@ -103,6 +110,16 @@ public class SearchData extends ActivitiesData {
readSearchResults();
}
+ private void readDisplayFlags(HttpServletRequest request, HttpServletResponse response) {
+ String showCategoriesParam = request.getParameter(SHOW_CATEGORIES);
+ if (showCategoriesParam != null) {
+ showCategories = "true".equalsIgnoreCase(showCategoriesParam); //$NON-NLS-1$
+ RequestScope.setFlag(request, response, SHOW_CATEGORIES, showCategories);
+ } else {
+ showCategories = RequestScope.getFlag(request, SHOW_CATEGORIES);
+ }
+ }
+
public void readSearchResults() {
// try loading search results or get the indexing progress info.
@@ -174,7 +191,8 @@ public class SearchData extends ActivitiesData {
* @return boolean
*/
public boolean isSearchRequest() {
- return (request.getParameter("searchWord") != null); //$NON-NLS-1$
+ String searchWordParam = request.getParameter("searchWord"); //$NON-NLS-1$
+ return (searchWordParam != null && searchWordParam.length() > 0);
}
/**
@@ -289,16 +307,7 @@ public class SearchData extends ActivitiesData {
}
public boolean isShowCategories() {
- Cookie[] cookies = request.getCookies();
- if (cookies != null) {
- for (int i=0;i<cookies.length;++i) {
- if ("showCategories".equals(cookies[i].getName())) { //$NON-NLS-1$
- return String.valueOf(true).equals(cookies[i].getValue());
- }
- }
- }
- // default off
- return false;
+ return showCategories;
}
public boolean isShowDescriptions() {
@@ -310,8 +319,9 @@ public class SearchData extends ActivitiesData {
}
}
}
- // default on
- return true;
+ // get default from preferences
+ return Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_SHOW_SEARCH_DESCRIPTION, true, null);
}
/**

Back to the top