1 11 package org.eclipse.debug.internal.ui.sourcelookup; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 16 import org.eclipse.debug.core.sourcelookup.ISourceContainerType; 17 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; 18 import org.eclipse.debug.ui.DebugUITools; 19 import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 22 25 public class EditContainerAction extends SourceContainerAction { 26 27 private ISourceLookupDirector fDirector; 28 private ISourceContainer[] fContainers; 29 private ISourceContainerBrowser fBrowser; 30 31 public EditContainerAction() { 32 super(SourceLookupUIMessages.EditContainerAction_0); 33 } 34 35 40 public void run() { 41 ISourceContainer[] replacements = fBrowser.editSourceContainers(getShell(), fDirector, fContainers); 42 int j = 0; 43 ISourceContainer[] existing = getViewer().getEntries(); 44 for (int i = 0; i < existing.length && j < replacements.length; i++) { 45 ISourceContainer toBeReplaced = fContainers[j]; 46 ISourceContainer container = existing[i]; 47 if (container.equals(toBeReplaced)) { 48 existing[i] = replacements[j]; 49 j++; 50 } 51 } 52 getViewer().setEntries(existing); 53 } 54 55 public void setSourceLookupDirector(ISourceLookupDirector director) { 56 fDirector = director; 57 } 58 59 62 protected boolean updateSelection(IStructuredSelection selection) { 63 if(selection == null || selection.isEmpty()) { 64 return false; 65 } 66 if (getViewer().getTree().getSelection()[0].getParentItem()==null) { 67 fContainers = new ISourceContainer[selection.size()]; 69 Iterator iterator = selection.iterator(); 70 ISourceContainer container = (ISourceContainer) iterator.next(); 71 ISourceContainerType type = container.getType(); 72 fContainers[0] = container; 73 int i = 1; 74 while (iterator.hasNext()) { 75 container = (ISourceContainer) iterator.next(); 76 fContainers[i] = container; 77 i++; 78 if (!container.getType().equals(type)) { 79 return false; 80 } 81 } 82 fBrowser = DebugUITools.getSourceContainerBrowser(type.getId()); 84 if (fBrowser != null) { 85 return fBrowser.canEditSourceContainers(fDirector, fContainers); 86 } 87 } 88 return false; 89 } 90 } 91 | Popular Tags |