Bug 215040 - Add custom graph items
Summary: Add custom graph items
Status: RESOLVED FIXED
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Zest (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5.0 (Galileo) M7   Edit
Assignee: Ian Bull CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 214988 214989 214990 214991 (view as bug list)
Depends on:
Blocks: 154579
  Show dependency tree
 
Reported: 2008-01-11 10:58 EST by Ian Bull CLA
Modified: 2009-03-31 19:50 EDT (History)
7 users (show)

See Also:
irbull: galileo+


Attachments
AbstractStructuredGraphViewer: 6 methods private -> protected (20.85 KB, text/java)
2008-10-21 09:17 EDT, Tully Yates CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Bull CLA 2008-01-11 10:58:35 EST
Add support for custom graph items so users can use their own figures a nodes and edges.
Comment 1 Ian Bull CLA 2008-01-11 20:57:36 EST
*** Bug 214990 has been marked as a duplicate of this bug. ***
Comment 2 Ian Bull CLA 2008-01-11 20:57:57 EST
*** Bug 214991 has been marked as a duplicate of this bug. ***
Comment 3 Stefan Tucker CLA 2008-05-28 15:24:07 EDT
I have this same need. For example, I would like to create an oval figure (instead of a rounded rectangle) but still use the capabilities of GraphNode and GraphLabel; I don't want to re-implement everything those classes do so well. Unfortunately, GraphLabel and CachedLabel are internal, so I can't subclass them. Nor can I copy them into my source and subclass them because GraphNode#updateFigureForModel() returns if its figure isn't an instance of GraphLabel. initFigure() and createFigureForModel() are protected so they can't be overridden.

If there's an easy way of implementing custom shapes, I can't find it, so please educate us.
Comment 4 Ian Bull CLA 2008-09-29 17:49:11 EDT
*** Bug 214989 has been marked as a duplicate of this bug. ***
Comment 5 Ian Bull CLA 2008-09-29 17:49:14 EDT
*** Bug 214988 has been marked as a duplicate of this bug. ***
Comment 6 Urs Reupke CLA 2008-10-01 11:58:52 EDT
Looking forward to seeing custom shapes in galileo. Good news, Ian.
Comment 7 Tully Yates CLA 2008-10-21 09:17:01 EDT
Created attachment 115690 [details]
AbstractStructuredGraphViewer: 6 methods private -> protected
Comment 8 Tully Yates CLA 2008-10-21 09:18:31 EDT
I have a work around for this bug.

I added the protected keyword to the following methods in org.eclipse.zest.core.viewers.internal.AbstractStructuredGraphViewer:

#getNodesMap()
#getConnectionsMap()

#getGraphModelNode(Object obj)
#getGraphModelConnection(Object obj)

#addGraphModelNode(Object)
#addGraphModelConnection(Object element, GraphNode source, GraphNode target)

I then extend org.eclipse.zest.core.viewers.GraphViewer class and override adding of Nodes and Connections to the graph using the now exposed methods:

@Override
protected GraphNode addGraphModelNode(Object element) {
	GraphNode node = this.getGraphModelNode(element);
	if (node == null) {
		node = nodeDecorator.createGraphNode((Graph) getControl(), element);
		getNodesMap().put(element, node);
	}
	return node;
}

@Override
protected GraphConnection addGraphModelConnection(Object element, GraphNode source, GraphNode target) {
	GraphConnection connection = this.getGraphModelConnection(element);
	if (connection == null) {
		connection = arcDecorator.createGraphConnection((Graph) getControl(), element, source, target);
		getConnectionsMap().put(element, connection);
	}
	return connection;
}

Class nodeDecorator creates a CustomGraphNode by extending GraphNode (as in the UMLExample by Ian Bull). The arcDecorator class creates a GraphConnection and has logic to create specific  PolygonDecoration based on the arc type received.
Comment 9 Miles Parker CLA 2008-12-23 15:39:36 EST
Hey all-

Here's another workaround that doesn't require rebuilding Zest. The strategy is to draw the figure to an image and then return that. Bonus is that you might actually see some performance improvements in case where the figures are complex and not mutable. Note that this version does assume that the actual figure is immutable -- that's a big assumption but if you want it updated every time just get rid of all of the image caching stuff.

The big bummer with this approach is that there is no way that I can tell to get rid of the actual border, so your figure will appear inside of the regular node. I tried to play with colors to make the container gray, but that didn't work because of the auto highlighting within GraphNode. Obviously you want to turn off text etc..

-Miles

public class MyStyleProvider implements IConnectionStyleProvider, IEntityStyleProvider, ILabelProvider {

    public IFigure createFigure(Object object) {
        //create any figure here -- note that layout etc will have to be performed manually
       //Its fine to return null when a figure isn't appropriate
    }

    Map<Object, Image> imageForObject = new HashMap<Object, Image>();

    public Image getImage(Object object) {
        Image image = imageForObject.get(object);
        if (image == null) {
            IFigure figure = createFigure(object);
            if (figure != null) {
                image = new Image(PlatformUI.getWorkbench().getDisplay(), figure.getSize().width,
                        figure.getSize().height);
                GC imageGC = new GC(image);
                SWTGraphics imageGraphics = new SWTGraphics(imageGC);
                figure.paint(imageGraphics);
                imageGraphics.drawImage(image, 0, 0);
                imageForObject.put(object, image);
            }
        }
        return image;
    }

 
    public String getText(Object entity) {
        return null;
    }

//setup colors
}
Comment 10 Ian Bull CLA 2009-03-17 16:35:28 EDT
This bug is about adding Custom Graph Items (like CGraphNode).  Bug 154579 is about adding this to the viewer. I have a basic version of both of these working. On the Graph API side I have added CGraphNode and then I added a IFigureProvider which can be used (as a lable provider) to provide a custom figure for your graph.

Comment 11 Ian Bull CLA 2009-03-31 19:50:46 EDT
I have added the custom graph nodes as part of Bug 154579.  See CGraphNode to add a custom figure.