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 160572 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/InputAttachmentSourcePage.java (-4 / +43 lines)
Lines 78-83 Link Here
78
78
79
	public static final String CLIPBOARD_LABEL = "<Clipboard>";
79
	public static final String CLIPBOARD_LABEL = "<Clipboard>";
80
80
81
	public static final String SCREENSHOT_LABEL = "<Screenshot>";
82
81
	// input constants
83
	// input constants
82
	protected final static int CLIPBOARD = 1;
84
	protected final static int CLIPBOARD = 1;
83
85
Lines 85-90 Link Here
85
87
86
	protected final static int WORKSPACE = 3;
88
	protected final static int WORKSPACE = 3;
87
89
90
	protected final static int SCREENSHOT = 4;
91
88
	static final char SEPARATOR = System.getProperty("file.separator").charAt(0); //$NON-NLS-1$
92
	static final char SEPARATOR = System.getProperty("file.separator").charAt(0); //$NON-NLS-1$
89
93
90
	private boolean showError = false;
94
	private boolean showError = false;
Lines 94-99 Link Here
94
	// SWT widgets
98
	// SWT widgets
95
	private Button useClipboardButton;
99
	private Button useClipboardButton;
96
100
101
	private Button useScreenshotButton;
102
97
	private Combo fileNameField;
103
	private Combo fileNameField;
98
104
99
	private Button fileBrowseButton;
105
	private Button fileBrowseButton;
Lines 183-189 Link Here
183
189
184
	@Override
190
	@Override
185
	public IWizardPage getNextPage() {
191
	public IWizardPage getNextPage() {
186
		return wizard.getNextPage(this);
192
		if (getInputMethod() == SCREENSHOT) {
193
			return wizard.getPage("ScreenShotAttachment");
194
		} else
195
			return wizard.getNextPage(this);
187
	}
196
	}
188
197
189
	/*
198
	/*
Lines 224-229 Link Here
224
		useClipboardButton.setSelection(initUseClipboard);
233
		useClipboardButton.setSelection(initUseClipboard);
225
234
226
		// 2nd row
235
		// 2nd row
236
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
237
		gd.horizontalSpan = 3;
238
		useScreenshotButton = new Button(composite, SWT.RADIO);
239
		useScreenshotButton.setText("Screenshot");
240
		useScreenshotButton.setLayoutData(gd);
241
242
		// 3rd row
227
		useFileButton = new Button(composite, SWT.RADIO);
243
		useFileButton = new Button(composite, SWT.RADIO);
228
		useFileButton.setText("File");
244
		useFileButton.setText("File");
229
245
Lines 241-247 Link Here
241
		data.widthHint = Math.max(widthHint, minSize.x);
257
		data.widthHint = Math.max(widthHint, minSize.x);
242
		fileBrowseButton.setLayoutData(data);
258
		fileBrowseButton.setLayoutData(data);
243
259
244
		// 3rd row
260
		// 4th row
245
		useWorkspaceButton = new Button(composite, SWT.RADIO);
261
		useWorkspaceButton = new Button(composite, SWT.RADIO);
246
		useWorkspaceButton.setText("Workspace");
262
		useWorkspaceButton.setText("Workspace");
247
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
263
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
Lines 266-271 Link Here
266
			}
282
			}
267
		});
283
		});
268
284
285
		useScreenshotButton.addSelectionListener(new SelectionAdapter() {
286
			@Override
287
			public void widgetSelected(SelectionEvent e) {
288
				if (!useScreenshotButton.getSelection())
289
					return;
290
291
				clearErrorMessage();
292
				showError = true;
293
				int state = getInputMethod();
294
				setEnableAttachmentFile(state == FILE);
295
				setEnableWorkspaceAttachment(state == WORKSPACE);
296
				updateWidgetEnablements();
297
			}
298
		});
299
269
		useFileButton.addSelectionListener(new SelectionAdapter() {
300
		useFileButton.addSelectionListener(new SelectionAdapter() {
270
			@Override
301
			@Override
271
			public void widgetSelected(SelectionEvent e) {
302
			public void widgetSelected(SelectionEvent e) {
Lines 405-410 Link Here
405
					error = "Clipboard does not contain text";
436
					error = "Clipboard does not contain text";
406
			} else
437
			} else
407
				error = "Cannot retrieve clipboard contents";
438
				error = "Cannot retrieve clipboard contents";
439
		} else if (inputMethod == SCREENSHOT) {
440
			attachmentFound = true;
408
		} else if (inputMethod == FILE) {
441
		} else if (inputMethod == FILE) {
409
			String path = fileNameField.getText();
442
			String path = fileNameField.getText();
410
			if (path != null && path.length() > 0) {
443
			if (path != null && path.length() > 0) {
Lines 442-449 Link Here
442
	}
475
	}
443
476
444
	/**
477
	/**
445
	 * Sets the source name of the import to be the supplied path. Adds the name
478
	 * Sets the source name of the import to be the supplied path. Adds the name of the path to the list of items in the
446
	 * of the path to the list of items in the source combo and selects it.
479
	 * source combo and selects it.
447
	 * 
480
	 * 
448
	 * @param path
481
	 * @param path
449
	 *            the path to be added
482
	 *            the path to be added
Lines 498-503 Link Here
498
			}
531
			}
499
			return FILE;
532
			return FILE;
500
		}
533
		}
534
		if (useScreenshotButton.getSelection()) {
535
			return SCREENSHOT;
536
		}
501
		if (useClipboardButton.getSelection()) {
537
		if (useClipboardButton.getSelection()) {
502
			return CLIPBOARD;
538
			return CLIPBOARD;
503
		}
539
		}
Lines 518-523 Link Here
518
		switch (getInputMethod()) {
554
		switch (getInputMethod()) {
519
		case CLIPBOARD:
555
		case CLIPBOARD:
520
			return CLIPBOARD_LABEL;
556
			return CLIPBOARD_LABEL;
557
		case SCREENSHOT:
558
			return SCREENSHOT_LABEL;
521
		case WORKSPACE:
559
		case WORKSPACE:
522
			IResource[] resources = getResources(treeViewer.getSelection());
560
			IResource[] resources = getResources(treeViewer.getSelection());
523
			if (resources.length > 0 && resources[0].getRawLocation() != null) {
561
			if (resources.length > 0 && resources[0].getRawLocation() != null) {
Lines 606-609 Link Here
606
		}
644
		}
607
		initUseClipboard = b;
645
		initUseClipboard = b;
608
	}
646
	}
647
609
}
648
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentWizard.java (-5 / +31 lines)
Lines 44-49 Link Here
44
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditorInput;
44
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditorInput;
45
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
45
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
46
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
46
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
47
import org.eclipse.swt.SWT;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.swt.graphics.ImageData;
50
import org.eclipse.swt.graphics.ImageLoader;
47
import org.eclipse.swt.widgets.Display;
51
import org.eclipse.swt.widgets.Display;
48
import org.eclipse.ui.PlatformUI;
52
import org.eclipse.ui.PlatformUI;
49
53
Lines 58-63 Link Here
58
62
59
	protected static final String CLIPBOARD_FILENAME = "clipboard.txt";
63
	protected static final String CLIPBOARD_FILENAME = "clipboard.txt";
60
64
65
	protected static final String SCREENSHOT_FILENAME = "screenshot.jpg";
66
61
	private LocalAttachment attachment;
67
	private LocalAttachment attachment;
62
68
63
	private InputAttachmentSourcePage inputPage;
69
	private InputAttachmentSourcePage inputPage;
Lines 66-71 Link Here
66
72
67
	private NewAttachmentWizardDialog dialog;
73
	private NewAttachmentWizardDialog dialog;
68
74
75
	private ScreenShotAttachmentPage shotPage;
76
69
	private boolean hasNewDialogSettings;
77
	private boolean hasNewDialogSettings;
70
78
71
	private TaskRepository repository;
79
	private TaskRepository repository;
Lines 137-158 Link Here
137
					}
145
					}
138
					monitor.beginTask("Attaching file...", 2);
146
					monitor.beginTask("Attaching file...", 2);
139
					task.setSubmitting(true);
147
					task.setSubmitting(true);
140
					task.setSynchronizationState(RepositoryTaskSyncState.OUTGOING);					
148
					task.setSynchronizationState(RepositoryTaskSyncState.OUTGOING);
141
149
142
					if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(path)) {
150
					if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(path)) {
143
						String contents = inputPage.getClipboardContents();
151
						String contents = inputPage.getClipboardContents();
144
						if (contents == null) {
152
						if (contents == null) {
145
							throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Clipboard is empty", null)));
153
							throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR,
154
									TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Clipboard is empty",
155
									null)));
146
						}
156
						}
147
						attachment.setContent(contents.getBytes());
157
						attachment.setContent(contents.getBytes());
148
						attachment.setFilename(CLIPBOARD_FILENAME);
158
						attachment.setFilename(CLIPBOARD_FILENAME);
159
					} else if (InputAttachmentSourcePage.SCREENSHOT_LABEL.equals(path)) {
160
						Image image = shotPage.getScreenshotImage();
161
						if (image == null) {
162
							throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR,
163
									TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Screenshot is empty",
164
									null)));
165
						}
166
						String path = TasksUiPlugin.getDefault().getDefaultDataDirectory();
167
						ImageLoader loader = new ImageLoader();
168
						loader.data = new ImageData[] { image.getImageData() };
169
						String fileName = path + "/" + SCREENSHOT_FILENAME;
170
						loader.save(fileName, SWT.IMAGE_JPEG);
171
						attachment.setFile(new File(fileName));
172
						attachment.setFilename(SCREENSHOT_FILENAME);
149
					} else {
173
					} else {
150
						File file = new File(path);
174
						File file = new File(path);
151
						attachment.setFile(file);
175
						attachment.setFile(file);
152
						attachment.setFilename(file.getName());
176
						attachment.setFilename(file.getName());
153
					}
177
					}
154
					
178
155
					attachmentHandler.uploadAttachment(repository, task, attachment, attachment.getComment(), 
179
					attachmentHandler.uploadAttachment(repository, task, attachment, attachment.getComment(),
156
							new SubProgressMonitor(monitor, 1));
180
							new SubProgressMonitor(monitor, 1));
157
181
158
					if (monitor.isCanceled()) {
182
					if (monitor.isCanceled()) {
Lines 160-166 Link Here
160
					}
184
					}
161
185
162
					if (attachContext && connector.getAttachmentHandler() != null) {
186
					if (attachContext && connector.getAttachmentHandler() != null) {
163
						connector.getAttachmentHandler().attachContext(repository, task, "", new SubProgressMonitor(monitor, 1));
187
						connector.getAttachmentHandler().attachContext(repository, task, "",
188
								new SubProgressMonitor(monitor, 1));
164
					}
189
					}
165
				} catch (CoreException e) {
190
				} catch (CoreException e) {
166
					throw new InvocationTargetException(e);
191
					throw new InvocationTargetException(e);
Lines 267-272 Link Here
267
			addPage(inputPage);
292
			addPage(inputPage);
268
		}
293
		}
269
		addPage((attachPage = new NewAttachmentPage(attachment)));
294
		addPage((attachPage = new NewAttachmentPage(attachment)));
295
		addPage((shotPage = new ScreenShotAttachmentPage(attachment)));
270
	}
296
	}
271
297
272
	public LocalAttachment getAttachment() {
298
	public LocalAttachment getAttachment() {
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentPage.java (-1 / +19 lines)
Lines 54-59 Link Here
54
54
55
	private Button attachContextButton;
55
	private Button attachContextButton;
56
56
57
	private Combo contentTypeList;
58
57
	private static List<String> contentTypes;
59
	private static List<String> contentTypes;
58
60
59
	private static Map<String, String> extensions2Types;
61
	private static Map<String, String> extensions2Types;
Lines 134-140 Link Here
134
136
135
		new Label(composite, SWT.NONE).setText("Content Type");// .setBackground(parent.getBackground());
137
		new Label(composite, SWT.NONE).setText("Content Type");// .setBackground(parent.getBackground());
136
138
137
		final Combo contentTypeList = new Combo(composite, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
139
		contentTypeList = new Combo(composite, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
138
		contentTypeList.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false, 2, 1));
140
		contentTypeList.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false, 2, 1));
139
		final HashMap<String, Integer> contentTypeIndices = new HashMap<String, Integer>();
141
		final HashMap<String, Integer> contentTypeIndices = new HashMap<String, Integer>();
140
		Iterator<String> iter = contentTypes.iterator();
142
		Iterator<String> iter = contentTypes.iterator();
Lines 247-252 Link Here
247
249
248
	@Override
250
	@Override
249
	public boolean canFlipToNextPage() {
251
	public boolean canFlipToNextPage() {
252
		if (filePath.getText().equals(InputAttachmentSourcePage.SCREENSHOT_LABEL))
253
			return false;
250
		return isPageComplete();
254
		return isPageComplete();
251
	}
255
	}
252
256
Lines 271-274 Link Here
271
	public boolean getAttachContext() {
275
	public boolean getAttachContext() {
272
		return attachContextButton.getSelection();
276
		return attachContextButton.getSelection();
273
	}
277
	}
278
279
	public void setContentType() {
280
		String type = attachment.getContentType();
281
		String[] typeList = contentTypeList.getItems();
282
		for (int i = 0; i < typeList.length; i++) {
283
			if (typeList[i].equals(type)) {
284
				contentTypeList.select(i);
285
				contentTypeList.setEnabled(false);
286
				isPatchButton.setEnabled(false);
287
				return;
288
			}
289
		}
290
	}
291
274
}
292
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/ScreenShotAttachmentPage.java (+199 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2007 University Of British Columbia 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
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui.wizards;
13
14
import org.eclipse.jface.layout.GridDataFactory;
15
import org.eclipse.jface.wizard.IWizardPage;
16
import org.eclipse.jface.wizard.WizardPage;
17
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.ScrolledComposite;
20
import org.eclipse.swt.events.PaintEvent;
21
import org.eclipse.swt.events.PaintListener;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.events.SelectionListener;
24
import org.eclipse.swt.graphics.GC;
25
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Point;
27
import org.eclipse.swt.graphics.Rectangle;
28
import org.eclipse.swt.layout.FillLayout;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.Button;
32
import org.eclipse.swt.widgets.Canvas;
33
import org.eclipse.swt.widgets.Composite;
34
import org.eclipse.swt.widgets.Display;
35
import org.eclipse.swt.widgets.Shell;
36
37
/**
38
 * A wizard page to create a screenshot from the display.
39
 * 
40
 * @author Balazs Brinkus (bug 160572)
41
 */
