1 11 12 package org.eclipse.ui.internal; 13 14 import java.util.Collection ; 15 16 import org.eclipse.core.expressions.IEvaluationContext; 17 import org.eclipse.jface.viewers.ISelection; 18 import org.eclipse.swt.widgets.Shell; 19 import org.eclipse.ui.IEditorPart; 20 import org.eclipse.ui.ISources; 21 import org.eclipse.ui.IWorkbenchPart; 22 import org.eclipse.ui.IWorkbenchSite; 23 import org.eclipse.ui.IWorkbenchWindow; 24 25 40 public class InternalHandlerUtil { 41 51 public static Object getVariable(Object appContext, String name) { 52 if (appContext instanceof IEvaluationContext) { 53 return ((IEvaluationContext) appContext).getVariable(name); 54 } 55 return null; 56 } 57 58 65 public static Collection getActiveContexts(Object appContext) { 66 Object o = getVariable(appContext, ISources.ACTIVE_CONTEXT_NAME); 67 if (o instanceof Collection ) { 68 return (Collection ) o; 69 } 70 return null; 71 } 72 73 81 public static Shell getActiveShell(Object appContext) { 82 Object o = getVariable(appContext, ISources.ACTIVE_SHELL_NAME); 83 if (o instanceof Shell) { 84 return (Shell) o; 85 } 86 return null; 87 } 88 89 96 public static IWorkbenchWindow getActiveWorkbenchWindow(Object appContext) { 97 Object o = getVariable(appContext, 98 ISources.ACTIVE_WORKBENCH_WINDOW_NAME); 99 if (o instanceof IWorkbenchWindow) { 100 return (IWorkbenchWindow) o; 101 } 102 return null; 103 } 104 105 112 public static IEditorPart getActiveEditor(Object appContext) { 113 Object o = getVariable(appContext, ISources.ACTIVE_EDITOR_NAME); 114 if (o instanceof IEditorPart) { 115 return (IEditorPart) o; 116 } 117 return null; 118 } 119 120 127 public static String getActiveEditorId(Object appContext) { 128 Object o = getVariable(appContext, ISources.ACTIVE_EDITOR_ID_NAME); 129 if (o instanceof String ) { 130 return (String ) o; 131 } 132 return null; 133 } 134 135 142 public static IWorkbenchPart getActivePart(Object appContext) { 143 Object o = getVariable(appContext, ISources.ACTIVE_PART_NAME); 144 if (o instanceof IWorkbenchPart) { 145 return (IWorkbenchPart) o; 146 } 147 return null; 148 } 149 150 157 public static String getActivePartId(Object appContext) { 158 Object o = getVariable(appContext, ISources.ACTIVE_PART_ID_NAME); 159 if (o instanceof String ) { 160 return (String ) o; 161 } 162 return null; 163 } 164 165 172 public static IWorkbenchSite getActiveSite(Object appContext) { 173 Object o = getVariable(appContext, ISources.ACTIVE_SITE_NAME); 174 if (o instanceof IWorkbenchSite) { 175 return (IWorkbenchSite) o; 176 } 177 return null; 178 } 179 180 187 public static ISelection getCurrentSelection(Object appContext) { 188 Object o = getVariable(appContext, 189 ISources.ACTIVE_CURRENT_SELECTION_NAME); 190 if (o instanceof ISelection) { 191 return (ISelection) o; 192 } 193 return null; 194 } 195 } 196 | Popular Tags |