前两天csdn不稳定,所以一直没有更新。
我这里面是解决eclipse3.6.2遇到的问题,所以如果你是使用的3.7的话就不用看了。
我们的结构与之前相同在一个multipage里面嵌入gef和xml。
在我们的程序开发中遇到了一个问题:王哥用的是eclipse3.6.2 而我用的是3.7。而我们的需求中需要在properties view中显示属性,同样的写法我的能同步他的却不行但是规定的版本是3.6.2没办法哎。只能换ide找问题。
因为要想实现editor和view通信的话就必须要在editor中重写
@Override
public Object getAdapter(Class type) {
}
而IPropertySheetPage的通信已经被写入父类里面了但是我仔细看了一下3.6和3.7竟然不一样:
3.6:
public Object getAdapter(Class type) {
if (type == org.eclipse.ui.views.properties.IPropertySheetPage.class) {
return new UndoablePropertySheetPage(getCommandStack(),
getActionRegistry().getAction(ActionFactory.UNDO.getId()),
getActionRegistry().getAction(ActionFactory.REDO.getId()));
}
if (type == GraphicalViewer.class)
return getGraphicalViewer();
if (type == CommandStack.class)
return getCommandStack();
if (type == ActionRegistry.class)
return getActionRegistry();
if (type == EditPart.class && getGraphicalViewer() != null)
return getGraphicalViewer().getRootEditPart();
if (type == IFigure.class && getGraphicalViewer() != null)
return ((GraphicalEditPart) getGraphicalViewer().getRootEditPart())
.getFigure();
return super.getAdapter(type);
}
3.7:
public Object getAdapter(Class type) {
if (type == org.eclipse.ui.views.properties.IPropertySheetPage.class) {
PropertySheetPage page = new PropertySheetPage();
page.setRootEntry(new UndoablePropertySheetEntry(getCommandStack()));
return page;
}
if (type == GraphicalViewer.class)
return getGraphicalViewer();
if (type == CommandStack.class)
return getCommandStack();
if (type == ActionRegistry.class)
return getActionRegistry();
if (type == EditPart.class && getGraphicalViewer() != null)
return getGraphicalViewer().getRootEditPart();
if (type == IFigure.class && getGraphicalViewer() != null)
return ((GraphicalEditPart) getGraphicalViewer().getRootEditPart())
.getFigure();
return super.getAdapter(type);
}
既然3.7科技解决问题那么我们就用3.7的吧
@Override
public Object getAdapter(Class type) {
if (type == IContentOutlinePage.class) {
return new MyContentOutlinePage();
} else if (type == org.eclipse.ui.views.properties.IPropertySheetPage.class) {
page = new PropertySheetPage();
page.setRootEntry(new UndoablePropertySheetEntry(getCommandStack()));
return page;
}
return super.getAdapter(type);
}
但是运行了之后并不能解决问题。和没改一样。所以估计应该是没有监听到的问题。而对于监听这个问题我们以前就遇到过所以我们可以用我们自己的方法来实现:
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
super.selectionChanged(part, selection);
updateActions(getSelectionActions());
if (page != null)
page.selectionChanged(part, selection);
}
如果你看了之前的日志的话那么对这个就会很熟悉。具体的内容一看就知道。最后实现了: