Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to draw directed edges and tooltip using IGraphContentProvider(How to draw directed edges and tooltip using IGraphContentProvider)
How to draw directed edges and tooltip using IGraphContentProvider [message #541088] Fri, 18 June 2010 05:46 Go to next message
syeed is currently offline syeed
Messages: 19
Registered: June 2010
Junior Member
Hi,
I am using ZEST and JFace viewer to build a graph visalization tool. I used "IGraphContentProvider" and the "LabelProvider" for drawing the grpah.

My question is: how can I draw a directed edge between two nodes using IGraphContentProvider? and also how to genereate customized tooltip.


Thanks in advance

-rajit
Re: How to draw directed edges and tooltip using IGraphContentProvider [message #541201 is a reply to message #541088] Fri, 18 June 2010 12:26 Go to previous messageGo to next message
Fabian Steeg is currently offline Fabian Steeg
Messages: 65
Registered: July 2009
Member
You can get directed edges by setting the connection style on your GraphViewer:
viewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);

For custom tooltips you could get the connections from the viewer and set a tooltip on each of them:
List<?> connections = viewer.getGraphControl().getConnections();
for (Object c : connections) ((GraphConnection) c).setTooltip(new Label("Custom Tooltip"));

There might be a better way to customize the tooltips, though.
Re: How to draw directed edges and tooltip using IGraphContentProvider [message #541236 is a reply to message #541201] Fri, 18 June 2010 16:25 Go to previous messageGo to next message
syeed is currently offline syeed
Messages: 19
Registered: June 2010
Junior Member
Hi,
I used your solution but it gives error. I created the graph in a RCP view. I attatched the code. Please take a look.

In CreatePartControl method i add the code provided. but it gives the following error:

- Unable to create view ID zest_directed.view: Plug-in "zest_directed" was unable to instantiate class "zest_directed.View".



import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphContentProvider;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;


public class View extends ViewPart implements IZoomableWorkbenchPart{
public static final String ID = "zest_directed.view";

private int layout = 1;

// public static final String ID = "de.vogella.zest.first.view";
static class MyContentProvider implements IGraphContentProvider {

public Object getDestination(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 getSource(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 5;
}

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;
}
else if(element.equals("Rock2Paper"))
return image;

return null;
}


public String getText(Object element) {

if (element instanceof String){
if(element.toString().equalsIgnoreCase("Rock2Paper"))
return "Hurray 10";
//return element.toString();
}

//return element.toString();
return "DEFAULT";
}

}

static GraphViewer viewer = null;



/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
viewer = new GraphViewer(parent, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)) ;
viewer.setInput(new Object());

//===================================
//???ERROR IS HERE
//=================================== viewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);


List<GraphConnection> connections = viewer.getGraphControl().getConnections();

for (Object c : connections) ((GraphConnection) c).setTooltip(new Label("Custom Tooltip"));

fillToolBar();
}


/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {}

private void fillToolBar() {
ZoomContributionViewItem toolbarZoomContributionViewItem = new ZoomContributionViewItem( this);
IActionBars bars = getViewSite().getActionBars();
bars.getMenuManager().add(toolbarZoomContributionViewItem);
}

@Override
public AbstractZoomableViewer getZoomableViewer() { return viewer; }

}
Re: How to draw directed edges and tooltip using IGraphContentProvider [message #541245 is a reply to message #541236] Fri, 18 June 2010 17:28 Go to previous messageGo to next message
Fabian Steeg is currently offline Fabian Steeg
Messages: 65
Registered: July 2009
Member
From looking at your code I guess the problem is this:

List<GraphConnection> connections = viewer.getGraphControl().getConnections();


Since the returned list is a raw type you have to declare the list like in my code above:

List<?> connections = viewer.getGraphControl().getConnections();


You should also see an error in the editor (and in the Problems view), which is more precise than the error you gave (which sounds like you got it when you tried running your app). If not, check if build automatically is enabled (in the Project menu).
Re: How to draw directed edges and tooltip using IGraphContentProvider [message #541247 is a reply to message #541245] Fri, 18 June 2010 17:35 Go to previous messageGo to next message
syeed is currently offline syeed
Messages: 19
Registered: June 2010
Junior Member
Hi,
Thanks for your reply. The directed edge worked. But the tooltip is still a problem. I identified the problem but dont know how to solve it.

The problem is with the IFigure package. it says, java.lang.NoClassDefFoundError: org/eclipse/draw2d/IFigure.

IFigure tooltip = new Label("Rajit"); // error is for this line...
List<GraphConnection> connections = viewer.getGraphControl().getConnections();
for (Object c : connections) ((GraphConnection) c).setTooltip(tooltip);

But i included the package and it did not show any error. can you provide some solution?

Thanks,
-rajit
Re: How to draw directed edges and tooltip using IGraphContentProvider [message #541250 is a reply to message #541247] Fri, 18 June 2010 18:34 Go to previous message
syeed is currently offline syeed
Messages: 19
Registered: June 2010
Junior Member
hi,
i solved the problem... its all running now. thanks a lot for your kind solution and help.

-rajit
Previous Topic:Drag Drop
Next Topic:Diagram -->> code conversion
Goto Forum:
  


Current Time: Sun May 19 04:36:52 EDT 2013

Powered by FUDForum. Page generated in 0.02418 seconds