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 209897
Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentPage.java (-10 / +4 lines)
Lines 239-245 Link Here
239
239
240
	@Override
240
	@Override
241
	public boolean isPageComplete() {
241
	public boolean isPageComplete() {
242
		return !"".equals(filePath.getText().trim()) && (attachmentDesc == null || !"".equals(attachmentDesc.getText().trim()));
242
		return !"".equals(filePath.getText().trim())
243
				&& (attachmentDesc == null || !"".equals(attachmentDesc.getText().trim()));
243
	}
244
	}
244
245
245
	public void populateAttachment() {
246
	public void populateAttachment() {
Lines 253-265 Link Here
253
		return attachment;
254
		return attachment;
254
	}
255
	}
255
256
256
	@Override
257
	public boolean canFlipToNextPage() {
258
		if (filePath.getText().equals(InputAttachmentSourcePage.SCREENSHOT_LABEL))
259
			return false;
260
		return isPageComplete();
261
	}
262
263
	public void setFilePath(String path) {
257
	public void setFilePath(String path) {
264
		filePath.setText(path);
258
		filePath.setText(path);
265
		if (path.endsWith(".patch")) {
259
		if (path.endsWith(".patch")) {
Lines 298-306 Link Here
298
	public boolean supportsDescription() {
292
	public boolean supportsDescription() {
299
		return supportsDescription;
293
		return supportsDescription;
300
	}
294
	}
301
	
295
302
	public void setSupportsDescription(boolean supportsDescription) {
296
	public void setSupportsDescription(boolean supportsDescription) {
303
		this.supportsDescription = supportsDescription;
297
		this.supportsDescription = supportsDescription;
304
	}
298
	}
305
	
299
306
}
300
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentWizard.java (-21 / +18 lines)
Lines 42-51 Link Here
42
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditorInput;
42
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditorInput;
43
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
43
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
44
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
44
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.graphics.Image;
47
import org.eclipse.swt.graphics.ImageData;
48
import org.eclipse.swt.graphics.ImageLoader;
49
import org.eclipse.swt.widgets.Display;
45
import org.eclipse.swt.widgets.Display;
50
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.ui.PlatformUI;
51
47
Lines 81-87 Link Here
81
	private boolean screenshotMode;
77
	private boolean screenshotMode;
82
78
83
	public NewAttachmentWizard(TaskRepository repository, AbstractTask task, boolean screenshotMode) {
79
	public NewAttachmentWizard(TaskRepository repository, AbstractTask task, boolean screenshotMode) {
84
		super();
85
		this.task = task;
80
		this.task = task;
86
		this.repository = repository;
81
		this.repository = repository;
87
		this.screenshotMode = screenshotMode;
82
		this.screenshotMode = screenshotMode;
Lines 95-101 Link Here
95
		}
90
		}
96
91
97
		inputPage = new InputAttachmentSourcePage(this);
92
		inputPage = new InputAttachmentSourcePage(this);
98
		attachment = new LocalAttachment();
93
		if (screenshotMode) {
94
			shotPage = new ScreenshotAttachmentPage();
95
			attachment = new ImageAttachment(shotPage);
96
		} else {
97
			attachment = new LocalAttachment();
98
		}
99
		attachment.setFilePath("");
99
		attachment.setFilePath("");
100
		setNeedsProgressMonitor(true);
100
		setNeedsProgressMonitor(true);
101
		IDialogSettings workbenchSettings = TasksUiPlugin.getDefault().getDialogSettings();
101
		IDialogSettings workbenchSettings = TasksUiPlugin.getDefault().getDialogSettings();
Lines 125-130 Link Here
125
	}
125
	}
126
126
127
	@Override
127
	@Override
128
	public void dispose() {
129
		// Ensures the temporary screenshot image is deleted
130
		if (attachment != null && attachment instanceof ImageAttachment) {
131
			((ImageAttachment) attachment).clearImageFile();
132
		}
133
		super.dispose();
134
	}
135
136
	@Override
128
	public boolean performFinish() {
137
	public boolean performFinish() {
129
		/* TODO jpound - support non-text in clipboard */
138
		/* TODO jpound - support non-text in clipboard */
130
		attachPage.populateAttachment();
139
		attachPage.populateAttachment();
Lines 159-177 Link Here
159
					task.setSynchronizationState(RepositoryTaskSyncState.OUTGOING);
168
					task.setSynchronizationState(RepositoryTaskSyncState.OUTGOING);
160
169
161
					if (screenshotMode || InputAttachmentSourcePage.SCREENSHOT_LABEL.equals(path)) {
170
					if (screenshotMode || InputAttachmentSourcePage.SCREENSHOT_LABEL.equals(path)) {
162
						Image image = shotPage.getScreenshotImage();
171
						((ImageAttachment) attachment).ensureImageFileWasCreated();
163
						if (image == null) {
164
							throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR,
165
									TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Screenshot is empty",
166
									null)));
167
						}
168
						String path = TasksUiPlugin.getDefault().getDefaultDataDirectory();
169
						ImageLoader loader = new ImageLoader();
170
						loader.data = new ImageData[] { image.getImageData() };
171
						String fileName = path + "/" + SCREENSHOT_FILENAME;
172
						loader.save(fileName, SWT.IMAGE_JPEG);
173
						attachment.setFile(new File(fileName));
174
						attachment.setFilename(SCREENSHOT_FILENAME);
175
					} else if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(path)) {
172
					} else if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(path)) {
176
						String contents = inputPage.getClipboardContents();
173
						String contents = inputPage.getClipboardContents();
177
						if (contents == null) {
174
						if (contents == null) {
Lines 293-299 Link Here
293
	@Override
290
	@Override
294
	public boolean canFinish() {
291
	public boolean canFinish() {
295
		if (screenshotMode) {
292
		if (screenshotMode) {
296
			return shotPage.isPageComplete();
293
			return shotPage.isPageComplete() && attachPage.isPageComplete();
297
		} else {
294
		} else {
298
			return attachPage.isPageComplete();
295
			return attachPage.isPageComplete();
299
		}
296
		}
Lines 303-309 Link Here
303
	public void addPages() {
300
	public void addPages() {
304
		super.addPages();
301
		super.addPages();
305
		if (screenshotMode) {
302
		if (screenshotMode) {
306
			addPage((shotPage = new ScreenshotAttachmentPage(attachment)));
303
			addPage(shotPage);
307
			addPage((attachPage = new NewAttachmentPage(attachment)));
304
			addPage((attachPage = new NewAttachmentPage(attachment)));
308
		} else {
305
		} else {
309
			if ("".equals(attachment.getFilePath())) {
306
			if ("".equals(attachment.getFilePath())) {
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/PreviewAttachmentPage.java (-1 / +23 lines)
Lines 13-22 Link Here
13
import java.io.FileNotFoundException;
13
import java.io.FileNotFoundException;
14
import java.io.FileReader;
14
import java.io.FileReader;
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.lang.reflect.InvocationTargetException;
16
import java.util.HashMap;
17
import java.util.HashMap;
17
18
19
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.jface.layout.GridDataFactory;
20
import org.eclipse.jface.layout.GridDataFactory;
19
import org.eclipse.jface.layout.GridLayoutFactory;
21
import org.eclipse.jface.layout.GridLayoutFactory;
22
import org.eclipse.jface.operation.IRunnableWithProgress;
20
import org.eclipse.jface.wizard.WizardPage;
23
import org.eclipse.jface.wizard.WizardPage;
21
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment;
24
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment;
22
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.SWT;
Lines 50-56 Link Here
50
	private static final String TITLE = "Attachment Preview";
53
	private static final String TITLE = "Attachment Preview";
51
54
52
	private static final String DESCRIPTION = "Review the attachment before submitting";
55
	private static final String DESCRIPTION = "Review the attachment before submitting";
53
	
56
54
	private LocalAttachment attachment;
57
	private LocalAttachment attachment;
55
58
56
	private static HashMap<String, String> textTypes;
59
	private static HashMap<String, String> textTypes;
Lines 93-98 Link Here
93
		composite.setLayout(new GridLayout());
96
		composite.setLayout(new GridLayout());
94
		setControl(composite);
97
		setControl(composite);
95
98
99
		if (attachment instanceof ImageAttachment) {
100
			try {
101
				getContainer().run(true, false, new IRunnableWithProgress() {
102
					public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
103
						monitor.beginTask("Preparing image for preview...", 1);
104
						((ImageAttachment) attachment).ensureImageFileWasCreated();
105
						monitor.worked(1);
106
						monitor.done();
107
					}
108
				});
109
			} catch (InvocationTargetException e) {
110
				createErrorPreview(composite, "Could not create image for preview");
111
				return;
112
			} catch (InterruptedException e) {
113
				createErrorPreview(composite, "Could not create image for preview");
114
				return;
115
			}
116
		}
117
96
		if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(attachment.getFilePath())) {
118
		if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(attachment.getFilePath())) {
97
			createTextPreview(composite, ((NewAttachmentWizard) getWizard()).getClipboardContents());
119
			createTextPreview(composite, ((NewAttachmentWizard) getWizard()).getClipboardContents());
98
		} else if (PreviewAttachmentPage.isTextAttachment(attachment.getContentType())) {
120
		} else if (PreviewAttachmentPage.isTextAttachment(attachment.getContentType())) {
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/ImageAttachment.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.wizards;
10
11
import java.io.File;
12
13
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment;
14
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.graphics.ImageData;
18
import org.eclipse.swt.graphics.ImageLoader;
19
20
/**
21
 * Represents a attachment created from a {@link Image}; handles lazy persistence into a {@link File} and image data
22
 * change
23
 * 
24
 * @author Willian Mitsuda
25
 */
26
public class ImageAttachment extends LocalAttachment {
27
28
	private static final long serialVersionUID = 28264291629999181L;
29
30
	/**
31
	 * Provides the {@link Image} object that will be converted to desired file format, and then attached
32
	 */
33
	private IImageCreator imageCreator;
34
35
	public ImageAttachment(IImageCreator imageCreator) {
36
		this.imageCreator = imageCreator;
37
	}
38
39
	@Override
40
	public void setContentType(String contentType) {
41
		// Does not apply; actually always save as JPEG
42
		// Will be implemented on bug#210179
43
	}
44
45
	@Override
46
	public String getContentType() {
47
		return "image/jpeg";
48
	}
49
50
	@Override
51
	public String getFilename() {
52
		return "screenshot.jpg";
53
	}
54
55
	private boolean dirty = true;
56
57
	public void markDirty() {
58
		dirty = true;
59
	}
60
61
	public void ensureImageFileWasCreated() {
62
		if (!dirty) {
63
			return;
64
		}
65
66
		dirty = false;
67
		createContents();
68
	}
69
70
	private void createContents() {
71
		Image image = imageCreator.createImage();
72
		try {
73
			String path = TasksUiPlugin.getDefault().getDefaultDataDirectory();
74
			ImageLoader loader = new ImageLoader();
75
			loader.data = new ImageData[] { image.getImageData() };
76
			String fileName = path + "/" + getFilename();
77
			loader.save(fileName, SWT.IMAGE_JPEG);
78
			setFile(new File(fileName));
79
			setFilePath(fileName);
80
		} finally {
81
			image.dispose();
82
		}
83
	}
84
85
	public void clearImageFile() {
86
		String path = TasksUiPlugin.getDefault().getDefaultDataDirectory();
87
		new File(path + "/" + getFilename()).delete();
88
	}
89
90
}

Return to bug 209897