(转载)RCP的一些细节部分

Posted on 2008-07-13 10:07 Li Ya Qiang 阅读(536) 评论(0)  编辑  收藏 所属分类: Eclipse RCP
来自http://cary.javaeye.com/blog/32419

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); //BundleUtility类在ui里,非UI的没法用

还有其它方法:URL fileURL = FileLocator.find(bundle, new Path("some file relative path"), null);


得到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]);
}


只有注册用户登录后才能发表评论。


网站导航:
 

posts - 10, comments - 0, trackbacks - 0, articles - 2

Copyright © Li Ya Qiang