eroself

关于人生的程式,在这里谱写......
  BlogJava :: 首页 :: 新随笔 :: 联系 ::  :: 管理

把GEF editor集成到Multi-page editor中

Posted on 2008-01-07 12:10 鬼谷子 阅读(976) 评论(0)  编辑  收藏 所属分类: GEF&EMF&GMF

转自:http://superinfinite.spaces.live.com/blog/cns!59C5F00DCFF3DBDB!221.entry

由于一个需求是要在GEF的一个画布外,再提供一个view显示JSP的流程(其实这个功能没大必要,但实现起来却不容易)。
 
不管怎么说,还是要照着需求去做滴。
 
其实,在看了需求后,我就意识到了可能要做成一个Multi-page。 由于时间不多,没来的及仔细考虑,
一开始还是做成普通的GEF编辑器,在把application flow基本上搞定之后,再次回到这个问题上。
 
没办法,继续看别人的代码(反编译的),myeclipse中的web-designer,就象dreamweaver一样有3种视图,虽然这是我以后要做的,但却没有采用它的做法。
 
记的struts-box的struts-config editor有个visualizer的页面(真巧,和我现在写的plugin名字一样),它是一个GraphicalViewer ,做法其实挺简单的。
 
构建一个Multi-page editor的框架。
 
把一个视图作为一个page放到这个Multi-page editor中。
 
为这个page写一个Section,
 
protected void createClient(Section section, FormToolkit toolkit) {
  Composite container = toolkit.createComposite(section);
  FillLayout layout = new FillLayout();
  container.setLayout(layout);
  GraphicalViewer viewer = ((VisualizerEditor)editor).createGraphicalViewer(container);
 section.setClient(container);
}
 
这个viewer呢 ,当然是原来那个GEF editor中的viewer了。
 
这时候那个新建的Multi-page当然也要改了,addPage()就不说了,
 
以后是要用这个Multi-page editor打开的,所以原来那个GEF 的editor中的几个方法是调用不到的。
 
public void init(IEditorSite site, IEditorInput input)
   throws PartInitException {
  super.init(site,input);
  appFlowVisualEditor.init(site, input);
  this.visualizer = appFlowVisualEditor.getVisualizer();
  appFlowVisualEditor.setVisualizerEditor(this);
 }
 
这是一个,其它的就缺什么补什么,debug的时候可以看出来的。
 
还有一点,就是如果没在section中另外加listener 的话,你在page中编辑GEF的元素,编辑器是不会标志dirty的,所以在section中为CommandStack加一个listener:
viewer.getEditDomain().getCommandStack().addCommandStackEventListener(new CommandStackEventListener(){
   public void stackChanged(CommandStackEvent arg0) {
    markDirty();
   }
   
  });
 
 
在editor init()的时候 getCommandStack().addCommandStackListener(this) (editor实现CommandStackListener) Section中就不需要加了。
 
要覆盖FormEditor的isDirty()方法
 
这样编辑器会在你对GEF元素进行操作后会给title标上一个*号。今天试了一下,却发现无论怎么保存,那个星号还在,仔细一看,原来忘加了个comit的方法:
 
private void commitFormPages(boolean b) {
  IFormPage[] pages = getPages();
  for (int i = 0; i < pages.length; i++) {
   IFormPage page = pages[i];
   IManagedForm mform = page.getManagedForm();
   if (mform != null && mform.isDirty())
    mform.commit(true);
  }
 }
 
 protected IFormPage[] getPages() {
  List formPages = new ArrayList();
  for (int i = 0; i < pages.size(); i++) {
   Object page = pages.get(i);
   if (page instanceof IFormPage)
    formPages.add(page);
  }
  return (IFormPage[]) formPages.toArray(new IFormPage[formPages.size()]);
 }
 
呵呵,以后不会忘了吧。

只有注册用户登录后才能发表评论。


网站导航: