summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-05-17 16:22:39 (EDT)
committerGerrit Code Review @ Eclipse.org2013-06-28 17:24:29 (EDT)
commit0f39bd71eb7b7e092ae2af0d3d23d997864589c6 (patch)
treea23183494c0b1b2a7a2ea2f6337c77d1b1b7c397
parentb201f33098230d63738fa32c8099cc493cda356e (diff)
downloadorg.eclipse.mylyn.tasks-0f39bd71eb7b7e092ae2af0d3d23d997864589c6.zip
org.eclipse.mylyn.tasks-0f39bd71eb7b7e092ae2af0d3d23d997864589c6.tar.gz
org.eclipse.mylyn.tasks-0f39bd71eb7b7e092ae2af0d3d23d997864589c6.tar.bz2
use Mylyn Commons ExtensionPointReader in SearchUtilrefs/changes/51/12951/3
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchUtil.java82
1 files changed, 30 insertions, 52 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchUtil.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchUtil.java
index b9b3545..eeca970 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchUtil.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Tasktop Technologies and others.
+ * Copyright (c) 2010, 2013 Tasktop Technologies 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,11 +11,11 @@
package org.eclipse.mylyn.internal.tasks.ui.search;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
+import java.util.List;
+
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.ExtensionPointReader;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.internal.tasks.core.ITaskList;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
@@ -46,12 +46,9 @@ public class SearchUtil {
}
/** searchProvider extension point id */
- private static final String EXTENSION_SEARCH_PROVIDER = "org.eclipse.mylyn.tasks.ui.searchProvider"; //$NON-NLS-1$
-
- private static final String EXTENSION_SEARCH_HANDLER = "org.eclipse.mylyn.tasks.ui.searchHandler"; //$NON-NLS-1$
+ private static final String EXTENSION_SEARCH_PROVIDER = "searchProvider"; //$NON-NLS-1$
- /** searchProvider attribute 'class' */
- private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
+ private static final String EXTENSION_SEARCH_HANDLER = "searchHandler"; //$NON-NLS-1$
private static AbstractSearchProvider provider;
@@ -64,33 +61,21 @@ public class SearchUtil {
return provider;
}
- try {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
-
- IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(EXTENSION_SEARCH_PROVIDER);
- if (configurationElements.length > 0) {
- if (configurationElements.length > 1) {
- StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
- "More than one search provider was registered.")); //$NON-NLS-1$
- }
-
- IConfigurationElement providerConfiguration = configurationElements[0];
- Object object = providerConfiguration.createExecutableExtension(ATTR_CLASS);
- if (object instanceof AbstractSearchProvider) {
- provider = (AbstractSearchProvider) object;
- return provider;
- } else {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Specified search provider is not of type AbstractSearchProvider.")); //$NON-NLS-1$
- }
- } else {
- StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
- "No search provider was registed. Tasks search is not available.")); //$NON-NLS-1$
- }
- } catch (Throwable e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Loading of searchProvider extension failed.", e)); //$NON-NLS-1$
+ ExtensionPointReader<AbstractSearchProvider> reader = new ExtensionPointReader<AbstractSearchProvider>(
+ TasksUiPlugin.ID_PLUGIN, EXTENSION_SEARCH_PROVIDER, EXTENSION_SEARCH_PROVIDER,
+ AbstractSearchProvider.class);
+ reader.read();
+ List<AbstractSearchProvider> providers = reader.getItems();
+ if (providers.size() == 0) {
+ StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
+ "No search provider was registed. Tasks search is not available.")); //$NON-NLS-1$
+ } else if (providers.size() > 1) {
+ StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
+ "More than one search provider was registered.")); //$NON-NLS-1$
}
+
+ provider = reader.getItem();
+
if (provider == null) {
provider = new NullSearchProvider();
}
@@ -98,24 +83,17 @@ public class SearchUtil {
}
public static AbstractSearchHandler createSearchHandler() {
- AbstractSearchHandler searchHandler = null;
- try {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
-
- IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(EXTENSION_SEARCH_HANDLER);
- if (configurationElements.length > 0) {
- if (configurationElements.length > 1) {
- StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
- "More than one task list search handler was registered.")); //$NON-NLS-1$
- }
-
- IConfigurationElement providerConfiguration = configurationElements[0];
- searchHandler = (AbstractSearchHandler) providerConfiguration.createExecutableExtension(ATTR_CLASS);
- }
- } catch (Throwable e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Loading of searchHandler extension failed.", e)); //$NON-NLS-1$
+ ExtensionPointReader<AbstractSearchHandler> reader = new ExtensionPointReader<AbstractSearchHandler>(
+ TasksUiPlugin.ID_PLUGIN, EXTENSION_SEARCH_HANDLER, EXTENSION_SEARCH_HANDLER,
+ AbstractSearchHandler.class);
+ reader.read();
+ if (reader.getItems().size() > 1) {
+ StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
+ "More than one task list search handler was registered.")); //$NON-NLS-1$
}
+
+ AbstractSearchHandler searchHandler = reader.getItem();
+
if (searchHandler == null) {
searchHandler = new DefaultSearchHandler();
}