GEF中文教程笔记1

这是GEF中文教程第一章总结,当然也参考了别人的自学笔记,写完之后我能更好的理解整个开发过程和相关技术点
1.创建一个plug-in project, 名称为gef, Dependencies加上org.eclipse.gef和org.eclipse.ui.views
2.创建一个Editor, 名称为FlowEditor, 继承GraphicalEditor
Editor系列类的继承关系如下:
org.eclipse.ui.part.WorkbenchPart 所有workbench part的抽象基类,包含ViewPart和EditorPart。
-org.eclipse.ui.part.EditorPart 所有workbench editor的抽象基类,Eclipse项目中的Editor都派生于它。
--org.eclipse.gef.ui.parts.GraphicalEditor GEF提供的editor的抽象基类,它包含一个GraphicalViewer控件。
---org.eclipse.gef.ui.parts.GraphicalEditorWithPalette 提供带Palette的Editor,它包含一个PaletteViewer控件和一个GraphicalViewer控件。
---org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette 提供的是flyout palette。
3.创建一个EditorInput, 名称为HelloEditorInput。每个Editor都需要有EditorInput作为起内容的提供者
4.Extensions添加org.eclipse.ui.editors, id为com.openstudy.gef.ui.FlowEditor, name为Flow, class为com.openstudy.gef.ui.FlowEditor
5.新建模型HelloModel, 普通的JavaBean, 只有一个Field, private String text = "Hello World";
6.创建一个EditPart, 名称为HelloEditPart, 继承AbstractGraphicalEditPart
protected IFigure createFigure() {
HelloModel model = (HelloModel) getModel();
Label label = new Label(); // 是org.eclipse.draw2d.Label
label.setText(model.getText());
return label;
}
7.创建一个EditPartFactory, 名称为HelloEditPartFactory
public EditPart createEditPart(EditPart arg0, Object model) {
EditPart part = getPartForElement(model);
// 通过setModel()方法连接模型与控制器。这样从EditPart就可以通过getModel()方法取得对应的模型。
part.setModel(model);
return part;
}

private EditPart getPartForElement(Object modelElement) {
// 根据模型类型创建控制器,每种模型对应一种控制器。
if (modelElement instanceof HelloModel)
return new HelloEditPart();
throw new RuntimeException("Can't create part for model element: "
+ ((modelElement != null) ? modelElement.getClass().getName(): "null"));
}
8.在editor中创建视图, 编辑FlowEditor类,修改initializeGraphicalViewer和configureGraphicalViewer两个方法
@Override
protected void initializeGraphicalViewer() {
getGraphicalViewer().setContents(new HelloModel());
}

@Override
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();

getGraphicalViewer().setEditPartFactory(new HelloEditPartFactory());
}
9.创建一个FlowAction, 用来打开FlowEditor,主要内容为
IEditorInput input = new HelloEditorInput(new Path(path));
IWorkbenchPage page = window.getActivePage();
try {
page.openEditor(input, FlowEditor.ID, true);
} catch (PartInitException e) {
// handle error
}
10.修改ApplicationActionBarAdvisor,将FlowAction添加到菜单中.
11.修改ApplicationWorkbenchWindowAdvisor,改为在RCP启动后就自动打开一个FlowEditor
this.getWindowConfigurer().getWindow().getShell().setMaximized(true);
IEditorInput input = new HelloEditorInput();
IWorkbenchPage page = this.getWindowConfigurer().getWindow().getActivePage();
try {
page.openEditor(input, FlowEditor.ID, true);
} catch (PartInitException e) {
e.printStackTrace();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值