All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.ui.internal.InternalHandlerUtil Maven / Gradle / Ivy

Go to download

This plug-in contains the bulk of the Workbench implementation, and depends on JFace, SWT, and Core Runtime. It cannot be used independently from org.eclipse.ui. Workbench client plug-ins should not depend directly on this plug-in.

The newest version!
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.ui.internal;

import java.util.Collection;

import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.IWorkbenchWindow;

/**
 * Some common utilities for working with handlers and IEvaluationContexts in
 * Platform UI.
 * 

* Note: this class should not be instantiated or extended by clients. *

*

* PROVISIONAL. This class or interface has been added as part * of a work in progress. There is a guarantee neither that this API will work * nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. *

* * @since 3.3 */ public class InternalHandlerUtil { /** * Extract the variable. * * @param appContext * The application context * @param name * The variable name to extract. * @return The object from the application context, or null * if it could not be found. */ public static Object getVariable(Object appContext, String name) { if (appContext instanceof IEvaluationContext) { return ((IEvaluationContext) appContext).getVariable(name); } return null; } /** * Return the active contexts. * * @param appContext * The execution appContext that contains the application context * @return a collection of String contextIds, or null. */ public static Collection getActiveContexts(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_CONTEXT_NAME); if (o instanceof Collection) { return (Collection) o; } return null; } /** * Return the active shell. Is not necessarily the active workbench window * shell. * * @param appContext * The execution appContext that contains the application context * @return the active shell, or null. */ public static Shell getActiveShell(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_SHELL_NAME); if (o instanceof Shell) { return (Shell) o; } return null; } /** * Return the active workbench window. * * @param appContext * The execution appContext that contains the application context * @return the active workbench window, or null. */ public static IWorkbenchWindow getActiveWorkbenchWindow(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_WORKBENCH_WINDOW_NAME); if (o instanceof IWorkbenchWindow) { return (IWorkbenchWindow) o; } return null; } /** * Return the active editor. * * @param appContext * The execution appContext that contains the application context * @return the active editor, or null. */ public static IEditorPart getActiveEditor(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_EDITOR_NAME); if (o instanceof IEditorPart) { return (IEditorPart) o; } return null; } /** * Return the part id of the active editor. * * @param appContext * The execution appContext that contains the application context * @return the part id of the active editor, or null. */ public static String getActiveEditorId(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_EDITOR_ID_NAME); if (o instanceof String) { return (String) o; } return null; } /** * Return the active part. * * @param appContext * The execution appContext that contains the application context * @return the active part, or null. */ public static IWorkbenchPart getActivePart(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_PART_NAME); if (o instanceof IWorkbenchPart) { return (IWorkbenchPart) o; } return null; } /** * Return the part id of the active part. * * @param appContext * The execution appContext that contains the application context * @return the part id of the active part, or null. */ public static String getActivePartId(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_PART_ID_NAME); if (o instanceof String) { return (String) o; } return null; } /** * Return the active part site. * * @param appContext * The execution appContext that contains the application context * @return the active part site, or null. */ public static IWorkbenchSite getActiveSite(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_SITE_NAME); if (o instanceof IWorkbenchSite) { return (IWorkbenchSite) o; } return null; } /** * Return the current selection. * * @param appContext * The execution appContext that contains the application context * @return the current selection, or null. */ public static ISelection getCurrentSelection(Object appContext) { Object o = getVariable(appContext, ISources.ACTIVE_CURRENT_SELECTION_NAME); if (o instanceof ISelection) { return (ISelection) o; } return null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy