GEF开发eclipse插件,多页编辑器实现delete功能

本文介绍基于GEF开发的多页签编辑器两种实现方案,并详细讲解了第一种方案的具体步骤,包括自定义编辑器类、重载方法等关键技术点。
基于GEF开发,多页签编辑器实现

有两种方案:

  • 方案一
    继承FormEditor或MultiPageEditorPart,在其中嵌入自定义的继承自GraphicalEditor的子类的编辑器(作为一个page);并加入其它page。
  • 方案二
    -继承GraphicalEditor的子类,参照MultiPageEditorPart的实现(或者自己做)加入多页签机制。

由于感觉第二种方案工作量稍大,采用第一种方案。具体步骤如下:

  • 自定义继承自GraphicalEditorWithPalette的类WebEditor,具体做法略(网上有文)。
  • 定义继承FormEditor的类WebMultiPageEditor
    重载addPages()方法,在其中调用public int addPage(IEditorPart editor, IEditorInput input)方法添加WebEditor的实例:addPage(new WebEditor(), getEditorInput())
    添加其他编辑器。。。
  • 在改成多页编辑器之前,已经在WebEditor中重载了doSave方法。在WebMultiPageEditor中重载doSave方法,在其中传递调用((WebEditor)getEditor(0)).doSave(monitor)。
  • 在做了以上工作以后运行,已经看到一个多页编辑器了。但是,发现Delete功能却不能用。花费一番功夫才找到原因。还有一重要步骤要做:在WebEditor类中重载selectionChanged方法。我们来看看WebEditor的父类(或者更上层)GraphicalEditor中此方法的实现:
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
 // If not the active editor, ignore selection changed.
 if (this.equals(getSite().getPage().getActiveEditor()))
  updateActions(selectionActions);
}

selectionChanged事件发生时,此方法if语句条件为false。
因此要重载此方法,如下:

public void selectionChanged(IWorkbenchPart part, ISelection selection) {
  // 此处依赖WebUiEditor编辑器.
  if (this.equals(((WebMultiPageEditor)getSite().getPage().getActiveEditor()).getActiveEditor()))
   updateActions(getSelectionActions());
 }

注意 需要在多页编辑器中重写父类的getActiveEditor()方法,或者自己写方法将需要delete的Editor返回即可。

转载于:https://www.cnblogs.com/zhjj/p/6622415.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值