Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 189518 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (-1 / +32 lines)
Lines 99-105 Link Here
99
           class="org.eclipse.mylyn.internal.tasks.ui.wizards.TaskDataImportWizard"
99
           class="org.eclipse.mylyn.internal.tasks.ui.wizards.TaskDataImportWizard"
100
           icon="icons/eview16/task-list.gif"
100
           icon="icons/eview16/task-list.gif"
101
           id="org.eclipse.mylyn.tasks.ui.wizards.import"
101
           id="org.eclipse.mylyn.tasks.ui.wizards.import"
102
           name="Task List">
102
           name="Task Data">
103
        <description>
103
        <description>
104
           Import task data files from file system.
104
           Import task data files from file system.
105
        </description>
105
        </description>
Lines 342-348 Link Here
342
               </or>
342
               </or>
343
            </enablement>
343
            </enablement>
344
         </action>
344
         </action>
345
         
346
        <!-- <action
347
               class="org.eclipse.mylyn.internal.tasks.ui.actions.QueryCloneAction"
348
               definitionId="org.eclipse.ui.query.clone"
349
               enablesFor="org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery"
350
               id="org.eclipse.mylyn.tasks.ui.actions.clone.query"
351
               label="Clone Query..."
352
               menubarPath="repository"
353
               tooltip="Clone Repository Query">
354
         </action>-->
355
         
356
         <action
357
               class="org.eclipse.mylyn.internal.tasks.ui.actions.QueryExportAction"
358
               definitionId="org.eclipse.ui.query.export"
359
               enablesFor="org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery"
360
               id="org.eclipse.mylyn.tasks.ui.actions.export.query"
361
               label="Export Query..."
362
               menubarPath="repository"
363
               tooltip="Export Repository Query">
364
         </action>
345
  		
365
  		
366
		  <action
367
               class="org.eclipse.mylyn.internal.tasks.ui.actions.QueryImportAction"
368
               definitionId="org.eclipse.ui.query.import"
369
               enablesFor="*"
370
               icon="icons/etool16/import.gif"
371
               id="org.eclipse.mylyn.tasks.ui.actions.import.query"
372
               label="Import Query..."
373
               menubarPath="repository"
374
               tooltip="Import Repository Query">
375
         </action>
376
346
  		<action
377
  		<action
347
	        class="org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskAction"
378
	        class="org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskAction"
348
	        enablesFor="*"
379
	        enablesFor="*"
