1 11 package org.eclipse.jdt.internal.debug.ui.sourcelookup; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.debug.core.ILaunchConfiguration; 16 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 17 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; 18 import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser; 19 import org.eclipse.jdt.core.IClasspathEntry; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.launching.JavaRuntime; 23 import org.eclipse.jdt.launching.sourcelookup.containers.ClasspathContainerSourceContainer; 24 import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess; 25 import org.eclipse.swt.widgets.Shell; 26 27 32 public class ClasspathContainerSourceContainerBrowser extends AbstractSourceContainerBrowser { 33 36 public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) { 37 return editLibraries(shell, director, null); 38 } 40 43 public boolean canEditSourceContainers(ISourceLookupDirector director, ISourceContainer[] containers) { 44 return containers.length == 1; 45 } 46 49 public ISourceContainer[] editSourceContainers(Shell shell, ISourceLookupDirector director, ISourceContainer[] containers) { 50 ClasspathContainerSourceContainer sourceContainer = (ClasspathContainerSourceContainer)containers[0]; 51 IPath containerPath = (sourceContainer).getPath(); 52 IClasspathEntry classpathEntry = JavaCore.newContainerEntry(containerPath); 53 return editLibraries(shell, director, classpathEntry); 54 } 56 57 66 private ISourceContainer[] editLibraries(Shell shell, ISourceLookupDirector director, IClasspathEntry classpathEntry) { 67 IJavaProject project = null; 68 ILaunchConfiguration configuration = director.getLaunchConfiguration(); 69 if (configuration != null) { 70 try { 71 project = JavaRuntime.getJavaProject(configuration); 72 } catch (CoreException e) { 73 } 74 } 75 IClasspathEntry[] edits = null; 76 IClasspathEntry[] created = null; 77 if (classpathEntry == null) { 78 edits = new IClasspathEntry[0]; 79 created = BuildPathDialogAccess.chooseContainerEntries(shell, project, edits); 80 } else { 81 edits = new IClasspathEntry[]{classpathEntry}; 82 IClasspathEntry edit = BuildPathDialogAccess.configureContainerEntry(shell, classpathEntry, project, edits); 83 if (edit != null) { 84 created = new IClasspathEntry[]{edit}; 85 } 86 } 87 if (created != null) { 88 ISourceContainer[] newContainers = new ISourceContainer[created.length]; 89 for (int i = 0; i < created.length; i++) { 90 IClasspathEntry entry = created[i]; 91 ClasspathContainerSourceContainer container = new ClasspathContainerSourceContainer(entry.getPath()); 92 container.init(director); 93 newContainers[i] = container; 94 } 95 return newContainers; 96 } 97 return new ISourceContainer[0]; 98 } 99 } 100 | Popular Tags |