RCP的一些细节部分

ECLIPSE PLUG-IN RCP
此部分有的是自己的开发中的经验,有的是在论坛中看到别人的经验。我在这里把部分觉得好的部分收集,整理。希望对大家有帮助。
1:登陆对话框
public Object run(Object args) throws Exception {
Display display = PlatformUI.createDisplay();

try {
Platform.endSplash();
/**
* 登录
*/
if (!login())
return IPlatformRunnable.EXIT_OK;

logger.info("正在初始化客户端......");
//
InitUIProgress.addInfor("初始化主界面...");
int returnCode = PlatformUI.createAndRunWorkbench(display,
new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
}

return IPlatformRunnable.EXIT_OK;
} finally {
display.dispose();
}
}


2:该写actionBar 的 ActionFactory.OPEN_PERSPECTIVE_DIALOG.create(window)

IActionBarConfigurer configurer = getActionBarConfigurer();
final IWorkbenchWindow window = configurer.getWindowConfigurer().getWindow();

MenuManager perspectiveMenu = new MenuManager("Open Perspective");
IContributionItem perspectiveList = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(window);
perspectiveMenu.add(perspectiveList);
windowMenu.add(perspectiveMenu);

3:让其viewpart显示流线型
在 WorkbenchWindowAdvisor 中的preWindowOpen()中设置
//显示特效
PlatformUI.getPreferenceStore().setDefault(
IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS, true);
//不显示传统的窗口
PlatformUI.getPreferenceStore().setDefault(
IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
false);


4:可以使用action来做, 调用下面的方法:

IWorkbench.showPerspective(String perspectiveId, IWorkbenchWindow window)
or
IWorkbench.showPerspective(String perspectiveId, IWorkbenchWindow window, IAdaptable input)

IWorkbench和IWorkbenchWindow对象都可以在ViewPart中找到.

5:定义热键
getShell().getDisplay().addFilter(SWT.KeyDown, globEvent);

将plugin.xml里面hotkey
<extension
point="org.eclipse.ui.bindings">
<!--key
commandId="org.eclipse.ui.file.exit"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+X">
</key -->
</extension>

6.如何或得RCP中的一些路径问题
从插件中获得绝对路径:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());


通过文件得到Project:

IProject project = ((IFile)o).getProject();


通过文件得到全路径:

String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();


得到整个Workspace的根:

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();


从根来查找资源:

IResource resource = root.findMember(new Path(containerName));

从Bundle来查找资源:

Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, filePath);


得到Appliaction workspace:

Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();

得到runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();

从编辑器来获得编辑文件:

IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput){
IFile file = ((IFileEditorInput)input).getFile();
}

得到plugin.xml中的所以ACTION
IContributionItem[] items = getViewSite().getActionBars().getMenuManager().getItems();
for (int i = 0; i < items.length; i++) {
manager.add(items[i]);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值