2. 목 차
Eclipse GEF란?
Eclipse GEF 살펴보기
각 Part 살펴보기
Big Picture MVC
Eclipse GEF 살펴보기
Graphical Editor 만들기
실행 환경
개발순서
HelloWorld GEF RCP
EditParts
Graphical View
Editing and Edit Policies
Editpart Lifecycle
Tools and Palette
Interactions
실습
3. Eclipse GEF란?
SWT, Draw2D에 의존합니다.
Mouse, keyboard, workbench와 상호 작용 합니
다.
Model 기반으로 작동합니다.
www.eclipse.org/gef
4. 시각 기반 편집은?
모델은 어떤 데이터를 가진 객체의 구성
뷰는 화면상의 그림으로 구성
사용자는 마우스나 키보드로 모델을 편집
뷰를 통해 사용자의 명령이 내려 지거나
모델이 변경 되었을 때 뷰와 모델 사이의 어떠한
연결에 대응합니다.
5. 일반적인 시각 기반 편집 문제
모델은 화면에 어떻게 표시 될 것인지 모든 상
태 데이터를 포함 해야 합니다.
즉 뷰는 모델의 상태에 따라
어떻게 표현될지 전체가 결정될
수 있어야 합니다.
GUI 를 통한 사용자의
액션에 일어나는 모델을
수정
모델이 새로운 상태를
가짐으로 뷰를 업데이트
6. GEF 도와주는 것
에디터가 열렸을 때, 모델에 정의해 준 뷰들
이 저절로 빌드되어 표시되는 매커니즘
모델의 어떤 상태가 변경되었을 때 그와 연
결된 뷰의 특성을 업데이트 하는 매커니즘
사용자의 액션을 잡아내어 그것을 모델을
수정하는 변경 객체로 변경하는 매커니즘
7. GEF 모델
특성
모델은 편집하고자 하는 모든 데이터를 가지고
있어야 합니다.
모델은 뷰나 에디터를 구성하는 어떤 다른 요소
에 대해 아무것도 알아서 안됩니다. 참조도 안됩
니다.
모델은 변경이 일어나면 반드시 이벤트를 발신
하고 수신할 수 있어야 합니다.
java.beans.PropertyChangeListener
8. GEF 뷰
특성
뷰는 모델에 이미 저장된 데이터를 가지고 있어
서는 안됩니다. 뷰는 단지 보여주는 용도로 사용
되어야 합니다.
뷰는 모델이나 에디터를 구성하는 다른 요소에
대해 아무것도 몰라야 합니다.
Draw2D 사용
9. GEF 컨트롤러
특성
모델과 뷰를 연결을 합니다.
GEF에서 연결은 EditPart로 합니다.
하나의 모델 + 뷰 마다 EditPart가 존재 합니다.
EditPart는 모델과 뷰 를 다 알고 있으며 모델이 수
정될 때 뷰를 반영해야 하는지 알고 있습니다.
10. Eclipse GEF 살펴보기
Model : 표현하고자하는 Data.
자신의 변경을 통지받을수 있어야합니다.
java.beans.PropertyChangeListener
View : 보여주는 것.
IFigures, SWT의 Treeitem
Controller : Model과 View를 컨트롤
EditPart
11. 각 Part설명
Graphical Viewer
Outline Palette
Thumbnail
12. Graphical Editor 만들기
확장점
org.eclipse.ui.editors
Extendsion 클래스
GraphicalEditor : GEF 기본 에디터 클래스
GraphicalEditorWithPalette : 팔랫트를 포함한 에
디터 클래스
GraphicalEditorWithFlyoutPalette : 이동 가능한 팔
랫트를 포함한 에디터 클래스
15. 개발순서 2/4
1. 모델 정의
Public class HelloworldModel() {
String name;
public HellowlrldModel(String name) {
this.name = name;
}
getName()..
setName(String name)…
2. 모델을 어떻게 보여줄 컨트롤로 구현
public class HelloworldEditPart extends AbstractGraphicalEditPart {
protected IFigure createFigure () {
HelloworldModel model = (HelloworldModel) getModel ();
HelloworldFigure figure= new HelloworldFigure(model);
return figure;
}
}
16. 개발순서 3/4
Figure
public class HelloFigure extend Label {
public HelloFigure(String name) {
super(name);
}
}
17. 개발순서 4/4
3. 모델 + 뷰 연결 컨트롤러 구현
public class HelloworldEditPartFactory implements
EditPartFactory {
public EditPart createEditPart (EditPart context, Object model)
{
EditPart part = null;
if (model instanceof HelloworldModel) {
part = new HelloworldEditPart ()
}
part.setModel (model) ; / / 모델 설정
return part;
}
}
18. HelloWorld GEF RCP
1. Eclipse Plugin Project 생성
(HelloWorld GEF RCP)
2. Dependencies에 org.eclipse.gef 추가
3. Extensions에 org.eclipse.ui.editor추가
Id: com.sample.gef.helloworld.editor.gef
Name : First GEF – Helloworld
Class : com.sample.gef.helloworld.editor.HelloworldEditor
위의 클래스 생성
19. Helloworld GEF RCP
4. HelloworldEditor 생성
public class HelloworldEditor extends GraphicalEditor {
public static final String ID = "com.sample.gef.helloworld.editor.gef";
public HelloworldEditor() {
}
…..
}
20. Helloworld GEF RCP
5. HelloworldInput
public class HelloworldInput implements IEditorInput {
public String name = null;
public HelloworldInput(String name) {
this.name = name;
}
public boolean exists() {
return (this.name != null);
}
public boolean equals(Object o) {
if(!(o instanceof HelloworldInput)) return false;
return ((HelloworldInput)o).getName().equals(getName());
}
public ImageDescriptor getImageDescriptor() {
return ImageDescriptor.getMissingImageDescriptor();
}
public String getName() {
return this.name;
}
public IPersistableElement getPersistable() {
return null;
}
public String getToolTipText() {
return this.name;
}
public Object getAdapter(Class adapter) {
return null;
}
}
21. Helloworld GEF RCP
6. Helloworld - 모델클래스작성
public class HelloModel {
private String text = "Hello World";
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
22. Helloworld GEF RCP
7. 뷰 클래스작성
이번 예제 에서는
뷰는
org.eclipse.draw2d.Label class를 사용합니다.
public class HelloworldFigure extends Label {
public HelloworldFigure(String name) {
super(name);
}
}
23. Helloworld GEF RCP
8. HelloworldEditPart - Controller클래스작성
public class HelloEditPart extends AbstractGraphicalEditPart {
protected IFigure createFigure() {
HelloModel model = (HelloModel) getModel();
HelloworldFigure figure = new HelloworldFigure(model.getText());
return figure;
}
protected void createEditPolicies() {
}
}
24. Helloworld GEF RCP
9. MyEditPartFactory – Model과 EditPart 연결클래스작성
public class MyEditPartFactory implements EditPartFactory {
public EditPart createEditPart(EditPart context, Object model) {
EditPart part = null;
if (model instanceof HelloModel)
part = new HelloEditPart();
part.setModel(model);
return part;
}
}
25. Helloworld GEF RCP
10. HelloworldEditor – EditorFactory 생성
public class HelloworldEditor extends GraphicalEditor {
…
// 편집 도메인 설정
public HelloworldEditor() {
setEditDomain(new DefaultEditDomain(this));
}
// EditorFactory 생성
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
GraphicalViewer viewer = getGraphicalViewer();
viewer.setEditPartFactory(new HelloworldEditPartFactory());
}
// 최 상위모델 설정
protected void initializeGraphicalViewer() {
GraphicalViewer viewer = getGraphicalViewer();
viewer.setContents(new HelloModel());
}
…
}