1 11 package org.eclipse.jdt.internal.ui.dialogs; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.OperationCanceledException; 20 21 import org.eclipse.core.resources.IWorkspaceRunnable; 22 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Shell; 28 29 import org.eclipse.jface.dialogs.IDialogConstants; 30 import org.eclipse.jface.dialogs.StatusDialog; 31 import org.eclipse.jface.operation.IRunnableWithProgress; 32 33 import org.eclipse.ui.PlatformUI; 34 35 import org.eclipse.jdt.core.IJavaProject; 36 37 import org.eclipse.jdt.internal.corext.util.Messages; 38 39 import org.eclipse.jdt.internal.ui.JavaUIMessages; 40 import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter; 41 import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages; 42 import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; 43 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 44 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 45 import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathsBlock; 46 47 public class BuildPathDialog extends StatusDialog { 48 49 private IJavaProject fProject; 50 private BuildPathsBlock fBlock; 51 52 public BuildPathDialog(Shell parent, IJavaProject project) { 53 super(parent); 54 setShellStyle(getShellStyle() | SWT.RESIZE); 55 Assert.isNotNull(project); 56 fProject= project; 57 } 58 59 protected void configureShell(Shell shell) { 60 super.configureShell(shell); 61 shell.setText(Messages.format(JavaUIMessages.BuildPathDialog_title, fProject.getElementName())); 62 } 63 64 protected Control createDialogArea(Composite parent) { 65 IStatusChangeListener listener = new IStatusChangeListener() { 66 public void statusChanged(IStatus status) { 67 updateStatus(status); 68 } 69 }; 70 Composite result= (Composite)super.createDialogArea(parent); 71 fBlock= new BuildPathsBlock(new BusyIndicatorRunnableContext(), listener, 0, false, null); 72 fBlock.init(fProject, null, null); 73 fBlock.createControl(result).setLayoutData(new GridData(GridData.FILL_BOTH)); 74 applyDialogFont(result); 75 return result; 76 } 77 78 protected void buttonPressed(int buttonId) { 79 try { 80 if (buttonId == IDialogConstants.OK_ID) { 81 configureBuildPath(); 82 } 83 super.buttonPressed(buttonId); 84 } finally { 85 fBlock.dispose(); 86 } 87 } 88 89 private void configureBuildPath() { 90 Shell shell= getShell(); 91 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 92 public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { 93 fBlock.configureJavaProject(monitor); 94 } 95 }; 96 IRunnableWithProgress op= new WorkbenchRunnableAdapter(runnable); try { 98 PlatformUI.getWorkbench().getProgressService().run(true, true, op); 99 } catch (InvocationTargetException e) { 100 String title= PreferencesMessages.BuildPathDialog_error_title; 101 String message= PreferencesMessages.BuildPathDialog_error_message; 102 ExceptionHandler.handle(e, shell, title, message); 103 } catch (InterruptedException e) { 104 } 106 } 107 } 108 | Popular Tags |