您的位置:首页 > 其它

GEF-whole-upload 实验随笔一:搭建编辑器

2011-12-16 04:21 218 查看
看了dengues,突发奇想,如果能用gef-whole-upload的例子,也开发一个类似的studio,那对于学习和工作,帮助应该都很大

那么,从跟着gef-whole-upload开始,算是实验课吧,就记录在这里吧

首先,建立一个plugin工程,设置为rcp模式

1.new->plugin project

2.选择hello rcp

3.出来了一个包,里面存放着Activator.java(控制插件的生命周期),Application.java(控制程序执行的各个方面),ApplicationActionBar.java(应用程序的按钮等),ApplicationWorkbenchWindowAdvisor.java(显示程序启动的方式及初始状态等),ApplicationWorkbenchAdvisor(这个不知道是用来做什么的),perspective.java(程序的属性)

4.在extensions中加入org.eclipse.ui.editors插件,用来新建一个编辑器,并设置id作为该编辑器的标示符,设置一个class:editor.class,放在xxx.ui包中

5.在Application中实现IPlatformRunable接口及IApplication接口,在start方法中加入

Application中的start方法

public Object start(IApplicationContext context) throws Exception
{
Display display = PlatformUI.createDisplay();
try
{
int returnCode = PlatformUI.createAndRunWorkbench(display,
new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART)
return IApplication.EXIT_RESTART;
else
return IApplication.EXIT_OK;
} finally
{
display.dispose();
}

}


并且在run方法中加入

ApplicationActionBarAdvisor中加入按钮

protected void makeActions(IWorkbenchWindow window)
{
exitAction = ActionFactory.QUIT.create(window);
register(exitAction);
aboutAction = ActionFactory.ABOUT.create(window);
register(aboutAction);
editorAction = new EditorAction(window);
register(editorAction);

}

protected void fillMenuBar(IMenuManager menuBar)
{
MenuManager fileMenu = new MenuManager("&New", "New");
fileMenu.add(editorAction);
fileMenu.add(new Separator());
fileMenu.add(exitAction);

MenuManager helpMenu = new MenuManager("&Help","help");
helpMenu.add(aboutAction);

menuBar.add(fileMenu);
menuBar.add(helpMenu);
}


8.设置编辑器的输入类:新建类:EditorInput

在Perspective.java中设置可见

public void createInitialLayout(IPageLayout layout)
{
layout.setEditorAreaVisible(true);
}


11.设置gef命令堆栈的存放位置

editor中的构造方法加入

setEditDomain(new DefaultEditDomain(this));


这样一个编辑器基本搭建好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: