Eclipse RCP 学习记录

时间:2021-10-30 10:19:17

貌似RCP的资料比较少,仅有的也没发现介绍的比较详细的,现在都是东学一点西学一点,此帖简单记录一下要点

 1.RCP中怎么实现全屏显示的程序

 

ApplicationWorkbenchWindowAdvisor 类中增加以下代码
    public   void  postWindowCreate(){
        
super .postWindowCreate();
        getWindowConfigurer().getWindow().getShell().setMaximized(
true );

    } 

 2.在设置Layout为 BorderLayout时,会自动增加swing2swt.jar,但是在运行该工程时会报错,The activator ****.Activator for bundle aabb is invalid

我的解决办法是 打开plugin.xml文件,选择Runtime标签,在Classpath中将swing2swt.jar删除后再增加进来,并把swing2swt.jar  Add to Build Path

 3.增加table事件,点击某一行时改变颜色,始终没有效果出现

Eclipse RCP 学习记录Eclipse RCP 学习记录代码
table.addSelectionListener( new  SelectionAdapter(){
            
public   void  widgetSelected(SelectionEvent e){
                
int  total  =  table.getItemCount();
                
                TableItem tableItem 
=   new  TableItem(table, SWT.NONE,table.getSelectionIndex() + 1 );
                tableItem.setText(
new  String[]{ " 1 " , " 2 " , " 3 " });
                
                
for ( int  i = 0 ;i < total;i ++ ){
                    TableItem[] ii
=  table.getSelection();
                    table.getSelectionIndex();
                    table.getSelectionCount();
                    TableItem item 
=  table.getItem(i);
                    
                    
if (table.isSelected(i)){
                        item.setBackground(item.getDisplay().getSystemColor(SWT.COLOR_RED));
                        item.setForeground(item.getDisplay().getSystemColor(SWT.COLOR_GREEN));
                    }
else {
                        item.setBackground(
null );
                        item.setForeground(
null );
                    }
                }
            }
        });

 终于发现这个问题是创建TableView时选择样式FULL_SELECTION ,设置选择一行高亮的样式后,设置点击某一行时改变颜色(前景,后景色)就不起作用

但是出现新问题,只能选中第一列中的单元格 

4.表格中只能选择单元格中的文字,如何选择整个单元格 

5.在实现ITableColorProvider 接口后修改背景色之后,在TableItem中设置背景色时无效了

6.SWT/JFace的TableView为何设置行高这么麻烦,没有一个属性可以直接Set的 

table.addListener(SWT.MeasureItem,  new  Listener() {
            @Override
            
public   void  handleEvent(Event event) {
                event.height 
=   25 ;
            }
        });

 

 

7. 将首选项的"恢复"和"应用"按钮隐藏

noDefaultAndApplyButton();
setValid(
false );

 8.RCP开发中的missing required bundle

在dependencies中已经添加了所需要的插件,但是运行时出现了missing required bundle错误
在运行设置对话框的Plug-in中选择add required plug-ins,这样系统会自动加载RCP项目运行所需要的插件

9.系统Preference 首选项的调用

IWorkbenchAction preferenceAction  =  ActionFactory.PREFERENCES.create(window)

 

10.SWT中org.eclipse.core.runtime.AssertionFailedException: assertion failed

Eclipse RCP 学习记录Eclipse RCP 学习记录代码
/**  Cell Editor Row 2 * */
textEditor 
=   new  TextCellEditor(table);
((Text)textEditor.getControl()).setTextLimit(
10 );
editors[
1 =  textEditor;

org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:
111 )
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:
97 )
at org.eclipse.jface.viewers.TextCellEditor.doSetValue(TextCellEditor.java:
228 )
at org.eclipse.jface.viewers.CellEditor.setValue(CellEditor.java:
855 )
at org.eclipse.jface.viewers.EditingSupport.initializeCellEditorValue(EditingSupport.java:
96 )
at org.eclipse.jface.viewers.ColumnViewerEditor.activateCellEditor(ColumnViewerEditor.java:
194 )
at org.eclipse.jface.viewers.ColumnViewerEditor.handleEditorActivationEvent(ColumnViewerEditor.java:
443 )
at org.eclipse.jface.viewers.ColumnViewer.triggerEditorActivationEvent(ColumnViewer.java:
680 )
at org.eclipse.jface.viewers.ColumnViewer.handleMouseDown(ColumnViewer.java:
664 )
at org.eclipse.jface.viewers.ColumnViewer.access$
0 (ColumnViewer.java: 660 )
at org.eclipse.jface.viewers.ColumnViewer$
1 .mouseDown(ColumnViewer.java: 89 )
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:
179 )
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:
84 )
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:
1003 )
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:
3823 )
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:
3422 )
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:
2382 )
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:
2346 )
at org.eclipse.ui.internal.Workbench.access$
4 (Workbench.java: 2198 )
at org.eclipse.ui.internal.Workbench$
5 .run(Workbench.java: 493 )
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:
288 )
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:
488 )
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:
149 )
at com.tasc.swb.internal.application.SWBApplication.start(SWBApplication.java:
414 )
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:
193 )
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:
110 )
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:
79 )
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
382 )
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
179 )
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:
549 )
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:
504 )
at org.eclipse.equinox.launcher.Main.run(Main.java:
1236 )
at org.eclipse.equinox.launcher.Main.main(Main.java:
1212 )

 

 you have either not set the CellModifier for the TableViewer (using the setCellModifier() function)

or, if you have, then the getValue() function of your ICellModifier descendant returns either null or not a String object.
The return value of getValue() is an object, but if you are using a TextCellEditor, it has to return a String.

 11.保存工作区,以便在下次打开时恢复关闭时的状态

在ApplicationWorkbenchAdvisor 类中增加override      initialize方法

public   void  initialize(IWorkbenchConfigurer configurer) {
        configurer.setSaveAndRestore(
true );
    }

 12.固定透视图在createInitialLayout()内部调用通过layout的setFixed(true)方法,或者直接在plugin.xml文件件中添加fixed="true"属性