diff options
author | dgeorgiev | 2013-01-10 16:47:11 +0000 |
---|---|---|
committer | dgeorgiev | 2013-01-10 16:47:11 +0000 |
commit | 41165fdba2fce7d619283f9418c423f9d61f94a1 (patch) | |
tree | f2d796a88cd9e6103040415017a9305d690a6f4b | |
parent | 688b9ef0b97808601f2b431399e84f05f8050552 (diff) | |
download | org.eclipse.e4.search-41165fdba2fce7d619283f9418c423f9d61f94a1.tar.gz org.eclipse.e4.search-41165fdba2fce7d619283f9418c423f9d61f94a1.tar.xz org.eclipse.e4.search-41165fdba2fce7d619283f9418c423f9d61f94a1.zip |
Bug 379377 - last opened preference page is displayedI20130207-2200I20130206-1900I20130206-1000I20130205-2200I20130131-2200I20130130-1900I20130130-1000I20130129-2200I20130124-2200I20130123-1900I20130123-1000I20130122-2200I20130117-2200I20130116-1900I20130116-1000I20130115-2200I20130110-2200
35 files changed, 549 insertions, 208 deletions
diff --git a/bundles/org.eclipse.platform.discovery.core/src/org/eclipse/platform/discovery/core/internal/IDestinationsManager.java b/bundles/org.eclipse.platform.discovery.core/src/org/eclipse/platform/discovery/core/internal/IDestinationsManager.java new file mode 100644 index 0000000..81f9c48 --- /dev/null +++ b/bundles/org.eclipse.platform.discovery.core/src/org/eclipse/platform/discovery/core/internal/IDestinationsManager.java @@ -0,0 +1,15 @@ +package org.eclipse.platform.discovery.core.internal;
+
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription;
+import org.eclipse.swt.widgets.Shell;
+
+public interface IDestinationsManager {
+ /**
+ * Opens a preference dialog to manage destinations. It contains all registered preference pages, and a preference page pre-selected based on the
+ * current destination category selected.<br>
+ * This method can block and must be called in the UI thread.
+ * @param selectedDestCategory can be null
+ * @param searchConfig
+ */
+ public void manageDestinations(Shell parentShell, IDestinationCategoryDescription selectedDestCategory);
+}
diff --git a/bundles/org.eclipse.platform.discovery.core/src/org/eclipse/platform/discovery/core/internal/ISearchConsoleView.java b/bundles/org.eclipse.platform.discovery.core/src/org/eclipse/platform/discovery/core/internal/ISearchConsoleView.java index 08d9e45..31efa14 100644 --- a/bundles/org.eclipse.platform.discovery.core/src/org/eclipse/platform/discovery/core/internal/ISearchConsoleView.java +++ b/bundles/org.eclipse.platform.discovery.core/src/org/eclipse/platform/discovery/core/internal/ISearchConsoleView.java @@ -26,5 +26,7 @@ public interface ISearchConsoleView extends IDiscoveryView<ISearchConsoleControl * Sets the default session ID
* @param sessionId
*/
- public void setDefaultSessionId(final String sessionId);
+ public void setDefaultSessionId(final String sessionId); + + public void setDestinationsManager(final IDestinationsManager destManager);
}
diff --git a/bundles/org.eclipse.platform.discovery.destprefs/META-INF/MANIFEST.MF b/bundles/org.eclipse.platform.discovery.destprefs/META-INF/MANIFEST.MF index 942c52b..c2ed4eb 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.platform.discovery.destprefs/META-INF/MANIFEST.MF @@ -16,4 +16,6 @@ Export-Package: org.eclipse.platform.discovery.destprefs.api, Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.platform.discovery.runtime, - org.eclipse.platform.discovery.util + org.eclipse.platform.discovery.util, + org.eclipse.platform.discovery.core + diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/DestinationsManager.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/DestinationsManager.java new file mode 100644 index 0000000..5fa51a1 --- /dev/null +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/DestinationsManager.java @@ -0,0 +1,79 @@ +package org.eclipse.platform.discovery.destprefs.internal;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.platform.discovery.core.internal.IDestinationsManager;
+import org.eclipse.platform.discovery.destprefs.internal.xpparser.ISearchDestinationsConfiguratorDescription;
+import org.eclipse.platform.discovery.runtime.internal.ISearchProviderConfiguration;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationsProviderDescription;
+import org.eclipse.platform.discovery.runtime.internal.xp.impl.AbstractExtensionPointParser;
+import org.eclipse.swt.widgets.Shell;
+
+public class DestinationsManager implements IDestinationsManager {
+
+ public static final String GENERIC_PREFPAGE_ID = "org.eclipse.platform.discovery.destprefs.preferencepage"; //$NON-NLS-1$
+
+ private final AbstractExtensionPointParser<ISearchDestinationsConfiguratorDescription> destConfigurator;
+ private final ISearchProviderConfiguration searchConfig;
+ private final IPreferenceDialogCreator dialogCreator;
+
+ public DestinationsManager(AbstractExtensionPointParser<ISearchDestinationsConfiguratorDescription> destConfigurator, IPreferenceDialogCreator dialogCreator,
+ ISearchProviderConfiguration searchConfig) {
+ this.destConfigurator = destConfigurator;
+ this.dialogCreator = dialogCreator;
+ this.searchConfig = searchConfig;
+ }
+
+ @Override
+ public void manageDestinations(Shell parentShell, IDestinationCategoryDescription selectedDestCategory) {
+
+ final List<String> prefPageIDs = allPreferencePages();
+ dialogCreator.openPreferenceDialog(parentShell, getPrefPageIdToPreselect(selectedDestCategory), prefPageIDs.toArray(new String[prefPageIDs.size()]));
+
+ }
+
+ private List<String> allPreferencePages() {
+ final List<String> prefPageIDs = new LinkedList<String>();
+ prefPageIDs.add(GENERIC_PREFPAGE_ID);
+ for (IDestinationsProviderDescription provider: searchConfig.getAvailableDestinationProviders()) {
+ if (provider.getPreferencePageId()!=null) {
+ prefPageIDs.add(provider.getPreferencePageId());
+ }
+ }
+ return prefPageIDs;
+ }
+
+ private String getPrefPageIdToPreselect(IDestinationCategoryDescription selectedDestCategory) {
+ if(selectedDestCategory!=null && !hasDestinationsConfigurator(selectedDestCategory)) {
+ String prefPageId = getPrefPageIdFor(selectedDestCategory);
+ if(prefPageId!=null) {
+ return prefPageId;
+ }
+ }
+
+ return GENERIC_PREFPAGE_ID;
+ }
+
+ private String getPrefPageIdFor(IDestinationCategoryDescription selectedDestCategory) {
+ for(IDestinationsProviderDescription destProvider: searchConfig.getDestinationProvidersForCategory(selectedDestCategory)) {
+ if(destProvider.getPreferencePageId()!=null) {
+ return destProvider.getPreferencePageId();
+ }
+ }
+ return null;
+ }
+
+ private boolean hasDestinationsConfigurator(IDestinationCategoryDescription selectedDestCategory) {
+ for(IDestinationsProviderDescription destProvider: searchConfig.getDestinationProvidersForCategory(selectedDestCategory)) {
+ for(ISearchDestinationsConfiguratorDescription desc: destConfigurator.readContributions()) {
+ if(desc.destinationProviderId().equals(destProvider.getId()) && desc.destinationCategoryId().equals(selectedDestCategory.getId())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/IPreferenceDialogCreator.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/IPreferenceDialogCreator.java new file mode 100644 index 0000000..fd96c9b --- /dev/null +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/IPreferenceDialogCreator.java @@ -0,0 +1,13 @@ +package org.eclipse.platform.discovery.destprefs.internal;
+
+import org.eclipse.swt.widgets.Shell;
+
+/** To facilitate unit testing, the functionality to open a preference dialog is hidden
+ * behind this interface.
+ **/
+
+public interface IPreferenceDialogCreator {
+
+ public void openPreferenceDialog(Shell parentShell, String preselectedPageId, String[] pageIds);
+
+}
diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/PreferenceDialogCreator.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/PreferenceDialogCreator.java new file mode 100644 index 0000000..5e41870 --- /dev/null +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/PreferenceDialogCreator.java @@ -0,0 +1,16 @@ +package org.eclipse.platform.discovery.destprefs.internal;
+
+import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+
+public class PreferenceDialogCreator implements IPreferenceDialogCreator {
+
+ @Override
+ public void openPreferenceDialog(Shell parentShell, String preselectedPageId, String[] pageIds) {
+ PreferenceDialog prefDialog = PreferencesUtil.createPreferenceDialogOn(parentShell, preselectedPageId, pageIds, null);
+ prefDialog.getTreeViewer().expandAll();
+ prefDialog.open();
+ }
+
+}
diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/i18n/DestPrefsMessages.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/i18n/DestPrefsMessages.java index 50099ae..b4de5dc 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/i18n/DestPrefsMessages.java +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/i18n/DestPrefsMessages.java @@ -13,7 +13,7 @@ package org.eclipse.platform.discovery.destprefs.internal.i18n; import org.eclipse.osgi.util.NLS; public class DestPrefsMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.platform.discovery.destprefs.internal.i18n.DestPrefsMessages"; + private static final String BUNDLE_NAME = "org.eclipse.platform.discovery.destprefs.internal.i18n.DestPrefsMessages"; //$NON-NLS-1$ static { NLS.initializeMessages(BUNDLE_NAME, DestPrefsMessages.class); } diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java index e51ad4e..0d06d14 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java @@ -54,7 +54,7 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat return provider;
}
}
- throw new RuntimeException("cannot find dest provider:"+destinationProviderId);
+ throw new RuntimeException("cannot find dest provider:"+destinationProviderId); //$NON-NLS-1$
}
private IDestinationCategoryDescription findCategory(String destinationCategoryId) {
@@ -63,7 +63,7 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat return category;
}
}
- throw new RuntimeException("cannot find dest category:"+destinationCategoryId);
+ throw new RuntimeException("cannot find dest category:"+destinationCategoryId); //$NON-NLS-1$
}
@Override
@@ -88,7 +88,7 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat @Override
public void addDestination() {
- ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId");
+ ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId"); //$NON-NLS-1$
ISearchDestinationConfigurator<?> configurator = getConfigDescription(destinationProviderId).createConfigurator();
IStatus result = configurator.createDestination(view.getShell());
updateView(result);
@@ -107,13 +107,13 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat return desc;
}
}
- throw new RuntimeException("cannot find destination configurator for dest provider id:"+destinationProviderId);
+ throw new RuntimeException("cannot find destination configurator for dest provider id:"+destinationProviderId); //$NON-NLS-1$
}
@Override
public <T extends ISearchDestination> void editDestination() {
- ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId");
- ContractChecker.nullCheckField(destination, "destination");
+ ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId"); //$NON-NLS-1$
+ ContractChecker.nullCheckField(destination, "destination"); //$NON-NLS-1$
ISearchDestinationConfigurator<T> configurator = getConfigDescription(destinationProviderId).createConfigurator();
@SuppressWarnings("unchecked") IStatus result = configurator.editDestination(view.getShell(), (T)destination);
@@ -123,8 +123,8 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat @Override
public <T extends ISearchDestination> void removeDestination() {
- ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId");
- ContractChecker.nullCheckField(destination, "destination");
+ ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId"); //$NON-NLS-1$
+ ContractChecker.nullCheckField(destination, "destination"); //$NON-NLS-1$
ISearchDestinationConfigurator<T> configurator = getConfigDescription(destinationProviderId).createConfigurator();
@SuppressWarnings("unchecked") IStatus result = configurator.deleteDestination(view.getShell(), (T)destination);
@@ -134,8 +134,8 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat @SuppressWarnings("unchecked")
@Override
public <T extends ISearchDestination> void testDestination() {
- ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId");
- ContractChecker.nullCheckField(destination, "destination");
+ ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId"); //$NON-NLS-1$
+ ContractChecker.nullCheckField(destination, "destination"); //$NON-NLS-1$
ISearchDestinationTester<T> tester = (ISearchDestinationTester<T>) getConfigDescription(destinationProviderId).createConfigurator().getSearchDestinationTester();
IStatus result = tester.test(view.getShell(), (T)destination);
view.setStatus(result);
diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsLabelProvider.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsLabelProvider.java index 17c5aa4..70f0461 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsLabelProvider.java +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsLabelProvider.java @@ -32,7 +32,7 @@ public class DestinationsLabelProvider extends StyledCellLabelProvider { private StyledString getCategoryNodeText(CategoryNode category) { StyledString styledString = new StyledString(category.getDisplayName()); - styledString.append(" (" + category.getDestinationsCount() + ")", StyledString.COUNTER_STYLER); + styledString.append(" (" + category.getDestinationsCount() + ")", StyledString.COUNTER_STYLER); //$NON-NLS-1$ //$NON-NLS-2$ return styledString; } } diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java index 2cf89a1..264d061 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java @@ -55,7 +55,8 @@ public class DestinationsPreferencePage extends PreferencePage implements IWorkb } public DestinationsPreferencePage() { - this(new DestinationConfiguratorsPresenter(new SearchDestinationsConfiguratorXPParser(Platform.getExtensionRegistry()), SearchProviderConfigurationFactory.getDefault())); + this(new DestinationConfiguratorsPresenter(new SearchDestinationsConfiguratorXPParser(Platform.getExtensionRegistry()), + new SearchProviderConfigurationFactory().getSearchProviderConfiguration(Platform.getExtensionRegistry()))); } @Override @@ -124,7 +125,7 @@ public class DestinationsPreferencePage extends PreferencePage implements IWorkb presenter.selectionChanged(new DestinationConfiguratorSelection(destNode.getParentNode().getDestinationProviderId(), destNode.getDestination())); return; } - throw new IllegalArgumentException("Unsupported element: " + selectedElement); + throw new IllegalArgumentException("Unsupported element: " + selectedElement); //$NON-NLS-1$ } }; } diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/xpparser/SearchDestinationsConfiguratorXPParser.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/xpparser/SearchDestinationsConfiguratorXPParser.java index a46f985..e36a46f 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/xpparser/SearchDestinationsConfiguratorXPParser.java +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/xpparser/SearchDestinationsConfiguratorXPParser.java @@ -24,11 +24,11 @@ import org.eclipse.platform.discovery.runtime.internal.xp.impl.AbstractExtension public class SearchDestinationsConfiguratorXPParser extends AbstractExtensionPointParser<ISearchDestinationsConfiguratorDescription> implements ISearchDestinationsConfiguratorXPParser { - public static final String XP_ID = "org.eclipse.platform.discovery.destprefs.configurator"; - public static final String CONFIGURATOR_ELEMENT_NAME = "destinationConfigurator"; - public static final String CONFIGURATOR_ID_ELEMENT_NAME = "id"; - public static final String CONFIGURATOR_DEST_PROVIDER_ID_ELEMENT_NAME = "destProviderId"; - public static final String CONFIGURATOR_FQNAME_ELEMENT_NAME = "contributorClass"; + public static final String XP_ID = "org.eclipse.platform.discovery.destprefs.configurator"; //$NON-NLS-1$ + public static final String CONFIGURATOR_ELEMENT_NAME = "destinationConfigurator"; //$NON-NLS-1$ + public static final String CONFIGURATOR_ID_ELEMENT_NAME = "id"; //$NON-NLS-1$ + public static final String CONFIGURATOR_DEST_PROVIDER_ID_ELEMENT_NAME = "destProviderId"; //$NON-NLS-1$ + public static final String CONFIGURATOR_FQNAME_ELEMENT_NAME = "contributorClass"; //$NON-NLS-1$ public SearchDestinationsConfiguratorXPParser(final IExtensionRegistry extRegistry) { super(extRegistry, XP_ID, CONFIGURATOR_ELEMENT_NAME); @@ -49,7 +49,8 @@ public class SearchDestinationsConfiguratorXPParser extends AbstractExtensionPoi return destCategoryId; } - @Override + @SuppressWarnings("unchecked") + @Override public ISearchDestinationConfigurator<?> createConfigurator() { try { return (ISearchDestinationConfigurator<?>) element.createExecutableExtension(CONFIGURATOR_FQNAME_ELEMENT_NAME); @@ -68,7 +69,7 @@ public class SearchDestinationsConfiguratorXPParser extends AbstractExtensionPoi return destCategory.getId(); } } - throw new IllegalArgumentException("Could not find destination category for destination provider " + destProviderId); + throw new IllegalArgumentException("Could not find destination category for destination provider " + destProviderId); //$NON-NLS-1$ } private IDestinationsProviderDescription getDestinationProvider(IDestinationCategoryDescription destCategory, final String destProviderId) { @@ -81,6 +82,6 @@ public class SearchDestinationsConfiguratorXPParser extends AbstractExtensionPoi } protected ISearchProviderConfiguration searchProviderConfiguration() { - return SearchProviderConfigurationFactory.getDefault(); + return new SearchProviderConfigurationFactory().getSearchProviderConfiguration(extRegistry); } } diff --git a/bundles/org.eclipse.platform.discovery.integration/META-INF/MANIFEST.MF b/bundles/org.eclipse.platform.discovery.integration/META-INF/MANIFEST.MF index 32dd5c3..f2f5804 100644 --- a/bundles/org.eclipse.platform.discovery.integration/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.platform.discovery.integration/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.platform.discovery.runtime,
org.eclipse.ui.views,
org.eclipse.ui.views.properties.tabbed,
- org.eclipse.platform.discovery.util
+ org.eclipse.platform.discovery.util,
+ org.eclipse.platform.discovery.destprefs
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.platform.discovery.integration/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPlugin.java b/bundles/org.eclipse.platform.discovery.integration/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPlugin.java index 6f6b5f3..da7b429 100644 --- a/bundles/org.eclipse.platform.discovery.integration/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPlugin.java +++ b/bundles/org.eclipse.platform.discovery.integration/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPlugin.java @@ -16,8 +16,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; @@ -40,6 +42,9 @@ import org.eclipse.platform.discovery.core.internal.favorites.SearchFavoritesCon import org.eclipse.platform.discovery.core.internal.favorites.SearchFavoritesController; import org.eclipse.platform.discovery.core.internal.favorites.SearchFavoritesPersistenceUtil; import org.eclipse.platform.discovery.core.internal.favorites.SearchFavoritesPersistenceUtil.IPersistenceContext; +import org.eclipse.platform.discovery.destprefs.internal.DestinationsManager; +import org.eclipse.platform.discovery.destprefs.internal.PreferenceDialogCreator; +import org.eclipse.platform.discovery.destprefs.internal.xpparser.SearchDestinationsConfiguratorXPParser; import org.eclipse.platform.discovery.integration.internal.slavecontrollers.SlaveControllersConfiguration; import org.eclipse.platform.discovery.integration.internal.viewcustomization.ViewCustomizationConfiguration; import org.eclipse.platform.discovery.runtime.api.persistence.DestinationItemPair; @@ -331,7 +336,8 @@ public class DiscoveryIntegrationPlugin extends AbstractUIPlugin implements ISta final Set<IGenericViewCustomization> viewCust = new HashSet<IGenericViewCustomization>(viewCustomizationsConfig().availableSearchConsoleCustomizations());
customizeView(customizableView, masterView, new HashSet<ISlaveController>(slaveControllers), viewCust);
- consoleView.registerController(consoleController);
+ consoleView.registerController(consoleController); + consoleView.setDestinationsManager(new DestinationsManager(new SearchDestinationsConfiguratorXPParser(extensionRegistry()), new PreferenceDialogCreator(), searchProviderConfiguration()));
consoleView.initializationCompleted();
}
else
@@ -525,7 +531,11 @@ public class DiscoveryIntegrationPlugin extends AbstractUIPlugin implements ISta private ISearchProviderConfiguration searchProviderConfiguration()
{
- return SearchProviderConfigurationFactory.getDefault();
+ return new SearchProviderConfigurationFactory().getSearchProviderConfiguration(extensionRegistry());
+ } + + private IExtensionRegistry extensionRegistry() { + return Platform.getExtensionRegistry(); }
private IErrorHandler errorHandler()
diff --git a/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/SearchProviderConfigurationFactory.java b/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/SearchProviderConfigurationFactory.java index 1a17fac..2e931c5 100644 --- a/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/SearchProviderConfigurationFactory.java +++ b/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/SearchProviderConfigurationFactory.java @@ -10,28 +10,18 @@ *******************************************************************************/ package org.eclipse.platform.discovery.runtime.internal;
+import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.platform.discovery.runtime.internal.impl.SearchProviderConfiguration;
import org.eclipse.platform.discovery.runtime.internal.impl.XpParsersFactory;
import org.eclipse.platform.discovery.runtime.internal.search.activation.SearchProviderActivationConfigDummy;
public class SearchProviderConfigurationFactory
-{
- private static ISearchProviderConfiguration config;
+{ - public static ISearchProviderConfiguration getDefault()
+ public ISearchProviderConfiguration getSearchProviderConfiguration(IExtensionRegistry registry)
{
- if (config == null)
- {
- config = createConfig();
- }
-
- return config;
- }
-
- private static ISearchProviderConfiguration createConfig()
- {
- final XpParsersFactory parsersFactory = new XpParsersFactory();
- return new SearchProviderConfiguration(parsersFactory, new SearchProviderActivationConfigDummy(parsersFactory.createSearchProviderParser()), new SubdestinationsActivationConfig(parsersFactory
- .createSubdestinationsParser()));
+ final XpParsersFactory parsersFactory = new XpParsersFactory(registry); + return new SearchProviderConfiguration(parsersFactory, new SearchProviderActivationConfigDummy(parsersFactory.createSearchProviderParser()), new SubdestinationsActivationConfig(parsersFactory + .createSubdestinationsParser())); }
}
diff --git a/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/impl/XpParsersFactory.java b/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/impl/XpParsersFactory.java index 079d56f..72847a4 100644 --- a/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/impl/XpParsersFactory.java +++ b/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/impl/XpParsersFactory.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.platform.discovery.runtime.internal.impl;
+import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; import org.eclipse.platform.discovery.runtime.internal.IXPParsersFactory; import org.eclipse.platform.discovery.runtime.internal.xp.IDestinationCategoryExtensionParser; import org.eclipse.platform.discovery.runtime.internal.xp.IDestinationsProviderExtensionParser; @@ -29,35 +31,43 @@ import org.eclipse.platform.discovery.runtime.internal.xp.impl.SearchSubdestinat *
*/
public class XpParsersFactory implements IXPParsersFactory
-{
+{ + private final IExtensionRegistry extensionRegistry; + + public XpParsersFactory() { + this(Platform.getExtensionRegistry()); + }
+ public XpParsersFactory(IExtensionRegistry extensionRegistry) { + this.extensionRegistry = extensionRegistry; + } @Override
public IDestinationsProviderExtensionParser createDestinationsProviderParser()
{
- return new DestinationsProviderExtensionParser();
+ return new DestinationsProviderExtensionParser(extensionRegistry);
}
@Override public IDestinationCategoryExtensionParser createDestinationsCategoryParser()
{
- return new DestinationsCategoryExtensionParser();
+ return new DestinationsCategoryExtensionParser(extensionRegistry);
}
@Override
public IObjectTypeExtensionParser createObjectTypeParser()
{
- return new ObjectTypeExtensionParser();
+ return new ObjectTypeExtensionParser(extensionRegistry);
}
@Override
public ISearchProvidersExtensionParser createSearchProviderParser()
{
- return new SearchProvidersExtensionParser(createDestinationsCategoryParser(), createObjectTypeParser());
+ return new SearchProvidersExtensionParser(extensionRegistry);
}
@Override
public ISearchSubdestinationExtensionParser createSubdestinationsParser()
{
- return new SearchSubdestinationExtensionParser();
+ return new SearchSubdestinationExtensionParser(extensionRegistry);
}
}
diff --git a/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/xp/impl/AbstractExtensionPointParser.java b/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/xp/impl/AbstractExtensionPointParser.java index 96cdf41..46ef746 100644 --- a/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/xp/impl/AbstractExtensionPointParser.java +++ b/bundles/org.eclipse.platform.discovery.runtime/src/org/eclipse/platform/discovery/runtime/internal/xp/impl/AbstractExtensionPointParser.java @@ -28,7 +28,7 @@ import org.eclipse.platform.discovery.util.internal.logging.Logger; */
public abstract class AbstractExtensionPointParser<T> implements IContributionsReader<T>
{
- private final IExtensionRegistry extRegistry;
+ protected final IExtensionRegistry extRegistry;
private final String xpId;
private final String elementName;
diff --git a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/selector/SearchDestinationsSelector.java b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/selector/SearchDestinationsSelector.java index 841bc67..df70b19 100644 --- a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/selector/SearchDestinationsSelector.java +++ b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/selector/SearchDestinationsSelector.java @@ -17,8 +17,11 @@ import java.util.Set; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.platform.discovery.core.internal.selectors.IItemSelector; import org.eclipse.platform.discovery.runtime.api.IDestinationsProvider; @@ -232,5 +235,29 @@ public abstract class SearchDestinationsSelector implements IItemSelector<ISearc {
// TODO: Maybe take a percentage of screen size!?
return 80;
+ } + + public IDestinationCategoryDescription getActiveDestinationCategory() { + IStructuredSelection selection = lastKnownSelection.get(); + + if(!(selection instanceof TreeSelection)) { + //this means initial empty selection + return null; + } + + TreeSelection treeSelection = (TreeSelection) selection; + + Object selectedElement = treeSelection.getFirstElement(); + if (selectedElement instanceof IDestinationCategoryDescription) { + return (IDestinationCategoryDescription)selectedElement; + } + + if(selectedElement instanceof ISearchDestination) { + TreePath pathToSelected = treeSelection.getPathsFor(selectedElement)[0]; + assert pathToSelected.getFirstSegment() instanceof IDestinationCategoryDescription; + return (IDestinationCategoryDescription) pathToSelected.getFirstSegment() ; + } + + return null; }
}
diff --git a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/ISearchProviderSelector.java b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/ISearchProviderSelector.java index 530c012..76354a6 100644 --- a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/ISearchProviderSelector.java +++ b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/ISearchProviderSelector.java @@ -52,6 +52,8 @@ public interface ISearchProviderSelector extends IGetControlObject<Composite> { public ISearchProviderDescription getSelectedSearchProvider();
+ public IDestinationCategoryDescription getActiveDestinationCategory();
+
public void setObjectTypes(final List<IObjectTypeDescription> objectTypes);
public void setDestinations(List<IDestinationCategoryDescription> categories);
diff --git a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchConsoleView.java b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchConsoleView.java index b79a83f..604accc 100644 --- a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchConsoleView.java +++ b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchConsoleView.java @@ -13,14 +13,14 @@ package org.eclipse.platform.discovery.ui.internal.view; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.core.runtime.Platform; import org.eclipse.platform.discovery.core.api.ISearchContext; import org.eclipse.platform.discovery.core.api.SearchEvent; +import org.eclipse.platform.discovery.core.internal.IDestinationsManager; import org.eclipse.platform.discovery.core.internal.ISearchConsoleView; import org.eclipse.platform.discovery.core.internal.console.ISearchConsoleController; import org.eclipse.platform.discovery.core.internal.console.ISearchConsoleControllerOutputView; @@ -35,7 +35,6 @@ import org.eclipse.platform.discovery.runtime.internal.ISearchProviderConfigurat import org.eclipse.platform.discovery.runtime.internal.ProviderNotFoundException; import org.eclipse.platform.discovery.runtime.internal.SearchProviderConfigurationFactory; import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription; -import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationsProviderDescription; import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IObjectTypeDescription; import org.eclipse.platform.discovery.runtime.internal.model.descriptions.ISearchProviderDescription; import org.eclipse.platform.discovery.ui.api.IGenericViewCustomization; @@ -81,7 +80,6 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.events.IHyperlinkListener; import org.eclipse.ui.forms.widgets.FormToolkit; @@ -112,7 +110,7 @@ public class SearchConsoleView extends AbstractDiscoveryView<ISearchConsoleContr */
public static final int UI_IN_CONTROL_SPACING = 5;
- private ISearchProviderSelector searchProviderSelector; + protected ISearchProviderSelector searchProviderSelector; private IAdvancedSearchParamsDisplayer advancedSearchParamsDisplayer;
private ITabbedSessionDisplayer<ISearchContext> sdm;
@@ -135,7 +133,9 @@ public class SearchConsoleView extends AbstractDiscoveryView<ISearchConsoleContr private ControlBackgroundImageManager upperCompositeGradientManager;
- private ISearchConsoleController controller;
+ private ISearchConsoleController controller; + + private IDestinationsManager destManager;
public SearchConsoleView()
{
@@ -222,7 +222,7 @@ public class SearchConsoleView extends AbstractDiscoveryView<ISearchConsoleContr protected ISearchProviderConfiguration getSearchProviderConfiguration()
{
- return SearchProviderConfigurationFactory.getDefault();
+ return new SearchProviderConfigurationFactory().getSearchProviderConfiguration(Platform.getExtensionRegistry());
}
@Override
@@ -279,21 +279,12 @@ public class SearchConsoleView extends AbstractDiscoveryView<ISearchConsoleContr manageConfigurationHyperlink.setUnderlined(true);
manageConfigurationHyperlink.setCursor(hyperlinkCursor);
- final List<String> prefPageIDs = new LinkedList<String>();
- prefPageIDs.add("org.eclipse.platform.discovery.destprefs.preferencepage");
- for (IDestinationsProviderDescription provider : this.getSearchProviderConfiguration().getAvailableDestinationProviders()) {
- if (provider.getPreferencePageId()!=null) {
- prefPageIDs.add(provider.getPreferencePageId()); - } - }
-
manageConfigurationHyperlink.addHyperlinkListener(new IHyperlinkListener()
{
- public void linkActivated(HyperlinkEvent e) {
- final PreferenceDialog pageDialog = PreferencesUtil.createPreferenceDialogOn(parent.getShell(), null, prefPageIDs.toArray(new String[prefPageIDs.size()]), null);
- pageDialog.getTreeViewer().expandAll();
- pageDialog.open();
- }
+ public void linkActivated(HyperlinkEvent e) { + destManager.manageDestinations(parent.getShell(), searchProviderSelector.getActiveDestinationCategory()); + } +
public void linkEntered(HyperlinkEvent e) {
}
public void linkExited(HyperlinkEvent e) {
@@ -780,5 +771,11 @@ public class SearchConsoleView extends AbstractDiscoveryView<ISearchConsoleContr public ISearchConsoleControllerOutputView getControllerView()
{
return this;
- }
+ } + + @Override + public void setDestinationsManager(IDestinationsManager destManager) { + this.destManager = destManager; + } + }
diff --git a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchProviderSelector.java b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchProviderSelector.java index 73bbdbf..03125ea 100644 --- a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchProviderSelector.java +++ b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/SearchProviderSelector.java @@ -197,4 +197,9 @@ public class SearchProviderSelector implements ISearchProviderSelector { public Composite getControl() {
return this.selectorComposite;
}
+
+ @Override
+ public IDestinationCategoryDescription getActiveDestinationCategory() {
+ return destinationsSelector.getActiveDestinationCategory();
+ }
}
diff --git a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/impl/SearchConsoleDestinationsSelector.java b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/impl/SearchConsoleDestinationsSelector.java index c4b5c1d..57aab11 100644 --- a/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/impl/SearchConsoleDestinationsSelector.java +++ b/bundles/org.eclipse.platform.discovery.ui/src/org/eclipse/platform/discovery/ui/internal/view/impl/SearchConsoleDestinationsSelector.java @@ -131,5 +131,6 @@ public abstract class SearchConsoleDestinationsSelector extends SearchDestinatio }
}
currentDestinationProviders.clear();
- }
+ } + }
diff --git a/tests/org.eclipse.platform.discovery.core.test.unit/src/org/eclipse/platform/discovery/core/test/unit/internal/SearchConsoleControllerFixture.java b/tests/org.eclipse.platform.discovery.core.test.unit/src/org/eclipse/platform/discovery/core/test/unit/internal/SearchConsoleControllerFixture.java index 2344bfd..fc531f8 100644 --- a/tests/org.eclipse.platform.discovery.core.test.unit/src/org/eclipse/platform/discovery/core/test/unit/internal/SearchConsoleControllerFixture.java +++ b/tests/org.eclipse.platform.discovery.core.test.unit/src/org/eclipse/platform/discovery/core/test/unit/internal/SearchConsoleControllerFixture.java @@ -32,7 +32,7 @@ import org.eclipse.platform.discovery.util.internal.session.IHistoryTrack; import org.eclipse.platform.discovery.util.internal.session.ISessionManager; -public class SearchConsoleControllerFixture extends MockObjectTestCase {
+public abstract class SearchConsoleControllerFixture extends MockObjectTestCase {
protected static final String searchSessionId = "searchSessionId";
protected static final String defaultSessionId = "defaultSessionId";
diff --git a/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/DestinationsManagerTest.java b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/DestinationsManagerTest.java new file mode 100644 index 0000000..7d0766e --- /dev/null +++ b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/DestinationsManagerTest.java @@ -0,0 +1,174 @@ +package org.eclipse.platform.discovery.destprefs.test.unit;
+
+import static org.eclipse.platform.discovery.testutils.utils.matchers.Matchers.arrayEqualsWithoutOrder;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.verify;
+
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.platform.discovery.destprefs.internal.DestinationsManager;
+import org.eclipse.platform.discovery.destprefs.internal.IPreferenceDialogCreator;
+import org.eclipse.platform.discovery.destprefs.internal.xpparser.ISearchDestinationsConfiguratorDescription;
+import org.eclipse.platform.discovery.destprefs.internal.xpparser.SearchDestinationsConfiguratorXPParser;
+import org.eclipse.platform.discovery.runtime.internal.ISearchProviderConfiguration;
+import org.eclipse.platform.discovery.runtime.internal.SearchProviderConfigurationFactory;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription;
+import org.eclipse.platform.discovery.runtime.internal.xp.impl.AbstractExtensionPointParser;
+import org.eclipse.platform.discovery.testutils.utils.registry.ExtensionRegistryBuilder;
+import org.eclipse.swt.widgets.Shell;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class DestinationsManagerTest {
+
+ private static final String PREFPAGE_ID = "prefpage_id";
+ private static final String DEST_CATEGORY_ID = "category";
+
+ private DestinationsManager destinationsManager;
+
+ @Mock
+ private AbstractExtensionPointParser<ISearchDestinationsConfiguratorDescription> destConfigurator;
+
+ @Mock
+ private IPreferenceDialogCreator preferenceDialogCreator;
+ @Mock
+ private Shell shell;
+
+ private ExtensionRegistryBuilder registryBuilder;
+
+ private ISearchProviderConfiguration searchConfig;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ registryBuilder = new ExtensionRegistryBuilder();
+ }
+
+ @Test
+ public void noPreferencePages() {
+
+ IExtensionRegistry registry = registryBuilder.getRegistry();
+ init(registry);
+
+ destinationsManager.manageDestinations(shell, null);
+
+ verify(preferenceDialogCreator).openPreferenceDialog(same(shell), eq(DestinationsManager.GENERIC_PREFPAGE_ID), argThat(arrayEqualsWithoutOrder(DestinationsManager.GENERIC_PREFPAGE_ID)));
+ }
+
+ @Test
+ public void onePreferencePageNoSelection() {
+
+ registryBuilder.addDestinationCategory(DEST_CATEGORY_ID, DEST_CATEGORY_ID);
+ registryBuilder.addDestinationsProvider("destprovider", DEST_CATEGORY_ID, PREFPAGE_ID, "foo", null);
+
+ IExtensionRegistry registry = registryBuilder.getRegistry();
+ init(registry);
+
+ destinationsManager.manageDestinations(shell, null);
+
+ verify(preferenceDialogCreator).openPreferenceDialog(same(shell), eq(DestinationsManager.GENERIC_PREFPAGE_ID), argThat(arrayEqualsWithoutOrder(DestinationsManager.GENERIC_PREFPAGE_ID, PREFPAGE_ID)));
+ }
+
+ @Test
+ public void onePreferencePageAndDestCategorySelected() {
+ registryBuilder.addDestinationCategory(DEST_CATEGORY_ID, DEST_CATEGORY_ID);
+ registryBuilder.addDestinationsProvider("destprovider", DEST_CATEGORY_ID, PREFPAGE_ID, "foo", null);
+
+ IExtensionRegistry registry = registryBuilder.getRegistry();
+ init(registry);
+
+ IDestinationCategoryDescription category = getCategory(DEST_CATEGORY_ID);
+
+ destinationsManager.manageDestinations(shell, category);
+
+ verify(preferenceDialogCreator).openPreferenceDialog(same(shell), eq(PREFPAGE_ID), argThat(arrayEqualsWithoutOrder(DestinationsManager.GENERIC_PREFPAGE_ID, PREFPAGE_ID)));
+
+ }
+
+ @Test
+ public void oneDestinationNoPreferencePageAndDestCategorySelected() {
+ registryBuilder.addDestinationCategory(DEST_CATEGORY_ID, DEST_CATEGORY_ID);
+ registryBuilder.addDestinationsProvider("destprovider", DEST_CATEGORY_ID, null, "foo", null);
+
+ IExtensionRegistry registry = registryBuilder.getRegistry();
+ init(registry);
+
+ IDestinationCategoryDescription category = getCategory(DEST_CATEGORY_ID);
+
+ destinationsManager.manageDestinations(shell, category);
+
+ verify(preferenceDialogCreator).openPreferenceDialog(same(shell), eq(DestinationsManager.GENERIC_PREFPAGE_ID), argThat(arrayEqualsWithoutOrder(DestinationsManager.GENERIC_PREFPAGE_ID)));
+
+ }
+
+ @Test
+ public void oneConfiguratorNoSelection() {
+
+ registryBuilder.addDestinationCategory(DEST_CATEGORY_ID, DEST_CATEGORY_ID);
+ registryBuilder.addDestinationsProvider("destprovider", DEST_CATEGORY_ID, null, "foo", null);
+ registryBuilder.addSearchDestinationsConfigurator("configurator", "destprovider", "bar", null);
+
+ IExtensionRegistry registry = registryBuilder.getRegistry();
+ init(registry);
+
+ destinationsManager.manageDestinations(shell, null);
+
+ verify(preferenceDialogCreator).openPreferenceDialog(same(shell), eq(DestinationsManager.GENERIC_PREFPAGE_ID), argThat(arrayEqualsWithoutOrder(DestinationsManager.GENERIC_PREFPAGE_ID)));
+ }
+
+ @Test
+ public void oneConfiguratorAndDestCategorySelected() {
+
+ registryBuilder.addDestinationCategory(DEST_CATEGORY_ID, DEST_CATEGORY_ID);
+ registryBuilder.addDestinationsProvider("destprovider", DEST_CATEGORY_ID, null, "foo", null);
+ registryBuilder.addSearchDestinationsConfigurator("configurator", "destprovider", "bar", null);
+
+ IExtensionRegistry registry = registryBuilder.getRegistry();
+ init(registry);
+
+ IDestinationCategoryDescription category = getCategory(DEST_CATEGORY_ID);
+
+ destinationsManager.manageDestinations(shell, category);
+
+ verify(preferenceDialogCreator).openPreferenceDialog(same(shell), eq(DestinationsManager.GENERIC_PREFPAGE_ID), argThat(arrayEqualsWithoutOrder(DestinationsManager.GENERIC_PREFPAGE_ID)));
+ }
+
+ @Test
+ public void configuratorTakesPrecedenceOverPrefPage() {
+
+ registryBuilder.addDestinationCategory(DEST_CATEGORY_ID, DEST_CATEGORY_ID);
+ registryBuilder.addDestinationsProvider("destprovider", DEST_CATEGORY_ID, PREFPAGE_ID, "foo", null);
+ registryBuilder.addSearchDestinationsConfigurator("configurator", "destprovider", "bar", null);
+
+ IExtensionRegistry registry = registryBuilder.getRegistry();
+ init(registry);
+
+ IDestinationCategoryDescription category = getCategory(DEST_CATEGORY_ID);
+
+ destinationsManager.manageDestinations(shell, category);
+
+ verify(preferenceDialogCreator).openPreferenceDialog(same(shell), eq(DestinationsManager.GENERIC_PREFPAGE_ID), argThat(arrayEqualsWithoutOrder(DestinationsManager.GENERIC_PREFPAGE_ID,PREFPAGE_ID)));
+ }
+
+
+
+ private IDestinationCategoryDescription getCategory(String destCategoryId) {
+ for(IDestinationCategoryDescription desc: searchConfig.getDestinationCategories()) {
+ if(desc.getId().equals(destCategoryId)) {
+ return desc;
+ }
+ }
+
+ fail("dest category not found:"+destCategoryId);return null;
+ }
+
+ private void init(IExtensionRegistry registry) {
+ searchConfig = new SearchProviderConfigurationFactory().getSearchProviderConfiguration(registry);
+ destinationsManager = new DestinationsManager(new SearchDestinationsConfiguratorXPParser(registry), preferenceDialogCreator, searchConfig);
+
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/SearchConfiguratorsFixture.java b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/SearchConfiguratorsFixture.java index 70e49af..efeb716 100644 --- a/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/SearchConfiguratorsFixture.java +++ b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/SearchConfiguratorsFixture.java @@ -15,7 +15,6 @@ import java.util.HashSet; import java.util.List;
import java.util.Set;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.platform.discovery.destprefs.api.ISearchDestinationConfigurator;
import org.eclipse.platform.discovery.runtime.api.IDestinationsProvider;
import org.eclipse.platform.discovery.runtime.api.ISearchDestination;
@@ -65,7 +64,7 @@ public class SearchConfiguratorsFixture { public void setup(ExtensionRegistryBuilder registryBuilder) {
MockitoAnnotations.initMocks(this);
setupSearchProviderConfiguration();
-
+
setupDestProvider();
registryBuilder.addDestinationCategory(CATEGORY_1, CATEGORY_1);
@@ -77,13 +76,9 @@ public class SearchConfiguratorsFixture { .addDestinationsProvider(DEST_PROVIDER_CAT1_2, CATEGORY_1, null, "someprovider_1_2", destprovider1);
registryBuilder.addDestinationsProvider(DEST_PROVIDER_CAT2, CATEGORY_2, null, "someprovider2", destprovider1);
- try {
- registryBuilder.addSearchDestinationsConfigurator(CONFIGURATOR_1_1_ID, DEST_PROVIDER_CAT1_1, CONFIGURATOR_1_1_FQNAME, configurator_1_1);
- registryBuilder.addSearchDestinationsConfigurator(CONFIGURATOR_1_2_ID, DEST_PROVIDER_CAT1_2, CONFIGURATOR_1_2_FQNAME, configurator_1_2);
- registryBuilder.addSearchDestinationsConfigurator(CONFIGURATOR_2_ID, DEST_PROVIDER_CAT2, CONFIGURATOR_2_FQNAME, configurator_2);
- } catch (CoreException e) {
- throw new IllegalStateException(e);
- }
+ registryBuilder.addSearchDestinationsConfigurator(CONFIGURATOR_1_1_ID, DEST_PROVIDER_CAT1_1, CONFIGURATOR_1_1_FQNAME, configurator_1_1);
+ registryBuilder.addSearchDestinationsConfigurator(CONFIGURATOR_1_2_ID, DEST_PROVIDER_CAT1_2, CONFIGURATOR_1_2_FQNAME, configurator_1_2);
+ registryBuilder.addSearchDestinationsConfigurator(CONFIGURATOR_2_ID, DEST_PROVIDER_CAT2, CONFIGURATOR_2_FQNAME, configurator_2);
}
private void setupDestProvider() {
diff --git a/tests/org.eclipse.platform.discovery.integration.test.unit/META-INF/MANIFEST.MF b/tests/org.eclipse.platform.discovery.integration.test.unit/META-INF/MANIFEST.MF index 71fa401..2fc0083 100644 --- a/tests/org.eclipse.platform.discovery.integration.test.unit/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.platform.discovery.integration.test.unit/META-INF/MANIFEST.MF @@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.platform.discovery.test.testutils, org.eclipse.platform.discovery.util,
org.eclipse.core.runtime,
org.eclipse.platform.discovery.integration,
- org.eclipse.jface
+ org.eclipse.jface,
+ org.eclipse.platform.discovery.destprefs
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.platform.discovery.integration.internal.plugin,
org.eclipse.platform.discovery.integration.test.unit,
diff --git a/tests/org.eclipse.platform.discovery.integration.test.unit/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPluginTest.java b/tests/org.eclipse.platform.discovery.integration.test.unit/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPluginTest.java index 801aa9d..38c78ab 100644 --- a/tests/org.eclipse.platform.discovery.integration.test.unit/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPluginTest.java +++ b/tests/org.eclipse.platform.discovery.integration.test.unit/src/org/eclipse/platform/discovery/integration/internal/plugin/DiscoveryIntegrationPluginTest.java @@ -76,7 +76,8 @@ public class DiscoveryIntegrationPluginTest extends MockObjectTestCase consoleViewOutputController = mock(ISearchConsoleControllerOutputView.class);
consoleView = mock(ISearchConsoleView.class);
- consoleView.stubs().method("getControllerView").will(returnValue(consoleViewOutputController.proxy()));
+ consoleView.stubs().method("getControllerView").will(returnValue(consoleViewOutputController.proxy())); +
consoleController = mock(ISearchConsoleController.class);
contributedAction = mock(IContributedAction.class);
customizableView = mock(ICustomizableView.class);
@@ -91,6 +92,7 @@ public class DiscoveryIntegrationPluginTest extends MockObjectTestCase setupSlaveControllers();
setupViewCustomizations();
+ plugin = new TestedIntegrationPlugin();
}
@@ -140,7 +142,9 @@ public class DiscoveryIntegrationPluginTest extends MockObjectTestCase customizableView.expects(once()).method("setUiContext").with(isA(IViewUiContext.class));
slaveController.expects(once()).method("setMasterController").with(eq(consoleController.proxy()));
- searchConsoleViewCustomization.expects(once()).method("setMasterView").with(eq(masterView.proxy()));
+ searchConsoleViewCustomization.expects(once()).method("setMasterView").with(eq(masterView.proxy())); + consoleView.expects(once()).method("setDestinationsManager"); +
plugin.partOpenedInternal(wbPartReference.proxy());
}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/META-INF/MANIFEST.MF b/tests/org.eclipse.platform.discovery.test.testutils/META-INF/MANIFEST.MF index 78f2dfb..d88e41e 100644 --- a/tests/org.eclipse.platform.discovery.test.testutils/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.platform.discovery.test.testutils/META-INF/MANIFEST.MF @@ -27,6 +27,7 @@ Export-Package: org.eclipse.platform.discovery.testutils.internal.plugin, org.eclipse.platform.discovery.testutils.utils.jmock,
org.eclipse.platform.discovery.testutils.utils.junit.util.assertions,
org.eclipse.platform.discovery.testutils.utils.junit.util.threading,
+ org.eclipse.platform.discovery.testutils.utils.matchers,
org.eclipse.platform.discovery.testutils.utils.model,
org.eclipse.platform.discovery.testutils.utils.pageobjects,
org.eclipse.platform.discovery.testutils.utils.reflection,
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/matchers/Matchers.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/matchers/Matchers.java new file mode 100644 index 0000000..779ffdc --- /dev/null +++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/matchers/Matchers.java @@ -0,0 +1,33 @@ +package org.eclipse.platform.discovery.testutils.utils.matchers;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+
+public class Matchers {
+
+ public static <T> Matcher<T[]> arrayEqualsWithoutOrder(final T... elements) {
+ return new BaseMatcher<T[]>() {
+
+ @Override
+ public boolean matches(Object item) {
+ @SuppressWarnings("unchecked")
+ T[] args = (T[])item;
+ return set(elements).equals(set(args));
+ }
+
+ private <Q> Set<Q> set(Q... elems) {
+ return new HashSet<Q>(Arrays.asList(elems));
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(Arrays.toString(elements));
+ }
+ };
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/registry/ExtensionRegistryBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/registry/ExtensionRegistryBuilder.java index 3e50cc2..3984a17 100644 --- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/registry/ExtensionRegistryBuilder.java +++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/registry/ExtensionRegistryBuilder.java @@ -42,9 +42,9 @@ import org.eclipse.platform.discovery.ui.internal.xp.impl.CustomResultUiXpParser import org.eclipse.platform.discovery.util.internal.StatusUtils;
import org.osgi.framework.FrameworkUtil;
public class ExtensionRegistryBuilder {
-
+
private IExtensionRegistry extensionRegistry;
-
+
private IExtensionPoint objectTypesExtensionPoint;
private IExtensionPoint destinationProvidersExtensionPoint;
private IExtensionPoint destinationCategoriesExtensionPoint;
@@ -69,7 +69,7 @@ public class ExtensionRegistryBuilder { public ExtensionRegistryBuilder() {
-
+
this.extensionRegistry = mock(IExtensionRegistry.class, "extension registry");
objectTypesExtensionPoint = setupExtensionPoint(ObjectTypeExtensionParser.XP_ID);
destinationProvidersExtensionPoint = setupExtensionPoint(DestinationsProviderExtensionParser.XP_ID);
@@ -88,14 +88,14 @@ public class ExtensionRegistryBuilder { when(extensionRegistry.getExtensionPoint(eq(xpId))).thenReturn(point);
return point;
}
-
+
public void addObjectType(String id, String displayName) {
IConfigurationElement element = createConfigurationElement(ObjectTypeExtensionParser.XP_ELEMENT_NAME);
setAttribute(element, ObjectTypeExtensionParser.ID_ATTR_NAME, id);
setAttribute(element, ObjectTypeExtensionParser.DISPLAY_NAME_ATTR_NAME, displayName);
objectTypes.add(element);
}
-
+
public void addDestinationsProvider(String providerId, String destinationCategory, String preferencePageId, String providerInstanceFqName, IDestinationsProvider providerInstance) {
IConfigurationElement element = createConfigurationElement(DestinationsProviderExtensionParser.XP_ELEMENT_NAME);
setAttribute(element, DestinationsProviderExtensionParser.PROVIDER_ID_ATTR, providerId);
@@ -123,21 +123,21 @@ public class ExtensionRegistryBuilder { when(element.getName()).thenReturn(elementName);
return element;
}
-
+
public void addDestinationCategory(String categoryId, String categoryName, Class<? extends ISearchDestination> destinationsClass) {
IConfigurationElement element = createConfigurationElement(DestinationsCategoryExtensionParser.XP_ELEMENT_NAME);
setAttribute(element, DestinationsCategoryExtensionParser.CATEGORY_ID_ATTRIBUTE, categoryId);
setAttribute(element, DestinationsCategoryExtensionParser.CATEGORY_DISPLAY_NAME_ATTRIBUTE, categoryName);
-
+
if(destinationsClass!=null) {
String bundleSymbolicName = FrameworkUtil.getBundle(destinationsClass).getSymbolicName();
setNamespaceIdentifier(element, bundleSymbolicName);
setAttribute(element, DestinationsCategoryExtensionParser.DESTINATIONS_CLASS_ATTRIBUTE, destinationsClass.getName());
}
-
+
destinationCategories.add(element);
}
-
+
public void addDestinationCategory(String categoryId, String categoryName) {
addDestinationCategory(categoryId, categoryName, null);
}
@@ -175,15 +175,15 @@ public class ExtensionRegistryBuilder { categoriesList.add(categoryElement);
}
setChildren(searchProviderElement, categoriesList, SearchProvidersExtensionParser.CATEGORY_ELEMENT_NAME);
-
+
searchProviders.add(searchProviderElement);
-
+
}
private void setChildren(IConfigurationElement element, List<IConfigurationElement> children, String childrenElementsName) {
when(element.getChildren(childrenElementsName)).thenReturn(children.toArray(new IConfigurationElement[]{}));
}
-
+
public void addSearchSubdestination(String id, String displayName, String categoryId, String objectTypeId, String defaultSelected, String... conflicts) {
IConfigurationElement subdestinationElement = createConfigurationElement(SearchSubdestinationExtensionParser.XP_ELEMENT_NAME);
setAttribute(subdestinationElement, SearchSubdestinationExtensionParser.ID_ATTR, id);
@@ -191,7 +191,7 @@ public class ExtensionRegistryBuilder { setAttribute(subdestinationElement, SearchSubdestinationExtensionParser.CATEGORY_ID_ATTR, categoryId);
setAttribute(subdestinationElement, SearchSubdestinationExtensionParser.OBJECT_ATTR, objectTypeId);
setAttribute(subdestinationElement, SearchSubdestinationExtensionParser.DEFAULT_SELECTED_ATTR, defaultSelected);
-
+
List<IConfigurationElement> conflictsList = new ArrayList<IConfigurationElement>();
for(String conflictId: conflicts) {
IConfigurationElement conflictElement = mock(IConfigurationElement.class);
@@ -199,10 +199,10 @@ public class ExtensionRegistryBuilder { conflictsList.add(conflictElement);
}
setChildren(subdestinationElement, conflictsList, SearchSubdestinationExtensionParser.CONFLICT_ELEMENT_NAME);
-
+
searchSubdestinations.add(subdestinationElement);
}
-
+
public void addAdvancedSearchParamsUiContributor(String id, String searchProviderId, String contributorFQName, IAdvancedSearchParamsUiContributor contributorInstance) {
IConfigurationElement advancedUiContributorElement = createAdvancedParamsUiElement(id, searchProviderId, contributorFQName);
@@ -218,7 +218,7 @@ public class ExtensionRegistryBuilder { setAttribute(advancedUiContributorElement, AdvancedSearchParamsUiContribXpParser.CONTRIBUTOR_CLASS_NAME_ATTR_NAME, contributorFQName);
return advancedUiContributorElement;
}
-
+
public void addExceptionThrowingAdvancedSearchParamsUiContributor(String id, String searchProviderId, String contributorFQName) {
IConfigurationElement advancedUiContributorElement = createAdvancedParamsUiElement(id, searchProviderId, contributorFQName);
setupCreateExecutableExtensionToThrowException(advancedUiContributorElement, AdvancedSearchParamsUiContribXpParser.CONTRIBUTOR_CLASS_NAME_ATTR_NAME);
@@ -228,7 +228,7 @@ public class ExtensionRegistryBuilder { protected void setupCreateExecutableExtensionToThrowException(IConfigurationElement element, String classAttributeName) {
setupCreateExecutableExtensionToThrowException(element, classAttributeName, new CoreException(StatusUtils.statusError("TEST")));
}
-
+
protected void setupCreateExecutableExtensionToThrowException(IConfigurationElement element, String classAttributeName, CoreException toThrow) {
try {
when(element.createExecutableExtension(classAttributeName)).thenThrow(toThrow);
@@ -236,7 +236,7 @@ public class ExtensionRegistryBuilder { throw new RuntimeException(e);
}
}
-
+
public void addCustomResultUiContributor(String id, String searchProviderId, String contributorFQName, ISearchResultCustomUiCreator cobntributorInstance) {
IConfigurationElement customResultUiElement = createCustomResultUIElement(id, searchProviderId, contributorFQName);
setExecutableExtension(customResultUiElement, cobntributorInstance, CustomResultUiXpParser.UI_CREATOR_CLASS_NAME_ATTR_NAME);
@@ -251,7 +251,7 @@ public class ExtensionRegistryBuilder { setAttribute(customResultUiElement, CustomResultUiXpParser.UI_CREATOR_CLASS_NAME_ATTR_NAME, contributorFQName);
return customResultUiElement;
}
-
+
public void addExceptionThrowingCustomResultUiContributor(String id, String searchProviderId, String contributorFQName) {
IConfigurationElement customResultUiElement = createCustomResultUIElement(id, searchProviderId, contributorFQName);
setupCreateExecutableExtensionToThrowException(customResultUiElement, CustomResultUiXpParser.UI_CREATOR_CLASS_NAME_ATTR_NAME);
@@ -264,22 +264,27 @@ public class ExtensionRegistryBuilder { clearState();
return extensionRegistry;
}
-
- public void addSearchDestinationsConfigurator(final String id, final String destinationProviderId, final String configuratorFQName, final ISearchDestinationConfigurator<?> configuratorInstance) throws CoreException {
- searchDestinationConfigurators.add(createSearchDestinationsConfiguratorElement(id, destinationProviderId, configuratorFQName, configuratorInstance));
+
+ public void addSearchDestinationsConfigurator(final String id, final String destinationProviderId, final String configuratorFQName, final ISearchDestinationConfigurator<?> configuratorInstance) {
+ searchDestinationConfigurators.add(createSearchDestinationsConfiguratorElement(id, destinationProviderId, configuratorFQName, configuratorInstance));
}
- private IConfigurationElement createSearchDestinationsConfiguratorElement(final String id, final String destinationProviderId, final String configuratorFQName, final ISearchDestinationConfigurator<?> configuratorInstance) throws CoreException {
- final IConfigurationElement element = createConfigurationElement(SearchDestinationsConfiguratorXPParser.CONFIGURATOR_ELEMENT_NAME);
- setAttribute(element, SearchDestinationsConfiguratorXPParser.CONFIGURATOR_ID_ELEMENT_NAME, id);
- setAttribute(element, SearchDestinationsConfiguratorXPParser.CONFIGURATOR_DEST_PROVIDER_ID_ELEMENT_NAME, destinationProviderId);
- setAttribute(element, SearchDestinationsConfiguratorXPParser.CONFIGURATOR_FQNAME_ELEMENT_NAME, configuratorFQName);
- when(element.createExecutableExtension(eq(SearchDestinationsConfiguratorXPParser.CONFIGURATOR_FQNAME_ELEMENT_NAME))).thenReturn(configuratorInstance);
-
- return element;
- }
-
- protected void setupExtensionPointConfigElements() {
+ private IConfigurationElement createSearchDestinationsConfiguratorElement(final String id, final String destinationProviderId, final String configuratorFQName, final ISearchDestinationConfigurator<?> configuratorInstance) {
+ try{
+ final IConfigurationElement element = createConfigurationElement(SearchDestinationsConfiguratorXPParser.CONFIGURATOR_ELEMENT_NAME);
+ setAttribute(element, SearchDestinationsConfiguratorXPParser.CONFIGURATOR_ID_ELEMENT_NAME, id);
+ setAttribute(element, SearchDestinationsConfiguratorXPParser.CONFIGURATOR_DEST_PROVIDER_ID_ELEMENT_NAME, destinationProviderId);
+ setAttribute(element, SearchDestinationsConfiguratorXPParser.CONFIGURATOR_FQNAME_ELEMENT_NAME, configuratorFQName);
+ when(element.createExecutableExtension(eq(SearchDestinationsConfiguratorXPParser.CONFIGURATOR_FQNAME_ELEMENT_NAME))).thenReturn(configuratorInstance);
+
+ return element;
+ } catch(CoreException ex) {
+ throw new IllegalStateException(ex);
+ }
+
+ }
+
+ protected void setupExtensionPointConfigElements() {
when(objectTypesExtensionPoint.getConfigurationElements()).thenReturn(objectTypes.toArray(new IConfigurationElement[]{}));
when(destinationProvidersExtensionPoint.getConfigurationElements()).thenReturn(destinationProviders.toArray(new IConfigurationElement[]{}));
when(destinationCategoriesExtensionPoint.getConfigurationElements()).thenReturn(destinationCategories.toArray(new IConfigurationElement[]{}));
@@ -288,14 +293,14 @@ public class ExtensionRegistryBuilder { when(searchProvidersExtensionPoint.getConfigurationElements()).thenReturn(searchProviders.toArray(new IConfigurationElement[]{}));
when(searchSubdestinationsExtensionPoint.getConfigurationElements()).thenReturn(searchSubdestinations.toArray(new IConfigurationElement[]{}));
when(advancedSearchUiContributorsExtensionPoint.getConfigurationElements()).thenReturn(advancedSearchUiContributors.toArray(new IConfigurationElement[]{}));
- when(customResultUiContributorsExtensionPoint.getConfigurationElements()).thenReturn(customResultUiContributors.toArray(new IConfigurationElement[]{}));
- when(searchDestinationsConfiguratorExtensionPoint.getConfigurationElements()).thenReturn(searchDestinationConfigurators.toArray(new IConfigurationElement[]{}));
+ when(customResultUiContributorsExtensionPoint.getConfigurationElements()).thenReturn(customResultUiContributors.toArray(new IConfigurationElement[]{}));
+ when(searchDestinationsConfiguratorExtensionPoint.getConfigurationElements()).thenReturn(searchDestinationConfigurators.toArray(new IConfigurationElement[]{}));
}
-
+
protected void clearState() {
for(List<?> list: new List<?>[]{objectTypes, destinationProviders, destinationCategories, loadProviders, storeProviders, searchProviders, searchSubdestinations,
advancedSearchUiContributors, customResultUiContributors, searchDestinationConfigurators})
list.clear();
}
-
+
}
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/OpenPropsViewActionTest.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/OpenPropsViewActionTest.java index 0c95291..7b644a1 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/OpenPropsViewActionTest.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/OpenPropsViewActionTest.java @@ -13,6 +13,7 @@ package org.eclipse.platform.discovery.ui.test.comp.internal; import static org.junit.Assert.assertEquals; import org.eclipse.platform.discovery.ui.internal.view.impl.OpenPropsViewAction; +import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.junit.Before; @@ -37,19 +38,22 @@ public class OpenPropsViewActionTest { PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
- IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- if (page.getActivePart().getTitle().equals("Properties")) {
- throw new IllegalStateException(
- "properties view is the active part at the beginning of the fixture so the test cant decide if the"
- + "console action code behaves correctly");
- }
-
+ closePropsIfOpen();
+
+ action.run(); - action.run();
- page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
assertEquals("properties view is not the active part", "Properties", page.getActivePart().getTitle());
- }
+ } + });
+ } + + private void closePropsIfOpen() { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (page.getActivePart().getTitle().equals("Properties")) { + //close it, so we can verify search console opened it + page.hideView((IViewPart) page.getActivePart()); + } }
}
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/SearchConsolePageObject.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/SearchConsolePageObject.java index 7640289..98ac3cf 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/SearchConsolePageObject.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/SearchConsolePageObject.java @@ -1,7 +1,6 @@ package org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects;
import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
-import static org.junit.Assert.assertNotNull;
import java.text.MessageFormat;
import java.util.Collection;
@@ -11,6 +10,7 @@ import junit.framework.Assert; import org.eclipse.platform.discovery.core.api.ISearchContext;
import org.eclipse.platform.discovery.core.api.SearchEvent;
+import org.eclipse.platform.discovery.core.internal.IDestinationsManager;
import org.eclipse.platform.discovery.core.internal.ISearchSession;
import org.eclipse.platform.discovery.core.internal.SearchConsoleController;
import org.eclipse.platform.discovery.core.internal.console.ISearchConsoleControllerOutputView;
@@ -24,6 +24,7 @@ import org.eclipse.platform.discovery.ui.api.IViewUiContext; import org.eclipse.platform.discovery.ui.api.impl.DefaultSessionIds;
import org.eclipse.platform.discovery.ui.internal.plugin.DiscoveryUIMessages;
import org.eclipse.platform.discovery.ui.internal.search.advancedparams.IAdvancedSearchParamsDisplayer;
+import org.eclipse.platform.discovery.ui.internal.view.ISearchProviderSelector;
import org.eclipse.platform.discovery.ui.internal.view.SearchConsoleView;
import org.eclipse.platform.discovery.ui.internal.view.impl.ITabbedSessionDisplayer;
import org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects.swtbot.SWTBotHyperlink;
@@ -45,24 +46,24 @@ import org.eclipse.swtbot.swt.finder.results.VoidResult; import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
public class SearchConsolePageObject extends InShellPageObject
{
- private static final String TEST_PREFERENCE_PAGE_NAME = "DiscoveryUiTestPreferencePage";
@Mock
private IWorkbenchPartSite viewSite;
+
+ @Mock
+ private IDestinationsManager destManager;
+
private final ISearchProviderConfiguration searchProviderConfiguration;
private final ITabbedSessionDisplayer<ISearchContext> sessionDisplayer;
@@ -103,6 +104,7 @@ public class SearchConsolePageObject extends InShellPageObject {
parent.setLayout(new FillLayout(SWT.VERTICAL));
consoleView = new PageObjectConsoleView();
+
consoleView.setEnvironment(env);
consoleView.setUiContext(uiContext);
consoleView.createPartControl(parent);
@@ -125,6 +127,7 @@ public class SearchConsolePageObject extends InShellPageObject consoleView.setEnvironment(env);
viewController = new PageObjectController(searchProviderConfiguration, consoleView, env, null, DefaultSessionIds.mainSearchSessionId);
consoleView.registerController(viewController);
+ consoleView.setDestinationsManager(destManager);
consoleView.initializationCompleted();
}
});
@@ -162,12 +165,9 @@ public class SearchConsolePageObject extends InShellPageObject final SWTBotHyperlink manageDestinationsLink = new SWTBotHyperlink(botUtils.findOneChildControlOfExactType(shell().widget, Hyperlink.class, true));
manageDestinationsLink.click();
- final SWTBotShell preferencePageShell = findPreferencePageShell();
- verifyDestinationPreferenceDisplayed(preferencePageShell);
- verifyGenericDestinationPreferencesDisplayed(preferencePageShell);
- preferencePageShell.close();
+ Mockito.verify(destManager).manageDestinations(Mockito.same(shell().widget), Mockito.same(consoleView.getSearchProviderSelector().getActiveDestinationCategory()));
+
}
-
public void verifySearchPerformed(final String objectTypeId, final String destinationName, final String keyword)
{
Assert.assertNotNull("Search was not invoked", viewController.lastSearchEvent);
@@ -380,57 +380,6 @@ public class SearchConsolePageObject extends InShellPageObject return new SWTBotCombo(findSiblingByLabel(DiscoveryUIMessages.GROUP_BY_LABEL, Combo.class));
}
- private SWTBotShell findPreferencePageShell()
- {
- final SWTBotShell preferencePageShell = botUtils.findShell(new BaseMatcher<Shell>()
- {
- @Override
- public boolean matches(Object item)
- {
- if (!(item instanceof SWTBotShell))
- {
- return false;
- }
- final SWTBotShell theShell = (SWTBotShell)item;
- try
- {
- theShell.bot().tree().getTreeItem(TEST_PREFERENCE_PAGE_NAME);
- return true;
- }
- catch (WidgetNotFoundException e)
- {
- return false;
- }
- }
-
- @Override
- public void describeTo(Description description)
- {
- }
- });
-
- return preferencePageShell;
- }
-
- private void verifyDestinationPreferenceDisplayed(final SWTBotShell preferencePageShell)
- {
- preferencePageShell.bot().tree().getTreeItem(TEST_PREFERENCE_PAGE_NAME).click();
- try
- {
- preferencePageShell.bot().text("MyTestLabel");
- preferencePageShell.bot().button("Button1");
- }
- catch (WidgetNotFoundException e)
- {
- }
- }
-
- private void verifyGenericDestinationPreferencesDisplayed(SWTBotShell preferencePageShell) {
- assertNotNull(preferencePageShell.bot().tree().getTreeItem("Search Destinations"));
- }
-
-
-
private class PageObjectConsoleView extends SearchConsoleView
{
protected ISearchProviderConfiguration getSearchProviderConfiguration()
@@ -455,6 +404,10 @@ public class SearchConsolePageObject extends InShellPageObject {
return advancedParamsDisplayer;
}
+
+ protected ISearchProviderSelector getSearchProviderSelector() {
+ return searchProviderSelector;
+ }
}
private class PageObjectController extends SearchConsoleController
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotHyperlink.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotHyperlink.java index da11ae2..37bb780 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotHyperlink.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotHyperlink.java @@ -14,19 +14,19 @@ import org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects.swtbot.u import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
-import org.eclipse.ui.forms.widgets.Hyperlink;
+import org.eclipse.ui.forms.widgets.AbstractHyperlink;
-public class SWTBotHyperlink extends AbstractSWTBotControl<Hyperlink>
+public class SWTBotHyperlink extends AbstractSWTBotControl<AbstractHyperlink>
{
private final MouseUtils mouseUtils;
- public SWTBotHyperlink(Hyperlink w) throws WidgetNotFoundException
+ public SWTBotHyperlink(AbstractHyperlink h) throws WidgetNotFoundException
{
- super(w);
+ super(h);
this.mouseUtils = new MouseUtils(display);
}
- public AbstractSWTBot<Hyperlink> click()
+ public AbstractSWTBot<AbstractHyperlink> click()
{
mouseUtils.clickOn(this);
return this;
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotSection.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotSection.java index bac4e91..d363904 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotSection.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/SWTBotSection.java @@ -10,10 +10,12 @@ *******************************************************************************/
package org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects.swtbot;
-import org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects.swtbot.utils.MouseUtils;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.ChildrenControlFinder;
+import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
import org.eclipse.swtbot.swt.finder.results.BoolResult;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
+import org.eclipse.ui.forms.widgets.AbstractHyperlink;
import org.eclipse.ui.forms.widgets.Section;
/**
@@ -26,19 +28,16 @@ import org.eclipse.ui.forms.widgets.Section; */
public class SWTBotSection extends AbstractSWTBotControl<Section>
{
- private final MouseUtils mouseUtils;
-
public SWTBotSection(Section w) throws WidgetNotFoundException
{
super(w);
- this.mouseUtils = new MouseUtils(display);
}
public void toggle()
{
- mouseUtils.clickOn(this, 10, 5);
-
- };
+ AbstractHyperlink hyperlink = new ChildrenControlFinder(widget).findControls(WidgetOfType.widgetOfType(AbstractHyperlink.class)).get(0);
+ new SWTBotHyperlink(hyperlink).click();
+ }
private boolean isExpanded()
{
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/utils/MouseUtils.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/utils/MouseUtils.java index 6c57377..eb5e444 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/utils/MouseUtils.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/swtbot/utils/MouseUtils.java @@ -126,7 +126,7 @@ public class MouseUtils moveMouseTo(new Point(targetX, targetY));
}
- private void click()
+ public void click()
{
final Robot awtRobot = awtRobot();
syncExec(new VoidResult()
diff --git a/tests/org.eclipse.platform.discovery.ui.test.unit/src/org/eclipse/platform/discovery/ui/test/unit/internal/AbstractTooltipConfiguratorTest.java b/tests/org.eclipse.platform.discovery.ui.test.unit/src/org/eclipse/platform/discovery/ui/test/unit/internal/AbstractTooltipConfiguratorTest.java index 0966374..9069796 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.unit/src/org/eclipse/platform/discovery/ui/test/unit/internal/AbstractTooltipConfiguratorTest.java +++ b/tests/org.eclipse.platform.discovery.ui.test.unit/src/org/eclipse/platform/discovery/ui/test/unit/internal/AbstractTooltipConfiguratorTest.java @@ -22,7 +22,7 @@ import org.eclipse.platform.discovery.ui.internal.tooltip.IToolTipConfigurator; import org.eclipse.platform.discovery.ui.internal.tooltip.AbstractTooltipConfigurator.TooltipFormTextBuilder;
-public class AbstractTooltipConfiguratorTest extends MockObjectTestCase
+public abstract class AbstractTooltipConfiguratorTest extends MockObjectTestCase
{
protected Mock<IFormTextBuilder> textBuilder;
private IToolTipConfigurator configurator;
|