001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.dialogs;
011:
012: import java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.runtime.Assert;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IProgressMonitor;
017: import org.eclipse.core.runtime.IStatus;
018: import org.eclipse.core.runtime.OperationCanceledException;
019:
020: import org.eclipse.core.resources.IWorkspaceRunnable;
021:
022: import org.eclipse.swt.SWT;
023: import org.eclipse.swt.layout.GridData;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Control;
026: import org.eclipse.swt.widgets.Shell;
027:
028: import org.eclipse.jface.dialogs.IDialogConstants;
029: import org.eclipse.jface.dialogs.StatusDialog;
030: import org.eclipse.jface.operation.IRunnableWithProgress;
031:
032: import org.eclipse.ui.PlatformUI;
033:
034: import org.eclipse.jdt.core.IJavaProject;
035:
036: import org.eclipse.jdt.internal.corext.util.Messages;
037:
038: import org.eclipse.jdt.internal.ui.JavaUIMessages;
039: import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
040: import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages;
041: import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
042: import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
043: import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
044: import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathsBlock;
045:
046: public class BuildPathDialog extends StatusDialog {
047:
048: private IJavaProject fProject;
049: private BuildPathsBlock fBlock;
050:
051: public BuildPathDialog(Shell parent, IJavaProject project) {
052: super (parent);
053: setShellStyle(getShellStyle() | SWT.RESIZE);
054: Assert.isNotNull(project);
055: fProject = project;
056: }
057:
058: protected void configureShell(Shell shell) {
059: super .configureShell(shell);
060: shell.setText(Messages.format(
061: JavaUIMessages.BuildPathDialog_title, fProject
062: .getElementName()));
063: }
064:
065: protected Control createDialogArea(Composite parent) {
066: IStatusChangeListener listener = new IStatusChangeListener() {
067: public void statusChanged(IStatus status) {
068: updateStatus(status);
069: }
070: };
071: Composite result = (Composite) super .createDialogArea(parent);
072: fBlock = new BuildPathsBlock(
073: new BusyIndicatorRunnableContext(), listener, 0, false,
074: null);
075: fBlock.init(fProject, null, null);
076: fBlock.createControl(result).setLayoutData(
077: new GridData(GridData.FILL_BOTH));
078: applyDialogFont(result);
079: return result;
080: }
081:
082: protected void buttonPressed(int buttonId) {
083: try {
084: if (buttonId == IDialogConstants.OK_ID) {
085: configureBuildPath();
086: }
087: super .buttonPressed(buttonId);
088: } finally {
089: fBlock.dispose();
090: }
091: }
092:
093: private void configureBuildPath() {
094: Shell shell = getShell();
095: IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
096: public void run(IProgressMonitor monitor)
097: throws CoreException, OperationCanceledException {
098: fBlock.configureJavaProject(monitor);
099: }
100: };
101: IRunnableWithProgress op = new WorkbenchRunnableAdapter(
102: runnable); // lock on root
103: try {
104: PlatformUI.getWorkbench().getProgressService().run(true,
105: true, op);
106: } catch (InvocationTargetException e) {
107: String title = PreferencesMessages.BuildPathDialog_error_title;
108: String message = PreferencesMessages.BuildPathDialog_error_message;
109: ExceptionHandler.handle(e, shell, title, message);
110: } catch (InterruptedException e) {
111: // cancelled
112: }
113: }
114: }
|