<commit_before>package org.jboss.reddeer.swt.lookup;

import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPartReference;
import org.jboss.reddeer.swt.util.Display;
import org.jboss.reddeer.swt.util.ResultRunnable;

/**
 * Workbench lookup class. Provides access to active workbench 
 * or active view reference
 * 
 * @author jjankovi
 *
 */
@SuppressWarnings("restriction")
public class WorkbenchLookup {

	/**
	 * Returns active workbench window
	 * @return active workbench window
	 */
	public static IWorkbenchWindow activeWorkbenchWindow() {
		return Display.syncExec(new ResultRunnable<IWorkbenchWindow>() {
			public IWorkbenchWindow run() {
				return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
			}
		});
	}
	
	/**
	 * Returns active workbench part reference from current active workbench window
	 * @return active workbench part reference
	 */
	public static IWorkbenchPartReference findActiveWorkbenchPart() {
		return Display.syncExec(new ResultRunnable<IWorkbenchPartReference>() {
			@Override
			public IWorkbenchPartReference run() {
				return activeWorkbenchWindow().getActivePage().getActivePartReference();
			}
		});
	}
	
	/**
	 * Returns all active views references 
	 * @return all active views references
	 */
	public static IViewReference[] findAllViews() {
		return Display.syncExec(new ResultRunnable<IViewReference[]>() {
			@Override
			public IViewReference[] run() {
				return activeWorkbenchWindow().getActivePage().getViewReferences();
			}
		});
	}
	
	/**
	 * Returns all active editor references
	 * @return all active editor references
	 */
	public static IEditorReference[] findAllEditors() {
		return Display.syncExec(new ResultRunnable<IEditorReference[]>() {
			@Override
			public IEditorReference[] run() {
				return activeWorkbenchWindow().getActivePage().getEditorReferences();
			}
		});
	}
	
	
	/**
	 * Returns active view reference from current active workbench window
	 * @return active view reference
	 */
	public static IViewReference findActiveView() {
		return Display.syncExec(new ResultRunnable<IViewReference>() {
			public IViewReference run() {
				return findActiveViewInternal();
			}
		});
	}
	
	/**
	 * Returns active editor reference from current active workbench window
	 * @return active editor reference
	 */
	public static IEditorReference findActiveEditor() {
		return Display.syncExec(new ResultRunnable<IEditorReference>() {
			public IEditorReference run() {
				return findActiveEditorInternal();
			}
		});
	}
	
	/**
	 * Return control object associated to active workbench
	 * @param activeWorkbenchReference
	 * @return
	 */
	public static Control getWorkbenchControl(
			final IWorkbenchPartReference activeWorkbenchReference) {
		return Display.syncExec(new ResultRunnable<Control>() {

			@Override
			public Control run() {
				return ((WorkbenchPartReference)activeWorkbenchReference)
						.getPane()
						.getControl();
			}
		});
	}

	private static IViewReference findActiveViewInternal() {
		IWorkbenchPartReference activeWorkbenchPart = findActiveWorkbenchPart(); 
		if (activeWorkbenchPart instanceof IViewReference) {
			return (IViewReference)activeWorkbenchPart;
		}
		return null;
	}
	
	private static IEditorReference findActiveEditorInternal() {
		IWorkbenchPartReference activeWorkbenchPart = findActiveWorkbenchPart(); 
		if (activeWorkbenchPart instanceof IEditorReference) {
			return (IEditorReference)activeWorkbenchPart;
		}
		return null;
	}
	
}<commit_msg>Deprecate WorkbenchLookup in swt plugin #898<commit_after>package org.jboss.reddeer.swt.lookup;

import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPartReference;
import org.jboss.reddeer.swt.util.Display;
import org.jboss.reddeer.swt.util.ResultRunnable;

/**
 * Workbench lookup class. Provides access to active workbench 
 * or active view reference
 * @deprecated use {@link org.jboss.reddeer.workbench.lookup.WorkbenchPartLookup}
 * @author jjankovi
 *
 */
@Deprecated
public class WorkbenchLookup {

	/**
	 * Returns active workbench window
	 * @return active workbench window
	 */
	public static IWorkbenchWindow activeWorkbenchWindow() {
		return Display.syncExec(new ResultRunnable<IWorkbenchWindow>() {
			public IWorkbenchWindow run() {
				return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
			}
		});
	}
	
	/**
	 * Returns active workbench part reference from current active workbench window
	 * @return active workbench part reference
	 */
	public static IWorkbenchPartReference findActiveWorkbenchPart() {
		return Display.syncExec(new ResultRunnable<IWorkbenchPartReference>() {
			@Override
			public IWorkbenchPartReference run() {
				return activeWorkbenchWindow().getActivePage().getActivePartReference();
			}
		});
	}
	
	/**
	 * Returns all active views references 
	 * @return all active views references
	 */
	public static IViewReference[] findAllViews() {
		return Display.syncExec(new ResultRunnable<IViewReference[]>() {
			@Override
			public IViewReference[] run() {
				return activeWorkbenchWindow().getActivePage().getViewReferences();
			}
		});
	}
	
	/**
	 * Returns all active editor references
	 * @return all active editor references
	 */
	public static IEditorReference[] findAllEditors() {
		return Display.syncExec(new ResultRunnable<IEditorReference[]>() {
			@Override
			public IEditorReference[] run() {
				return activeWorkbenchWindow().getActivePage().getEditorReferences();
			}
		});
	}
	
	
	/**
	 * Returns active view reference from current active workbench window
	 * @return active view reference
	 */
	public static IViewReference findActiveView() {
		return Display.syncExec(new ResultRunnable<IViewReference>() {
			public IViewReference run() {
				return findActiveViewInternal();
			}
		});
	}
	
	/**
	 * Returns active editor reference from current active workbench window
	 * @return active editor reference
	 */
	public static IEditorReference findActiveEditor() {
		return Display.syncExec(new ResultRunnable<IEditorReference>() {
			public IEditorReference run() {
				return findActiveEditorInternal();
			}
		});
	}
	
	/**
	 * Return control object associated to active workbench
	 * @param activeWorkbenchReference
	 * @return
	 */
	public static Control getWorkbenchControl(
			final IWorkbenchPartReference activeWorkbenchReference) {
		return Display.syncExec(new ResultRunnable<Control>() {

			@Override
			public Control run() {
				return ((WorkbenchPartReference)activeWorkbenchReference)
						.getPane()
						.getControl();
			}
		});
	}

	private static IViewReference findActiveViewInternal() {
		IWorkbenchPartReference activeWorkbenchPart = findActiveWorkbenchPart(); 
		if (activeWorkbenchPart instanceof IViewReference) {
			return (IViewReference)activeWorkbenchPart;
		}
		return null;
	}
	
	private static IEditorReference findActiveEditorInternal() {
		IWorkbenchPartReference activeWorkbenchPart = findActiveWorkbenchPart(); 
		if (activeWorkbenchPart instanceof IEditorReference) {
			return (IEditorReference)activeWorkbenchPart;
		}
		return null;
	}
	
}
{'fraction_non_alphanumeric': 0.0948690539818279, 'fraction_numerical': 0.00040085515766969537, 'mean_word_length': 4.69634703196347, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6206436', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2022, 'n_words': 489}