View | Details | Raw Unified | Return to bug 220314 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java (-6 / +23 lines)
Lines 34-44 Link Here
34
import org.eclipse.jface.window.ToolTip;
34
import org.eclipse.jface.window.ToolTip;
35
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
35
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
36
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
36
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
37
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler;
37
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
38
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
38
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
39
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
39
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
40
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
40
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
41
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
41
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
42
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
42
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
43
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.SWT;
44
import org.eclipse.swt.events.SelectionAdapter;
44
import org.eclipse.swt.events.SelectionAdapter;
Lines 51-56 Link Here
51
import org.eclipse.swt.widgets.Menu;
51
import org.eclipse.swt.widgets.Menu;
52
import org.eclipse.swt.widgets.Table;
52
import org.eclipse.swt.widgets.Table;
53
import org.eclipse.swt.widgets.TableColumn;
53
import org.eclipse.swt.widgets.TableColumn;
54
import org.eclipse.ui.IWorkbenchPage;
54
import org.eclipse.ui.forms.events.ExpansionAdapter;
55
import org.eclipse.ui.forms.events.ExpansionAdapter;
55
import org.eclipse.ui.forms.events.ExpansionEvent;
56
import org.eclipse.ui.forms.events.ExpansionEvent;
56
import org.eclipse.ui.forms.widgets.FormToolkit;
57
import org.eclipse.ui.forms.widgets.FormToolkit;
Lines 136-146 Link Here
136
				getTaskEditorPage().getAttributeEditorToolkit()));
137
				getTaskEditorPage().getAttributeEditorToolkit()));
137
		attachmentsViewer.addOpenListener(new IOpenListener() {
138
		attachmentsViewer.addOpenListener(new IOpenListener() {
138
			public void open(OpenEvent event) {
139
			public void open(OpenEvent event) {
139
				if (!event.getSelection().isEmpty()) {
140
				openAttachments(event);
140
					StructuredSelection selection = (StructuredSelection) event.getSelection();
141
					ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
142
					TasksUiUtil.openUrl(attachment.getUrl());
143
				}
144
			}
141
			}
145
		});
142
		});
146
		attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
143
		attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
Lines 260-263 Link Here
260
		toolBarManager.add(attachFileAction);
257
		toolBarManager.add(attachFileAction);
261
	}
258
	}
262
259
260
	protected void openAttachments(OpenEvent event) {
261
		List<ITaskAttachment> attachments = new ArrayList<ITaskAttachment>();
262
263
		StructuredSelection selection = (StructuredSelection) event.getSelection();
264
265
		List<?> items = selection.toList();
266
		for (Object item : items) {
267
			if (item instanceof ITaskAttachment) {
268
				attachments.add((ITaskAttachment) item);
269
			}
270
		}
271
272
		if (attachments.isEmpty()) {
273
			return;
274
		}
275
276
		IWorkbenchPage page = getTaskEditorPage().getSite().getWorkbenchWindow().getActivePage();
277
278
		OpenTaskAttachmentHandler.openAttachments(page, attachments);
279
	}
263
}
280
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentStorage.java (-28 / +3 lines)
Lines 23-28 Link Here
23
import org.eclipse.core.runtime.PlatformObject;
23
import org.eclipse.core.runtime.PlatformObject;
24
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.runtime.Status;
25
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
25
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
26
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
26
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
27
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
27
import org.eclipse.mylyn.tasks.core.ITask;
28
import org.eclipse.mylyn.tasks.core.ITask;
28
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
29
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
Lines 36-52 Link Here
36
 * @author Steffen Pingel
37
 * @author Steffen Pingel
37
 */
38
 */
38
public class TaskAttachmentStorage extends PlatformObject implements IStorage {
39
public class TaskAttachmentStorage extends PlatformObject implements IStorage {
39
40
	private static final String ATTACHMENT_DEFAULT_NAME = "attachment"; //$NON-NLS-1$
41
42
	private static final String CTYPE_ZIP = "zip"; //$NON-NLS-1$
43
44
	private static final String CTYPE_OCTET_STREAM = "octet-stream"; //$NON-NLS-1$
45
46
	private static final String CTYPE_TEXT = "text"; //$NON-NLS-1$
47
48
	private static final String CTYPE_HTML = "html"; //$NON-NLS-1$
49
50
	private final TaskRepository taskRepository;
40
	private final TaskRepository taskRepository;
51
41
52
	private final ITask task;
42
	private final ITask task;
Lines 75-97 Link Here
75
	}
65
	}
