1: 建立plugin project, (加入org.eclipse.gef)
2: 編輯plugin.xml, 設置editor
<extension
point="org.eclipse.ui.editors">
<editor
id="gef.tutorial.step.ui.DiagramEditor"
name="Diagram Editor"
icon="icons/alt_window_32.gif"
class="gef.tutorial.step.ui.DiagramEditor"
default="false">
</editor>
</extension>
3:建立editor類
public class DiagramEditor extends GraphicalEditor {
public static final String ID = "gef.tutorial.step.ui.DiagramEditor";
.....}
4: 在ApplicationActionBarAdvisor中加入菜單和菜單項(Action類)
建立各個相關action類(菜單項界面顯示)
有些action是直接調用得,如下
IWorkbenchAction exitAction exitAction = ActionFactory.QUIT.create(window);
register(exitAction);
IWorkbenchAction aboutAction = ActionFactory.ABOUT.create(window);
register(aboutAction);
5: 建立editorinput類
6: 在action得run函數中處理點擊事件
建立editorinput實例,打開editor
public void run() {
String path = openFileDialog();
if (path != null) {
IEditorInput input = new DiagramEditorInput(new Path(path));
IWorkbenchPage page = window.getActivePage();
try {
page.openEditor(input, DiagramEditor.ID, true);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
7: 在Perspective中設置editor可視
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(true);
}
8: 在DiagramEditor中設置DefaultEditDomain
public DiagramEditor() {
setEditDomain(new DefaultEditDomain(this));
}
在plugin.xml得overview頁面點擊"launce an eclipase application",可以進行測試
簡單例子代碼: 下載