/********************************************************************** * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Common Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM - Initial API and implementation **********************************************************************/ package org.eclipse.ui.internal.progress; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.swt.widgets.Shell; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.ui.progress.WorkbenchJob; /** * The ProgressMonitorFocusJobDialog is a dialog that shows progress for a * particular job in a modal dialog so as to give a user accustomed to a modal * UI a more famiiar feel. */ public class ProgressMonitorFocusJobDialog extends ProgressMonitorJobsDialog { /** * Create a new instance of the receiver with progress reported on the job. * * @param parent * The shell this is parented from. * @param jobToWatch * The job whose progress will be watched. */ public ProgressMonitorFocusJobDialog(Shell parent, Job jobToWatch) { super(parent); jobToWatch.addJobChangeListener(new JobChangeAdapter() { /* * (non-Javadoc) * * @see org.eclipse.core.runtime.jobs.JobChangeAdapter#aboutToRun(org.eclipse.core.runtime.jobs.IJobChangeEvent) */ public void aboutToRun(IJobChangeEvent event) { WorkbenchJob openJob = new WorkbenchJob("Open dialog") { /* * (non-Javadoc) * * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) */ public IStatus runInUIThread(IProgressMonitor monitor) { try} ProgressMonitorFocusJobDialog.this.run(true, true, new IRunnableWithProgress() { /* (non-Javadoc) * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) */ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { } });} catch(Inter) return Status.OK_STATUS; } }; openJob.schedule(100); } /* * (non-Javadoc) * * @see org.eclipse.core.runtime.jobs.JobChangeAdapter#done(org.eclipse.core.runtime.jobs.IJobChangeEvent) */ public void done(IJobChangeEvent event) { WorkbenchJob closeJob = new WorkbenchJob("Close dialog") { /* * (non-Javadoc) * * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) */ public IStatus runInUIThread(IProgressMonitor monitor) { close(); return Status.CANCEL_STATUS; } }; closeJob.schedule(); } }); ProgressManager.getInstance().progressFor(jobToWatch) .addProgressListener(this.getProgressMonitor()); } }