(-)src/org/eclipse/mylyn/internal/tasks/ui/actions/QueryImportAction.java (+90 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui.actions;
10
11
import java.io.File;
12
import java.util.List;
13
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants;
19
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
20
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
21
import org.eclipse.swt.widgets.FileDialog;
22
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.ui.IViewActionDelegate;
24
import org.eclipse.ui.IViewPart;
25
import org.eclipse.ui.PlatformUI;
26
27
/**
28
 * Makes able to select an exported query file and import it back to the system.
29
 * @author Jevgeni Holodkov
30
 */
31
public class QueryImportAction extends Action implements IViewActionDelegate {
32
33
	protected ISelection selection;
34
	
35
	public void init(IViewPart view) {
36
		// ignore
37
	}
38
39
	public void run(IAction action) {
40
		run();
41
	}
42
43
	public void selectionChanged(IAction action, ISelection selection) {
44
		// ignore
45
	}
46
47
	
48
	public void run() {
49
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
50
		FileDialog dialog = new FileDialog(shell);
51
		dialog.setFilterExtensions(new String[] { "*" + ITasksUiConstants.FILE_EXTENSION });
52
		
53
		String path = dialog.open();
54
		if (path != null) {
55
			File file = new File(path);
56
			if (file.isFile()) {
57
				List<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager()
58
						.getTaskListWriter()
59
						.readQueries(file);
60
				
61
				if (queries.size() > 0) {
62
					List<AbstractRepositoryQuery> badQueries = TasksUiPlugin.getTaskListManager().insertQueries(queries);
63
					
64
					// notify user about importing
65
					String message = "The following queries were imported successfully: ";
66
					for(AbstractRepositoryQuery imported : queries) {
67
						if(!badQueries.contains(imported)) {
68
							message += "\n" + imported.getHandleIdentifier();
69
						}
70
					}
71
					
72
					if(badQueries.size() > 0) {
73
						message += "\n\n These queries were not imported, since their repository was not found: ";
74
						for (AbstractRepositoryQuery bad : badQueries) {
75
							message += "\n" + bad.getHandleIdentifier();
76
						}
77
					}
78
					
79
					MessageDialog.openInformation(shell, "Query Export Completed", message);
80
				} else {
81
					MessageDialog.openError(shell, "Query Export Error",
82
							"The specified file is not an exported query. Please, check that you have provided the correct file.");
83
					return;
84
				}
85
			}
86
		}
87
		 return;
88
	}
89
90
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/actions/QueryExportAction.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui.actions;
10
11
import java.io.File;
12
import java.text.SimpleDateFormat;
13
import java.util.ArrayList;
14
import java.util.Date;
15
import java.util.List;
16
import java.util.Locale;
17
18
import org.eclipse.jface.action.Action;
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.StructuredSelection;
23
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants;
24
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
25
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.widgets.FileDialog;
28
import org.eclipse.swt.widgets.Shell;
29
import org.eclipse.ui.IViewActionDelegate;
30
import org.eclipse.ui.IViewPart;
31
import org.eclipse.ui.PlatformUI;
32
33
/**
34
 * Makes able to export selected query to the file system.
35
 * @author Jevgeni Holodkov
36
 */
37
public class QueryExportAction extends Action implements IViewActionDelegate {
38
39
	protected ISelection selection;
40
	
41
	public void init(IViewPart view) {
42
		// ignore
43
	}
44
45
	public void run(IAction action) {
46
		run(getSelectedQueries(selection));
47
	}
48
49
	public void selectionChanged(IAction action, ISelection selection) {
50
		this.selection = selection;
51
		List<AbstractRepositoryQuery> selectedQueries = getSelectedQueries(selection);
52
		action.setEnabled(true);
53
		if (selectedQueries.size() > 0) {
54
			action.setEnabled(true);
55
		} else {
56
			action.setEnabled(false);
57
		}
58
	}
59
	
60
	@SuppressWarnings("unchecked")
61
	protected List<AbstractRepositoryQuery> getSelectedQueries(ISelection newSelection) {
62
		List<AbstractRepositoryQuery> selectedQueries = new ArrayList<AbstractRepositoryQuery>();
63
		if (selection instanceof StructuredSelection) {
64
			List selectedObjects = ((StructuredSelection) selection).toList();
65
			for (Object selectedObject : selectedObjects) {
66
				if (selectedObject instanceof AbstractRepositoryQuery) {
67
					selectedQueries.add((AbstractRepositoryQuery)selectedObject);
68
				}
69
			}
70
		}
71
		return selectedQueries;
72
	}
73
	
74
75
	
76
	public void run(List<AbstractRepositoryQuery> queries) {
77
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
78
		FileDialog dialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
79
		dialog.setFilterExtensions(new String[] { "*" + ITasksUiConstants.FILE_EXTENSION });
80
		if (queries.size() == 1) {
81
			dialog.setFileName(queries.get(0).getHandleIdentifier());
82
		} else {
83
			String fomratString = "yyyy-MM-dd";
84
			SimpleDateFormat format = new SimpleDateFormat(fomratString, Locale.ENGLISH);
85
			String date = format.format(new Date());
86
			dialog.setFileName(date + "-exported-queries");
87
		}
88
		
89
		String path = dialog.open();
90
		if (path != null) {
91
			File file = new File(path);
92
			if (file.isDirectory()) {
93
				MessageDialog.openError(shell, "Query Export Error", "Could not export query because specified location is a folder");
94
				return;
95
			}
96
97
			// Prompt the user to confirm if save operation will cause an overwrite
98
			if (file.exists()) {
99
				if (!MessageDialog.openConfirm(shell, "Confirm File Replace", "The file " + file.getPath()
100
						+ " already exists. Do you want to overwrite it?")) {
101
					return;
102
				}
103
			}
104
			
105
			TasksUiPlugin.getTaskListManager().getTaskListWriter().writeQueries(queries, file);
106
		}
107
		 return;
108
	}
109
}

Return to bug 189518