首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

获取急需平台的信息

2012-10-08 
获取需要平台的信息开发rcp程序的时候,需要获取许多平台和编辑器的相关信息。/*** 获取当前活动的IWorkbenc

获取需要平台的信息

开发rcp程序的时候,需要获取许多平台和编辑器的相关信息。

/**
* 获取当前活动的IWorkbenchPage
*
* @return
*/
public static IWorkbenchPage getActivePage() {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
}

?

/**
* 获取当前活动的编辑器
*
* @return
*/
public static IEditorPart getActiveEditor() {
if (PlatformUI.getWorkbench().isStarting()) {
return null;
}
IEditorPart editorPart = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
return editorPart;
}

?

/**
* 通过编辑器获取命令栈执行命令
*
* @param command
*/
public static void excuteCommand(Command command) {
((CommandStack) getActiveEditor().getAdapter(CommandStack.class))
.execute(command);
}

?

/**
* 关闭某一个编辑器
*
* @param input
* @param save
*/
public static void closeEditor(IEditorInput input, boolean save) {
if (input != null) {
IWorkbenchPage page = getActivePage();
IEditorPart editor = page.findEditor(input);
if (editor != null) {
page.closeEditor(editor, save);
}
}
}

?

/**
* 根据视图ID打开视图
*
* @param viewId
*/
public static void showView(String viewId) {
try {
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
page.showView(viewId);
} catch (Exception e) {
e.printStackTrace();
}
}

热点排行