diff options
author | David Green | 2012-02-29 16:11:31 +0000 |
---|---|---|
committer | Steffen Pingel | 2012-02-29 16:11:31 +0000 |
commit | 219619481e31b51dcdad987ca3b0d832dd75e873 (patch) | |
tree | c1e8b45a6d5c212ba49bf6959948ce0fac6d1297 | |
parent | 09cf426897289e062c07a4bc9472441467cd3797 (diff) | |
download | org.eclipse.mylyn.tasks-219619481e31b51dcdad987ca3b0d832dd75e873.tar.gz org.eclipse.mylyn.tasks-219619481e31b51dcdad987ca3b0d832dd75e873.tar.xz org.eclipse.mylyn.tasks-219619481e31b51dcdad987ca3b0d832dd75e873.zip |
bug 371029: add a Reindex menu item to the task list view
https://bugs.eclipse.org/bugs/show_bug.cgi?id=371029
Change-Id: I2dc67a2082a7ff001f84a00b9eeb791d8583d33a
8 files changed, 192 insertions, 44 deletions
diff --git a/org.eclipse.mylyn.tasks.index.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.index.ui/META-INF/MANIFEST.MF index fd8d03eb7..a0ca23325 100644 --- a/org.eclipse.mylyn.tasks.index.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.index.ui/META-INF/MANIFEST.MF @@ -12,4 +12,5 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.mylyn.tasks.core;bundle-version="3.7.0", org.eclipse.mylyn.tasks.ui;bundle-version="3.7.0", org.eclipse.mylyn.tasks.index.core -Export-Package: org.eclipse.mylyn.internal.tasks.index.ui;x-internal:=true +Export-Package: org.eclipse.mylyn.internal.tasks.index.ui;x-internal:=true, + org.eclipse.mylyn.internal.tasks.index.ui.commands;x-internal:=true diff --git a/org.eclipse.mylyn.tasks.index.ui/OSGI-INF/l10n/bundle.properties b/org.eclipse.mylyn.tasks.index.ui/OSGI-INF/l10n/bundle.properties index f18488576..a99257c88 100644 --- a/org.eclipse.mylyn.tasks.index.ui/OSGI-INF/l10n/bundle.properties +++ b/org.eclipse.mylyn.tasks.index.ui/OSGI-INF/l10n/bundle.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2011 Tasktop Technologies and others. +# Copyright (c) 2011, 2012 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 @@ -9,4 +9,6 @@ # Tasktop Technologies - initial API and implementation ############################################################################### #Properties file for org.eclipse.mylyn.tasks.index.ui -Bundle-Name = Index
\ No newline at end of file +Bundle-Name = Index +command.name = Refresh Search Index +command.label = Refresh Search Index
\ No newline at end of file diff --git a/org.eclipse.mylyn.tasks.index.ui/plugin.xml b/org.eclipse.mylyn.tasks.index.ui/plugin.xml index 57353cb43..fb671c61b 100644 --- a/org.eclipse.mylyn.tasks.index.ui/plugin.xml +++ b/org.eclipse.mylyn.tasks.index.ui/plugin.xml @@ -6,4 +6,24 @@ <searchHandler class="org.eclipse.mylyn.internal.tasks.index.ui.IndexSearchHandler"/> </extension> + <extension + point="org.eclipse.ui.commands"> + <command + id="org.eclipse.mylyn.tasks.index.ui.command.ResetIndex" + categoryId="org.eclipse.mylyn.tasks.ui.commands" + defaultHandler="org.eclipse.mylyn.internal.tasks.index.ui.commands.ResetIndexHandler" + name="%command.name"> + </command> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="menu:org.eclipse.mylyn.tasks.ui.views.tasks?after=additions"> + <command + commandId="org.eclipse.mylyn.tasks.index.ui.command.ResetIndex" + label="%command.label" + style="push"> + </command> + </menuContribution> + </extension> </plugin> diff --git a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java new file mode 100644 index 000000000..742986d60 --- /dev/null +++ b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2012 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.tasks.index.ui; + +import java.io.File; +import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.mylyn.internal.tasks.index.core.TaskListIndex; +import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.tasks.core.IRepositoryManager; + +/** + * @author David Green + */ +public class IndexReference { + + private static TaskListIndex theIndex; + + private static AtomicInteger referenceCount = new AtomicInteger(); + + /** + * When not null serves as flag indicating that theIndex is referenced, thus preventing bad behaviour if dispose is + * called multiple times. + */ + private TaskListIndex index; + + public TaskListIndex index() { + synchronized (IndexReference.class) { + if (index == null) { + if (theIndex == null) { + final IRepositoryManager repositoryManager = TasksUiPlugin.getRepositoryManager(); + final File indexLocation = new File(TasksUiPlugin.getDefault().getDataDirectory(), ".taskListIndex"); //$NON-NLS-1$ + + theIndex = new TaskListIndex(TasksUiPlugin.getTaskList(), TasksUiPlugin.getTaskDataManager(), + repositoryManager, indexLocation); + + } + index = theIndex; + referenceCount.incrementAndGet(); + } + } + return index; + } + + public void dispose() { + synchronized (IndexReference.class) { + if (index != null) { + index = null; + + if (referenceCount.decrementAndGet() == 0) { + theIndex.close(); + theIndex = null; + } + } + } + } +} diff --git a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexSearchHandler.java b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexSearchHandler.java index d6946a96a..31febf32e 100644 --- a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexSearchHandler.java +++ b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexSearchHandler.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.mylyn.internal.tasks.index.ui; -import java.io.File; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -19,7 +18,6 @@ import java.util.GregorianCalendar; import java.util.List; import java.util.Set; import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.jface.fieldassist.ContentProposalAdapter; import org.eclipse.jface.fieldassist.IContentProposal; @@ -30,7 +28,6 @@ import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.index.core.TaskListIndex; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.search.AbstractSearchHandler; -import org.eclipse.mylyn.tasks.core.IRepositoryManager; import org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema; import org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; @@ -85,7 +82,7 @@ public class IndexSearchHandler extends AbstractSearchHandler { } else { // suggest field name prefixes - for (Field field : index.getIndexedFields()) { + for (Field field : reference.index().getIndexedFields()) { // searching on URL is not useful if (field.equals(TaskListIndex.FIELD_IDENTIFIER)) { @@ -137,7 +134,7 @@ public class IndexSearchHandler extends AbstractSearchHandler { String label = NLS.bind(Messages.IndexSearchHandler_Past_week_date_range_label, field.getIndexKey()); - String queryText = index.computeQueryFieldDateRange(field, dateSearchOneWeekLowerBound, + String queryText = reference.index().computeQueryFieldDateRange(field, dateSearchOneWeekLowerBound, dateSearchUpperBound); proposals.add(new ContentProposal(queryText, label, description)); } @@ -165,21 +162,14 @@ public class IndexSearchHandler extends AbstractSearchHandler { } } - private static TaskListIndex theIndex; - - private static AtomicInteger referenceCount = new AtomicInteger(); - - /** - * When not null serves as flag indicating that theIndex is referenced, thus preventing bad behaviour if dispose is - * called multiple times. - */ - private TaskListIndex index; + private IndexReference reference; public IndexSearchHandler() { + reference = new IndexReference(); } public Field computeIndexField(String fieldPrefix) { - for (Field field : index.getIndexedFields()) { + for (Field field : reference.index().getIndexedFields()) { if (field.getIndexKey().equals(fieldPrefix)) { return field; } @@ -203,7 +193,7 @@ public class IndexSearchHandler extends AbstractSearchHandler { Field newDefaultField = button.getSelection() ? TaskListIndex.FIELD_SUMMARY : TaskListIndex.FIELD_CONTENT; - index.setDefaultField(newDefaultField); + reference.index().setDefaultField(newDefaultField); fireFilterChanged(); } }); @@ -213,21 +203,7 @@ public class IndexSearchHandler extends AbstractSearchHandler { @Override public PatternFilter createFilter() { - synchronized (IndexSearchHandler.class) { - if (index == null) { - if (theIndex == null) { - final IRepositoryManager repositoryManager = TasksUiPlugin.getRepositoryManager(); - final File indexLocation = new File(TasksUiPlugin.getDefault().getDataDirectory(), ".taskListIndex"); //$NON-NLS-1$ - - theIndex = new TaskListIndex(TasksUiPlugin.getTaskList(), TasksUiPlugin.getTaskDataManager(), - repositoryManager, indexLocation); - - } - index = theIndex; - referenceCount.incrementAndGet(); - } - } - return new IndexedSubstringPatternFilter(index); + return new IndexedSubstringPatternFilter(reference.index()); } @Override @@ -248,16 +224,8 @@ public class IndexSearchHandler extends AbstractSearchHandler { @Override public void dispose() { - synchronized (IndexSearchHandler.class) { - if (index != null) { - index = null; - - if (referenceCount.decrementAndGet() == 0) { - theIndex.close(); - theIndex = null; - } - } - } + reference.dispose(); + reference = null; } } diff --git a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/Messages.java b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/Messages.java new file mode 100644 index 000000000..59fc301fa --- /dev/null +++ b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/Messages.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2012 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.tasks.index.ui.commands; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.tasks.index.ui.commands.messages"; //$NON-NLS-1$ + + public static String ResetIndexHandler_Rebuilding_Index_Progress_Label; + + public static String ResetIndexHandler_Refresh_Index_Job_Name; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + +} diff --git a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/ResetIndexHandler.java b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/ResetIndexHandler.java new file mode 100644 index 000000000..8e29c61f2 --- /dev/null +++ b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/ResetIndexHandler.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2012 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.tasks.index.ui.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.mylyn.internal.tasks.index.core.TaskListIndex; +import org.eclipse.mylyn.internal.tasks.index.ui.IndexReference; + +/** + * @author David Green + */ +public class ResetIndexHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + Job job = new Job(Messages.ResetIndexHandler_Refresh_Index_Job_Name) { + @Override + protected IStatus run(IProgressMonitor monitor) { + IndexReference reference = new IndexReference(); + try { + monitor.beginTask(Messages.ResetIndexHandler_Rebuilding_Index_Progress_Label, + IProgressMonitor.UNKNOWN); + final TaskListIndex index = reference.index(); + index.reindex(); + // wait for the reindex job to complete before we dispose of the reference + index.waitUntilIdle(); + } catch (InterruptedException e) { + return Status.CANCEL_STATUS; + } finally { + reference.dispose(); + monitor.done(); + } + return Status.OK_STATUS; + } + }; + job.setSystem(true); + job.setUser(false); + job.setPriority(Job.LONG); + job.schedule(); + return null; + } + +} diff --git a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/messages.properties b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/messages.properties new file mode 100644 index 000000000..462d81493 --- /dev/null +++ b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/messages.properties @@ -0,0 +1,2 @@ +ResetIndexHandler_Rebuilding_Index_Progress_Label=Rebuilding Index +ResetIndexHandler_Refresh_Index_Job_Name=Refreshing Task List Search Index |