|
Re: Using Swing with Graphiti [message #632578 is a reply to message #632212] |
Wed, 13 October 2010 13:46 |
Tim Kaiser Messages: 118 Registered: July 2009 |
Senior Member |
|
|
Hi,
this is not supported by Graphiti.
Nonetheless you may find a hack,
since the FigureCanvas (Draw2d) of the Graphical Viewer is a SWT Widget.
Then you might use SWT_AWT to create an AWT Frame
wherein you can try to embed your swing control.
But i am pretty sure that even if you get it working somehow it will not run stable....
Please post your findings!
Best regards, Tim
ps: ...and thanks for the positive feedback!
[Updated on: Wed, 13 October 2010 13:59] Report message to a moderator
|
|
|
|
|
|
Re: Using Swing with Graphiti [message #637188 is a reply to message #637096] |
Thu, 04 November 2010 14:27 |
VincentL Messages: 88 Registered: July 2009 |
Member |
|
|
Hi Edgar,
Here are the steps (it is only for tests purpose)
1- Create a CreateFeature. In this method you should add the SWT composite. I put the
composite creation there because it is easy to have a reference to the figure canvas.
I also stored a reference to this composite in my emf data model to be able to layout this
composite in the add feature.
public class CreateCompositeFeature extends AbstractCreateFeature {
...
public Object[] create(ICreateContext context) {
...
DiagramEditor de = (DiagramEditor) getDiagramEditor();
FigureCanvas canvas = de.getFigureCanvas();
Composite compositeRef = new Composite(canvas, SWT.NONE);
// For the test, I put the reference to my composite in the data model
dataObject.setCompositeReference(compositeRef)
...
...
2- Create a Add feature. In this method I set the location of the composite and also force
SWT to layout correctly the composite using changed and layout method
public class AddCompositeFeature extends AbstractAddShapeFeature {
...
public PictogramElement add(IAddContext context) {
...
x = context.getX();
y = context.getY();
dx = 100;
dy = 100;
// Create invisible outer rectangle
invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, x,y, dx,dy);
Composite composite = dataObject.getCompositeReference();
composite.setBounds(x+5, y+5, dx-10, dy-10);
// Note that the set bound method doesn't work correctly when
// there are scrollbar on the figure canvas
// add a swt button on the composite
composite.setLayout(new FillLayout(SWT.HORIZONTAL));
Button button = new Button(composite, SWT.NONE);
// Make sure the composite is layout correctly on add
//composite.getParent().layout();
composite.layout();
...
3- Create a a Move Feature. In this class you should move your composite based on the
shape coordinate.
public class MoveCompositeFeature extends DefaultMoveShapeFeature {
...
protected void postMoveShape(IMoveShapeContext context) {
...
Composite compositeReference = dataObject.getCompositeReference();
// Get canvas
FigureCanvas figureCanvas = (FigureCanvas) compositeReference.getParent();
// get viewport
Viewport viewPort = figureCanvas.getViewport();
int x = context.getX();
int y = context.getY();
// Create point
Point p = new Point(x,y);
// translate point in the SWT reference frame
viewPort.translateToAbsolute(p);
compositeReference.setLocation(p.x+5,p.y+5);
compositeReference.layout();
// Here instead of translateToAbsolute, I tried to used
// many different approach without success...
// For example, I tried to calculate composite location using
// information stored in :
// a) viewPort.getVerticalRangeModel()
// b) figureCanvas.getVerticalBar()
// c) viewPort.getViewLocation()
// d) viewPort.translateToParent
// e) viewPort.translateFromParent
// f) viewPort.translateToRelative
...
4- Create Resize feature. In this class you should resize your composite based on the
shape coordinate
public class ResizeCompositeFeature extends DefaultResizeShapeFeature {
...
public void resizeShape(IResizeShapeContext context) {
...
Composite compositeReference = dataObject.getCompositeReference();
int x = context.getX();
int y = context.getY();
int dx = context.getWidth();
int dy = context.getHeight();
// Create a rectangle
Rectangle r = new Rectangle(x,y,dx,dy);
// Make translation...
viewPort.translateToAbsolute(r);
compositeReference.setBounds(r.x+5,r.y+5,r.width-10,r.height -10);
compositeReference.layout();
...
5- Then you must add you feature to the feature provider...
Conclusion:
A) Scrollbar problem
Generally, everything works well except when there are scrollbar. There are many case with
scrollbar that doesn't work as explained in the previous mail.
a) move/resize/create a shape near the border of the canvas (few pixel inside the canvas)
b) move/resize/create a shape when there are scrollbars
c) move/resize/create when there are other shape outside of the visible area
B) I also experimented other problems that I didn't try to solve yet.
a) The mini view doesn't show swt composite.
b) In the delete feature, you should all remove the SWT composite.
c) When a save is performed (since SWT widget are not persistent with the data model)
they are not saved. It means that when you load a diagram, the swt composite is not
created in the diagram. I do not know yet where I should add the code to recreate the
composite.
d) Since the SWT figure canvas has as absolute layout(instead of grid, or fill, or
form,...), it will be difficult to layout multiple composite or control inside the main
composite of the figure canvas. I need to explore this SWT bug and limitation.
Of course, I will need some help evantually to solve this issues...
However, my company evaluate the possibility to pay external resources to help our company
to develop the feature of embedding SWT composites or Swing components into
GEF/Draw2D/Graphiti framework...
Regards,
Vincent
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03651 seconds