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

(-)src/org/eclipse/mylyn/tasks/tests/QueryExportImportTest.java (-6 / +2 lines)
Lines 14-26 Link Here
14
import java.io.File;
14
import java.io.File;
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.List;
16
import java.util.List;
17
import java.util.Set;
18
17
19
import junit.framework.TestCase;
18
import junit.framework.TestCase;
20
19
21
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
20
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
22
import org.eclipse.mylyn.tasks.core.AbstractTaskListFactory;
21
import org.eclipse.mylyn.tasks.core.AbstractTaskListFactory;
23
import org.eclipse.mylyn.tasks.core.TaskList;
24
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryQuery;
22
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryQuery;
25
import org.eclipse.mylyn.tasks.tests.connector.MockTaskListFactory;
23
import org.eclipse.mylyn.tasks.tests.connector.MockTaskListFactory;
26
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
24
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
Lines 69-79 Link Here
69
		TasksUiPlugin.getTaskListManager().getTaskListWriter().writeQuery(query, outFile);
67
		TasksUiPlugin.getTaskListManager().getTaskListWriter().writeQuery(query, outFile);
70
		assertTrue(outFile.exists());
68
		assertTrue(outFile.exists());
71
		
69
		
72
		TaskList taskList = TasksUiPlugin.getTaskListManager().resetTaskList();
73
74
		File inFile = new File(dest, "test-query.xml.zip");
70
		File inFile = new File(dest, "test-query.xml.zip");
75
		TasksUiPlugin.getTaskListManager().getTaskListWriter().readQueries(taskList, inFile);		
71
		List<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager().getTaskListWriter().readQueries(
76
		Set<AbstractRepositoryQuery> queries = taskList.getQueries();
72
				inFile);		
77
		assertEquals("1 Query is imported", 1, queries.size());
73
		assertEquals("1 Query is imported", 1, queries.size());
78
	}
74
	}
79
	
75
	
(-)src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java (-22 / +36 lines)
Lines 57-62 Link Here
57
 * @author Mik Kersten
57
 * @author Mik Kersten
58
 * @author Ken Sueda
58
 * @author Ken Sueda
59
 * @author Rob Elves
59
 * @author Rob Elves
60
 * @author Jevgeni Holodkov
60
 * 
61
 * 
61
 * TODO: move to core?
62
 * TODO: move to core?
62
 */
63
 */
Lines 338-345 Link Here
338
		}
339
		}
339
	}
340
	}
340
341
341
	private void readQuery(TaskList taskList, Node child) {
342
	/** 
342
		boolean wasRead = false;
343
	 * Reads the Query from the specified Node. If taskList is not null, then also adds this query to the TaskList
344
	 */
345
	private AbstractRepositoryQuery readQuery(TaskList taskList, Node child) {
346
		AbstractRepositoryQuery query = null;
343
		for (AbstractTaskListFactory externalizer : externalizers) {
347
		for (AbstractTaskListFactory externalizer : externalizers) {
344
			Set<String> queryTagNames = externalizer.getQueryElementNames();
348
			Set<String> queryTagNames = externalizer.getQueryElementNames();
345
			if (queryTagNames != null && queryTagNames.contains(child.getNodeName())) {
349
			if (queryTagNames != null && queryTagNames.contains(child.getNodeName())) {
Lines 355-386 Link Here
355
					label = childElement.getAttribute(DelegatingTaskExternalizer.KEY_LABEL);
359
					label = childElement.getAttribute(DelegatingTaskExternalizer.KEY_LABEL);
356
				}
360
				}
357
361
358
				AbstractRepositoryQuery query = externalizer.createQuery(repositoryUrl,
362
				query = externalizer.createQuery(repositoryUrl,	queryString, label, childElement);
359
						queryString, label, childElement);
360
				if (query != null) {
363
				if (query != null) {
361
					wasRead = true;
362
					if (childElement.getAttribute(DelegatingTaskExternalizer.KEY_LAST_REFRESH) != null
364
					if (childElement.getAttribute(DelegatingTaskExternalizer.KEY_LAST_REFRESH) != null
363
							&& !childElement.getAttribute(
365
							&& !childElement.getAttribute(
364
									DelegatingTaskExternalizer.KEY_LAST_REFRESH).equals("")) {
366
									DelegatingTaskExternalizer.KEY_LAST_REFRESH).equals("")) {
365
						query.setLastSynchronizedStamp(childElement.getAttribute(DelegatingTaskExternalizer.KEY_LAST_REFRESH));
367
						query.setLastSynchronizedStamp(childElement.getAttribute(DelegatingTaskExternalizer.KEY_LAST_REFRESH));
366
					}
368
					}
367
					taskList.internalAddQuery(query);
368
				}
369
				}
369
				NodeList queryChildren = child.getChildNodes();
370
				
370
				for (int ii = 0; ii < queryChildren.getLength(); ii++) {
371
				// add created Query to the TaskList and read QueryHits (Tasks related to the Query)
371
					Node queryNode = queryChildren.item(ii);
372
				if (taskList != null) {
372
					try {
373
					if (query != null) {
373
						delagatingExternalizer.readQueryHit((Element) queryNode, taskList, query);
374
						taskList.internalAddQuery(query);
374
					} catch (TaskExternalizationException e) {
375
					}
375
						hasCaughtException = true;
376
377
					NodeList queryChildren = child.getChildNodes();
378
					for (int ii = 0; ii < queryChildren.getLength(); ii++) {
379
						Node queryNode = queryChildren.item(ii);
380
						try {
381
							delagatingExternalizer.readQueryHit((Element) queryNode, taskList, query);
382
						} catch (TaskExternalizationException e) {
383
							hasCaughtException = true;
384
						}
376
					}
385
					}
377
				}
386
				}
387
				
388
378
				break;
389
				break;
379
			}
390
			}
380
		}
391
		}
381
		if (!wasRead) {
392
		if (query == null) {
382
			orphanedQueryNodes.add(child);
393
			orphanedQueryNodes.add(child);
383
		}
394
		}
395
		
396
		return query;
384
	}
397
	}
385
398
386
	/**
399
	/**
Lines 507-520 Link Here
507
		return;
520
		return;
508
	}
521
	}
509
522
510
	public void readQueries(TaskList taskList, File inFile) {
523
	public List<AbstractRepositoryQuery> readQueries(File inFile) {
524
		List<AbstractRepositoryQuery> queries = new ArrayList<AbstractRepositoryQuery>();
511
		try {
525
		try {
512
			if (!inFile.exists())
526
			if (!inFile.exists())
513
				return;
527
				return queries;
514
			Document doc = openAsDOM(inFile);
528
			Document doc = openAsDOM(inFile);
515
			if (doc == null) {
529
			if (doc == null) {
516
				handleException(inFile, null, new TaskExternalizationException("TaskList was not well formed XML"));
530
				handleException(inFile, null, new TaskExternalizationException("TaskList was not well formed XML"));
517
				return;
531
				return queries;
518
			}
532
			}
519
			Element root = doc.getDocumentElement();
533
			Element root = doc.getDocumentElement();
520
			readVersion = root.getAttribute(ATTRIBUTE_VERSION);
534
			readVersion = root.getAttribute(ATTRIBUTE_VERSION);
Lines 527-533 Link Here
527
					Node child = list.item(i);
541
					Node child = list.item(i);
528
					try {
542
					try {
529
						if (child.getNodeName().endsWith(AbstractTaskListFactory.KEY_QUERY)) {
543
						if (child.getNodeName().endsWith(AbstractTaskListFactory.KEY_QUERY)) {
530
							readQuery(taskList, child);
544
							AbstractRepositoryQuery query = readQuery(null, child);
545
							if (query != null) {
546
								queries.add(query);
547
							}
531
						}
548
						}
532
					} catch (Exception e) {
549
					} catch (Exception e) {
533
						handleException(inFile, child, e);
550
						handleException(inFile, child, e);
Lines 540-548 Link Here
540
			handleException(inFile, null, e);
557
			handleException(inFile, null, e);
541
		}
558
		}
542
		
559
		
543
		if (!hasCaughtException) {
560
		return queries;
544
			// save new task list only if there were no exception!
545
			writeTaskList(taskList, inFile);
546
		}
547
	}
561
	}
548
}
562
}
(-)src/org/eclipse/mylyn/tasks/ui/AbstractRepositoryConnectorUi.java (-22 / +31 lines)
Lines 44-49 Link Here
44
 * 
44
 * 
45
 * @author Mik Kersten
45
 * @author Mik Kersten
46
 * @author Eugene Kuleshov
46
 * @author Eugene Kuleshov
47
 * @author Jevgeni Holodkov
47
 * @since 2.0
48
 * @since 2.0
48
 */
