From 2befecfd0c9ea65a84504ad94eea486e317407cf Mon Sep 17 00:00:00 2001 From: Steffen Pingel Date: Fri, 2 Mar 2012 11:35:11 -0800 Subject: bug 372725: handle changes to task data directory https://bugs.eclipse.org/bugs/show_bug.cgi?id=372725 Change-Id: I24cc1a042b41a0fc83c28638b78c25fb74a818f1 --- .../internal/tasks/index/ui/IndexReference.java | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'org.eclipse.mylyn.tasks.index.ui/src') 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 index 742986d60..5181cbf43 100644 --- 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 @@ -14,12 +14,14 @@ package org.eclipse.mylyn.internal.tasks.index.ui; import java.io.File; import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.mylyn.internal.tasks.core.IRepositoryModelListener; 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 + * @author Steffen Pingel */ public class IndexReference { @@ -27,6 +29,20 @@ public class IndexReference { private static AtomicInteger referenceCount = new AtomicInteger(); + private static IRepositoryModelListener listener = new IRepositoryModelListener() { + public void loaded() { + synchronized (IndexReference.class) { + if (theIndex != null) { + theIndex.setLocation(getDefaultIndexLocation()); + } + } + } + }; + + static File getDefaultIndexLocation() { + return new File(TasksUiPlugin.getDefault().getDataDirectory(), ".taskListIndex"); //$NON-NLS-1$ + } + /** * When not null serves as flag indicating that theIndex is referenced, thus preventing bad behaviour if dispose is * called multiple times. @@ -38,11 +54,9 @@ public class IndexReference { 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); - + repositoryManager, getDefaultIndexLocation()); + TasksUiPlugin.getDefault().addModelListener(listener); } index = theIndex; referenceCount.incrementAndGet(); @@ -57,10 +71,12 @@ public class IndexReference { index = null; if (referenceCount.decrementAndGet() == 0) { + TasksUiPlugin.getDefault().removeModelListener(listener); theIndex.close(); theIndex = null; } } } } + } -- cgit v1.2.3