ScalableFreeformRootEditPart negative coordinates [message #1016282] |
Tue, 05 March 2013 19:48 |
Tim E. Messages: 56 Registered: November 2012 |
Member |
|
|
Hi,
I'm using a ScalableFreeformRootEditPart in my GEF editor and everything works fine.
I can move figures around, and the editor automatically shows scroll bars,
as long a I place the figures down or to the right.
But if I place a figure more to the left or more to the top,
than the editors actually size, no scrollbars are shown, and the figures are just gone...
So it's probably about negative coordinates, but I've read that ScalableFreeformRootEditPart can handle negative coordinates
I hope you understand what I mean, if not, I'll post some screenshots...
I could not find anything in this forum or google about this topic,
altough I'm surprised that I'm the only one?!
Probably, I've just overseen something...
I'd appreciate any help...
Thanks in advance,
Tim
|
|
|
Re: ScalableFreeformRootEditPart negative coordinates [message #1016378 is a reply to message #1016282] |
Wed, 06 March 2013 09:58 |
Jan Krakora Messages: 477 Registered: December 2009 Location: Prague |
Senior Member |
|
|
Hi,
I use the ScalableFreeformRootEditPart too and it works nice with negative coordinates.
You have to do more research and provide more information to find out what's wrong.
Do you have fulfilled all it requirements? Namely:
- The contents editpart must provide a FreeformFigure as its figure
- The contents editparts FreeformFigure should have set the FreeformLayout
- The freeform root uses a FreeformViewport as its primary figure. This class must be used with the org.eclipse.gef.ui.parts.ScrollingGraphicalViewer. The viewport gets installed into that viewer's org.eclipse.draw2d.FigureCanvas, which provides native scrollbars for scrolling the viewport.
[Updated on: Wed, 06 March 2013 10:05] Report message to a moderator
|
|
|
|
|
Re: ScalableFreeformRootEditPart negative coordinates [message #1016391 is a reply to message #1016384] |
Wed, 06 March 2013 10:27 |
Tim E. Messages: 56 Registered: November 2012 |
Member |
|
|
Only this did not help, but I tried to set only to positive coordinates like this:
@Override
public IFigure createFigure() {
FreeformLayer ffl = new FreeformLayer();
FreeformLayout layout = new FreeformLayout();
layout.setPositiveCoordinates(true);
ffl.setLayoutManager(layout);
return ffl;
}
and now it works. The behavior is not the behavior I wanted to achieve,
but at least figures aren't lost at the moment.
Thanks a lot!
But, I still don't understand why there is no scrolling when I don't do
setPositiveCoordinates(true);
Cheers,
Tim
PS: sorry, the email notification did not show the whole content of your answer,
and I just responded, without reading it again in this forum.
The part about the requirements was not shown in the mail...
I'd have checked it, without posting the second post then...
[Updated on: Wed, 06 March 2013 10:38] Report message to a moderator
|
|
|
|
|
|
Re: ScalableFreeformRootEditPart negative coordinates [message #1016399 is a reply to message #1016396] |
Wed, 06 March 2013 11:08 |
Tim E. Messages: 56 Registered: November 2012 |
Member |
|
|
Thanks for your help:
I'm not allowed to post my complete code, but I'll post as much as possible.
Important parts of Editor:
public GenericGraphicsEditor() {
setEditDomain(new DefaultEditDomain(this));
}
@Override
protected void configureGraphicalViewer() {// called after constructor
super.configureGraphicalViewer();
getGraphicalViewer().setRootEditPart(new ScalableFreeformRootEditPart());
setupZoom();
setupPrinting();
}
@Override
protected void initializeGraphicalViewer() {// called after configureGV
refreshContents();
}
private void refreshContents() {
// parse model file
// setup resource tracking
// register listeners
// setContents
viewer.setContents(<main model element>);
}
Content EditPart
public abstract class AbstractDiagramMCGraphicalEditPart extends AbstractMCGraphicalEditPart implements IMCDiagramEditPart {
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ResizeMoveShapeEditPolicy());
}
@Override
public IFigure createFigure() {
FreeformLayer ffl = new FreeformLayer();
FreeformLayout layout = new FreeformLayout();
// layout.setPositiveCoordinates(true);
ffl.setLayoutManager(layout);
return ffl;
}
@Override
public boolean isSelectable() {
return false;
}
@Override
protected void refreshVisuals() {
super.refreshVisuals();
ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
if ((getViewer().getControl().getStyle() & SWT.MIRRORED) == 0) {
cLayer.setAntialias(SWT.ON);
}
}
}
Layout Policy:
public class ResizeMoveShapeEditPolicy extends XYLayoutEditPolicy {
@Override
protected Command getCreateCommand(CreateRequest request) {
// we don't create anything
return null;
}
@Override
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
if (!(child instanceof IMCViewElementEditPart)) {
System.err.println("ResizeMoveShapeViewElementEditPolicy> Error! ViewElement is not a IShapeViewElement: " + child);
return super.createChangeConstraintCommand(request, child, constraint);
}
IMCViewElementEditPart ep = (IMCViewElementEditPart) child;
IViewElement ve = ep.getViewElement();
if (!(ve instanceof IShapeViewElement)) {
System.err.println("ResizeMoveShapeViewElementEditPolicy> Error! EditPart is not a IMCViewElementEditPart: " + child);
return super.createChangeConstraintCommand(request, child, constraint);
}
Rectangle box = (Rectangle) constraint;
return new ResizeMoveShapeCommand((IShapeViewElement) ve, box.x, box.y, box.width, box.height, ep.getModel().toString());
}
@Override
protected Rectangle getCurrentConstraintFor(GraphicalEditPart child) {
// see bug:
// https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&id=349042
IFigure figure = child.getFigure();
Object constraint = figure.getParent().getLayoutManager().getConstraint(figure);
return constraint instanceof Rectangle ? (Rectangle) constraint : null;
}
}
The corresponding commands just apply the x,y,width,height values...
Cheers,
Tim
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05290 seconds