49
 */
49
public abstract class AbstractRepositoryConnectorUi {
50
public abstract class AbstractRepositoryConnectorUi {
Lines 134-161 Link Here
134
	}
135
	}
135
136
136
	public void openEditQueryDialog(AbstractRepositoryQuery query) {
137
	public void openEditQueryDialog(AbstractRepositoryQuery query) {
137
		try {
138
		openQueryDialog(query, "Edit Repository Query");
138
			TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(query.getRepositoryKind(),
139
	}
139
					query.getRepositoryUrl());
140
	
140
			if (repository == null)
141
	public void openImportQueryDialog(AbstractRepositoryQuery query) {
141
				return;
142
		openQueryDialog(query, "Import Repository Query");
142
143
			IWizard wizard = this.getQueryWizard(repository, query);
144
145
			Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
146
			if (wizard != null && shell != null && !shell.isDisposed()) {
147
				WizardDialog dialog = new WizardDialog(shell, wizard);
148
				dialog.create();
149
				dialog.setTitle("Edit Repository Query");
150
				dialog.setBlockOnOpen(true);
151
				if (dialog.open() == Dialog.CANCEL) {
152
					dialog.close();
153
					return;
154
				}
155
			}
156
		} catch (Exception e) {
157
			StatusHandler.fail(e, e.getMessage(), true);
158
		}
159
	}
143
	}
