本文整理汇总了Java中org.eclipse.ui.handlers.HandlerUtil.getActiveSite方法的典型用法代码示例。如果您正苦于以下问题:Java HandlerUtil.getActiveSite方法的具体用法?Java HandlerUtil.getActiveSite怎么用?Java HandlerUtil.getActiveSite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ui.handlers.HandlerUtil
的用法示例。
在下文中一共展示了HandlerUtil.getActiveSite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
final ICommandService cs = (ICommandService) site
.getService(ICommandService.class);
final IHandlerService hs = (IHandlerService) site
.getService(IHandlerService.class);
final Command command = cs
.getCommand(IWorkbenchCommandConstants.FILE_IMPORT);
try {
hs.executeCommand(ParameterizedCommand.generateCommand(command,
Collections.singletonMap(
IWorkbenchCommandConstants.FILE_IMPORT_PARM_WIZARDID,
SessionImportWizard.ID)),
null);
} catch (CommandException e) {
EclEmmaUIPlugin.log(e);
}
return null;
}
示例2: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
final ICommandService cs = (ICommandService) site
.getService(ICommandService.class);
final IHandlerService hs = (IHandlerService) site
.getService(IHandlerService.class);
final Command command = cs
.getCommand(IWorkbenchCommandConstants.FILE_EXPORT);
try {
hs.executeCommand(ParameterizedCommand.generateCommand(command,
Collections.singletonMap(
IWorkbenchCommandConstants.FILE_EXPORT_PARM_WIZARDID,
SessionExportWizard.ID)),
null);
} catch (CommandException e) {
EclEmmaUIPlugin.log(e);
}
return null;
}
示例3: getService
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
/**
* Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
* locations (if exist) in the given order:
*
* {@code HandlerUtil.getActiveSite(event)}
* {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
* {@code HandlerUtil.getActiveEditor(event).getSite()}
* {@code HandlerUtil.getActiveWorkbenchWindow(event)}
* {@code PlatformUI.getWorkbench()}
*/
public static <T> T getService(ExecutionEvent event, Class<T> api) {
IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
if (activeSite != null) {
return activeSite.getService(api);
}
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor != null) {
IEditorSite editorSite = activeEditor.getEditorSite();
if (editorSite != null) {
return editorSite.getService(api);
}
IWorkbenchPartSite site = activeEditor.getSite();
if (site != null) {
return site.getService(api);
}
}
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
if (workbenchWindow != null) {
return workbenchWindow.getService(api);
}
return PlatformUI.getWorkbench().getService(api);
}