1 11 12 package org.eclipse.ui.views.tasklist; 13 14 import java.util.ArrayList ; 15 import java.util.Map ; 16 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.IWorkspaceRunnable; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.jface.dialogs.ErrorDialog; 23 import org.eclipse.jface.viewers.StructuredSelection; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.ide.undo.CreateMarkersOperation; 26 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 27 import org.eclipse.ui.internal.views.tasklist.TaskListMessages; 28 import org.eclipse.ui.part.MarkerTransfer; 29 30 38 class PasteTaskAction extends TaskAction { 39 40 46 public PasteTaskAction(TaskList tasklist, String id) { 47 super(tasklist, id); 48 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 49 ITaskListHelpContextIds.PASTE_TASK_ACTION); 50 } 51 52 55 public void run() { 56 MarkerTransfer transfer = MarkerTransfer.getInstance(); 58 final IMarker[] markerData = (IMarker[]) getTaskList().getClipboard() 59 .getContents(transfer); 60 61 if (markerData == null) { 62 return; 63 } 64 65 final ArrayList newMarkerAttributes = new ArrayList (); 66 final ArrayList newMarkerResources = new ArrayList (); 67 68 try { 69 getTaskList().getWorkspace().run(new IWorkspaceRunnable() { 70 public void run(IProgressMonitor monitor) throws CoreException { 71 for (int i = 0; i < markerData.length; i++) { 72 if (!markerData[i].getType().equals(IMarker.TASK)) { 74 continue; 75 } 76 newMarkerResources.add(markerData[i].getResource()); 77 newMarkerAttributes.add(markerData[i].getAttributes()); 78 } 79 } 80 }, null); 81 } catch (CoreException e) { 82 ErrorDialog.openError(getShell(), TaskListMessages.PasteTask_errorMessage, 83 null, e.getStatus()); 84 return; 85 } 86 87 final Map [] attrs = (Map []) newMarkerAttributes.toArray(new Map [newMarkerAttributes.size()]); 88 final IResource [] resources = (IResource []) newMarkerResources.toArray(new IResource [newMarkerResources.size()]); 89 final CreateMarkersOperation op = new CreateMarkersOperation(IMarker.TASK, attrs, 90 resources, getText()); 91 execute(op, TaskListMessages.PasteTask_errorMessage, null, 92 WorkspaceUndoUtil.getUIInfoAdapter(getShell())); 93 94 if (op.getMarkers() != null) { 100 getShell().getDisplay().asyncExec(new Runnable () { 101 public void run() { 102 TaskList taskList = getTaskList(); 103 taskList.setSelection(new StructuredSelection(op.getMarkers()), 104 true); 105 } 106 }); 107 } 108 } 109 110 } 111 112 | Popular Tags |