1 11 12 package org.eclipse.ui.views.bookmarkexplorer; 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.resources.ResourcesPlugin; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.jface.dialogs.ErrorDialog; 24 import org.eclipse.jface.viewers.StructuredSelection; 25 import org.eclipse.ui.PlatformUI; 26 import org.eclipse.ui.ide.undo.CreateMarkersOperation; 27 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 28 import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages; 29 import org.eclipse.ui.part.MarkerTransfer; 30 31 34 class PasteBookmarkAction extends BookmarkAction { 35 36 private BookmarkNavigator view; 37 38 43 public PasteBookmarkAction(BookmarkNavigator view) { 44 super(view, BookmarkMessages.PasteBookmark_text); 45 this.view = view; 46 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 47 IBookmarkHelpContextIds.PASTE_BOOKMARK_ACTION); 48 setEnabled(false); 49 } 50 51 54 public void run() { 55 MarkerTransfer transfer = MarkerTransfer.getInstance(); 57 final IMarker[] markerData = (IMarker[]) view.getClipboard() 58 .getContents(transfer); 59 60 if (markerData == null) { 61 return; 62 } 63 final ArrayList newMarkerAttributes = new ArrayList (); 64 final ArrayList newMarkerResources = new ArrayList (); 65 try { 66 ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { 67 public void run(IProgressMonitor monitor) throws CoreException { 68 for (int i = 0; i < markerData.length; i++) { 69 if (!markerData[i].getType().equals(IMarker.BOOKMARK)) { 72 continue; 73 } 74 newMarkerResources.add(markerData[i].getResource()); 75 newMarkerAttributes.add(markerData[i].getAttributes()); 76 } 77 } 78 }, null); 79 } catch (CoreException e) { 80 ErrorDialog.openError(view.getShell(), BookmarkMessages.PasteBookmark_errorTitle, 81 null, e.getStatus()); 82 return; 83 } 84 final Map [] attrs = (Map []) newMarkerAttributes.toArray(new Map [newMarkerAttributes.size()]); 85 final IResource [] resources = (IResource []) newMarkerResources.toArray(new IResource [newMarkerResources.size()]); 86 final CreateMarkersOperation op = new CreateMarkersOperation(IMarker.BOOKMARK, attrs, 87 resources, BookmarkMessages.PasteBookmark_undoText); 88 execute(op, BookmarkMessages.PasteBookmark_errorTitle, null, 89 WorkspaceUndoUtil.getUIInfoAdapter(view.getShell())); 90 91 if (op.getMarkers() != null) { 97 view.getShell().getDisplay().asyncExec(new Runnable () { 98 public void run() { 99 view.getViewer().setSelection( 100 new StructuredSelection(op.getMarkers())); 101 view.updatePasteEnablement(); 102 } 103 }); 104 } 105 } 106 107 } 108 | Popular Tags |