
1. Create an RCP project (See how to create a RCP project)
3. From plugin.xml, go to Depedencies tab and add org.eclipse.zest.core, org.eclipse,gef, org.eclipse.zest.layouts to the Required Plug-ins section.
4. Create a view called "MyGraph"
--
package views;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphContentProvider;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
public class MyGraph extends ViewPart
{
public static final String ID = "MyGraph.Graph";
static class MyContentProvider implements IGraphContentProvider
{
private static final String edge3 = "edge3";
private static final String edge2 = "edge2";
private static final String edge1 = "edge1";
public Object getSource(Object rel)
{
if (edge1.equals(rel))
{
return "AAA";
}
else if (edge2.equals(rel))
{
return "BBB";
}
else if (edge3.equals(rel))
{
return "CCC";
}
return null;
}
public Object [] getElements(Object input)
{
return new Object[] { edge1, edge2, edge3 };
}
public Object getDestination(Object rel)
{
if (edge1.equals(rel))
{
return "BBB";
}
else if (edge2.equals(rel))
{
return "CCC";
}
else if (edge3.equals(rel))
{
return "AAA";
}
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("BBB") || element.equals("AAA") || element.equals("CCC"))
{
return image;
}
return null;
}
public String getText(Object element)
{
return element.toString();
}
}
static GraphViewer viewer = null;
@Override
public void createPartControl(Composite parent)
{
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new FillLayout(SWT.VERTICAL));
comp.setSize(400, 400);
viewer = new GraphViewer(comp, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setInput(new Object());
}
@Override
public void setFocus()
{
}
}
--
5. Make sure you add the view to your plugin.xml with the id "MyGraph.Graph". (See how to add a view to an RCP project)
6. Add this view to perspective. (See how to add a view to perspective)

0 yorum:
Yorum Gönder