/*******************************************************************************
 * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Markus Schorn - initial API and implementation
 *    IBM Corporation
 *******************************************************************************/ 

/* -- ST-Origin --
 * Source folder: org.eclipse.cdt.ui/src
 * Class: org.eclipse.cdt.internal.ui.includebrowser.IBSetInputJob
 * Version: 1.3
 */

package org.eclipse.ptp.internal.rdt.ui.includebrowser;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.includebrowser.IBMessages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.widgets.Display;

public class IBSetInputJob extends Job {

	private ITranslationUnit fInput;
	private Display fDisplay;
	private IBViewPart fViewPart;


	public IBSetInputJob(IBViewPart viewPart, Display disp) {
		super(IBMessages.IBViewPart_waitingOnIndexerMessage);
		setSystem(true);
		fViewPart= viewPart;
		fDisplay= disp;
	}
	
	@Override
	protected IStatus run(IProgressMonitor monitor) {
    	if (CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, monitor)) {
    		try {
				fDisplay.asyncExec(new Runnable() {
					public void run() {
						fViewPart.setInput(fInput);
					}
				});
			} catch (SWTException e) {
				// display may be disposed
			}
		}
    	return Status.OK_STATUS;
	}

	public void setInput(ITranslationUnit input) {
		fInput= input;
	}
}
