KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > dialogs > BuildPathDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.dialogs;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
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); // lock on root
97
try {
98             PlatformUI.getWorkbench().getProgressService().run(true, true, op);
99         } catch (InvocationTargetException JavaDoc e) {
100             String JavaDoc title= PreferencesMessages.BuildPathDialog_error_title;
101             String JavaDoc message= PreferencesMessages.BuildPathDialog_error_message;
102             ExceptionHandler.handle(e, shell, title, message);
103         } catch (InterruptedException JavaDoc e) {
104             // cancelled
105
}
106     }
107 }
108
Popular Tags