1 11 package org.eclipse.jdt.ui.wizards; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.net.URI ; 15 16 import org.eclipse.core.filesystem.URIUtil; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.NullProgressMonitor; 23 import org.eclipse.core.runtime.OperationCanceledException; 24 import org.eclipse.core.runtime.SubProgressMonitor; 25 26 import org.eclipse.core.resources.IProject; 27 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Control; 33 34 import org.eclipse.jface.dialogs.Dialog; 35 import org.eclipse.jface.operation.IRunnableWithProgress; 36 37 import org.eclipse.ui.PlatformUI; 38 39 import org.eclipse.jdt.core.IClasspathEntry; 40 import org.eclipse.jdt.core.IJavaProject; 41 42 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 43 import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; 44 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 45 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 46 import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathsBlock; 47 48 61 public class JavaCapabilityConfigurationPage extends NewElementWizardPage { 62 63 private static final String PAGE_NAME= "JavaCapabilityConfigurationPage"; 65 private IJavaProject fJavaProject; 66 private BuildPathsBlock fBuildPathsBlock; 67 68 76 public JavaCapabilityConfigurationPage() { 77 super(PAGE_NAME); 78 fJavaProject= null; 79 80 setTitle(NewWizardMessages.JavaCapabilityConfigurationPage_title); 81 setDescription(NewWizardMessages.JavaCapabilityConfigurationPage_description); 82 } 83 84 private BuildPathsBlock getBuildPathsBlock() { 85 if (fBuildPathsBlock == null) { 86 IStatusChangeListener listener= new IStatusChangeListener() { 87 public void statusChanged(IStatus status) { 88 updateStatus(status); 89 } 90 }; 91 fBuildPathsBlock= new BuildPathsBlock(new BusyIndicatorRunnableContext(), listener, 0, useNewSourcePage(), null); 92 } 93 return fBuildPathsBlock; 94 } 95 96 100 public void dispose() { 101 try { 102 super.dispose(); 103 } finally { 104 if (fBuildPathsBlock != null) { 105 fBuildPathsBlock.dispose(); 106 fBuildPathsBlock= null; 107 } 108 } 109 } 110 111 118 protected boolean useNewSourcePage() { 119 return false; 120 } 121 122 141 public void init(IJavaProject jproject, IPath defaultOutputLocation, IClasspathEntry[] defaultEntries, boolean defaultsOverrideExistingClasspath) { 142 if (!defaultsOverrideExistingClasspath && jproject.exists() && jproject.getProject().getFile(".classpath").exists()) { defaultOutputLocation= null; 144 defaultEntries= null; 145 } 146 getBuildPathsBlock().init(jproject, defaultOutputLocation, defaultEntries); 147 fJavaProject= jproject; 148 } 149 150 153 public void createControl(Composite parent) { 154 Composite composite= new Composite(parent, SWT.NONE); 155 composite.setFont(parent.getFont()); 156 composite.setLayout(new GridLayout(1, false)); 157 Control control= getBuildPathsBlock().createControl(composite); 158 control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 159 Dialog.applyDialogFont(composite); 160 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.NEW_JAVAPROJECT_WIZARD_PAGE); 161 setControl(composite); 162 } 163 164 170 public IPath getOutputLocation() { 171 return getBuildPathsBlock().getOutputLocation(); 172 } 173 174 180 public IClasspathEntry[] getRawClassPath() { 181 return getBuildPathsBlock().getRawClassPath(); 182 } 183 184 190 public IJavaProject getJavaProject() { 191 return fJavaProject; 192 } 193 194 195 203 public IRunnableWithProgress getRunnable() { 204 if (getJavaProject() != null) { 205 return new IRunnableWithProgress() { 206 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 207 try { 208 configureJavaProject(monitor); 209 } catch (CoreException e) { 210 throw new InvocationTargetException (e); 211 } 212 } 213 }; 214 } 215 return null; 216 } 217 218 230 public static void createProject(IProject project, IPath locationPath, IProgressMonitor monitor) throws CoreException { 231 createProject(project, locationPath != null ? URIUtil.toURI(locationPath) : null, monitor); 232 } 233 234 246 public static void createProject(IProject project, URI locationURI, IProgressMonitor monitor) throws CoreException { 247 BuildPathsBlock.createProject(project, locationURI, monitor); 248 } 249 250 258 public void configureJavaProject(IProgressMonitor monitor) throws CoreException, InterruptedException { 259 if (monitor == null) { 260 monitor= new NullProgressMonitor(); 261 } 262 263 int nSteps= 6; 264 monitor.beginTask(NewWizardMessages.JavaCapabilityConfigurationPage_op_desc_java, nSteps); 265 266 try { 267 IProject project= getJavaProject().getProject(); 268 BuildPathsBlock.addJavaNature(project, new SubProgressMonitor(monitor, 1)); 269 getBuildPathsBlock().configureJavaProject(new SubProgressMonitor(monitor, 5)); 270 } catch (OperationCanceledException e) { 271 throw new InterruptedException (); 272 } finally { 273 monitor.done(); 274 } 275 } 276 277 282 protected void setFocus() { 283 getBuildPathsBlock().setFocus(); 284 } 285 } 286 | Popular Tags |