160
144
161
	public IWizard getAddExistingTaskWizard(TaskRepository repository) {
145
	public IWizard getAddExistingTaskWizard(TaskRepository repository) {
Lines 237-240 Link Here
237
	public String getKindLabel(String kindLabel) {
221
	public String getKindLabel(String kindLabel) {
238
		return null;
222
		return null;
239
	}
223
	}
224
	
225
	protected void openQueryDialog(AbstractRepositoryQuery query, String dialogTitle) {
226
		try {
227
			TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(query.getRepositoryKind(),
228
					query.getRepositoryUrl());
229
			if (repository == null)
230
				return;
231
232
			IWizard wizard = this.getQueryWizard(repository, query);
233
234
			Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
235
			if (wizard != null && shell != null && !shell.isDisposed()) {
236
				WizardDialog dialog = new WizardDialog(shell, wizard);
237
				dialog.create();
238
				dialog.setTitle(dialogTitle);
239
				dialog.setBlockOnOpen(true);
240
				if (dialog.open() == Dialog.CANCEL) {
241
					dialog.close();
242
					return;
243
				}
244
			}
245
		} catch (Exception e) {
246
			StatusHandler.fail(e, e.getMessage(), true);
247
		}
248
	}
240
}
249
}
(-)plugin.xml (-1 / +22 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.QueryExportAction"
348
               definitionId="org.eclipse.ui.query.export"
349
               enablesFor="org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery"
350
               id="org.eclipse.mylyn.tasks.ui.actions.export.query"
351
               label="Export Query..."
352
               menubarPath="repository"
353
               tooltip="Export Repository Query">
354
         </action>
345
  		
355
  		
356
		  <action
357
               class="org.eclipse.mylyn.internal.tasks.ui.actions.QueryImportAction"
358
               definitionId="org.eclipse.ui.query.import"
359
               enablesFor="*"
360
               icon="icons/etool16/import.gif"
361
               id="org.eclipse.mylyn.tasks.ui.actions.import.query"
362
               label="Import Query..."
363
               menubarPath="repository"
364
               tooltip="Import Repository Query">
365
         </action>
366
346
  		<action
367
  		<action
347
	        class="org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskAction"
368
	        class="org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskAction"
348
	        enablesFor="*"
369
	        enablesFor="*"
(-)src/org/eclipse/mylyn/internal/tasks/ui/actions/QueryImportAction.java (+79 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.Iterator;
13
import java.util.List;
14
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants;
20
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
21
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
22
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
23
import org.eclipse.swt.widgets.FileDialog;
24
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.ui.IViewActionDelegate;
26
import org.eclipse.ui.IViewPart;
27
import org.eclipse.ui.PlatformUI;
28
29
/**
30
 * Makes able to select an exported query file and import it back to the system.
31
 * @author Jevgeni Holodkov
32
 */
33
public class QueryImportAction extends Action implements IViewActionDelegate {
34
35
	protected ISelection selection;
36
	
37
	public void init(IViewPart view) {
38
		// ignore
39
	}
40
41
	public void run(IAction action) {
42
		run();
43
	}
44
45
	public void selectionChanged(IAction action, ISelection selection) {
46
		// ignore
47
	}
48
49
	
50
	public void run() {
51
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
52
		FileDialog dialog = new FileDialog(shell);
53
		dialog.setFilterExtensions(new String[] { "*" + ITasksUiConstants.FILE_EXTENSION });
54
		
55
		String path = dialog.open();
56
		if (path != null) {
57
			File file = new File(path);
58
			if (file.isFile()) {
59
				List<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager()
60
						.getTaskListWriter()
61
						.readQueries(file);
62
				
63
				if (queries.size() > 0) {
64
				for (Iterator<AbstractRepositoryQuery> it = queries.iterator(); it.hasNext();) {
65
					AbstractRepositoryQuery repositoryQuery = it.next();
66
					AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(repositoryQuery.getRepositoryKind());
67
					connectorUi.openImportQueryDialog(repositoryQuery);
68
				}
69
				} else {
70
					MessageDialog.openError(shell, "Query Export Error",
71
							"The specified file is not an exported query. Please, check that you have provided the correct file.");
72
					return;
73
				}
74
			}
75
		}
76
		 return;
77
	}
78
79
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/actions/QueryExportAction.java (+92 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
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.dialogs.MessageDialog;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
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.SWT;
22
import org.eclipse.swt.widgets.FileDialog;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.IViewActionDelegate;
25
import org.eclipse.ui.IViewPart;
26
import org.eclipse.ui.PlatformUI;
27
28
/**
29
 * Makes able to export selected query to the file system.
30
 * @author Jevgeni Holodkov
31
 */
32
public class QueryExportAction extends Action implements IViewActionDelegate {
33
34
	protected ISelection selection;
35
	
36
	public void init(IViewPart view) {
37
		// ignore
38
	}
39
40
	public void run(IAction action) {
41
		run(getSelectedQuery(selection));
42
	}
43
44
	public void selectionChanged(IAction action, ISelection selection) {
45
		this.selection = selection;
46
		AbstractRepositoryQuery selectedQuery = getSelectedQuery(selection);
47
		action.setEnabled(true);
48
		if (selectedQuery != null) {
49
			action.setEnabled(true);
50
		} else {
51
			action.setEnabled(false);
52
		}
53
	}
54
	
55
	protected AbstractRepositoryQuery getSelectedQuery(ISelection newSelection) {
56
		if (selection instanceof StructuredSelection) {
57
			Object selectedObject = ((StructuredSelection) selection).getFirstElement();
58
			if (selectedObject instanceof AbstractRepositoryQuery) {
59
				return (AbstractRepositoryQuery) selectedObject;
60
			}
61
		}
62
		return null;
63
	}
64
	
65
66
	
67
	public void run(AbstractRepositoryQuery query) {
68
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
69
		FileDialog dialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
70
		dialog.setFilterExtensions(new String[] { "*" + ITasksUiConstants.FILE_EXTENSION });
71
		dialog.setFileName(query.getHandleIdentifier());
72
		
73
		String path = dialog.open();
74
		if (path != null) {
75
			File file = new File(path);
76
			if (file.isDirectory()) {
77
				MessageDialog.openError(shell, "Query Export Error", "Could not export query because specified location is a folder");
78
				return;
79
			}
80
81
			// Prompt the user to confirm if save operation will cause an overwrite
82
			if (file.exists()) {
83
				if (!MessageDialog.openConfirm(shell, "Confirm File Replace", "The file " + file.getPath()
84
						+ " already exists. Do you want to overwrite it?")) {
85
					return;
86
				}
87
			}
88
			TasksUiPlugin.getTaskListManager().getTaskListWriter().writeQuery(query, file);
89
		}
90
		 return;
91
	}
92
}

Return to bug 189518