Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2009-11-30 21:24:30 +0000
committerChris Goldthorpe2009-11-30 21:24:30 +0000
commit4e84d864163b6e36de5bcaa5708ea42669bf1849 (patch)
tree8123c7b1db55936abea6c758c11d1d3adf93d06b
parentc39c32c8fe53ee81f0571c212ecb4882d6fb7e27 (diff)
downloadeclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.tar.gz
eclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.tar.xz
eclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.zip
Bug 280354 – [Help] Action for doc plugins that reside locally and remotely:v20091130
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java3
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/DefaultPreferenceFileHandler.java17
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/PreferenceFileHandler.java25
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java15
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java45
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.java8
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.properties8
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentBlock.java92
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentPreferencePage.java84
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICList.java7
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICViewer.java20
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java27
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java7
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java10
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java32
-rwxr-xr-xorg.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java83
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java3
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java3
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java29
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java108
22 files changed, 547 insertions, 84 deletions
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 42a8f1187..1b57cbbf4 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
@@ -23,6 +23,7 @@ public interface IHelpBaseConstants {
String P_KEY_ALWAYS_EXTERNAL_BROWSER = "always_external_browser"; //$NON-NLS-1$
String P_KEY_SEARCH_FROM_BROWSER = "search_from_browser"; //$NON-NLS-1$
String P_KEY_REMOTE_HELP_ON = "remoteHelpOn"; //$NON-NLS-1$
+ String P_KEY_REMOTE_HELP_PREFERRED = "remoteHelpPreferred"; //$NON-NLS-1$
String P_KEY_REMOTE_HELP_NAME = "remoteHelpName"; //$NON-NLS-1$
String P_KEY_REMOTE_HELP_HOST = "remoteHelpHost"; //$NON-NLS-1$
String P_KEY_REMOTE_HELP_PATH = "remoteHelpPath"; //$NON-NLS-1$
@@ -30,5 +31,5 @@ public interface IHelpBaseConstants {
String P_KEY_REMOTE_HELP_PORT = "remoteHelpPort"; //$NON-NLS-1$
String P_KEY_REMOTE_HELP_ICEnabled = "remoteHelpICEnabled"; //$NON-NLS-1$
String P_SHOW_BREADCRUMBS = "showBreadcrumbs"; //$NON-NLS-1$
- String P_PAGE_NOT_FOUND = "page_not_found"; //$NON-NLS-1$
+ String P_PAGE_NOT_FOUND = "page_not_found"; //$NON-NLS-1$
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/DefaultPreferenceFileHandler.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/DefaultPreferenceFileHandler.java
index 10f2af408..94310c971 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/DefaultPreferenceFileHandler.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/DefaultPreferenceFileHandler.java
@@ -19,8 +19,7 @@ import org.eclipse.help.internal.base.IHelpBaseConstants;
public class DefaultPreferenceFileHandler extends PreferenceFileHandler {
- private boolean isRemoteOn;
-
+ private boolean isRemoteOn, isRemoteHelpPreferred;
/**
* Class handles the default preferences for the Help Content preference page
*/
@@ -34,7 +33,7 @@ public class DefaultPreferenceFileHandler extends PreferenceFileHandler {
portPreference = prefs.get(IHelpBaseConstants.P_KEY_REMOTE_HELP_PORT, ""); //$NON-NLS-1$
icEnabledPreference = prefs.get(IHelpBaseConstants.P_KEY_REMOTE_HELP_ICEnabled, ""); //$NON-NLS-1$
isRemoteOn = prefs.getBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false);
-
+ isRemoteHelpPreferred = prefs.getBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, false);
//Get host array first, and initialize values
if(hostPreference.length()==0)
@@ -62,9 +61,13 @@ public class DefaultPreferenceFileHandler extends PreferenceFileHandler {
this.numEntries = this.nameEntries.length;
}
-
- public boolean isRemoteHelpOn()
- {
- return isRemoteOn;
+
+ public boolean isRemoteHelpOn() {
+ return isRemoteOn;
}
+
+ public boolean isRemoteHelpPreferred() {
+ return isRemoteHelpPreferred;
+ }
+
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/PreferenceFileHandler.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/PreferenceFileHandler.java
index da43fe165..5a3805a81 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/PreferenceFileHandler.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/PreferenceFileHandler.java
@@ -31,6 +31,10 @@ public class PreferenceFileHandler {
protected static String PREFERENCE_ENTRY_DELIMITER = ","; //$NON-NLS-1$
+ public static final int LOCAL_HELP_ONLY=0;
+ public static final int LOCAL_HELP_PRIORITY=1;
+ public static final int REMOTE_HELP_PRIORITY=2;
+
public PreferenceFileHandler() {
/*
@@ -211,6 +215,27 @@ public class PreferenceFileHandler {
}
+ public static int getEmbeddedHelpOption() {
+ boolean isRemoteOn = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false, null);
+
+ boolean isRemotePreferred = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, false, null);
+
+ if(!isRemoteOn)
+ {
+ return LOCAL_HELP_ONLY;
+ }
+ else if(!isRemotePreferred)
+ {
+ return LOCAL_HELP_PRIORITY;
+ }
+ else
+ {
+ return REMOTE_HELP_PRIORITY;
+ }
+ }
+
public String[] getHostEntries() {
return hostEntries;
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java
index cd30dcf00..25740460a 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -77,7 +77,7 @@ public class RemoteTocProvider extends AbstractTocProvider {
URL url = null;
String urlStr = ""; //$NON-NLS-1$
- for (int i = 0; i < numICs; i++) {
+ for (int i = numICs-1; i >= 0; i--) {
if (isEnabled[i].equalsIgnoreCase("true")) { //$NON-NLS-1$
try {
url = new URL("http", host[i], new Integer(port[i]) .intValue(), //$NON-NLS-1$
@@ -133,4 +133,15 @@ public class RemoteTocProvider extends AbstractTocProvider {
return new ITocContribution[0];
}
+ /* (non-Javadoc)
+ * @see org.eclipse.help.AbstractTocProvider#getPriority()
+ */
+ public int getPriority() {
+
+ int helpOption=PreferenceFileHandler.getEmbeddedHelpOption();
+
+ if(helpOption ==PreferenceFileHandler.LOCAL_HELP_ONLY || helpOption==PreferenceFileHandler.LOCAL_HELP_PRIORITY)
+ return TOC_FILE_PRIORITY+1;
+ else return DEFAULT_PRIORITY-1;
+ }
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java b/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
index a88313c0f..4047e8281 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
@@ -112,24 +112,19 @@ public class HelpURLConnection extends URLConnection {
throw new IOException("Resource not found."); //$NON-NLS-1$
}
+ int helpOption=PreferenceFileHandler.getEmbeddedHelpOption();
InputStream in = null;
- if (plugin != null) {
- // first try using content provider, then try to find the file
- // inside doc.zip, and finally try the file system
- in = ResourceLocator.openFromProducer(plugin,
- query == null ? getFile() : getFile() + "?" + query, //$NON-NLS-1$
- getLocale());
-
- if (in == null) {
- in = ResourceLocator.openFromZip(plugin, "doc.zip", //$NON-NLS-1$
- getFile(), getLocale());
- }
- if (in == null) {
- in = ResourceLocator.openFromPlugin(plugin, getFile(), getLocale());
- }
+ if (plugin != null && (helpOption==PreferenceFileHandler.LOCAL_HELP_ONLY || helpOption==PreferenceFileHandler.LOCAL_HELP_PRIORITY)) {
+ in = getLocalHelp(plugin);
}
- if (in == null) {
- in = openFromRemoteServer(getHref(), getLocale());
+ if (in == null && (helpOption==PreferenceFileHandler.LOCAL_HELP_PRIORITY || helpOption==PreferenceFileHandler.REMOTE_HELP_PRIORITY)) {
+
+ in = openFromRemoteServer(getHref(), getLocale());
+
+ if(in==null && plugin!=null && helpOption==PreferenceFileHandler.REMOTE_HELP_PRIORITY)
+ {
+ in = getLocalHelp(plugin);
+ }
}
if (in == null) {
throw new IOException("Resource not found."); //$NON-NLS-1$
@@ -137,6 +132,24 @@ public class HelpURLConnection extends URLConnection {
return in;
}
+ private InputStream getLocalHelp(Bundle plugin) {
+ InputStream in;
+ // first try using content provider, then try to find the file
+ // inside doc.zip, and finally try the file system
+ in = ResourceLocator.openFromProducer(plugin,
+ query == null ? getFile() : getFile() + "?" + query, //$NON-NLS-1$
+ getLocale());
+
+ if (in == null) {
+ in = ResourceLocator.openFromZip(plugin, "doc.zip", //$NON-NLS-1$
+ getFile(), getLocale());
+ }
+ if (in == null) {
+ in = ResourceLocator.openFromPlugin(plugin, getFile(), getLocale());
+ }
+ return in;
+ }
+
public long getExpiration() {
return isCacheable() ? new Date().getTime() + 10000 : 0;
}
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.java
index 434c00e9a..f933a4ec1 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.java
@@ -166,9 +166,12 @@ public final class Messages extends NLS {
public static String IndexInstructions;
public static String IndexButton;
- public static String HelpContentPreferencePage_remote;
public static String NoWorkbenchForExecuteCommand_msg;
+ public static String SearchEmbeddedHelpOnly;
+ public static String SearchEmbeddedHelpFirst;
+ public static String SearchEmbeddedHelpLast;
+
// Remote Help Preferences
public static String AddICDialog_10;
@@ -210,7 +213,8 @@ public final class Messages extends NLS {
public static String HelpContentBlock_testConnectionTitle;
public static String HelpContentBlock_rmvTitle;
public static String HelpContentBlock_rmvLabel;
-
+ public static String HelpContentBlock_upTitle;
+ public static String HelpContentBlock_downTitle;
public static String RemoteICLabelProvider_4;
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.properties b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.properties
index 595fa3039..706eb0b02 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.properties
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/Messages.properties
@@ -145,7 +145,9 @@ HelpPreferencePage_helpBrowser = In the help browser
HelpPreferencePage_externalBrowser = In an external browser
HelpPreferencePage_searchLocation = Open help &search
-HelpContentPreferencePage_remote=&Include help content from a remote infocenter
+SearchEmbeddedHelpOnly = Include local help only
+SearchEmbeddedHelpFirst = Include remote help and give local help priority
+SearchEmbeddedHelpLast = Include remote help and give it priority
ScopePreferenceDialog_wtitle = Search Scope - {0}
ScopePreferenceDialog_new=&New...
@@ -183,7 +185,7 @@ IndexButton = Display
NoWorkbenchForExecuteCommand_msg = No workbench available for command execution.
-HelpContentPage_title = Remote Infocenters:
+HelpContentPage_title = Configure Infocenters:
HelpContentBlock_addICTitle = &New
HelpContentBlock_editICTitle = &Edit
HelpContentBlock_removeICTitle = De&lete
@@ -191,6 +193,8 @@ HelpContentBlock_viewICTitle = &View Properties
HelpContentBlock_testConnectionTitle = &Test Connection
HelpContentBlock_rmvTitle=Remove {0} &Infocenter
HelpContentBlock_rmvLabel=Are you sure you want to remove {0}?
+HelpContentBlock_upTitle=&Up
+HelpContentBlock_downTitle=&Down
AddICDialog_2=Add new infocenter
AddICDialog_4=&Name:
AddICDialog_5=&Host:
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentBlock.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentBlock.java
index acf226a82..5dc2f4671 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentBlock.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008, 2009 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
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.help.ui.internal.preferences;
+import java.util.Vector;
+
import org.eclipse.help.internal.base.remote.RemoteIC;
import org.eclipse.help.ui.internal.Messages;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -37,6 +39,8 @@ public class HelpContentBlock {
private Button viewPropertiesButton;
private Button testICConnectionButton;
private Button enableDisableICButton;
+ private Button upButton;
+ private Button downButton;
private IHelpContentBlockContainer container;
private RemoteICViewer remoteICviewer = null;
private int validated = 2;
@@ -57,6 +61,10 @@ public class HelpContentBlock {
testICConnection();
} else if (enableDisableICButton == source) {
enableDisableIC();
+ } else if (upButton == source) {
+ moveICUp();
+ } else if (downButton == source) {
+ moveICDown();
}
}
};
@@ -93,9 +101,16 @@ public class HelpContentBlock {
Messages.HelpContentBlock_3 : Messages.HelpContentBlock_4;
enableDisableICButton = container.createPushButton(parent, enableTitle);
enableDisableICButton.addSelectionListener(selectionListener);
-
+
+ upButton = container.createPushButton(parent,
+ Messages.HelpContentBlock_upTitle);
+ upButton.addSelectionListener(selectionListener);
+
+ downButton = container.createPushButton(parent,
+ Messages.HelpContentBlock_downTitle);
+ downButton.addSelectionListener(selectionListener);
}
-
+
private void viewICProperties() {
// Get selected item
@@ -205,6 +220,9 @@ public class HelpContentBlock {
enableDisableICButton.setText(Messages.HelpContentBlock_3);
enableDisableICButton.setEnabled(true);
+
+ upButton.setEnabled(true);
+ downButton.setEnabled(true);
}
}
@@ -257,6 +275,61 @@ public class HelpContentBlock {
}
/**
+ * Raise the search priority of the selected InfoCenter
+ */
+ public void moveICUp() {
+ // Get selected item
+ RemoteIC remoteic = (RemoteIC) ((IStructuredSelection) remoteICviewer
+ .getSelection()).getFirstElement();
+
+ RemoteIC[] rics = remoteICviewer.getRemoteICList().getRemoteICArray();
+
+ for(int i = 0; i < rics.length; i++) {
+ if(rics[i] == remoteic) {
+ // Move the item as long as it's not already at the top of the list
+ if(i > 0) {
+ remoteic = rics[i - 1];
+ rics[i - 1] = rics[i];
+ rics[i] = remoteic;
+ }
+ }
+ }
+ updateRemoteICs(rics);
+ }
+
+ /**
+ * Lower the search priority of the selected InfoCenter
+ */
+ public void moveICDown() {
+ // Get selected item
+ RemoteIC remoteic = (RemoteIC) ((IStructuredSelection) remoteICviewer
+ .getSelection()).getFirstElement();
+
+ RemoteIC[] rics = remoteICviewer.getRemoteICList().getRemoteICArray();
+
+ for(int i = 0; i < rics.length; i++) {
+ if(rics[i] == remoteic) {
+ // Move the item as long as it's not already at the bottom of the list
+ if(i < (rics.length - 1)) {
+ remoteic = rics[i + 1];
+ rics[i + 1] = rics[i];
+ rics[i] = remoteic;
+ }
+ }
+ }
+ updateRemoteICs(rics);
+ }
+
+ /**
+ * @param rics the ordered ICs
+ */
+ public void updateRemoteICs(RemoteIC[] rics) {
+ Vector v = new Vector();
+ for(int i = 0; i < rics.length; i++) { v.add(rics[i]); }
+ getRemoteICviewer().updateRemoteICList(v);
+ }
+
+ /**
* Creates the group which will contain the buttons.
*/
private void createButtonGroup(Composite top) {
@@ -320,6 +393,10 @@ public class HelpContentBlock {
enableDisableICButton.setEnabled(true);
selectedEntry.setEnabled(false);
}
+
+ upButton.setEnabled(true);
+ downButton.setEnabled(true);
+
} else {
restoreDefaultButtons();
}
@@ -352,14 +429,16 @@ public class HelpContentBlock {
testICConnectionButton.setEnabled(false);
enableDisableICButton.setEnabled(false);
enableDisableICButton.setText(Messages.HelpContentBlock_4);
+ upButton.setEnabled(false);
+ downButton.setEnabled(false);
- //Clear previous table selection
+ // Clear previous table selection
indexSelected = - 1;
}
+
public void disableAllButtons() {
-
addNewICButton.setEnabled(false);
editICButton.setEnabled(false);
removeICButton.setEnabled(false);
@@ -367,7 +446,8 @@ public class HelpContentBlock {
testICConnectionButton.setEnabled(false);
enableDisableICButton.setEnabled(false);
enableDisableICButton.setText(Messages.HelpContentBlock_4);
-
+ upButton.setEnabled(false);
+ downButton.setEnabled(false);
}
public RemoteICViewer getRemoteICviewer()
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentPreferencePage.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentPreferencePage.java
index f4ef90fb2..c17d654ce 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentPreferencePage.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpContentPreferencePage.java
@@ -43,14 +43,15 @@ public class HelpContentPreferencePage extends PreferencePage implements
private InfocenterDisplay remoteICPage;
- private Button checkbox;
+ private Button searchLocalHelpOnly;
+ private Button searchLocalHelpFirst;
+ private Button searchLocalHelpLast;
private Label descLabel;
/**
* Creates the preference page
*/
public HelpContentPreferencePage() {
-
}
/*
@@ -71,18 +72,19 @@ public class HelpContentPreferencePage extends PreferencePage implements
IHelpUIConstants.PREF_PAGE_HELP_CONTENT);
initializeDialogUnits(parent);
-
- createCheckbox(parent);
descLabel = new Label(parent, SWT.NONE);
descLabel.setText(Messages.HelpContentPage_title);
Dialog.applyDialogFont(descLabel);
+ createSearchLocalHelpOnly(parent);
+ createSearchLocalHelpFirst(parent);
+ createSearchLocalHelpLast(parent);
+
remoteICPage = new InfocenterDisplay(this);
remoteICPage.createContents(parent);
-
- initializeTableEnablement(checkbox.getSelection());
+ initializeTableEnablement(searchLocalHelpOnly.getSelection());
return parent;
}
@@ -100,7 +102,9 @@ public class HelpContentPreferencePage extends PreferencePage implements
currentBlock.getRemoteICviewer().getRemoteICList().removeAllRemoteICs(currentBlock.getRemoteICList());
currentBlock.getRemoteICviewer().getRemoteICList().loadDefaultPreferences();
currentBlock.restoreDefaultButtons();
- checkbox.setSelection(new DefaultPreferenceFileHandler().isRemoteHelpOn());
+ searchLocalHelpOnly.setSelection(!(new DefaultPreferenceFileHandler().isRemoteHelpOn()));
+ searchLocalHelpFirst.setSelection(new DefaultPreferenceFileHandler().isRemoteHelpPreferred());
+ searchLocalHelpLast.setSelection(new DefaultPreferenceFileHandler().isRemoteHelpPreferred());
changeListener.handleEvent(null);
}
@@ -121,7 +125,8 @@ public class HelpContentPreferencePage extends PreferencePage implements
*
* @see org.eclipse.jface.preference.PreferencePage#performOk()
*/
- prefs.putBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, checkbox.getSelection());
+ prefs.putBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, !(searchLocalHelpOnly.getSelection()));
+ prefs.putBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, searchLocalHelpLast.getSelection());
currentBlock=remoteICPage.getHelpContentBlock();
currentRemoteICArray=currentBlock.getRemoteICList();
@@ -141,33 +146,62 @@ public class HelpContentPreferencePage extends PreferencePage implements
return super.setButtonLayoutData(button);
}
- private void createCheckbox(Composite parent) {
- checkbox = new Button(parent, SWT.CHECK);
- checkbox.setText(Messages.HelpContentPreferencePage_remote);
- checkbox.addListener(SWT.Selection, changeListener);
+ private void createSearchLocalHelpOnly(Composite parent) {
+ searchLocalHelpOnly = new Button(parent, SWT.RADIO);
+ searchLocalHelpOnly.setText(Messages.SearchEmbeddedHelpOnly);
+ searchLocalHelpOnly.addListener(SWT.Selection, changeListener);
- boolean isOn = Platform.getPreferencesService().getBoolean
+ boolean isRemoteOn = Platform.getPreferencesService().getBoolean
(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false, null);
- checkbox.setSelection(isOn);
- Dialog.applyDialogFont(checkbox);
+
+ searchLocalHelpOnly.setSelection(!isRemoteOn);
+ Dialog.applyDialogFont(searchLocalHelpOnly);
+ }
+
+ private void createSearchLocalHelpFirst(Composite parent) {
+ searchLocalHelpFirst = new Button(parent, SWT.RADIO);
+ searchLocalHelpFirst.setText(Messages.SearchEmbeddedHelpFirst);
+ searchLocalHelpFirst.addListener(SWT.Selection, changeListener);
+
+ boolean isRemoteOn = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false, null);
+ boolean isRemotePreferred = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, false, null);
+
+ searchLocalHelpFirst.setSelection(isRemoteOn && !isRemotePreferred);
+ Dialog.applyDialogFont(searchLocalHelpFirst);
+ }
+
+ private void createSearchLocalHelpLast(Composite parent) {
+ searchLocalHelpLast = new Button(parent, SWT.RADIO);
+ searchLocalHelpLast.setText(Messages.SearchEmbeddedHelpLast);
+ searchLocalHelpLast.addListener(SWT.Selection, changeListener);
+
+ boolean isRemoteOn = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false, null);
+ boolean isRemotePreferred = Platform.getPreferencesService().getBoolean
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, false, null);
+
+ searchLocalHelpLast.setSelection(isRemoteOn && isRemotePreferred);
+ Dialog.applyDialogFont(searchLocalHelpLast);
}
/*
* Initialize the table enablement with the current checkbox selection
*/
- private void initializeTableEnablement(boolean isRemoteHelpEnabled)
+ private void initializeTableEnablement(boolean isRemoteHelpDisabled)
{
HelpContentBlock currentBlock=remoteICPage.getHelpContentBlock();
- if(isRemoteHelpEnabled)
- currentBlock.restoreDefaultButtons();
- else
+ if(isRemoteHelpDisabled)
currentBlock.disableAllButtons();
+ else
+ currentBlock.restoreDefaultButtons();
// Disable/Enable table
- currentBlock.getRemoteICviewer().getTable().setEnabled(isRemoteHelpEnabled);
+ currentBlock.getRemoteICviewer().getTable().setEnabled(!isRemoteHelpDisabled);
}
/*
@@ -179,19 +213,17 @@ public class HelpContentPreferencePage extends PreferencePage implements
HelpContentBlock currentBlock=remoteICPage.getHelpContentBlock();
- boolean isRemoteHelpEnabled=checkbox.getSelection();
+ boolean isRemoteHelpEnabled = !(searchLocalHelpOnly.getSelection());
// Disable/Enable buttons
if(isRemoteHelpEnabled)
currentBlock.restoreDefaultButtons();
else
currentBlock.disableAllButtons();
-
+
// Disable/Enable table
currentBlock.getRemoteICviewer().getTable().setEnabled(isRemoteHelpEnabled);
-
-
-
}
+
};
-
+
}
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICList.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICList.java
index 3c1d9fe6f..b5d03b1ec 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICList.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICList.java
@@ -113,6 +113,13 @@ public class RemoteICList {
}
/**
+ * @param rics the new set of remote ICs
+ */
+ public void setRemoteICs(Vector rics) {
+ remote_ics = rics;
+ }
+
+ /**
* Return the remote IC at the given index in the table
*/
public RemoteIC getRemoteICAtIndex(int index)
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICViewer.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICViewer.java
index 79203f586..fffa0dc97 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICViewer.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/RemoteICViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008, 2009 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
@@ -11,6 +11,7 @@
package org.eclipse.help.ui.internal.preferences;
import java.util.Arrays;
+import java.util.Vector;
import org.eclipse.help.internal.base.remote.RemoteIC;
import org.eclipse.help.ui.internal.Messages;
@@ -174,6 +175,21 @@ public class RemoteICViewer {
}
/**
+ * @param rics the ordered remote InfoCenters
+ */
+ public void updateRemoteICList(Vector rics) {
+ getRemoteICList().setRemoteICs(rics);
+ updateView();
+ }
+
+ /**
+ * Make sure the table viewer shows the latest copy of the ordered InfoCenters
+ */
+ public void updateView() {
+ getTableViewer().refresh(getRemoteICList());
+ }
+
+ /**
* Return the column names in a collection
*
* @return List containing column names
@@ -188,7 +204,7 @@ public class RemoteICViewer {
public ISelection getSelection() {
return tableViewer.getSelection();
}
-
+
/**
* Return the RemoteICList
*/
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
index 34f58aa24..3f28e0577 100644
--- a/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -20,7 +20,7 @@ import org.eclipse.help.internal.HelpPlugin;
* @since 3.3
*/
public abstract class AbstractTocProvider {
-
+
/**
* Returns all toc contributions for this provider. Providers
* are free to provide any number of contributions (zero or more).
@@ -39,4 +39,27 @@ public abstract class AbstractTocProvider {
// will force a reload next time around
HelpPlugin.getTocManager().clearCache();
}
+
+ /**
+ * Default priority for toc providers that do not override getPriority()
+ * @since 3.5
+ */
+ public static final int DEFAULT_PRIORITY=10;
+
+ /**
+ * Priority for toc files read from the local file system
+ * @since 3.5
+ */
+ public static final int TOC_FILE_PRIORITY=20;
+
+ /**
+ * If two toc contributions have the same id, the one with higher priority will be shown.
+ * For example, a provider with priority 1 will take precedence over a provider with priority 2.
+ * @return the priority of this provider
+ * @since 3.5
+ */
+ public int getPriority()
+ {
+ return DEFAULT_PRIORITY;
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
index b05c6760d..b4e13feca 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
@@ -87,4 +87,11 @@ public class TocFileProvider extends AbstractTocProvider {
}
return (TocFile[])tocFiles.toArray(new TocFile[tocFiles.size()]);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.AbstractTocProvider#getPriority()
+ */
+ public int getPriority() {
+ return TOC_FILE_PRIORITY;
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
index 56f7fac27..f911f2a94 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
@@ -13,6 +13,7 @@ package org.eclipse.help.internal.toc;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -201,7 +202,7 @@ public class TocManager {
private synchronized TocContribution[] getAndCacheTocContributions(String locale, Map contributionsByLocale) {
TocContribution[] cached = (TocContribution[])contributionsByLocale.get(locale);
if (cached == null) {
- List contributions = new ArrayList();
+ HashMap contributions = new HashMap();
AbstractTocProvider[] providers = getTocProviders();
for (int i=0;i<providers.length;++i) {
ITocContribution[] contrib;
@@ -219,7 +220,8 @@ public class TocManager {
Toc t = toc instanceof Toc ? (Toc)toc : (Toc)UAElementFactory.newElement(toc);
t.setLinkTo(contrib[j].getLinkTo());
contribution.setToc(t);
- contributions.add(contribution);
+ if(!contributions.containsKey(contrib[j].getId()))
+ contributions.put(contrib[j].getId(), contribution);
}
}
catch (Throwable t) {
@@ -230,7 +232,7 @@ public class TocManager {
}
}
- cached = (TocContribution[])contributions.toArray(new TocContribution[contributions.size()]);
+ cached = (TocContribution[])contributions.values().toArray(new TocContribution[contributions.size()]);
contributionsByLocale.put(locale, cached);
}
return cached;
@@ -246,6 +248,7 @@ public class TocManager {
tocsByLocale.clear();
tocsById.clear();
tocsByTopic = null;
+ tocProviders=null;
}
/*
@@ -270,6 +273,7 @@ public class TocManager {
}
}
}
+ Collections.sort(providers, new TocProviderComparator());
tocProviders = (AbstractTocProvider[])providers.toArray(new AbstractTocProvider[providers.size()]);
}
return tocProviders;
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java
new file mode 100644
index 000000000..9b1eeca42
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.help.internal.toc;
+
+import java.util.Comparator;
+
+import org.eclipse.help.AbstractTocProvider;
+
+
+public class TocProviderComparator implements Comparator{
+
+ public int compare(Object obj1,Object obj2)
+ {
+ AbstractTocProvider provider1 = (AbstractTocProvider)obj1;
+ AbstractTocProvider provider2 = (AbstractTocProvider)obj2;
+
+ if(provider1.getPriority()<provider2.getPriority())
+ return -1;
+ else if(provider1.getPriority()>provider2.getPriority())
+ return 1;
+ else
+ return 0;
+ }
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
index f78b669ba..1a56646d7 100755
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
@@ -40,5 +40,6 @@ public class AllRemoteTests extends TestSuite {
addTestSuite(LoadIndexUsingRemoteHelp.class);
addTestSuite(GetContentUsingRemoteHelp.class);
addTestSuite(GetContextUsingRemoteHelp.class);
+ addTestSuite(TocManagerTest.class);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java
index d70c5e9f8..6f940ff8a 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java
@@ -50,30 +50,97 @@ public class GetContentUsingRemoteHelp extends TestCase {
public void testContentFound() throws Exception {
final String path = "/data/help/index/topic1.html";
String remoteContent = getHelpContent("mock.toc", path, "en");
- String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "en");
+ int port = TestServerManager.getPort(0);
+ String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "en", port);
assertEquals(expectedContent, remoteContent);
}
public void testContentFoundDe() throws Exception {
final String path = "/data/help/index/topic2.html";
String remoteContent = getHelpContent("mock.toc", path, "de");
- String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "de");
+ int port = TestServerManager.getPort(0);
+ String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "de", port);
assertEquals(expectedContent, remoteContent);
}
-
+
public void testLocalBeatsRemote() throws Exception {
final String path = "/doc/help_home.html";
String plugin = "org.eclipse.help.base";
- String remoteContent = getHelpContent(plugin, path, "en");
+ String helpContent = getHelpContent(plugin, path, "en");
String localContent = RemoteTestUtils.getLocalContent(plugin, path);
- assertEquals(localContent, remoteContent);
+ assertEquals(localContent, helpContent);
+ }
+
+ public void testRemoteHelpPreferredPreference() throws Exception {
+ RemotePreferenceStore.setMockRemotePriority();
+ HelpPlugin.getTocManager().clearCache();
+ HelpPlugin.getTocManager().getTocs("en");
+ final String path = "/doc/help_home.html";
+ String plugin = "org.eclipse.help.base";
+ String helpContent = getHelpContent(plugin, path, "en");
+
+ int port = TestServerManager.getPort(0);
+ String remoteContent = RemoteTestUtils.createMockContent(plugin, path, "en", port);
+ assertEquals(remoteContent, helpContent);
+ }
+
+ public void testRemoteOrdering() throws Exception {
+ RemotePreferenceStore.setTwoMockRemoteServers();
+ RemotePreferenceStore.setMockRemotePriority();
+ HelpPlugin.getTocManager().clearCache();
+ HelpPlugin.getTocManager().getTocs("en");
+ //Verify help coming from first one
+ final String path = "/doc/help_home.html";
+ String plugin = "org.eclipse.help.base";
+ String helpContent = GetContentUsingRemoteHelp.getHelpContent(plugin, path, "en");
+
+ //Get remote content from first one in prefs
+
+ int port0 = TestServerManager.getPort(0);
+ String remoteContent0 = RemoteTestUtils.createMockContent(plugin, path, "en", port0);
+
+ int port1 = TestServerManager.getPort(1);
+ String remoteContent1 = RemoteTestUtils.createMockContent(plugin, path, "en", port1);
+
+ assertEquals(remoteContent0, helpContent);
+ assertFalse(remoteContent1.equals(helpContent));
+
}
+
+ public void testRemoteOrderingReversed() throws Exception {
+ RemotePreferenceStore.setTwoMockRemoteServersReversePriority();
+ RemotePreferenceStore.setMockRemotePriority();
+ HelpPlugin.getTocManager().clearCache();
+ HelpPlugin.getTocManager().getTocs("en");
+ //Verify help coming from first one
+ final String path = "/doc/help_home.html";
+ String plugin = "org.eclipse.help.base";
+ String helpContent = GetContentUsingRemoteHelp.getHelpContent(plugin, path, "en");
+
+ //Get remote content from second in prefs
+
+ int port0 = TestServerManager.getPort(0);
+ String remoteContent0 = RemoteTestUtils.createMockContent(plugin, path, "en", port0);
+
+ int port1 = TestServerManager.getPort(1);
+ String remoteContent1 = RemoteTestUtils.createMockContent(plugin, path, "en", port1);
+
+
+ assertEquals(remoteContent1, helpContent);
+ assertFalse(remoteContent0.equals(helpContent));
+ }
+
+
public void testRemoteUsedIfLocalUnavaliable() throws Exception {
- final String path = "/data/help/nonlocal.html";
+ RemotePreferenceStore.setMockRemoteServer();
+ HelpPlugin.getTocManager().clearCache();
+ HelpPlugin.getTocManager().getTocs("en");
+ final String path = "/data/help/nonlocal.html";
String plugin = "org.eclipse.help.base";
- String remoteContent = getHelpContent(plugin, path, "en");
- String expectedContent = RemoteTestUtils.createMockContent(plugin, path, "en");
+ String remoteContent = getHelpContent(plugin, path, "en");
+ int port = TestServerManager.getPort(0);
+ String expectedContent = RemoteTestUtils.createMockContent(plugin, path, "en", port);
assertEquals(expectedContent, remoteContent);
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java
index 11a5353e1..764102076 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java
@@ -63,8 +63,6 @@ public class LoadTocUsingRemoteHelp extends TestCase {
RemotePreferenceStore.disableRemoteHelp();
}
- /*
- * Fails, see Bug 292176
public void testTocContributionFromTwoServers() throws Exception {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
RemotePreferenceStore.setTwoMockRemoteServers();
@@ -76,7 +74,6 @@ public class LoadTocUsingRemoteHelp extends TestCase {
assertEquals(0, deTocs);
RemotePreferenceStore.disableRemoteHelp();
}
- */
/*
* Return the number of tocs with this label
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java
index e1546aa23..63d2d47de 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java
@@ -40,7 +40,8 @@ public class MockContentServlet extends HttpServlet {
if (file.startsWith("/invalid")) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
} else {
- String response = RemoteTestUtils.createMockContent(plugin, file, locale);
+ int port = req.getLocalPort();
+ String response = RemoteTestUtils.createMockContent(plugin, file, locale, port);
resp.getWriter().write(response);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java
index 3c8f859a8..1ec508428 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java
@@ -26,6 +26,7 @@ public class RemotePreferenceStore {
private static String icEnabledPreference;
private static String helpOn;
private static String defaultPort;
+ private static String remoteHelpPreferred;
private static String pageNotFound;
public static void savePreferences() throws Exception {
@@ -50,6 +51,9 @@ public class RemotePreferenceStore {
helpOn = Platform.getPreferencesService().getString
(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON,
"", null);
+ remoteHelpPreferred = Platform.getPreferencesService().getString
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED,
+ "", null);
pageNotFound = Platform.getPreferencesService().getString
(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_PAGE_NOT_FOUND,
"", null);
@@ -65,6 +69,7 @@ public class RemotePreferenceStore {
prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_DEFAULT_PORT, defaultPort);
prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, helpOn);
prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_ICEnabled, icEnabledPreference);
+ prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, remoteHelpPreferred);
prefs.put(IHelpBaseConstants.P_PAGE_NOT_FOUND, pageNotFound);
}
@@ -79,7 +84,7 @@ public class RemotePreferenceStore {
RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true");
RemotePreferenceTest.setPreference("remoteHelpICContributed", "false");
}
-
+
public static void setTwoMockRemoteServers() throws Exception {
TestServerManager.start("ua.test", 0);
TestServerManager.start("ua.test2", 1);
@@ -93,6 +98,19 @@ public class RemotePreferenceStore {
RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true,true");
RemotePreferenceTest.setPreference("remoteHelpICContributed", "false,false");
}
+ public static void setTwoMockRemoteServersReversePriority() throws Exception {
+ TestServerManager.start("ua.test", 0);
+ TestServerManager.start("ua.test2", 1);
+ RemotePreferenceTest.setPreference("remoteHelpOn", "true");
+ RemotePreferenceTest.setPreference("remoteHelpHost", "localhost,localhost");
+ RemotePreferenceTest.setPreference("remoteHelpPath", "/help,/help");
+ RemotePreferenceTest.setPreference("remoteHelpUseDefaultPort", "true,true");
+ RemotePreferenceTest.setPreference("remoteHelpPort", ""
+ + TestServerManager.getPort(1) + ',' + TestServerManager.getPort(0));
+ RemotePreferenceTest.setPreference("remoteHelpName", "uatest,uatest2");
+ RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true,true");
+ RemotePreferenceTest.setPreference("remoteHelpICContributed", "false,false");
+ }
public static void disableRemoteHelp() throws Exception {
RemotePreferenceTest.setPreference("remoteHelpOn", "false");
@@ -102,4 +120,13 @@ public class RemotePreferenceStore {
RemotePreferenceTest.setPreference(IHelpBaseConstants.P_PAGE_NOT_FOUND, "");
}
+ public static void setMockLocalPriority() throws Exception {
+ RemotePreferenceTest.setPreference("remoteHelpOn", "true");
+ RemotePreferenceTest.setPreference("remoteHelpPreferred", "false");
+ }
+
+ public static void setMockRemotePriority() throws Exception {
+ RemotePreferenceTest.setPreference("remoteHelpOn", "true");
+ RemotePreferenceTest.setPreference("remoteHelpPreferred", "true");
+ }
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
index d83e78487..30ac88c73 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
@@ -25,11 +25,11 @@ import org.osgi.framework.Bundle;
public class RemoteTestUtils {
public static String createMockContent(String plugin, String path,
- String locale) {
+ String locale, int port) {
String result = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">"
+ "<HTML lang =\"" + locale + "\"><HEAD>"
+ "<TITLE> Content from: " + plugin + "</TITLE></HEAD>"
- + "<BODY><P>Path is: " + path + "</P></BODY></HTML>";
+ + "<BODY><P>Path is: " + path + ",Port is: "+port+"</P></BODY></HTML>";
return result;
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java
new file mode 100644
index 000000000..3e028c003
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ua.tests.help.remote;
+
+import java.util.HashSet;
+import junit.framework.TestCase;
+
+import org.eclipse.help.AbstractTocProvider;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.base.BaseHelpSystem;
+import org.eclipse.help.internal.base.remote.RemoteTocProvider;
+import org.eclipse.help.internal.toc.TocContribution;
+import org.eclipse.help.internal.toc.TocFileProvider;
+
+public class TocManagerTest extends TestCase {
+
+ private int mode;
+
+ protected void setUp() throws Exception {
+ BaseHelpSystem.ensureWebappRunning();
+ mode = BaseHelpSystem.getMode();
+ RemotePreferenceStore.savePreferences();
+ BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
+ }
+
+ protected void tearDown() throws Exception {
+ BaseHelpSystem.setMode(mode);
+ RemotePreferenceStore.restorePreferences();
+ }
+
+ public void testDuplicatesOneRemote() throws Exception {
+
+ RemotePreferenceStore.setMockRemoteServer();
+ HelpPlugin.getTocManager().clearCache();
+ boolean hasDuplicates=hasDuplicateContributions(HelpPlugin.getTocManager().getTocContributions("en"));
+ assertFalse(hasDuplicates);
+ }
+
+ public void testDuplicatesTwoRemote() throws Exception {
+
+ RemotePreferenceStore.setTwoMockRemoteServers();
+ HelpPlugin.getTocManager().clearCache();
+ boolean hasDuplicates=hasDuplicateContributions(HelpPlugin.getTocManager().getTocContributions("en"));
+ assertFalse(hasDuplicates);
+ }
+
+ public void testLocalProviderPriority() throws Exception {
+
+ int localPriority=0,remotePriority=0;
+ RemotePreferenceStore.setMockRemoteServer();
+ RemotePreferenceStore.setMockLocalPriority();
+ HelpPlugin.getTocManager().clearCache();
+ AbstractTocProvider [] tocProviders = HelpPlugin.getTocManager().getTocProviders();
+ for(int i=0;i<tocProviders.length;i++)
+ {
+ if(tocProviders[i] instanceof TocFileProvider)
+ localPriority = tocProviders[i].getPriority();
+
+ if(tocProviders[i] instanceof RemoteTocProvider)
+ remotePriority = tocProviders[i].getPriority();
+ }
+
+ assertTrue(localPriority<remotePriority);
+ }
+
+ public void testRemoteProviderPriority() throws Exception {
+
+ RemotePreferenceStore.setMockRemoteServer();
+ RemotePreferenceStore.setMockRemotePriority();
+ HelpPlugin.getTocManager().clearCache();
+ int localPriority=0,remotePriority=0;
+
+ AbstractTocProvider [] tocProviders = HelpPlugin.getTocManager().getTocProviders();
+ for(int i=0;i<tocProviders.length;i++)
+ {
+ if(tocProviders[i] instanceof TocFileProvider)
+ localPriority = tocProviders[i].getPriority();
+
+ if(tocProviders[i] instanceof RemoteTocProvider)
+ remotePriority = tocProviders[i].getPriority();
+ }
+
+ assertTrue(remotePriority<localPriority);
+ }
+
+ public static boolean hasDuplicateContributions(TocContribution[] tocContributions)
+ {
+ HashSet contributionsFound = new HashSet();
+
+ for(int i=0;i<tocContributions.length;i++)
+ {
+ if(contributionsFound.contains(tocContributions[i].getId()))
+ return true;
+ else
+ contributionsFound.add(tocContributions[i].getId());
+ }
+
+ return false;
+ }
+}

Back to the top