Eclipse RCP GEF开发学习笔记

本文档总结了Eclipse RCP开发过程中遇到的各种问题及其解决方案,包括但不限于编辑器工具栏创建、图形编辑、属性页定制、项目资源视图显示等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自己的个人笔记公享共享出来希望对大家有帮助

1. DiagramEditorInput  中 getName() 、getToolTipText()方法返回值不能为空

2.IPropertySource 接口需要引用plug-ins :org.eclipse.ui.views 

3. 第六回连接线问题时,LineConnectionEditPart 方法需要安装 
installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE,new   CustomConnectionEndpointEditPolicy());

4.图片及资源文件注意plugin.xml-> build ->  图片文件夹要选中

5.RCP使用product 导出时,发现欢迎页面没有了。原因gef.product ->Splash -> plug-in 需要选中当前插件

6. 绘图中右击菜单实现
  (1) CustomContextMenuProvider extends ContextMenuProvider
  (2)  /*** 右击菜单 ***/
  CustomContextMenuProvider contextMenuProvider = new CustomContextMenuProvider(viewer, getActionRegistry());
  viewer.setContextMenu(contextMenuProvider);
  this.getSite().registerContextMenu(contextMenuProvider, viewer );
      /*** 右击菜单 ***/

7.编辑器工具栏的创建(主要指save \saveAs 等 undo 已经被封装)
DiagramActionBarContributor.buildActions() 方法
RetargetAction saveRetargetAction = new RetargetAction(ActionFactory.SAVE.getId(), "Save");    saveRetargetAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID,IImageKeys.IMG_SAVE));    saveRetargetAction.setDisabledImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID,IImageKeys.IMG_SAVE_DISABLE));
DiagramActionBarContributor.contributeToToolBar() 方法
toolBarManager.add(getAction(ActionFactory.SAVE.getId()));//保存


8. 普通连线,如果为圆形(Ellipse)时需要换成锚点连接( EllipseAnchor )
    修改代码:HelloEditorPart中对应return new ChopboxAnchor(getFigure()); 修改为return new EllipseAnchor(getFigure()); 


9. 属性扩展问题Model中 getPropertyDescriptors方法
TextPropertyDescriptor 中的ID 一定不能重复

10 RCP PropertySheetPage设置属性排序功能

11.  BasicNewProjectResourceWizard 新建工程向导需要导入org.eclipse.ui.ide 否则会提示包不存在

12. 主窗口标准设置配置项,如果代码中也设置了它会优先代码中设置值(ApplicationWorkbenchWindowAdvisor)
   <extension    id="product"   point="org.eclipse.core.runtime.products"> 
      <product    application="gef.demo1.application"      name="%c4isr.application.title">


13 布局问题(Perspective.createInitialLayout)
左(上下) 右 结构布局
  IFolderLayout LeftFolder =  layout.createFolder("LeftFolder",IPageLayout.LEFT, 0.2f, editorArea);
  IFolderLayout rightBottomFolder= layout.createFolder("RightBottom",IPageLayout.BOTTOM,0.5f,editorArea);
  rightBottomFolder.addView(properties);
  LeftFolder.addView(IPageLayout.ID_PROJECT_EXPLORER);
  IFolderLayout LeftBottom = layout.createFolder("LeftBottom",IPageLayout.BOTTOM, 0.5f, "LeftFolder");
  LeftBottom.addView(outline);
注意使用   layout.createFolder("LeftBottom",IPageLayout.BOTTOM, 0.5f, "LeftFolder");就不会有空窗体,
如果两个view 都指定到LeftFolder 就会存在一个空窗体(比较奇葩的写法)



14.新建Action (即打开选择向导)
private IWorkbenchAction newAction;
newAction = ActionFactory.NEW.create(window);
register(newAction); 

15 项目资源视图 RCP运行时无法增加子级文件夹及文件 解决办法
ApplicationWorkbenchAdvisor.createWorkbenchWindowAdvisor 增加该方法
WorkbenchAdapterBuilder.registerAdapters();
http://www.blogjava.net/USTCEric/archive/2006/01/08/27141.html  (工程图标无法显示可以参考该文章)

16  项目资源视图 RCP导出时无法正常显示 
错误如下: descriptor not found: org.eclipse.ui.navigator.ProjectExplorer
解决办法:增加依赖 org.eclipse.ui.navigator;org.eclipse.ui.navigator.resources;
*****************************************************************************************


17 连线带文本
 PolylineConnection connection = new PolylineConnection();
  Label label = new Label("Label");
  connection.add(label, new MidpointLocator(connection,0));
   label.setOpaque(true);

