Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Dong2016-07-05 14:53:58 -0400
committerGerrit Code Review @ Eclipse.org2016-07-15 13:04:46 -0400
commiteece2a8c5e98b614feb7ba28a004f4768a90129f (patch)
tree902fc8889aa29f8e1b964b13c25761c617d8c3db /org.eclipse.mylyn.tasks.core
parent4351b5505b4614adcdb1a093ef8f61fba69efc44 (diff)
downloadorg.eclipse.mylyn.tasks-eece2a8c5e98b614feb7ba28a004f4768a90129f.tar.gz
org.eclipse.mylyn.tasks-eece2a8c5e98b614feb7ba28a004f4768a90129f.tar.xz
org.eclipse.mylyn.tasks-eece2a8c5e98b614feb7ba28a004f4768a90129f.zip
TaskDataManager has API to migrate attributes in its task datas
Change-Id: Iba999001a1989783543aa45ae6530fd6e040896f Signed-off-by: Brandon Dong <brandon.dong@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java2
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java19
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataState.java26
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties1
4 files changed, 48 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java
index ec7fb5270..658f04aa3 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java
@@ -79,6 +79,8 @@ public class Messages extends NLS {
public static String DefaultTaskSchema_Summary_Label;
public static String DefaultTaskSchema_URL_Label;
+
+ public static String TaskDataState_RefactorRoot;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java
index 710239789..83f2664b9 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java
@@ -639,4 +639,23 @@ public class TaskDataManager implements ITaskDataManager {
});
}
+
+ public void refactorAttribute(ITask itask, TaskAttribute attribute) throws CoreException {
+ Assert.isTrue(itask instanceof AbstractTask);
+ final AbstractTask task = (AbstractTask) itask;
+ final String kind = task.getConnectorKind();
+ taskList.run(new ITaskListRunnable() {
+ public void execute(IProgressMonitor monitor) throws CoreException {
+ File file = getMigratedFile(task, kind);
+ if (file.exists()) {
+ TaskDataState state = taskDataStore.getTaskDataState(file);
+ if (state != null) {
+ state.refactorAttribute(attribute);
+ taskDataStore.putTaskData(file, state);
+ }
+ }
+ }
+ });
+
+ }
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataState.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataState.java
index ee39a1b34..0e91acdc6 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataState.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataState.java
@@ -11,11 +11,15 @@
package org.eclipse.mylyn.internal.tasks.core.data;
+import java.util.Arrays;
import java.util.Set;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
@@ -240,4 +244,26 @@ public class TaskDataState implements ITaskDataWorkingCopy {
return newData;
}
+ public void refactorAttribute(TaskAttribute attribute) throws CoreException {
+ refactorAttribute(localTaskData, attribute);
+ refactorAttribute(repositoryTaskData, attribute);
+ refactorAttribute(editsTaskData, attribute);
+ refactorAttribute(lastReadTaskData, attribute);
+ }
+
+ private void refactorAttribute(TaskData taskData, TaskAttribute attribute) throws CoreException {
+ if (taskData != null) {
+ String[] path = attribute.getPath();
+ if (path.length == 0) {
+ throw new CoreException(
+ new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, Messages.TaskDataState_RefactorRoot));
+ }
+ String[] shortenedPath = Arrays.copyOfRange(path, 0, path.length - 1);
+ TaskAttribute parent = taskData.getRoot().getMappedAttribute(shortenedPath);
+ if (parent != null) {
+ parent.removeAttribute(attribute.getId());
+ parent.deepAddCopy(attribute);
+ }
+ }
+ }
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties
index 72f341366..ebac44433 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties
@@ -40,3 +40,4 @@ DefaultTaskSchema_Size_Label=Size
DefaultTaskSchema_Status_Label=Status
DefaultTaskSchema_Summary_Label=Summary
DefaultTaskSchema_URL_Label=URL
+TaskDataState_RefactorRoot=Cannot refactor root attribute

Back to the top