Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » ScalableFreeformRootEditPart negative coordinates
ScalableFreeformRootEditPart negative coordinates [message #1016282] Tue, 05 March 2013 19:48 Go to next message
Tim E. is currently offline Tim E.Friend
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 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
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 #1016381 is a reply to message #1016378] Wed, 06 March 2013 10:11 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
Hi,

thanks for your answer. I would provide more information,
if I would know, which information Smile

This is the part of my Editor:
  public GenericGraphicsEditor() {
    setEditDomain(new DefaultEditDomain(this));
  }
  
  @Override
  protected void configureGraphicalViewer() {// called after constructor
    super.configureGraphicalViewer();
    
    getGraphicalViewer().setRootEditPart(new ScalableFreeformRootEditPart());
    
    setupZoom();
    setupPrinting();
  }


And the diagram editpart (the editpart for the top element of my model) creates its
figure as follows:
  @Override
  public IFigure createFigure() {
    FreeformLayer ffl = new FreeformLayer();
    ffl.setLayoutManager(new XYLayout());
    return ffl;
  }


Is there something wrong about this?

[Updated on: Wed, 06 March 2013 10:15]

Report message to a moderator

Re: ScalableFreeformRootEditPart negative coordinates [message #1016384 is a reply to message #1016381] Wed, 06 March 2013 10:16 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
try ffl.setLayoutManager(new FreeformLayout());
Re: ScalableFreeformRootEditPart negative coordinates [message #1016391 is a reply to message #1016384] Wed, 06 March 2013 10:27 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
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. Smile

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 #1016392 is a reply to message #1016391] Wed, 06 March 2013 10:39 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
@Override
protected IFigure createFigure() {
	FreeformLayer layer = new FreeformLayer();
	layer.setLayoutManager(new FreeformLayout());
	return layer;
}


This works fine. There must be another problem somewhere.
Try to comment your code to absolute working minimum and then uncomment it step by step until you find where is the problem.
Re: ScalableFreeformRootEditPart negative coordinates [message #1016395 is a reply to message #1016392] Wed, 06 March 2013 10:52 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
That sounds like a lot of work Smile

But I can't really think of where to start, since I only use
the ScalableFreeformRootEditPart and the FreeformLayout and never
change it, or customize some behavior.

I have no clue, how this is possible....
So if you have any ideas, let me know Smile

Thanks again,
Tim
Re: ScalableFreeformRootEditPart negative coordinates [message #1016396 is a reply to message #1016395] Wed, 06 March 2013 10:58 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
It's hard to say. But I can't help you when I don't know where is the problem.

Post here your graphical editor, contents editPart and its layout policy.
Re: ScalableFreeformRootEditPart negative coordinates [message #1016399 is a reply to message #1016396] Wed, 06 March 2013 11:08 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
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
Re: ScalableFreeformRootEditPart negative coordinates [message #1016402 is a reply to message #1016399] Wed, 06 March 2013 11:20 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Looks good to me. Did you try to debug what bounds is set on a child figure when it's moved to the negative space?
Re: ScalableFreeformRootEditPart negative coordinates [message #1016404 is a reply to message #1016402] Wed, 06 March 2013 11:24 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
Yes, I did and they seemed to be correct.

The only thing is, that as soon as at least one of the coordinates is negative,
the figure is drawn out of the FreeformLayer bounds, and no scrolling or other kind of adjustments happens...
Re: ScalableFreeformRootEditPart negative coordinates [message #1016408 is a reply to message #1016404] Wed, 06 March 2013 11:35 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, I have no idea. You'll need to figure it out alone.

If you find an answer, let me know.
Re: ScalableFreeformRootEditPart negative coordinates [message #1016412 is a reply to message #1016408] Wed, 06 March 2013 11:42 Go to previous message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
Thanks for your help, anyway..

I'll let you know, as soon as I figured it out, if I figure it out Smile
Previous Topic:How to add new Layers and show specific figures in Them?
Next Topic:GEF 3.9 and Eclipse 4
Goto Forum:
  


Current Time: Thu Mar 28 13:50:23 GMT 2024

Powered by FUDForum. Page generated in 0.04711 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top