Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/Messages.java3
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/TaskActivationExternalizationParticipant.java163
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/messages.properties1
3 files changed, 167 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/Messages.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/Messages.java
index 792f462b1..b53d2049e 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/Messages.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/Messages.java
@@ -32,4 +32,7 @@ public class Messages extends NLS {
public static String ExternalizationManager_Task_List_Save_Job;
public static String TaskListExternalizationParticipant_Task_List;
+
+ public static String TaskActivationExternalizationParticipant_Task_Activation_History;
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/TaskActivationExternalizationParticipant.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/TaskActivationExternalizationParticipant.java
new file mode 100644
index 000000000..a4e2011e2
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/TaskActivationExternalizationParticipant.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core.externalization;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+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.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.mylyn.commons.core.XmlMemento;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
+import org.eclipse.mylyn.internal.tasks.core.TaskActivationHistory;
+import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.ITaskActivationListener;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TaskActivationExternalizationParticipant extends AbstractExternalizationParticipant implements
+ ITaskActivationListener {
+
+ private final ExternalizationManager externalizationManager;
+
+ private boolean dirty;
+
+ private final TaskActivationHistory activationHistory;
+
+ private final File file;
+
+ private final TaskList taskList;
+
+ public TaskActivationExternalizationParticipant(ExternalizationManager externalizationManager, TaskList taskList,
+ TaskActivationHistory history, File file) {
+ this.externalizationManager = externalizationManager;
+ this.taskList = taskList;
+ this.activationHistory = history;
+ this.file = file;
+ }
+
+ @Override
+ public String getDescription() {
+ return Messages.TaskActivationExternalizationParticipant_Task_Activation_History;
+ }
+
+ @Override
+ public ISchedulingRule getSchedulingRule() {
+ return ITasksCoreConstants.ACTIVITY_SCHEDULING_RULE;
+ }
+
+ @Override
+ public boolean isDirty() {
+ return dirty;
+ }
+
+ private void requestSave() {
+ synchronized (TaskActivationExternalizationParticipant.this) {
+ dirty = true;
+ }
+ externalizationManager.requestSave();
+ }
+
+ @Override
+ public void load(File sourceFile, IProgressMonitor monitor) throws CoreException {
+ try {
+ activationHistory.clear();
+ if (file.exists()) {
+ FileReader reader = new FileReader(file);
+ try {
+ XmlMemento memento = XmlMemento.createReadRoot(reader);
+ XmlMemento[] items = memento.getChildren("task"); //$NON-NLS-1$
+ for (XmlMemento child : items) {
+ String handle = child.getString("handle"); //$NON-NLS-1$
+ if (handle != null) {
+ AbstractTask task = taskList.getTask(handle);
+ if (task != null) {
+ activationHistory.addTaskInternal(task);
+ }
+ }
+ }
+ } finally {
+ reader.close();
+ }
+ }
+ } catch (InvocationTargetException e) {
+ throw new CoreException(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Failed to load task activation history", e)); //$NON-NLS-1$
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Failed to load task activation history", e)); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void save(File targetFile, IProgressMonitor monitor) throws CoreException {
+ synchronized (TaskActivationExternalizationParticipant.this) {
+ dirty = false;
+ }
+
+ XmlMemento memento = XmlMemento.createWriteRoot("taskActivationHistory"); //$NON-NLS-1$
+ for (AbstractTask task : activationHistory.getPreviousTasks()) {
+ XmlMemento child = memento.createChild("task"); //$NON-NLS-1$
+ child.putString("handle", task.getHandleIdentifier()); //$NON-NLS-1$
+ }
+
+ try {
+ file.getParentFile().mkdirs();
+ FileWriter writer = new FileWriter(file);
+ try {
+ memento.save(writer);
+ } finally {
+ writer.close();
+ }
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Failed to save task activation history", e)); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public String getFileName() {
+ return file.getName();
+ }
+
+ @Override
+ public File getFile(String rootPath) throws CoreException {
+ return file;
+ }
+
+ public void preTaskActivated(ITask task) {
+ // ignore
+ }
+
+ public void preTaskDeactivated(ITask task) {
+ // ignore
+ }
+
+ public void taskActivated(ITask task) {
+ activationHistory.addTask((AbstractTask) task);
+ requestSave();
+ }
+
+ public void taskDeactivated(ITask task) {
+ // ignore
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/messages.properties b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/messages.properties
index 50a62ccd1..68b87f4e4 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/messages.properties
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/externalization/messages.properties
@@ -13,3 +13,4 @@ ExternalizationManager_Saving_=Saving...
ExternalizationManager_Task_List_Save_Job=Task List Save Job
TaskListExternalizationParticipant_Task_List=Task List
+TaskActivationExternalizationParticipant_Task_Activation_History=Task Activation History

Back to the top