76
66
77
	private static String getName(ITaskAttachment attachment) {
67
	private static String getName(ITaskAttachment attachment) {
78
		String name = attachment.getFileName();
68
		String name = AttachmentUtil.getAttachmentFilename(attachment);
79
		// if no filename is set, make one up with the proper extension so
69
80
		// we can support opening in that filetype's default editor
81
		if (name == null || "".equals(name)) { //$NON-NLS-1$
82
			String ctype = attachment.getContentType();
83
			if (ctype.endsWith(CTYPE_HTML)) {
84
				name = ATTACHMENT_DEFAULT_NAME + ".html"; //$NON-NLS-1$
85
			} else if (ctype.startsWith(CTYPE_TEXT)) {
86
				name = ATTACHMENT_DEFAULT_NAME + ".txt"; //$NON-NLS-1$
87
			} else if (ctype.endsWith(CTYPE_OCTET_STREAM)) {
88
				name = ATTACHMENT_DEFAULT_NAME;
89
			} else if (ctype.endsWith(CTYPE_ZIP)) {
90
				name = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP; //$NON-NLS-1$
91
			} else {
92
				name = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1); //$NON-NLS-1$ //$NON-NLS-2$
93
			}
94
		}
95
		// treat .patch files as text files
70
		// treat .patch files as text files
96
		if (name.endsWith(".patch")) { //$NON-NLS-1$
71
		if (name.endsWith(".patch")) { //$NON-NLS-1$
97
			name += ".txt"; //$NON-NLS-1$
72
			name += ".txt"; //$NON-NLS-1$
(-)src/org/eclipse/mylyn/internal/tasks/ui/actions/SaveAttachmentsAction.java (-32 / +2 lines)
Lines 35-50 Link Here
35
 */
35
 */
36
public class SaveAttachmentsAction extends Action {
36
public class SaveAttachmentsAction extends Action {
37
37
38
	private static final String ATTACHMENT_DEFAULT_NAME = "attachment"; //$NON-NLS-1$
39
40
	private static final String CTYPE_ZIP = "zip"; //$NON-NLS-1$
41
42
	private static final String CTYPE_OCTET_STREAM = "octet-stream"; //$NON-NLS-1$
43
44
	private static final String CTYPE_TEXT = "text"; //$NON-NLS-1$
45
46
	private static final String CTYPE_HTML = "html"; //$NON-NLS-1$
47
48
	public SaveAttachmentsAction(String text) {
38
	public SaveAttachmentsAction(String text) {
49
		super(text);
39
		super(text);
50
	}
40
	}
Lines 66-72 Link Here
66
	 */
56
	 */
67
	private void saveSingleAttachment(ITaskAttachment attachment) {
57
	private void saveSingleAttachment(ITaskAttachment attachment) {
68
		FileDialog fileChooser = new FileDialog(WorkbenchUtil.getShell(), SWT.SAVE);
58
		FileDialog fileChooser = new FileDialog(WorkbenchUtil.getShell(), SWT.SAVE);
69
		fileChooser.setFileName(getAttachmentFilename(attachment));
59
		fileChooser.setFileName(AttachmentUtil.getAttachmentFilename(attachment));
70
60
71
		File initDirectory = getInitialDirectory();
61
		File initDirectory = getInitialDirectory();
72
		if (initDirectory != null) {
62
		if (initDirectory != null) {
Lines 123-129 Link Here
123
		}
113
		}
124
114
125
		for (ITaskAttachment attachment : attachments) {
115
		for (ITaskAttachment attachment : attachments) {
126
			String filename = getAttachmentFilename(attachment);
116
			String filename = AttachmentUtil.getAttachmentFilename(attachment);
127
			File file = getTargetFile(WorkbenchUtil.getShell(), directory, filename);
117
			File file = getTargetFile(WorkbenchUtil.getShell(), directory, filename);
128
			if (file != null) {
118
			if (file != null) {
129
				DownloadAttachmentJob job = new DownloadAttachmentJob(attachment, file);
119
				DownloadAttachmentJob job = new DownloadAttachmentJob(attachment, file);
Lines 160-185 Link Here
160
		}
150
		}
161
	}
151
	}
162
152
163
	private String getAttachmentFilename(ITaskAttachment attachment) {
164
		String fname = attachment.getFileName();
165
		// default name if none is found
166
		if (fname.equals("")) { //$NON-NLS-1$
167
			String ctype = attachment.getContentType();
168
			if (ctype.endsWith(CTYPE_HTML)) {
169
				fname = ATTACHMENT_DEFAULT_NAME + ".html"; //$NON-NLS-1$
170
			} else if (ctype.startsWith(CTYPE_TEXT)) {
171
				fname = ATTACHMENT_DEFAULT_NAME + ".txt"; //$NON-NLS-1$
172
			} else if (ctype.endsWith(CTYPE_OCTET_STREAM)) {
173
				fname = ATTACHMENT_DEFAULT_NAME;
174
			} else if (ctype.endsWith(CTYPE_ZIP)) {
175
				fname = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP; //$NON-NLS-1$
176
			} else {
177
				fname = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1); //$NON-NLS-1$ //$NON-NLS-2$
178
			}
179
		}
180
		return fname;
181
	}
182
183
	private File getInitialDirectory() {
153
	private File getInitialDirectory() {
184
		String dirName = TasksUiPlugin.getDefault().getPreferenceStore().getString(
154
		String dirName = TasksUiPlugin.getDefault().getPreferenceStore().getString(
185
				ITasksUiPreferenceConstants.DEFAULT_ATTACHMENTS_DIRECTORY);
155
				ITasksUiPreferenceConstants.DEFAULT_ATTACHMENTS_DIRECTORY);
(-)src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java (+32 lines)
Lines 70-75 Link Here
70
70
71
	private static final String CONTEXT_CONTENT_TYPE = "application/octet-stream"; //$NON-NLS-1$
71
	private static final String CONTEXT_CONTENT_TYPE = "application/octet-stream"; //$NON-NLS-1$
72
72
73
	private static final String ATTACHMENT_DEFAULT_NAME = "attachment"; //$NON-NLS-1$
74
75
	private static final String CTYPE_ZIP = "zip"; //$NON-NLS-1$
76
77
	private static final String CTYPE_OCTET_STREAM = "octet-stream"; //$NON-NLS-1$
78
79
	private static final String CTYPE_TEXT = "text"; //$NON-NLS-1$
80
81
	private static final String CTYPE_HTML = "html"; //$NON-NLS-1$
82
73
	public static boolean postContext(AbstractRepositoryConnector connector, TaskRepository repository, ITask task,
83
	public static boolean postContext(AbstractRepositoryConnector connector, TaskRepository repository, ITask task,
74
			String comment, TaskAttribute attribute, IProgressMonitor monitor) throws CoreException {
84
			String comment, TaskAttribute attribute, IProgressMonitor monitor) throws CoreException {
75
		AbstractTaskAttachmentHandler attachmentHandler = connector.getTaskAttachmentHandler();
85
		AbstractTaskAttachmentHandler attachmentHandler = connector.getTaskAttachmentHandler();
Lines 307-310 Link Here
307
		}
317
		}
308
		return Collections.emptyList();
318
		return Collections.emptyList();
309
	}
319
	}
320
321
	public static String getAttachmentFilename(ITaskAttachment attachment) {
322
		String name = attachment.getFileName();
323
		// if no filename is set, make one up with the proper extension so
324
		// we can support opening in that filetype's default editor
325
		if (name == null || "".equals(name)) { //$NON-NLS-1$
326
			String ctype = attachment.getContentType();
327
			if (ctype.endsWith(CTYPE_HTML)) {
328
				name = ATTACHMENT_DEFAULT_NAME + ".html"; //$NON-NLS-1$
329
			} else if (ctype.startsWith(CTYPE_TEXT)) {
330
				name = ATTACHMENT_DEFAULT_NAME + ".txt"; //$NON-NLS-1$
331
			} else if (ctype.endsWith(CTYPE_OCTET_STREAM)) {
332
				name = ATTACHMENT_DEFAULT_NAME;
333
			} else if (ctype.endsWith(CTYPE_ZIP)) {
334
				name = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP; //$NON-NLS-1$
335
			} else {
336
				name = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1); //$NON-NLS-1$ //$NON-NLS-2$
337
			}
338
		}
339
340
		return name;
341
	}
310
}
342
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/ITasksUiPreferenceConstants.java (+2 lines)
Lines 83-86 Link Here
83
	public static final String PREF_DATA_DIR = "org.eclipse.mylyn.data.dir"; //$NON-NLS-1$
83
	public static final String PREF_DATA_DIR = "org.eclipse.mylyn.data.dir"; //$NON-NLS-1$
84
84
85
	public static final String DEFAULT_ATTACHMENTS_DIRECTORY = "org.eclipse.mylyn.tasks.ui.attachments.defaultDirectory"; //$NON-NLS-1$
85
	public static final String DEFAULT_ATTACHMENTS_DIRECTORY = "org.eclipse.mylyn.tasks.ui.attachments.defaultDirectory"; //$NON-NLS-1$
86
87
	public static final String PREFERRED_TASK_ATTACHMENT_VIEWER_ID = "org.eclipse.mylyn.tasks.ui.attachments.preferredViewerID"; //$NON-NLS-1$
86
}
88
}
(-)plugin.xml (-8 / +24 lines)
Lines 1286-1291 Link Here
1286
      </command>
1286
      </command>
1287
      <command
1287
      <command
1288
            categoryId="org.eclipse.mylyn.tasks.ui.category.editor"
1288
            categoryId="org.eclipse.mylyn.tasks.ui.category.editor"
1289
            id="org.eclipse.mylyn.tasks.ui.command.attachment.open"
1290
            name="%command.attachment.open.name">
1291
      </command>
1292
      <command
1293
            categoryId="org.eclipse.mylyn.tasks.ui.category.editor"
1289
            id="org.eclipse.mylyn.tasks.ui.command.attachment.openInBrowser"
1294
            id="org.eclipse.mylyn.tasks.ui.command.attachment.openInBrowser"
1290
            name="%command.attachment.openInBrowser.name">
1295
            name="%command.attachment.openInBrowser.name">
1291
      </command>
1296
      </command>
Lines 1539-1544 Link Here
1539
            commandId="org.eclipse.mylyn.tasks.ui.command.attachment.openInBrowser">
1544
            commandId="org.eclipse.mylyn.tasks.ui.command.attachment.openInBrowser">
1540
      </handler>
1545
      </handler>
1541
      <handler
1546
      <handler
1547
            class="org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler"
1548
            commandId="org.eclipse.mylyn.tasks.ui.command.attachment.open">
1549
      </handler>
1550
      <handler
1542
            class="org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentInDefaultEditorHandler"
1551
            class="org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentInDefaultEditorHandler"
1543
            commandId="org.eclipse.mylyn.tasks.ui.command.attachment.openInDefaultEditor">
1552
            commandId="org.eclipse.mylyn.tasks.ui.command.attachment.openInDefaultEditor">
1544
      </handler>
1553
      </handler>
Lines 1643-1662 Link Here
1643
      <menuContribution
1652
      <menuContribution
1644
            locationURI="popup:org.eclipse.mylyn.tasks.ui.editor.menu.attachments?after=group.open">
1653
            locationURI="popup:org.eclipse.mylyn.tasks.ui.editor.menu.attachments?after=group.open">
1645
         <command
1654
         <command
1646
               commandId="org.eclipse.mylyn.tasks.ui.command.attachment.openInBrowser"
1655
               commandId="org.eclipse.mylyn.tasks.ui.command.attachment.open"
1647
               label="%command.attachment.openInBrowser.label"
1656
               label="%command.attachment.open.label"
1648
               mnemonic="O"
1657
               mnemonic="O"
1649
               style="push">
1658
               style="push">
1650
         </command>
1659
         </command>
1651
         <menu
1660
         <menu
1652
               label="%command.attachment.openInDefaultEditor.menu.label"
1661
               label="%command.attachment.openInDefaultEditor.menu.label"
1653
               mnemonic="H">
1662
               mnemonic="H">
1654
            <command
1663
            <dynamic
1655
                  commandId="org.eclipse.mylyn.tasks.ui.command.attachment.openInDefaultEditor"
1664
                  class="org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentWithMenu"
1656
                  label="%command.attachment.openInDefaultEditor.label"
1665
                  id="org.eclipse.mylyn.tasks.ui.command.attachment.openTaskAttachmentWithMenu">
1657
                  mnemonic="D"
1666
                  <visibleWhen
1658
                  style="push">
1667
                        checkEnabled="false">
1659
            </command>
1668
                     <with
1669
                           variable="selection">
1670
                        <count
1671
                              value="1">
1672
                        </count>
1673
                     </with>
1674
                  </visibleWhen>
1675
            </dynamic>
1660
         </menu>
1676
         </menu>
1661
      </menuContribution>
1677
      </menuContribution>
1662
      <menuContribution
1678
      <menuContribution
(-)src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerBrowser.java (+23 lines)
Added Link Here
1
package org.eclipse.mylyn.internal.tasks.ui;
2
3
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
4
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
5
import org.eclipse.ui.IWorkbenchPage;
6
7
public class TaskAttachmentViewerBrowser implements ITaskAttachmentViewer {
8
	public String getID() {
9
		return "inBrowser";
10
	}
11
12
	public String getLabel() {
13
		return "Browser";
14
	}
15
16
	public boolean isAvailable(ITaskAttachment attachment) {
17
		return attachment.getUrl() != null;
18
	}
19
20
	public void openAttachment(IWorkbenchPage page, ITaskAttachment attachment) {
21
		TasksUiUtil.openUrl(attachment.getUrl());
22
	}
23
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/commands/OpenTaskAttachmentWithMenu.java (+118 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui.commands;
13
14
import java.util.List;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.jface.action.ContributionItem;
18
import org.eclipse.mylyn.internal.tasks.ui.ITaskAttachmentViewer;
19
import org.eclipse.mylyn.internal.tasks.ui.TaskAttachmentViewersManager;
20
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
21
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
22
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.widgets.Menu;
27
import org.eclipse.swt.widgets.MenuItem;
28
import org.eclipse.ui.IWorkbench;
29
import org.eclipse.ui.IWorkbenchPage;
30
import org.eclipse.ui.IWorkbenchWindow;
31
import org.eclipse.ui.PlatformUI;
32
33
public class OpenTaskAttachmentWithMenu extends ContributionItem {
34
	private final TaskAttachmentViewersManager manager = TaskAttachmentViewersManager.getInstance();
35
36
	public OpenTaskAttachmentWithMenu() {
37
	}
38
39
	public OpenTaskAttachmentWithMenu(String id) {
40
		super(id);
41
	}
42
43
	@Override
44
	public void fill(Menu menu, int index) {
45
		List<ITaskAttachment> attachments = AttachmentUtil.getSelectedAttachments();
46
		if (attachments.isEmpty() || attachments.size() > 1) {
47
			return;
48
		}
49
50
		// find all interesting editors, and add them into menu
51
		ITaskAttachment at = attachments.get(0);
52
53
		String prefViewerID = manager.getPreferredViewerID(at);
54
55
		int i = 0;
56
57
		List<ITaskAttachmentViewer> viewers = manager.getTaskAttachmentViewers(at);
58
		for (ITaskAttachmentViewer v : viewers) {
59
			MenuItem it = new MenuItem(menu, SWT.RADIO, index + i);
60
61
			it.setText(v.getLabel());
62
			it.addSelectionListener(new RunAssociatedViewer(it, v));
63
			if (prefViewerID != null && prefViewerID.equals(v.getID())) {
64
				it.setSelection(true);
65
			}
66
67
			i++;
68
		}
69
	}
70
71
	private class RunAssociatedViewer extends SelectionAdapter {
72
		private final MenuItem menuItem;
73
74
		private final ITaskAttachmentViewer viewer;
75
76
		RunAssociatedViewer(MenuItem item, ITaskAttachmentViewer handler) {
77
			this.menuItem = item;
78
			this.viewer = handler;
79
		}
80
81
		@Override
82
		public void widgetSelected(SelectionEvent e) {
83
			// this event is fired also for item which gets unselected (i.e. previous 'preferred' viewer)
84
			if (!menuItem.getSelection()) {
85
				return;
86
			}
87
88
			IWorkbench wb = PlatformUI.getWorkbench();
89
90
			IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
91
			if (win == null) {
92
				return;
93
			}
94
95
			IWorkbenchPage page = win.getActivePage();
96
			if (page == null) {
97
				return;
98
			}
99
100
			List<ITaskAttachment> attachments = AttachmentUtil.getSelectedAttachments();
101
			for (ITaskAttachment ta : attachments) {
102
				manager.savePreferredViewerID(ta, viewer.getID());
103
104
				try {
105
					viewer.openAttachment(page, ta);
106
				} catch (CoreException ex) {
107
					TasksUiInternal.logAndDisplayStatus("Failed to open viewer", ex.getStatus());
108
				}
109
			}
110
		}
111
	}
112
113
	@Override
114
	public boolean isDynamic() {
115
		// depends on selected attachments
116
		return true;
117
	}
118
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java (+133 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import java.io.File;
15
import java.io.FileOutputStream;
16
import java.io.IOException;
17
import java.io.OutputStream;
18
import java.util.concurrent.atomic.AtomicReference;
19
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.runtime.jobs.Job;
25
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
26
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
27
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.ui.IWorkbenchPage;
29
import org.eclipse.ui.PartInitException;
30
31
class DownloadAndOpenTaskAttachmentJob extends Job {
32
	private final ITaskAttachment attachment;
33
34
	private final IWorkbenchPage page;
35
36
	private final String editorID;
37
38
	DownloadAndOpenTaskAttachmentJob(String jobName, ITaskAttachment attachment, IWorkbenchPage page, String editorID) {
39
		super(jobName);
40
41
		this.attachment = attachment;
42
		this.page = page;
43
		this.editorID = editorID;
44
	}
45
46
	@Override
47
	protected IStatus run(IProgressMonitor monitor) {
48
		final String attachmentFilename = AttachmentUtil.getAttachmentFilename(attachment);
49
50
		File file = null;
51
		try {
52
			file = File.createTempFile("attach-", "-" + attachmentFilename);
53
		} catch (IOException e) {
54
			return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to download attachment", e);
55
		}
56
		file.deleteOnExit();
57
58
		FileOutputStream fos = null;
59
		try {
60
			fos = new FileOutputStream(file);
61
			AttachmentUtil.downloadAttachment(attachment, fos, monitor);
62
			fos.close();
63
			fos = null;
64
		} catch (IOException e) {
65
			closeAndDelete(fos, file);
66
			fos = null;
67
			return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to download attachment", e);
68
		} catch (CoreException e) {
69
			closeAndDelete(fos, file);
70
			fos = null;
71
			return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to download attachment", e);
72
		} finally {
73
			if (fos != null) {
74
				try {
75
					fos.close();
76
				} catch (IOException e) {
77
					// ignore ... something bad is happening here
78
				}
79
			}
80
		}
81
82
		Display disp = page.getWorkbenchWindow().getWorkbench().getDisplay();
83
		if (disp.isDisposed()) {
84
			return new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN, "Display is disposed");
85
		}
86
87
		if (disp.getThread() == Thread.currentThread()) {
88
			try {
89
				page.openEditor(new FileEditorInput(file, attachmentFilename, attachment.getUrl()), editorID);
90
			} catch (PartInitException e) {
91
				return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Cannot open editor", e);
92
			}
93
94
			return new Status(IStatus.OK, TasksUiPlugin.ID_PLUGIN, "OK");
95
		} else {
96
			final AtomicReference<IStatus> status = new AtomicReference<IStatus>();
97
			final File tmpFile = file;
98
99
			disp.syncExec(new Runnable() {
100
				public void run() {
101
					try {
102
						page.openEditor(new FileEditorInput(tmpFile, attachmentFilename, attachment.getUrl()), editorID);
103
						status.set(new Status(IStatus.OK, TasksUiPlugin.ID_PLUGIN, "OK"));
104
					} catch (PartInitException e) {
105
						status.set(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Cannot open editor", e));
106
					}
107
				};
108
			});
109
110
			if (status.get() == null) {
111
				return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Cannot open editor");
112
			}
113
114
			return status.get();
115
		}
116
	}
117
118
	void closeAndDelete(OutputStream os, File file) {
119
		if (os != null) {
120
			try {
121
				os.close();
122
			} catch (IOException ex) {
123
				// ignore ... we are going to delete the file anyway
124
			}
125
		}
126
127
		if (file == null) {
128
			return;
129
		}
130
131
		file.delete();
132
	}
133
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/FileEditorInput.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import java.io.File;
15
16
import org.eclipse.core.resources.IStorage;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.PlatformObject;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.ui.IPathEditorInput;
23
import org.eclipse.ui.IPersistableElement;
24
import org.eclipse.ui.IStorageEditorInput;
25
26
public class FileEditorInput extends PlatformObject implements IPathEditorInput, IStorageEditorInput {
27
	private final File file;
28
29
	private final String name;
30
31
	private final String tooltipText;
32
33
	FileEditorInput(File file, String name, String tooltipText) {
34
		this.file = file;
35
		this.name = name;
36
		this.tooltipText = tooltipText;
37
	}
38
39
	public IPath getPath() {
40
		return Path.fromOSString(file.getAbsolutePath());
41
	}
42
43
	public boolean exists() {
44
		return file.exists();
45
	}
46
47
	public ImageDescriptor getImageDescriptor() {
48
		return null;
49
	}
50
51
	public String getName() {
52
		return name;
53
	}
54
55
	public IPersistableElement getPersistable() {
56
		// ignore
57
		return null;
58
	}
59
60
	public String getToolTipText() {
61
		return tooltipText;
62
	}
63
64
	public IStorage getStorage() throws CoreException {
65
		return new FileStorage(file, name);
66
	}
67
68
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerDefaultEditor.java (+41 lines)
Added Link Here
1
package org.eclipse.mylyn.internal.tasks.ui;
2
3
import org.eclipse.core.runtime.CoreException;
4
import org.eclipse.core.runtime.IStatus;
5
import org.eclipse.core.runtime.Status;
6
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
7
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
8
import org.eclipse.ui.IEditorDescriptor;
9
import org.eclipse.ui.IWorkbenchPage;
10
import org.eclipse.ui.PlatformUI;
11
12
public class TaskAttachmentViewerDefaultEditor implements ITaskAttachmentViewer {
13
	public String getID() {
14
		return "defaultEditor";
15
	}
16
17
	public String getLabel() {
18
		return "Default Editor";
19
	}
20
21
	public boolean isAvailable(ITaskAttachment attachment) {
22
		String name = AttachmentUtil.getAttachmentFilename(attachment);
23
		IEditorDescriptor d = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(name);
24
25
		return d != null;
26
	}
27
28
	public void openAttachment(IWorkbenchPage page, ITaskAttachment attachment) throws CoreException {
29
		String name = AttachmentUtil.getAttachmentFilename(attachment);
30
		IEditorDescriptor description = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(name);
31
32
		if (description == null) {
33
			throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
34
					"Cannot find default editor for attachment"));
35
		}
36
37
		DownloadAndOpenTaskAttachmentJob job = new DownloadAndOpenTaskAttachmentJob(
38
				"Downloading and opening attachment in default editor", attachment, page, description.getId());
39
		job.schedule();
40
	}
41
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerSystemExternalEditor.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
18
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
19
import org.eclipse.ui.IEditorRegistry;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.PlatformUI;
22
23
public class TaskAttachmentViewerSystemExternalEditor implements ITaskAttachmentViewer {
24
	public String getID() {
25
		return "systemExternalEditor";
26
	}
27
28
	public String getLabel() {
29
		// ignore
30
		return "System Editor";
31
	}
32
33
	public boolean isAvailable(ITaskAttachment attachment) {
34
		String name = AttachmentUtil.getAttachmentFilename(attachment);
35
		return PlatformUI.getWorkbench().getEditorRegistry().isSystemExternalEditorAvailable(name);
36
	}
37
38
	public void openAttachment(IWorkbenchPage page, ITaskAttachment attachment) throws CoreException {
39
		String name = AttachmentUtil.getAttachmentFilename(attachment);
40
		boolean avail = PlatformUI.getWorkbench().getEditorRegistry().isSystemExternalEditorAvailable(name);
41
42
		if (!avail) {
43
			throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
44
					"Cannot find default editor for attachment"));
45
		}
46
47
		DownloadAndOpenTaskAttachmentJob job = new DownloadAndOpenTaskAttachmentJob(
48
				"Downloading and opening attachment in external editor", attachment, page,
49
				IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
50
		job.schedule();
51
	}
52
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewersManager.java (+90 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.List;
17
18
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
19
20
public class TaskAttachmentViewersManager {
21
	private static final TaskAttachmentViewersManager instance = new TaskAttachmentViewersManager();
22
23
	public static TaskAttachmentViewersManager getInstance() {
24
		return instance;
25
	}
26
27
	private final List<ITaskAttachmentViewer> viewers;
28
29
	private TaskAttachmentViewersManager() {
30
		List<ITaskAttachmentViewer> vl = new ArrayList<ITaskAttachmentViewer>();
31
32
		vl.add(new TaskAttachmentViewerBrowser());
33
		vl.add(new TaskAttachmentViewerDefaultEditor());
34
		vl.add(new TaskAttachmentViewerSystemInplaceEditor());
35
		vl.add(new TaskAttachmentViewerSystemExternalEditor());
36
37
		viewers = Collections.unmodifiableList(vl);
38
	}
39
40
	public List<ITaskAttachmentViewer> getTaskAttachmentViewers(ITaskAttachment attachment) {
41
		List<ITaskAttachmentViewer> result = new ArrayList<ITaskAttachmentViewer>();
42
43
		for (ITaskAttachmentViewer v : viewers) {
44
			if (v.isAvailable(attachment)) {
45
				result.add(v);
46
			}
47
		}
48
49
		return result;
50
	}
51
52
	/**
53
	 * @param attachment
54
	 * @return list of attachment viewers, with preferred viewers in front
55
	 */
56
	public List<ITaskAttachmentViewer> getSortedTaskAttachmentViewers(ITaskAttachment attachment) {
57
		List<ITaskAttachmentViewer> viewers = getTaskAttachmentViewers(attachment);
58
59
		String preferred = getPreferredViewerID(attachment);
60
		if (preferred == null) {
61
			return viewers;
62
		}
63
64
		// put preferred handler to the beginning
65
		int prefIndex = -1;
66
		for (int i = 0; i < viewers.size(); i++) {
67
			if (preferred.equals(viewers.get(i).getID())) {
68
				prefIndex = i;
69
				break;
70
			}
71
		}
72
73
		if (prefIndex >= 0) {
74
			ITaskAttachmentViewer h = viewers.remove(prefIndex);
75
			viewers.add(0, h);
76
		}
77
78
		return viewers;
79
	}
80
81
	public String getPreferredViewerID(ITaskAttachment attachment) {
82
		return TasksUiPlugin.getDefault().getPreferenceStore().getString(
83
				ITasksUiPreferenceConstants.PREFERRED_TASK_ATTACHMENT_VIEWER_ID);
84
	}
85
86
	public void savePreferredViewerID(ITaskAttachment attachment, String handlerID) {
87
		TasksUiPlugin.getDefault().getPreferenceStore().putValue(
88
				ITasksUiPreferenceConstants.PREFERRED_TASK_ATTACHMENT_VIEWER_ID, handlerID);
89
	}
90
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerSystemInplaceEditor.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
18
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
19
import org.eclipse.ui.IEditorRegistry;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.PlatformUI;
22
23
public class TaskAttachmentViewerSystemInplaceEditor implements ITaskAttachmentViewer {
24
	public String getID() {
25
		return "systemInplaceEditor";
26
	}
27
28
	public String getLabel() {
29
		// ignore
30
		return "In-Place Editor";
31
	}
32
33
	public boolean isAvailable(ITaskAttachment attachment) {
34
		String name = AttachmentUtil.getAttachmentFilename(attachment);
35
		return PlatformUI.getWorkbench().getEditorRegistry().isSystemExternalEditorAvailable(name);
36
	}
37
38
	public void openAttachment(IWorkbenchPage page, ITaskAttachment attachment) throws CoreException {
39
		String name = AttachmentUtil.getAttachmentFilename(attachment);
40
		boolean avail = PlatformUI.getWorkbench().getEditorRegistry().isSystemExternalEditorAvailable(name);
41
42
		if (!avail) {
43
			throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
44
					"Cannot find default in-place editor for attachment"));
45
		}
46
47
		DownloadAndOpenTaskAttachmentJob job = new DownloadAndOpenTaskAttachmentJob(
48
				"Downloading and opening attachment in in-place editor", attachment, page,
49
				IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
50
		job.schedule();
51
	}
52
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/ITaskAttachmentViewer.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
16
import org.eclipse.ui.IWorkbenchPage;
17
18
/**
19
 * Simple interface for attachment 'viewers'. Most viewers are based on existing eclipse editors.
20
 */
21
public interface ITaskAttachmentViewer {
22
	/**
23
	 * @return arbitrary string, used to remember preferred viewer
24
	 */
25
	public String getID();
26
27
	/**
28
	 * @return name of the editor, displayed to user
29
	 */
30
	public String getLabel();
31
32
	/**
33
	 * @param attachment
34
	 * @return whether viewer is available for this attachment
35
	 */
36
	public boolean isAvailable(ITaskAttachment attachment);
37
38
	public void openAttachment(IWorkbenchPage page, ITaskAttachment attachment) throws CoreException;
39
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/FileStorage.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import java.io.File;
15
import java.io.FileInputStream;
16
import java.io.FileNotFoundException;
17
import java.io.InputStream;
18
19
import org.eclipse.core.resources.IStorage;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.PlatformObject;
24
import org.eclipse.core.runtime.Status;
25
26
class FileStorage extends PlatformObject implements IStorage {
27
	private final File file;
28
29
	private final String name;
30
31
	FileStorage(File file, String name) {
32
		this.file = file;
33
		this.name = name;
34
	}
35
36
	public InputStream getContents() throws CoreException {
37
		try {
38
			return new FileInputStream(file);
39
		} catch (FileNotFoundException e) {
40
			throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unable to read file", e));
41
		}
42
	}
43
44
	public IPath getFullPath() {
45
		// ignore
46
		return null;
47
	}
48
49
	public String getName() {
50
		return name;
51
	}
52
53
	public boolean isReadOnly() {
54
		return true;
55
	}
56
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/commands/OpenTaskAttachmentHandler.java (+76 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui.commands;
13
14
import java.util.List;
15
16
import org.eclipse.core.commands.AbstractHandler;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.core.commands.IHandler;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.mylyn.internal.tasks.ui.ITaskAttachmentViewer;
24
import org.eclipse.mylyn.internal.tasks.ui.TaskAttachmentViewersManager;
25
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
26
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
27
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
28
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
29
import org.eclipse.ui.IWorkbench;
30
import org.eclipse.ui.IWorkbenchPage;
31
import org.eclipse.ui.IWorkbenchWindow;
32
import org.eclipse.ui.PlatformUI;
33
34
public class OpenTaskAttachmentHandler extends AbstractHandler implements IHandler {
35
36
	public Object execute(ExecutionEvent event) throws ExecutionException {
37
		IWorkbench wb = PlatformUI.getWorkbench();
38
39
		IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
40
		if (win == null) {
41
			return null;
42
		}
43
44
		IWorkbenchPage page = win.getActivePage();
45
		if (page == null) {
46
			return null;
47
		}
48
49
		List<ITaskAttachment> attachments = AttachmentUtil.getSelectedAttachments();
50
51
		openAttachments(page, attachments);
52
53
		return null;
54
	}
55
56
	public static void openAttachments(IWorkbenchPage page, List<ITaskAttachment> attachments) {
57
		TaskAttachmentViewersManager manager = TaskAttachmentViewersManager.getInstance();
58
59
		for (ITaskAttachment a : attachments) {
60
			List<ITaskAttachmentViewer> h = manager.getSortedTaskAttachmentViewers(a);
61
62
			if (h.isEmpty()) {
63
				TasksUiInternal.logAndDisplayStatus("Failed to open editor", new Status(IStatus.WARNING,
64
						TasksUiPlugin.ID_PLUGIN, "No suitable attachment viewer found"));
65
				continue;
66
			}
67
68
			ITaskAttachmentViewer dflt = h.get(0);
69
			try {
70
				dflt.openAttachment(page, a);
71
			} catch (CoreException e) {
72
				TasksUiInternal.logAndDisplayStatus("Failed to open editor", e.getStatus());
73
			}
74
		}
75
	}
76
}

Return to bug 220314