Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2005-11-07 16:16:30 -0500
committermkersten2005-11-07 16:16:30 -0500
commit8a9458df9d80da2005a25eb8a4a24118bf1ceb43 (patch)
tree4cb17a3bb946eac1c97d8a4bdcf90a8d437038c1
parent5863a0e5bb8b4443a2fdcf6102d50aae66ef1287 (diff)
downloadorg.eclipse.mylyn.tasks-8a9458df9d80da2005a25eb8a4a24118bf1ceb43.tar.gz
org.eclipse.mylyn.tasks-8a9458df9d80da2005a25eb8a4a24118bf1ceb43.tar.xz
org.eclipse.mylyn.tasks-8a9458df9d80da2005a25eb8a4a24118bf1ceb43.zip
Patch for Bugzilla Bug 114162 Export to zip files
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/wizards/TaskDataExportWizard.java236
1 files changed, 146 insertions, 90 deletions
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 3a4c9e226..5e3a9cc5c 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
@@ -6,13 +6,16 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.mylar.core.MylarPlugin;
@@ -24,6 +27,8 @@ import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
import org.eclipse.mylar.tasklist.internal.TaskList;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
/**
* Wizard for exporting tasklist data files to the file system. This wizard uses
@@ -32,27 +37,27 @@ import org.eclipse.ui.IWorkbench;
* @author Wesley Coelho
*/
public class TaskDataExportWizard extends Wizard implements IExportWizard {
-
+
/**
* The name of the dialog store's section associated with the task data
* export wizard
*/
private final static String SETTINGS_SECTION = "org.eclipse.mylar.tasklist.ui.exportWizard";
-
+
public final static String ZIP_FILE_NAME = TaskDataExportWizardPage.ZIP_FILE_NAME;
private final static String WINDOW_TITLE = "Export";
-
+
private TaskDataExportWizardPage exportPage = null;
-
+
public TaskDataExportWizard() {
IDialogSettings masterSettings = MylarTasklistPlugin.getDefault()
- .getDialogSettings();
+ .getDialogSettings();
setDialogSettings(getSettingsSection(masterSettings));
setNeedsProgressMonitor(true);
setWindowTitle(WINDOW_TITLE);
}
-
+
/**
* Finds or creates a dialog settings section that is used to make the
* dialog control settings persistent
@@ -64,21 +69,21 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
}
return settings;
}
-
+
public void addPages() {
exportPage = new TaskDataExportWizardPage();
exportPage.setWizard(this);
addPage(exportPage);
}
-
+
public void init(IWorkbench workbench, IStructuredSelection selection) {
// no initialization needed
}
-
+
public boolean canFinish() {
return exportPage.isPageComplete();
}
-
+
/**
* Called when the user clicks finish. Saves the task data.
* Waits until all overwrite decisions have been made before
@@ -91,20 +96,20 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
//Get file paths to check for existence
String destDir = exportPage.getDestinationDirectory();
- File destDirFile = new File(destDir);
+ final File destDirFile = new File(destDir);
if (!destDirFile.exists() || !destDirFile.isDirectory()){
//This should never happen
MylarPlugin.fail(new Exception("File Export Exception"), "Could not export data because specified location does not exist or is not a folder", true);
return false;
}
- File destTaskListFile = new File(destDir + File.separator
+ final File destTaskListFile = new File(destDir + File.separator
+ MylarTasklistPlugin.DEFAULT_TASK_LIST_FILE);
- File destActivationHistoryFile = new File(destDir
+ final File destActivationHistoryFile = new File(destDir
+ File.separator
+ MylarContextManager.CONTEXT_HISTORY_FILE_NAME
+ MylarContextManager.FILE_EXTENSION);
- File destZipFile = new File(destDir + File.separator + ZIP_FILE_NAME);
+ final 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
@@ -131,8 +136,8 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
}
if (exportPage.exportTaskContexts()) {
- for(ITask task : getAllTasks())
- {
+ 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?")){
@@ -147,101 +152,152 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
}
}
- //Save the files
+
+ FileCopyJob job = new FileCopyJob(destZipFile, destTaskListFile, destActivationHistoryFile);
+ IProgressService service = PlatformUI.getWorkbench().getProgressService();
- //List of files to add to the zip archive
- List<File> filesToZip = new ArrayList<File>();
+ try {
+ service.run(true, false, job);
+ } catch (InvocationTargetException e) {
+ MylarPlugin.fail(e, "Could not export files", true);
+ } catch (InterruptedException e) {
+ MylarPlugin.fail(e, "Could not export files", true);
+ }
+
+ exportPage.saveSettings();
+ return true;
+ }
+
+ /** Job that performs the file copying and zipping*/
+ class FileCopyJob implements IRunnableWithProgress{
- //Map of file paths used to avoid duplicates
- Map<String,String> filesToZipMap = new HashMap<String, String>();
+ private static final String JOB_LABEL = "Exporting Data";
- if (exportPage.exportTaskList()) {
- MylarTasklistPlugin.getTaskListManager().saveTaskList();
-
- String sourceTaskListPath = MylarPlugin.getDefault()
- .getMylarDataDirectory()
- + File.separator
- + MylarTasklistPlugin.DEFAULT_TASK_LIST_FILE;
- File sourceTaskListFile = new File(sourceTaskListPath);
+ private File destZipFile = null;
+ private File destTaskListFile = null;
+ private File destActivationHistoryFile = null;
+ private boolean zip;
+ private boolean exportTaskList;
+ private boolean exportActivationHistory;
+ private boolean exportTaskContexts;
+ private String destinationDirectory;
+
+ public FileCopyJob(File destZipFile, File destTaskListFile, File destActivationHistoryFile){
+ this.destZipFile = destZipFile;
+ this.destTaskListFile = destTaskListFile;
+ this.destActivationHistoryFile = destActivationHistoryFile;
- if (zip){
- filesToZip.add(sourceTaskListFile);
- }
- else{
- if (!copy(sourceTaskListFile, destTaskListFile)) {
- MylarPlugin.fail(new Exception("Export Exception"), "Could not export task list file.", false);
- }
- }
-
+ //Get parameters here to avoid accessing the UI thread
+ this.zip = exportPage.zip();
+ this.exportTaskList = exportPage.exportTaskList();
+ this.exportActivationHistory = exportPage.exportActivationHistory();
+ this.exportTaskContexts = exportPage.exportTaskContexts();
+ this.destinationDirectory = exportPage.getDestinationDirectory();
}
-
- if (exportPage.exportActivationHistory()) {
- try {
- File sourceActivationHistoryFile = new File(MylarPlugin.getDefault().getMylarDataDirectory()
- + File.separator
- + MylarContextManager.CONTEXT_HISTORY_FILE_NAME
- + MylarContextManager.FILE_EXTENSION);
+
+ public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ List<ITask> tasks = getAllTasks();
+ monitor.beginTask(JOB_LABEL, tasks.size() + 2);
+
+ //List of files to add to the zip archive
+ List<File> filesToZip = new ArrayList<File>();
+
+ //Map of file paths used to avoid duplicates
+ Map<String,String> filesToZipMap = new HashMap<String, String>();
+
+ if (exportTaskList) {
+ MylarTasklistPlugin.getTaskListManager().saveTaskList();
- MylarPlugin.getContextManager().saveActivityHistoryContext();
+ String sourceTaskListPath = MylarPlugin.getDefault()
+ .getMylarDataDirectory()
+ + File.separator
+ + MylarTasklistPlugin.DEFAULT_TASK_LIST_FILE;
+ File sourceTaskListFile = new File(sourceTaskListPath);
if (zip){
- filesToZip.add(sourceActivationHistoryFile);
+ filesToZip.add(sourceTaskListFile);
}
else{
- copy(sourceActivationHistoryFile, destActivationHistoryFile);
- }
- } catch (RuntimeException e) {
- MylarPlugin.fail(e, "Could not export activity history context file", true);
- }
- }
-
- if (exportPage.exportTaskContexts()) {
- boolean errorDisplayed = false; //Prevent many repeated error messages
- for(ITask task : getAllTasks())
- {
-
- if (!MylarPlugin.getContextManager().hasContext(task.getPath())){
- continue; //Tasks without a context have no file to copy
+ if (!copy(sourceTaskListFile, destTaskListFile)) {
+ MylarPlugin.fail(new Exception("Export Exception"), "Could not export task list file.", false);
+ }
+ monitor.worked(1);
}
-
- 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 (zip){
- if (!filesToZipMap.containsKey(task.getPath())){
- filesToZip.add(sourceTaskFile);
- filesToZipMap.put(task.getPath(), null);
+ }
+
+ if (exportActivationHistory) {
+ try {
+ 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{
- 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;
- }
+ else{
+ copy(sourceActivationHistoryFile, destActivationHistoryFile);
+ monitor.worked(1);
+ }
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "Could not export activity history context file", true);
}
}
- }
-
- if (zip){
- try {
- if (destZipFile.exists()){
- destZipFile.delete();
+
+ if (exportTaskContexts) {
+ boolean errorDisplayed = false; //Prevent many repeated error messages
+ for(ITask task : tasks)
+ {
+
+ if (!MylarPlugin.getContextManager().hasContext(task.getPath())){
+ continue; //Tasks without a context have no file to copy
+ }
+
+ File destTaskFile = new File(destinationDirectory + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
+ File sourceTaskFile = new File(MylarPlugin.getDefault().getMylarDataDirectory() + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
+
+ if (zip){
+ if (!filesToZipMap.containsKey(task.getPath())){
+ filesToZip.add(sourceTaskFile);
+ filesToZipMap.put(task.getPath(), null);
+ }
+ }
+ 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;
+ }
+ monitor.worked(1);
+ }
}
- ZipFileUtil.createZipFile(destZipFile, filesToZip);
- } catch (Exception e) {
- MylarPlugin.fail(e, "Could not create zip file.", true);
- }
+ }
+
+ if (zip){
+ try {
+ if (destZipFile.exists()){
+ destZipFile.delete();
+ }
+ ZipFileUtil.createZipFile(destZipFile, filesToZip, monitor);
+ } catch (Exception e) {
+ MylarPlugin.fail(e, "Could not create zip file.", true);
+ }
+ }
+ monitor.done();
+
}
-
- exportPage.saveSettings();
- return true;
}
+
+
+
/** Returns all tasks in the task list root or a category in the task list */
protected List<ITask> getAllTasks(){
List<ITask> allTasks = new ArrayList<ITask>();
TaskList taskList = MylarTasklistPlugin.getTaskListManager().getTaskList();
-
+
allTasks.addAll(taskList.getRootTasks());
for (ITaskListCategory category : taskList.getCategories()){
@@ -256,7 +312,7 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
try {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
-
+
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
@@ -270,5 +326,5 @@ public class TaskDataExportWizard extends Wizard implements IExportWizard {
return false;
}
}
-
+
}

Back to the top