42
public class ScreenShotAttachmentPage extends WizardPage {
43
44
	private ScreenShotAttachmentPage page;
45
46
	private LocalAttachment attachment;
47
48
	private Button makeShotButton;
49
50
	private Button showShotButton;
51
52
	private Image screenshotImage;
53
54
	private Canvas canvas;
55
56
	protected ScreenShotAttachmentPage(LocalAttachment attachment) {
57
		super("ScreenShotAttachment");
58
		setTitle("Create a screenshot");
59
		this.attachment = attachment;
60
		this.page = this;
61
	}
62
63
	public void createControl(Composite parent) {
64
		Composite composite = new Composite(parent, SWT.NONE);
65
		GridLayout gridLayout = new GridLayout();
66
		gridLayout.numColumns = 2;
67
		composite.setLayout(gridLayout);
68
		setControl(composite);
69
70
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
71
		composite.setLayout(new GridLayout(3, false));
72
73
		makeShotButton = new Button(composite, SWT.PUSH);
74
		makeShotButton.setText("Take a screenshot");
75
		makeShotButton.addSelectionListener(new SelectionListener() {
76
77
			public void widgetSelected(SelectionEvent e) {
78
				storeScreenshotContent();
79
				page.setErrorMessage(null);
80
				showShotButton.setEnabled(true);
81
			}
82
83
			public void widgetDefaultSelected(SelectionEvent e) {
84
			}
85
86
		});
87
88
		showShotButton = new Button(composite, SWT.PUSH);
89
		showShotButton.setText("Show the screenshot");
90
		showShotButton.addSelectionListener(new SelectionListener() {
91
92
			public void widgetSelected(SelectionEvent e) {
93
				showScreenshotContent();
94
			}
95
96
			public void widgetDefaultSelected(SelectionEvent e) {
97
			}
98
99
		});
100
101
		canvas = new Canvas(composite, SWT.BORDER);
102
		canvas.setLayoutData(GridDataFactory.fillDefaults()
103
				.align(SWT.FILL, SWT.FILL)
104
				.grab(true, true)
105
				.span(2, 1)
106
				.create());
107
108
		canvas.addPaintListener(new PaintListener() {
109
			public void paintControl(PaintEvent e) {
110
				if (screenshotImage != null) {
111
					Rectangle screenBounds = screenshotImage.getBounds();
112
					Rectangle canvasBounds = canvas.getBounds();
113
					e.gc.drawImage(screenshotImage, 0, 0, screenBounds.width, screenBounds.height, 0, 0,
114
							canvasBounds.width, canvasBounds.height);
115
				} else {
116
					page.setErrorMessage("Screenshot required");
117
					showShotButton.setEnabled(false);
118
				}
119
			}
120
		});
121
122
	}
123
124
	@Override
125
	public boolean isPageComplete() {
126
		if (screenshotImage == null)
127
			return false;
128
		return true;
129
	}
130
131
	@Override
132
	public IWizardPage getNextPage() {
133
		NewAttachmentPage page = (NewAttachmentPage) getWizard().getPage("AttachmentDetails");
134
		attachment.setContentType("image/jpeg");
135
		page.setFilePath(InputAttachmentSourcePage.SCREENSHOT_LABEL);
136
		page.setContentType();
137
		return page;
138
	}
139
140
	@Override
141
	public boolean canFlipToNextPage() {
142
		return isPageComplete();
143
	}
144
145
	private void storeScreenshotContent() {
146
147
		final Display display = Display.getDefault();
148
		final Shell wizardShell = getWizard().getContainer().getShell();
149
		wizardShell.setVisible(false);
150
151
		display.asyncExec(new Runnable() {
152
			public void run() {
153
				GC gc = new GC(display);
154
				screenshotImage = new Image(display, display.getBounds());
155
				gc.copyArea(screenshotImage, 0, 0);
156
				gc.dispose();
157
				canvas.redraw();
158
				wizardShell.setVisible(true);
159
				if (screenshotImage != null)
160
					setPageComplete(true);
161
			}
162
		});
163
	}
164
165
	private void showScreenshotContent() {
166
		Display display = Display.getDefault();
167
168
		Shell popup = new Shell(display.getActiveShell(), SWT.SHELL_TRIM);
169
		popup.setLayout(new FillLayout());
170
		popup.setText("Screenshot Image");
171
172
		Rectangle displayBounds = Display.getDefault().getBounds();
173
		Point dialogSize = new Point(0, 0);
174
		dialogSize.x = displayBounds.width / 2;
175
		dialogSize.y = displayBounds.height / 2;
176
		Point dialoglocation = new Point(0, 0);
177
		dialoglocation.x = displayBounds.x + displayBounds.width / 2 - dialogSize.x / 2;
178
		dialoglocation.y = displayBounds.y + displayBounds.height / 2 - dialogSize.y / 2;
179
		popup.setSize(dialogSize);
180
		popup.setLocation(dialoglocation);
181
182
		ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL);
183
		Canvas canvas = new Canvas(sc, SWT.NONE);
184
		sc.setContent(canvas);
185
		canvas.setBounds(display.getBounds());
186
		canvas.addPaintListener(new PaintListener() {
187
			public void paintControl(PaintEvent e) {
188
				if (screenshotImage != null)
189
					e.gc.drawImage(screenshotImage, 0, 0);
190
			}
191
		});
192
		popup.open();
193
	}
194
195
	public Image getScreenshotImage() {
196
		return screenshotImage;
197
	}
198
199
}

Return to bug 160572