在Eclipse 中,每选中一个文件,底部的状态栏上都会显示出该文件的有关信息。客户端软件通常都会将一些全局的或当前的信息显示在底部的状态栏上。本文将在RCP中添加状态栏功能。
首先,必须在WorkbenchWindowAdvisor. preWindowOpen()启用状态栏功能,configurer.setShowStatusLine(true);
<style type="text/css"> <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--> </style> <!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
ApplicationWorkbenchWindowAdvisor.java
|
01publicvoidpreWindowOpen(){ 02IWorkbenchWindowConfigurerconfigurer=getWindowConfigurer(); 03configurer.setInitialSize(newPoint(600,400)); 04configurer.setShowCoolBar(true); 05configurer.setShowStatusLine(true); 06configurer.setShowFastViewBars(true); 07configurer.setShowPerspectiveBar(true); 08configurer.setShowMenuBar(true); 09configurer.setShowProgressIndicator(true); 10configurer.setShowStatusLine(true); 11PlatformUI.getPreferenceStore().setDefault( 12IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS,true); 13PlatformUI.getPreferenceStore().setDefault( 14IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, 15false); 16PlatformUI.getPreferenceStore().setDefault( 17IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR, 18IWorkbenchPreferenceConstants.TOP_RIGHT); 19} |
和menu bar和 toolbar一样,状态栏也是由ActionBarAdvisor控制,在ActionBarAdvisor.fillStatusLine (IStatusLineManager)中,状态栏信息的显示都由IStatusLineManager控制。
状态栏的结构
Fast views 可以将View拖到Fast views中,提供View的快捷访问。
Icon/message 这里可以显示图标和信息
Progress 用来显示进度条,通常是不可见的。当有IWorkbenchWindow.run() 调用时,显示一个进度条和一个取消按钮。
Contributions 由来显示一些额外信息,例如Eclipse选中一个java editor时,底部的读写状态,行数等信息。
Jobs progress 用来显示执行的Job,默认是不现实。要启用此功能,要设置IWorkbenchWindowConfigurator.setShowProgressIndicator(boolean).
一般Icon/message已经可以满足显示信息的要求,如果想要添加,可以在ActionBarAdvisor.fillStatusLine (IStatusLineManager)执行IStatusLineManager.add(IContributionItem).
在View中使用StatusLine,当选中某个节点时,在状态栏显示节点信息。
为View中的TreeViewer添加监听选择事件:
<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><style type="text/css"> <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--> </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
1viewer.addSelectionChangedListener(newISelectionChangedListener(){ 2publicvoidselectionChanged(SelectionChangedEventevent){ 3updateStatusline(event); 4} 5}); |
<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><style type="text/css"> <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--> </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
01protectedvoidupdateStatusline(SelectionChangedEventevent){ 02IStatusLineManagerstatusline=this.getViewSite().getActionBars() 03.getStatusLineManager(); 04IStructuredSelectionselection=(IStructuredSelection)event 05.getSelection(); 06Stringmsg=getSelectionMessage(selection); 07 08statusline.setMessage(msg); 09} 10 11privateStringgetSelectionMessage(IStructuredSelectionselection){ 12if(selection.isEmpty()){ 13return""; 14} 15if(selection.size()==1){ 16returnselection.getFirstElement().toString(); 17} 18returnselection.size()+"itemsselected"; 19} |
å¨Viewä¸ä½¿ç¨StatusLine,å½è¾å¥ä¸åæ³æ¶ï¼æ¾ç¤ºåºéä¿¡æ¯ã
<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><style type="text/css"> <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--> </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
1protectedvoidinputChagned(){ 2if(groupName.getText().length()==0){ 3showErrorOnStatusline("Groupnamecannotbeblank"); 4return; 5} 6showErrorOnStatusline(null); 7setDirty(true); 8} |
<!-- = END of automatically generated HTML code = --><!-- ======================================================== --><!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><style type="text/css"> <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--> </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
1protectedvoidshowErrorOnStatusline(Stringerror){ 2IStatusLineManagerstatusline=this.getEditorSite().getActionBars() 3.getStatusLineManager(); 4if(error==null){ 5statusline.setErrorMessage(null,error); 6}else{ 7statusline.setErrorMessage(ImageShop.get("error"),error); 8} 9} |
<!-- = END of automatically generated HTML code = --><!-- ======================================================== -->