1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.debug.core.ILaunchConfiguration; 18 import org.eclipse.jdt.internal.debug.ui.classpath.ClasspathEntry; 19 import org.eclipse.jdt.internal.debug.ui.classpath.IClasspathEditor; 20 import org.eclipse.jdt.internal.debug.ui.classpath.IClasspathEntry; 21 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer; 22 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 25 28 public class EditClasspathEntryAction extends RuntimeClasspathAction { 29 30 private ILaunchConfiguration fConfiguration; 31 32 public EditClasspathEntryAction(IClasspathViewer viewer, ILaunchConfiguration configuration) { 33 super(ActionMessages.EditClasspathEntryAction_0, viewer); 34 fConfiguration = configuration; 35 } 36 41 public void run() { 42 List targets = getOrderedSelection(); 43 if (targets.size() != 1) { 44 return; 45 } 46 IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) targets.get(0); 47 IRuntimeClasspathEntry[] original = new IRuntimeClasspathEntry[]{entry}; 48 IRuntimeClasspathEntry[] delegtes = new IRuntimeClasspathEntry[original.length]; 49 IClasspathEntry[] parents = new IClasspathEntry[original.length]; 50 for (int i = 0; i < delegtes.length; i++) { 51 ClasspathEntry classpathEntry = (ClasspathEntry)original[i]; 52 delegtes[i] = classpathEntry.getDelegate(); 53 parents[i] = classpathEntry.getParent(); 54 } 55 IClasspathEditor editor = getEditor(entry); 56 if (editor != null) { 57 IRuntimeClasspathEntry[] replacements = editor.edit(getShell(), fConfiguration, delegtes); 58 if (replacements != null) { 59 IRuntimeClasspathEntry[] wrappers = new IRuntimeClasspathEntry[replacements.length]; 60 List list = getEntriesAsList(); 61 int index = 0; 62 for (int i = 0; i < list.size(); i++) { 63 Object element = list.get(i); 64 if (element == original[index]) { 65 wrappers[index] = new ClasspathEntry(replacements[index], parents[index]); 66 list.set(i, wrappers[index]); 67 index++; 68 } 69 } 70 setEntries(list); 71 for (int i = 0; i < wrappers.length; i++) { 72 getViewer().refresh(wrappers[i]); 73 } 74 } 75 } 76 77 } 78 79 82 protected boolean updateSelection(IStructuredSelection selection) { 83 if (selection.size() == 1) { 84 Object element = selection.getFirstElement(); 85 if (element instanceof IRuntimeClasspathEntry) { 86 IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) element; 87 IClasspathEditor editor = getEditor(entry); 88 if (editor != null) { 89 return editor.canEdit(fConfiguration, new IRuntimeClasspathEntry[]{((ClasspathEntry)entry).getDelegate()}); 90 } 91 } 92 } 93 return false; 94 } 95 96 protected IClasspathEditor getEditor(IRuntimeClasspathEntry entry) { 97 if (entry instanceof IAdaptable) { 98 IAdaptable adaptable = (IAdaptable) entry; 99 return (IClasspathEditor) adaptable.getAdapter(IClasspathEditor.class); 100 } 101 return null; 102 } 103 104 } 105 | Popular Tags |