Quite often you need to export the current contents of a GEF editor to an image. Here is the simple code to do that:
GraphicalViewer graphicalViewer = ...; // get it from your editor
String saveLocation = ...; // get it thru a FileDialog
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) graphicalViewer.getEditPartRegistry().get(LayerManager.ID);
IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
Control figureCanvas = graphicalViewer.getControl();
Image img = new Image(Display.getDefault(), rootFigureBounds.width, rootFigureBounds.height);
GC imageGC = new GC(img);
figureCanvas.print(imageGC); // This is Eclipse 3.4 only API
ImageLoader imgLoader = new ImageLoader();
imgLoader.data = new ImageData[] { img.getImageData() };
imgLoader.save(saveLocation, SWT.IMAGE_JPEG);
imageGC.dispose();
img.dispose();
Just in case you need, here is a nice image
to represent this Action :-)
Mar 18, 2008
Exporting GEF figure to an image
Posted by
Prakash G.R.
at
10:44 PM
3
comments
Labels: gef
Mar 6, 2008
Eclipse CVS
The CVS Repositories view in Eclipse allows you to paste a CVS URL in the "New Repository Location" Wizard. (If you are on 3.3, you can directly paste on the view without the Wizard) In case you want to browse thru the Eclipse CVS repository, here are the URLs you can copy and paste into the wizard.
Platform, SWT, JFace, Equinox, JDT, launcher, UI, update, search, debug, team, etc) are available here:
:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse
Mylyn, GEF, CDT, COBOL, VE:
:pserver:anonymous@dev.eclipse.org:/cvsroot/tools
AspectJ, Nebula, EPP:
:pserver:anonymous@dev.eclipse.org:/cvsroot/technology
EMF, GMF, MDT:
:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling
WTP:
:pserver:anonymous@dev.eclipse.org:/cvsroot/webtools
Data Tools:
:pserver:anonymous@dev.eclipse.org:/cvsroot/datatools
If you want to browse thru the CVS, you can use the web based viewer also: http://dev.eclipse.org/viewcvs/
More info on connecting to Eclipse CVS: http://wiki.eclipse.org/index.php/CVS_Howto
Related:
Searching Eclipse Sources
Feb 13, 2008
Using ConnectionDragCreationTool in GEF
Connection creation tools in the palette are nice. But the only problem with those is that it would require three mouse clicks from the user. Click the connection creation tool in the palette; the click the source edit part and then finally click the target edit part.
How good if we can simplify this further? Like just drag-n-drop an edit part into another should create a connection between them. Implementing this feature might be much easier than you think. Override the getDragTracker in your source edit part and return the ConnectionDragCreationTool :-)
@Override
public DragTracker getDragTracker(Request request) {
return new ConnectionDragCreationTool();
}
Remember this will be applicable only if your edit parts are not moveable. If they have to be movable in your application, then drag-n-drop should change their position - not create a connection!
[Update]
You cannot select the source edit part, if you use the ConnectionDragCreationTool. The fix is simple:
@Override
public DragTracker getDragTracker(Request request) {
getViewer().select(this);
return new ConnectionDragCreationTool();
}
Posted by
Prakash G.R.
at
4:29 PM
0
comments
Labels: gef
Nov 30, 2007
Eclipse Demo Camp, Bangalore

Eclipse Demo Camp is coming to Bangalore on 10th Dec. Looking at other Demo Camps, Bangalore might be the one with highest number of registration (around 50) - and its still growing. In case you wish to attend, do register here.
Yup, I'm working on a presentation on GEF. Meet you all there.
