KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > sourcelookup > ClasspathContainerSourceContainerBrowser


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
28  * Used to choose a classpath container.
29  *
30  * @since 3.0
31  */

32 public class ClasspathContainerSourceContainerBrowser extends AbstractSourceContainerBrowser {
33     /* (non-Javadoc)
34      * @see org.eclipse.debug.internal.ui.sourcelookup.ISourceContainerBrowser#createSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.ILaunchConfiguration)
35      */

36     public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) {
37         return editLibraries(shell, director, null);
38         // SourceLookupMessages.getString("ClasspathContainerSourceContainerBrowser.0")
39
}
40     /* (non-Javadoc)
41      * @see org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser#canEditSourceContainers(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector, org.eclipse.debug.core.sourcelookup.ISourceContainer[])
42      */

43     public boolean canEditSourceContainers(ISourceLookupDirector director, ISourceContainer[] containers) {
44         return containers.length == 1;
45     }
46     /* (non-Javadoc)
47      * @see org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser#editSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.sourcelookup.ISourceLookupDirector, org.eclipse.debug.core.sourcelookup.ISourceContainer[])
48      */

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         //, SourceLookupMessages.getString("ClasspathContainerSourceContainerBrowser.1")
55
}
56     
57     /**
58      * Create or edit a container classpath entry.
59      *
60      * @param shell shell to open dialog on
61      * @param director source lookup director
62      * @param classpathEntry entry to edit, or <code>null</code> if creating
63      * @param title dialog title
64      * @return new or replacement source containers
65      */

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