Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Green2012-02-29 11:11:31 -0500
committerSteffen Pingel2012-02-29 11:11:31 -0500
commit219619481e31b51dcdad987ca3b0d832dd75e873 (patch)
treec1e8b45a6d5c212ba49bf6959948ce0fac6d1297 /org.eclipse.mylyn.tasks.index.ui/src
parent09cf426897289e062c07a4bc9472441467cd3797 (diff)
downloadorg.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
Diffstat (limited to 'org.eclipse.mylyn.tasks.index.ui/src')
-rw-r--r--org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java66
-rw-r--r--org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexSearchHandler.java50
-rw-r--r--org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/Messages.java32
-rw-r--r--org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/ResetIndexHandler.java57
-rw-r--r--org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/commands/messages.properties2
5 files changed, 166 insertions, 41 deletions
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

Back to the top