Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2005-11-04 16:29:44 -0500
committermkersten2005-11-04 16:29:44 -0500
commit3c7cf1ed1d72495b7ff3ea50b3eba40c1708e929 (patch)
tree1e75f92b584987c860d28a2218033170f9412047
parente22519ca0e9999a69c25435efd31f89c774867c2 (diff)
downloadorg.eclipse.mylyn.tasks-3c7cf1ed1d72495b7ff3ea50b3eba40c1708e929.tar.gz
org.eclipse.mylyn.tasks-3c7cf1ed1d72495b7ff3ea50b3eba40c1708e929.tar.xz
org.eclipse.mylyn.tasks-3c7cf1ed1d72495b7ff3ea50b3eba40c1708e929.zip
Patch for Bugzilla Bug 114162: Export to zip files
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskDataExportTest.java23
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActiveTimerListener.java62
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActivityListener.java106
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskListManager.java8
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizard.java112
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizardPage.java17
6 files changed, 226 insertions, 102 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskDataExportTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskDataExportTest.java
index a3648a64e..fb3991139 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskDataExportTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskDataExportTest.java
@@ -58,13 +58,25 @@ public class TaskDataExportTest extends TestCase{
assertTrue(MylarPlugin.getContextManager().hasContext(task1.getPath()));
assertTrue(taskFile.exists());
}
-
+
+ /** Tests the wizard when it has been asked to export all task data to a zip file*/
+ public void testExportAllToZip(){
+
+ //Set parameters in the wizard to simulate a user setting them and clicking "Finish"
+ wizardPage.setParameters(true, true, true, true, true, destinationDir.getPath());
+ wizard.performFinish();
+
+ //Check that the task list file was exported
+ File destZipFile = new File(destinationDir + File.separator
+ + TaskDataExportWizard.ZIP_FILE_NAME);
+ assertTrue(destZipFile.exists());
+ }
/** Tests the wizard when it has been asked to export all task data */
public void testExportAll(){
//Set parameters in the wizard to simulate a user setting them and clicking "Finish"
- wizardPage.setParameters(true, true, true, true, destinationDir.getPath());
+ wizardPage.setParameters(true, true, true, true, false, destinationDir.getPath());
wizard.performFinish();
//Check that the task list file was exported
@@ -87,7 +99,14 @@ public class TaskDataExportTest extends TestCase{
protected void tearDown() throws Exception{
//Delete the test destination folder
+
+ File[] files = destinationDir.listFiles();
+ for (File file : files) {
+ file.delete();
+ }
+
destinationDir.delete();
+ assertFalse(destinationDir.exists());
super.tearDown();
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActiveTimerListener.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActiveTimerListener.java
deleted file mode 100644
index a4ea89d22..000000000
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActiveTimerListener.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 - 2005 University Of British Columbia 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:
- * University Of British Columbia - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylar.tasklist;
-
-import org.eclipse.mylar.core.InteractionEvent;
-import org.eclipse.mylar.core.MylarPlugin;
-import org.eclipse.mylar.core.internal.ActivityTimerThread;
-import org.eclipse.mylar.core.util.IActiveTimerListener;
-import org.eclipse.mylar.core.util.IInteractionEventListener;
-
-/**
- * @author Shawn Minto
- */
-public class TaskActiveTimerListener implements IActiveTimerListener, IInteractionEventListener {
-
- private ActivityTimerThread timer;
-
- private ITask task;
-
- private boolean isTaskStalled = false;
-
- public TaskActiveTimerListener(ITask task){
- this.task = task;
- timer = new ActivityTimerThread(MylarPlugin.getContextManager().getActivityTimeoutSeconds());
- timer.addListener(this);
- timer.start();
- MylarPlugin.getDefault().addInteractionListener(this);
- }
-
- public void fireTimedOut() {
- task.setActive(task.isActive(), true);
- isTaskStalled = true;
- timer.resetTimer();
- }
-
- public void interactionObserved(InteractionEvent event) {
- timer.resetTimer();
-
- if(isTaskStalled){
- task.setActive(task.isActive(), false);
- }
- isTaskStalled = false;
- }
-
- public void start() {}
-
- public void stopTimer() {
- timer.killThread();
- MylarPlugin.getDefault().removeInteractionListener(this);
- }
-
- public void stop() {}
-}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActivityListener.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActivityListener.java
new file mode 100644
index 000000000..f86cd09f6
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskActivityListener.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2005 University Of British Columbia 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:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.tasklist;
+
+import java.util.Date;
+
+import org.eclipse.mylar.core.InteractionEvent;
+import org.eclipse.mylar.core.MylarPlugin;
+import org.eclipse.mylar.core.internal.ActivityTimerThread;
+import org.eclipse.mylar.core.util.IActiveTimerListener;
+import org.eclipse.mylar.core.util.IInteractionEventListener;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A Task uses this class to determine when it is active
+ * based on a timer that fires a timeout when there has been
+ * no activity and a shell listener that detects when the
+ * window has been deactivated.
+ *
+ * @author Shawn Minto
+ * @author Wesley Coelho (Added correction for PC sleep/hibernation errors)
+ */
+public class TaskActivityListener implements IActiveTimerListener, IInteractionEventListener, ShellListener {
+
+ /** Amount of time for which discrepencies between timer and timestamp values will be ignored */
+ private final static long SLOP_FACTOR_MILLIS = 1000 * 30; //30 seconds
+
+ private ActivityTimerThread timer;
+ private ITask task;
+ private boolean isTaskStalled = false;
+ private long windowDeactivationTime = 0;
+
+ public TaskActivityListener(ITask task){
+ this.task = task;
+ timer = new ActivityTimerThread(MylarPlugin.getContextManager().getActivityTimeoutSeconds());
+ timer.addListener(this);
+ timer.start();
+ MylarPlugin.getDefault().addInteractionListener(this);
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().addShellListener(this);
+ }
+
+ /** Called by the timer when the user has been idle */
+ public void fireTimedOut() {
+ task.setActive(task.isActive(), true);
+ isTaskStalled = true;
+ timer.resetTimer();
+ }
+
+ public void interactionObserved(InteractionEvent event) {
+ timer.resetTimer();
+
+ if(isTaskStalled){
+ task.setActive(task.isActive(), false);
+ }
+ isTaskStalled = false;
+ }
+
+ public void start() {}
+
+ public void stopTimer() {
+ timer.killThread();
+ MylarPlugin.getDefault().removeInteractionListener(this);
+ }
+
+ public void stop() {}
+
+ public void shellDeactivated(ShellEvent e) {
+ windowDeactivationTime = new Date().getTime();
+ }
+
+ /**
+ * Check for and correct PC Sleep/Hibernation error
+ */
+ public void shellActivated(ShellEvent e) {
+ if (!isTaskStalled){
+ long timeDifference = new Date().getTime() - windowDeactivationTime;
+ if (timeDifference > Task.INACTIVITY_TIME_MILLIS + SLOP_FACTOR_MILLIS){
+ long newTime = task.getElapsedTimeLong() - timeDifference;
+ task.setElapsedTime("" + newTime);
+ }
+ }
+ }
+
+ public void shellClosed(ShellEvent e) {
+ //Do nothing, deactivated will fire
+ }
+
+ public void shellDeiconified(ShellEvent e) {
+ //Do nothing, wait for interaction to signal that the task is continuing
+ }
+
+ public void shellIconified(ShellEvent e) {
+ //Do nothing, deactivated will fire
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskListManager.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskListManager.java
index 6d15c9ca0..c45dd478d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskListManager.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/TaskListManager.java
@@ -29,7 +29,7 @@ import org.eclipse.mylar.tasklist.ui.views.TaskListView;
*/
public class TaskListManager {
- private Map<ITask, TaskActiveTimerListener> listenerMap = new HashMap<ITask, TaskActiveTimerListener>();
+ private Map<ITask, TaskActivityListener> listenerMap = new HashMap<ITask, TaskActivityListener>();
private File taskListFile;
private TaskList taskList = new TaskList();
@@ -107,7 +107,7 @@ public class TaskListManager {
}
public void deleteTask(ITask task) {
- TaskActiveTimerListener activeListener = listenerMap.remove(task);
+ TaskActivityListener activeListener = listenerMap.remove(task);
if(activeListener != null)
activeListener.stopTimer();
taskList.setActive(task, false, false);
@@ -140,13 +140,13 @@ public class TaskListManager {
}
}
taskList.setActive(task, true, false);
- TaskActiveTimerListener activeListener = new TaskActiveTimerListener(task);
+ TaskActivityListener activeListener = new TaskActivityListener(task);
listenerMap.put(task, activeListener);
for (ITaskActivityListener listener : listeners) listener.taskActivated(task);
}
public void deactivateTask(ITask task) {
- TaskActiveTimerListener activeListener = listenerMap.remove(task);
+ TaskActivityListener activeListener = listenerMap.remove(task);
if(activeListener != null) activeListener.stopTimer();
taskList.setActive(task, false, false);
for (ITaskActivityListener listener : listeners) listener.taskDeactivated(task);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizard.java
index 0f88211a3..30e149872 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizard.java
@@ -15,6 +15,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.core.internal.MylarContextManager;
+import org.eclipse.mylar.core.util.ZipFileUtil;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.ITaskListCategory;
import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
@@ -36,6 +37,8 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
*/
private final static String SETTINGS_SECTION = "org.eclipse.mylar.tasklist.ui.exportWizard";
+ public final static String ZIP_FILE_NAME = "mylartaskdata.zip";
+
private final static String WINDOW_TITLE = "Export";
private TaskDataExportWizardPage exportPage = null;
@@ -44,7 +47,7 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
IDialogSettings masterSettings = MylarTasklistPlugin.getDefault()
.getDialogSettings();
setDialogSettings(getSettingsSection(masterSettings));
- setNeedsProgressMonitor(true); // ?
+ setNeedsProgressMonitor(true);
setWindowTitle(WINDOW_TITLE);
}
@@ -82,6 +85,7 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
*/
public boolean performFinish() {
boolean overwrite = exportPage.overwrite();
+ boolean zip = exportPage.zip();
//Get file paths to check for existence
String destDir = exportPage.getDestinationDirectory();
@@ -91,40 +95,52 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
+ File.separator
+ MylarContextManager.CONTEXT_HISTORY_FILE_NAME
+ MylarContextManager.FILE_EXTENSION);
+ File destZipFile = new File(destDir + File.separator + ZIP_FILE_NAME);
//Prompt the user to confirm if ANY of the save operations will cause an overwrite
if(!overwrite){
- if (exportPage.exportTaskList() && destTaskListFile.exists()){
- if (!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "The task list file " + destTaskListFile.getPath() + " already exists. Do you want to overwrite it?")){
- return false;
- }
- }
- if (exportPage.exportActivationHistory() && destActivationHistoryFile.exists()){
- if (!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "The task activation history file " + destActivationHistoryFile.getPath() + " already exists. Do you want to overwrite it?")){
- return false;
- }
+ if (zip){
+ if (destZipFile.exists()){
+ if (!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "The zip file " + destZipFile.getPath() + " already exists. Do you want to overwrite it?")){
+ return false;
+ }
+ }
}
-
- if (exportPage.exportTaskContexts()) {
- for(ITask task : getAllTasks())
- {
- File destTaskFile = new File(destDir + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
- if (destTaskFile.exists()){
- if(!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "Task context files already exist in " + destDir + ". Do you want to overwrite them?")){
- return false;
- }
- else{
- break;
- }
+ else{
+ if (exportPage.exportTaskList() && destTaskListFile.exists()){
+ if (!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "The task list file " + destTaskListFile.getPath() + " already exists. Do you want to overwrite it?")){
+ return false;
}
}
- }
+
+ if (exportPage.exportActivationHistory() && destActivationHistoryFile.exists()){
+ if (!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "The task activation history file " + destActivationHistoryFile.getPath() + " already exists. Do you want to overwrite it?")){
+ return false;
+ }
+ }
+
+ if (exportPage.exportTaskContexts()) {
+ for(ITask task : getAllTasks())
+ {
+ File destTaskFile = new File(destDir + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
+ if (destTaskFile.exists()){
+ if(!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "Task context files already exist in " + destDir + ". Do you want to overwrite them?")){
+ return false;
+ }
+ else{
+ break;
+ }
+ }
+ }
+ }
+ }
}
//Save the files
+ List<File> filesToZip = new ArrayList<File>();
if (exportPage.exportTaskList()) {
MylarTasklistPlugin.getTaskListManager().saveTaskList();
@@ -133,15 +149,33 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
+ File.separator
+ MylarTasklistPlugin.DEFAULT_TASK_LIST_FILE;
File sourceTaskListFile = new File(sourceTaskListPath);
-
- if (!copy(sourceTaskListFile, destTaskListFile)) {
- MylarPlugin.fail(new Exception("Export Exception"), "Could not export task list file.", false);
- }
+
+ if (zip){
+ filesToZip.add(sourceTaskListFile);
+ }
+ else{
+ if (!copy(sourceTaskListFile, destTaskListFile)) {
+ MylarPlugin.fail(new Exception("Export Exception"), "Could not export task list file.", false);
+ }
+ }
+
}
if (exportPage.exportActivationHistory()) {
try {
- MylarPlugin.getContextManager().saveActivityHistoryContextFileCopy(destActivationHistoryFile);
+ File sourceActivationHistoryFile = new File(MylarPlugin.getDefault().getMylarDataDirectory()
+ + File.separator
+ + MylarContextManager.CONTEXT_HISTORY_FILE_NAME
+ + MylarContextManager.FILE_EXTENSION);
+
+ MylarPlugin.getContextManager().saveActivityHistoryContext();
+
+ if (zip){
+ filesToZip.add(sourceActivationHistoryFile);
+ }
+ else{
+ copy(sourceActivationHistoryFile, destActivationHistoryFile);
+ }
} catch (RuntimeException e) {
MylarPlugin.fail(e, "Could not export activity history context file", true);
}
@@ -158,12 +192,28 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
File destTaskFile = new File(destDir + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
File sourceTaskFile = new File(MylarPlugin.getDefault().getMylarDataDirectory() + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
- if (!copy(sourceTaskFile, destTaskFile) && !errorDisplayed){
- MylarPlugin.fail(new Exception("Export Exception: " + sourceTaskFile.getPath() + " -> " + destTaskFile.getPath()), "Could not export one or more task context files.", true);
- errorDisplayed = true;
+ if (zip){
+ filesToZip.add(sourceTaskFile);
+ }
+ else{
+ if (!copy(sourceTaskFile, destTaskFile) && !errorDisplayed){
+ MylarPlugin.fail(new Exception("Export Exception: " + sourceTaskFile.getPath() + " -> " + destTaskFile.getPath()), "Could not export one or more task context files.", true);
+ errorDisplayed = true;
+ }
}
}
}
+
+ if (zip){
+ try {
+ if (destZipFile.exists()){
+ destZipFile.delete();
+ }
+ ZipFileUtil.createZipFile(destZipFile, filesToZip);
+ } catch (Exception e) {
+ MylarPlugin.fail(e, "Could not create zip file.", true);
+ }
+ }
exportPage.saveSettings();
return true;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizardPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizardPage.java
index b388aeee1..cdf8d0f7d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizardPage.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizardPage.java
@@ -31,7 +31,8 @@ public class TaskDataExportWizardPage extends WizardPage {
//Control fields
private Button taskListCheckBox = null;
private Button taskActivationHistoryCheckBox = null;
- private Button taskContextsCheckBox = null;;
+ private Button taskContextsCheckBox = null;
+ private Button zipCheckBox = null;
private Button browseButton = null;
private Text destDirText = null;
private Button overwriteCheckBox = null;
@@ -43,7 +44,7 @@ public class TaskDataExportWizardPage extends WizardPage {
private final static String CONTEXTS_SETTING = "Contexts setting";
private final static String DEST_DIR_SETTING = "Destination directory setting";
private final static String OVERWRITE_SETTING = "Overwrite setting";
-
+ private final static String ZIP_SETTING = "Zip Setting";
public TaskDataExportWizardPage(){
super("org.eclipse.mylar.tasklist.exportPage", PAGE_TITLE,
@@ -67,6 +68,7 @@ public class TaskDataExportWizardPage extends WizardPage {
createFileSelectionControl(container);
createExportDirectoryControl(container);
+ zipCheckBox = createCheckBox(container, "Export to zip file");
overwriteCheckBox = createCheckBox(container, "Overwrite existing files without warning");
initSettings();
@@ -145,6 +147,7 @@ public class TaskDataExportWizardPage extends WizardPage {
taskContextsCheckBox.setSelection(true);
destDirText.setText("");
overwriteCheckBox.setSelection(true);
+ zipCheckBox.setSelection(false);
}
else{
//Retrieve previous values from the dialog settings
@@ -156,6 +159,7 @@ public class TaskDataExportWizardPage extends WizardPage {
destDirText.setText(settings.get(DEST_DIR_SETTING));
}
overwriteCheckBox.setSelection(settings.getBoolean(OVERWRITE_SETTING));
+ zipCheckBox.setSelection(settings.getBoolean(ZIP_SETTING));
}
}
@@ -171,6 +175,7 @@ public class TaskDataExportWizardPage extends WizardPage {
settings.put(CONTEXTS_SETTING, taskContextsCheckBox.getSelection());
settings.put(DEST_DIR_SETTING, destDirText.getText());
settings.put(OVERWRITE_SETTING, overwriteCheckBox.getSelection());
+ settings.put(ZIP_SETTING, zipCheckBox.getSelection());
settings.put(SETTINGS_SAVED, SETTINGS_SAVED);
}
@@ -242,12 +247,18 @@ public class TaskDataExportWizardPage extends WizardPage {
return overwriteCheckBox.getSelection();
}
+ /** True if the user wants to write to a zip file */
+ public boolean zip(){
+ return zipCheckBox.getSelection();
+ }
+
/** For testing only. Sets controls to the specified values */
- public void setParameters(boolean overwrite, boolean exportTaskList, boolean exportActivationHistory, boolean exportTaskContexts, String destinationDir){
+ public void setParameters(boolean overwrite, boolean exportTaskList, boolean exportActivationHistory, boolean exportTaskContexts, boolean zip, String destinationDir){
overwriteCheckBox.setSelection(overwrite);
taskListCheckBox.setSelection(exportTaskList);
taskActivationHistoryCheckBox.setSelection(exportActivationHistory);
taskContextsCheckBox.setSelection(exportTaskContexts);
destDirText.setText(destinationDir);
+ zipCheckBox.setSelection(zip);
}
}

Back to the top