1 11 package org.eclipse.jdt.internal.launching; 12 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.IWorkspace; 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 18 import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate; 19 import org.eclipse.jdt.core.IJavaProject; 20 import org.eclipse.jdt.core.JavaCore; 21 import org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer; 22 import org.w3c.dom.Document ; 23 import org.w3c.dom.Element ; 24 import org.w3c.dom.Node ; 25 26 29 public class JavaProjectSourceContainerTypeDelegate extends AbstractSourceContainerTypeDelegate { 30 31 34 public ISourceContainer createSourceContainer(String memento) throws CoreException { 35 Node node = parseDocument(memento); 36 if (node.getNodeType() == Node.ELEMENT_NODE) { 37 Element element = (Element )node; 38 if ("javaProject".equals(element.getNodeName())) { String string = element.getAttribute("name"); if (string == null || string.length() == 0) { 41 abort(LaunchingMessages.JavaProjectSourceContainerTypeDelegate_5, null); 42 } 43 IWorkspace workspace = ResourcesPlugin.getWorkspace(); 44 IProject project = workspace.getRoot().getProject(string); 45 IJavaProject javaProject = JavaCore.create(project); 46 return new JavaProjectSourceContainer(javaProject); 47 } 48 abort(LaunchingMessages.JavaProjectSourceContainerTypeDelegate_6, null); 49 } 50 abort(LaunchingMessages.JavaProjectSourceContainerTypeDelegate_7, null); 51 return null; 52 } 53 56 public String getMemento(ISourceContainer container) throws CoreException { 57 JavaProjectSourceContainer project = (JavaProjectSourceContainer) container; 58 Document document = newDocument(); 59 Element element = document.createElement("javaProject"); element.setAttribute("name", project.getName()); document.appendChild(element); 62 return serializeDocument(document); 63 } 64 } 65 | Popular Tags |