Eclipse rcp 如何使用“绘制有向边”;IGraphContentProvider“是什么;?
我正在使用ZEST和RCP构建一个图形可视化工具。我使用了Eclipse rcp 如何使用“绘制有向边”;IGraphContentProvider“是什么;?,eclipse-rcp,Eclipse Rcp,我正在使用ZEST和RCP构建一个图形可视化工具。我使用了IGraphContentProvider和LabelProvider来绘制图形 如何使用IGraphContentProvider在两个节点之间绘制有向边?不是Zest专家,但似乎仅限于访问给定关系的基础obejct。 getSource()和getDestination()方法将帮助像Graphviewer这样的查看器查看由这些“源-目标”对定义的边 看 迟来的回答,但我有类似的想法: 您可以通过提供IEntityConnectio
IGraphContentProvider
和LabelProvider
来绘制图形
如何使用IGraphContentProvider
在两个节点之间绘制有向边?不是Zest专家,但似乎仅限于访问给定关系的基础obejct。getSource()
和getDestination()
方法将帮助像Graphviewer这样的查看器查看由这些“源-目标”对定义的边
看
迟来的回答,但我有类似的想法:
您可以通过提供IEntityConnectionStyleProvider
来实现这一点。它有一个名为getConnectionStyle(src,dest)
的方法。如果所有连接都是定向的,您可以在那里返回costantZestStyles.CONNECTIONS\u DIRECTED
。否则,您必须根据源和目标来决定是否绘制定向边
您可能还需要查看IGraphEntityRelationshipContentProvider
。使用该内容提供程序,您只需将对象添加到图形中,然后再决定连接的对象。那么解决方案是什么呢?@syeed:好的,通过定义自己的GraphContentProvider
,重新定义getSource()
和getDestination())
作为原始GraphContentProvider
的源和目标,但在这两个节点中明确指定所需的源和目标除外。
/*******************************************************************************
* Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC,
* Canada. All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: The Chisel Group, University of Victoria
******************************************************************************/
package org.eclipse.zest.core.examples.jface;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphContentProvider;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* This snippet shows how to use the IGraphContentProvider to create a graph with Zest.
* In this example, getElements returns 3 edges:
* * Rock2Paper
* * Paper2Scissors
* * Scissors2Rock
*
* And for each of these, the source and destination are returned in getSource and getDestination.
*
* A label provider is also used to create the text and icons for the graph.
*
* @author Ian Bull
*
*/
public class GraphJFaceSnippet2 {
static class MyContentProvider implements IGraphContentProvider {
public Object getSource(Object rel) {
if ("Rock2Paper".equals(rel)) {
return "Rock";
} else if ("Paper2Scissors".equals(rel)) {
return "Paper";
} else if ("Scissors2Rock".equals(rel)) {
return "Scissors";
}
return null;
}
public Object[] getElements(Object input) {
return new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" };
}
public Object getDestination(Object rel) {
if ("Rock2Paper".equals(rel)) {
return "Paper";
} else if ("Paper2Scissors".equals(rel)) {
return "Scissors";
} else if ("Scissors2Rock".equals(rel)) {
return "Rock";
}
return null;
}
public double getWeight(Object connection) {
return 0;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
static class MyLabelProvider extends LabelProvider {
final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING);
public Image getImage(Object element) {
if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) {
return image;
}
return null;
}
public String getText(Object element) {
return element.toString();
}
}
static GraphViewer viewer = null;
/**
* @param args
*/
public static void main(String[] args) {
Display d = new Display();
Shell shell = new Shell(d);
shell.setText("GraphJFaceSnippet2");
shell.setLayout(new FillLayout(SWT.VERTICAL));
shell.setSize(400, 400);
viewer = new GraphViewer(shell, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setInput(new Object());
shell.open();
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}
}
}