插件项目如何创建outline?

zxlbb 2008-11-06 07:34:57
GMF插件项目怎么建outline啊?就是几个模型之间有层次关系,让它们在outline中以树形结构排列?提供思路即可。
明天加100分。急,明天上午结贴。
...全文
134 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhujiahill 2008-11-06
  • 打赏
  • 举报
回复
2.创建outlinepage

public class DiagramOutlinePage extends ContentOutlinePage

里面重写的方法看它的父类

3把outline加到DiagramEditor的getAdapter方法中

public Object getAdapter(Class type) {
if (type == IShowInTargetList.class) {
return new IShowInTargetList() {
public String[] getShowInTargetIds() {
return new String[] { ProjectExplorer.VIEW_ID };
}
};
}

// **** modify start zhujia 2008/06/17 ****
if (type == IContentOutlinePage.class) {

DMTreeViewer viewer = new DMTreeViewer(this);
diagramOutlinePage = new DiagramOutlinePage(viewer, this);
PluginUtil.setOutlinePage(diagramOutlinePage);

viewer.setRootEditPart(new DiagramRootTreeEditPart());
return diagramOutlinePage;
}
// **** modify end zhujia 2008/06/17 ****

return super.getAdapter(type);
}


大概就这些步骤,你慢慢理解吧
zhujiahill 2008-11-06
  • 打赏
  • 举报
回复
1.首先定义outline中的要排列模型的层次关系:在你的DiagramEditor中重写getOutlineViewEditPartFactory()方法,举个例子

public EditPartFactory getOutlineViewEditPartFactory() {
return new EditPartFactory() {

public EditPart createEditPart(EditPart context, Object model) {
//下面这几个if是按顺序执行的,就是说前一个if返回的值为后一个所用
//模型关系一层比一层小
if (model instanceof Resource) {
//这一层得到当前编辑区中所有模型的EditPart
Resource resource = (Resource) model;
String editorInputName = ((FileEditorInput) DMDiagramEditor.this.getEditorInput()).getName();
editorInputName = editorInputName.substring(0, editorInputName.lastIndexOf("."));
return new RootDiagramTreeEditPart(DMDiagramEditorUtil.getActiveDiagram(resource), resource,
editorInputName);
}

if (model instanceof Diagram) {
//底层模型(容器)
return new DiagramContainerEditPart(model);

}
if (model instanceof Node) {
//子模型,这样就能跟底层模型形成结构关系
EObject obj = ((Node) model).getElement();
if (obj instanceof Entity) {

return new EntityTreeEditPart(model);

} else if (obj instanceof jp.co.intramart.app.producer.db.dm.model.View) {

return new ViewTreeEditPart(model);
}
}

return null;
}
};
}



//定义EditPart的例子
public class DiagramContainerEditPart extends TreeContainerEditPart {

private static String lblLogicalDataModel = ResourceMessages.getString("OutLineLabel_LogicalDataModel");
private static String lblPhycalDataModel = ResourceMessages.getString("OutLineLabel_PhysicalDataModel");

public DiagramContainerEditPart(Object model) {
super(model);
}

protected Image getImage() {//outline中节点的图形在这得到
return FigureUtil.getImage(DMDiagramEditorPlugin.ID, "images/opration.gif");
}

protected List<Node> getModelChildren() {//得到该模型的子节点
Object model = getModel();
boolean isLogical = ModelUtil.isLogicalEditType();
int cnt = 1;
if (model instanceof Diagram) {

List<Node> listAll = new ArrayList<Node>();
SortedMap<String, Node> sortMapEntity = new TreeMap<String, Node>();
SortedMap<String, Node> sortMapView = new TreeMap<String, Node>();
// get sorted entity and view list
for (Object child : ((Diagram) model).getChildren()) {
Node node = (Node) child;
EObject obj = node.getElement();
if (obj instanceof Entity) {
if (!(obj instanceof SubEntity)) {
Entity entity = (Entity) obj;
// let same name entity different
String name = NamedItemUtil.getDisplayName(entity, isLogical) + " " + cnt++;
sortMapEntity.put(name, node);
}
}

if (node.getElement() instanceof jp.co.intramart.app.producer.db.dm.model.View) {

jp.co.intramart.app.producer.db.dm.model.View view = (jp.co.intramart.app.producer.db.dm.model.View) obj;
// let same name view different
String name = NamedItemUtil.getDisplayName(view, isLogical) + " " + cnt++;
sortMapView.put(name, node);
}
}

// add views after all entities
listAll.addAll(sortMapEntity.values());
listAll.addAll(sortMapView.values());
return listAll;
}
return null;
}

protected String getText() {//在outline上显示的文本
if (ModelUtil.isLogicalEditType()) {
return lblLogicalDataModel;
} else {
return lblPhycalDataModel;
}
}

@Override
protected void handleNotificationEvent(Notification event) {

if (event.getEventType() == Notification.ADD || event.getEventType() == Notification.REMOVE) {
this.refreshChildren();
} else {
super.handleNotificationEvent(event);
}
}

public void setText(String text) {
((TreeItem) super.getWidget()).setText(text);
}
}

你可以根据自己的模型自己定义

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