18 RCP工程注意备份zip文件不要放在工程同级目录,会出现引导页面无法显示或报错。


19 多选项卡属性页
   需要引起包: org.eclipse.ui.views.properties.tabbed

20  工程项目在project Exlporer View 中不会显示问题解决ApplicationWorkbenchAdvisor重写 getDefaultPageInput()
 @Override
 public IAdaptable getDefaultPageInput() {
    return ResourcesPlugin.getWorkspace().getRoot();//核心代码
 }

21 draw2d Color 实例注意
Color color = new Color(null, rgb.red,rgb.green,rgb.blue); //只能将此参数处理new Color(null,rgb);会报空异常错误,又一个神奇的问题


22  *.product 文件配置生效问题,经过验证修改product 后需要export 才生更新到plugin.xml文件中对应位置。


23 rcp 国际化处理新版本eclipse 存在差异需要设置 MANIFEST.MF 中 Bundle-Localization: bundle/message
   bundle 为文件夹message 为资源文件名  
24 !MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
    即工程没有正常保存问题解决办法 ApplicationWorkbenchAdvisor 类中实现以下该方法
 @Override
 public IAdaptable getDefaultPageInput() {
  // TODO Auto-generated method stub
  return ResourcesPlugin.getWorkspace().getRoot();
 }


25   GraphicalEditorWithFlyoutPalette 工具栏左边位置实现
 @Override
 protected FlyoutPreferences getPalettePreferences() {
  final FlyoutPreferences prefs = super.getPalettePreferences();
  prefs.setPaletteState(FlyoutPaletteComposite.STATE_PINNED_OPEN);
  prefs.setDockLocation(PositionConstants.WEST);
  prefs.setPaletteWidth(180);
  return prefs;
 }


26 CreateConnectionCommand 要注意这两个方法的实现代码 
 public void setSource(LabelModel source) {
  this.source = source;
  this.connection.setSource(source);
 }
 public void setTarget(LabelModel target) {
   this.target = target;
   this.connection.setTarget(target);
 }

27 子父级实现关键代码部分 Tablepart
installEditPolicy(EditPolicy.LAYOUT_ROLE, new TableLayoutEditPolicy());
  installEditPolicy(EditPolicy.CONTAINER_ROLE, new TableContainerEditPolicy());

/**
  *返回子集
  */
 @Override
 protected List getModelChildren() {  
  List lst = this.getModel(TableModel.class).getChildrens();
  return lst;
 }
 
 /**
  * 从该方法的figure 中增加子集
  */
 @Override
 public IFigure getContentPane()
 {
  TableFigure figure = (TableFigure) getFigure();
  return figure.getColumnCompartmentFigure();
 }


28 无限子集控件问题注意,以下两个策略不可以同时实现addcommand否则会出现重复增加错误
installEditPolicy(EditPolicy.CONTAINER_ROLE, null);
installEditPolicy(EditPolicy.LAYOUT_ROLE, new CustomXYLayoutEditPolicy());  

29 Editor 保存生效,关键代码
 @Override
 public boolean isDirty() {
  return getCommandStack().isDirty();// 返回true 时在文档前面加一个*表示dirty  
 }
 public void commandStackChanged(EventObject event) {
  firePropertyChange(IEditorPart.PROP_DIRTY);
  super.commandStackChanged(event);
 }

30 透视图位置修改两种方式
//配置方式  plugin_customization.ini
//org.eclipse.ui./SHOW_TRADITIONAL_STYLE_TABS = false
//org.eclipse.ui/DOCK_PERSPECTIVE_BAR=TOP_RIGHT 
//代码方式 ApplicationWorkbenchWindowAdvisor.preWindowOpen 
PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, false);          PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR,IWorkbenchPreferenceConstants.TOP_RIGHT); 


31  防止连线相互覆盖RootPart.refreshVisuals 方法中加入下面代码
  ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
  AutomaticRouter router = new FanRouter();
  router.setNextRouter(new BendpointConnectionRouter());
  cLayer.setConnectionRouter(router);

32 获取工程信息文件结构问题,如果当前项目没有project explorer打开过来文件时,IProject 会有文件不存在现象,
     需要使用create(null)重新构建
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      IProject project = root.getProject(projectName);  
      if(!project.exists()){  
                try {
                 project.create(null); //关键代码,
                 project.open(null);  
       } catch (Exception e1) {
        e1.printStackTrace();
       }  
            }
 IFolder srcFolder = project.getFolder(viewName);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路西法01

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值