当前位置: 代码迷 >> Eclipse >> GEF-whole-upload 里把helloModel设为子模型的有关问题
  详细解决方案

GEF-whole-upload 里把helloModel设为子模型的有关问题

热度:108   发布时间:2016-04-23 13:31:51.0
GEF-whole-upload 里把helloModel设为子模型的问题
设为子模型后,运行时,报,HelloModel cannot be cast to org.eclipse.gef.EditPart!请问这个什么原因?
java.lang.ClassCastException: com.ubisensing.model.NodeModel cannot be cast to org.eclipse.gef.EditPart
  at org.eclipse.gef.editparts.AbstractEditPart.addNotify(AbstractEditPart.java:230)
  at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotify(AbstractGraphicalEditPart.java:212)
  at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:195)
  at org.eclipse.gef.editparts.ScalableRootEditPart.setContents(ScalableRootEditPart.java:404)
  at org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents(AbstractEditPartViewer.java:583)
  at org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents(AbstractEditPartViewer.java:592)
  at com.ubisensing.ui.UbisensingEditor.initializeGraphicalViewer(UbisensingEditor.java:36)

当我只设置,NodeMode时,显示正常,只设置,ContentsModel时,也显示正常,但是当把NodeMode放ContentsModel里就,出现上面的异常了!

在ContensEditPart里我,重载了getChildren方法
  public List getChildren() {
  // TODO Auto-generated method stub
  return ((ContentsModel)getModel()).getChildren();
  }

在 DiagramEditor里,
  protected void configureGraphicalViewer() {
  // TODO Auto-generated method stub
  super.configureGraphicalViewer();
  viewer = getGraphicalViewer();
  viewer.setEditPartFactory(new PartFactory());
  }

  protected void initializeGraphicalViewer() {
  // TODO Auto-generated method stub
  ContentsModel parent = new ContentsModel();
   
  NodeModel node = new NodeModel();
  parent.addChild(node);
   
  viewer.setContents(parent); // 这一行报错
   
  }

------解决方案--------------------
楼主~~~~~~~~~~~~~~~~~~~~~~~~~
  相关解决方案