1 11 12 package org.eclipse.ui.views.tasklist; 13 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.jface.dialogs.MessageDialog; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.viewers.TableViewer; 20 import org.eclipse.swt.SWTError; 21 import org.eclipse.swt.dnd.DND; 22 import org.eclipse.swt.dnd.TextTransfer; 23 import org.eclipse.swt.dnd.Transfer; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.internal.views.tasklist.TaskListMessages; 26 import org.eclipse.ui.part.MarkerTransfer; 27 28 31 class CopyTaskAction extends TaskAction { 32 33 38 public CopyTaskAction(TaskList tasklist, String id) { 39 super(tasklist, id); 40 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 41 ITaskListHelpContextIds.COPY_TASK_ACTION); 42 } 43 44 47 public void run() { 48 TaskList taskList = getTaskList(); 50 TableViewer viewer = taskList.getTableViewer(); 51 IStructuredSelection selection = (IStructuredSelection) viewer 52 .getSelection(); 53 if (selection.isEmpty()) { 54 return; 55 } 56 taskList.cancelEditing(); 57 List list = selection.toList(); 58 IMarker[] markers = new IMarker[list.size()]; 59 list.toArray(markers); 60 61 setClipboard(markers, TaskList.createMarkerReport(markers)); 62 63 taskList.updatePasteEnablement(); 65 } 66 67 private void setClipboard(IMarker[] markers, String markerReport) { 68 try { 69 Object [] data = new Object [] { markers, markerReport }; 71 Transfer[] transferTypes = new Transfer[] { 72 MarkerTransfer.getInstance(), TextTransfer.getInstance() }; 73 74 getTaskList().getClipboard().setContents(data, transferTypes); 76 } catch (SWTError e) { 77 if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { 78 throw e; 79 } 80 if (MessageDialog 81 .openQuestion( 82 getShell(), 83 TaskListMessages.CopyToClipboardProblemDialog_title, TaskListMessages.CopyToClipboardProblemDialog_message)) { 84 setClipboard(markers, markerReport); 85 } 86 } 87 } 88 } 89 90 | Popular Tags |