title: Determing size of visible area of a ScrollingGraphicalViewer in Eclipse GEF
body: <p>I am attempting to create a simple application using Eclipse GEF that displays a diagram inside a ScrollingGraphicalViewer. On start-up I want the diagram to be centered inside the viewer (imagine a star layout where the center of the star is in the center of the view).</p>
  
  <p>Here are what I think are the relevant code sections:</p>
  
  <p>My view:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class View extends ViewPart {
      public static final String ID = "GEFProofOfConcept.view";
  
  ...         
  
      public void createPartControl(Composite parent) {
          viewer.createControl(parent);
  
          viewer.setRootEditPart(rootEditPart);
          viewer.setEditPartFactory(editPartFactory);
  
          viewer.setContents(DummyModelCreator.generateModel());          
      }
  </code></pre>
  
  <p>The edit part code:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  protected void refreshVisuals() {
      Project project = (Project) getModel();
  
      // This is where the actual drawing is done,
      // Simply a rectangle with text
      Rectangle bounds = new Rectangle(50, 50, 75, 50);
      getFigure().setBounds(bounds);
      Label label = new Label(project.getName());
      projectFont = new Font(null, "Arial", 6, SWT.NORMAL);
      label.setFont(projectFont);
      label.setTextAlignment(PositionConstants.CENTER);
      label.setBounds(bounds.crop(IFigure.NO_INSETS));
  
      getFigure().add(label);
  
      setLocation();
  }
  
  private void setLocation() {
      Project project = (Project) getModel();
  
      if (project.isRoot()) {
          // Place in centre of the layout
          Point centrePoint = new Point(0, 0); // This is where I need the center of the view
          getFigure().setLocation(centrePoint);
      } else {
          ...
      }       
  }
  </code></pre>
  
  <p>And the parent of the above edit part:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class ProjectDependencyModelEditPart extends AbstractGraphicalEditPart {
  
  @Override
  protected IFigure createFigure() {
      Figure f = new FreeformLayer();
      f.setLayoutManager(new XYLayout());
  
      return f;
  }
  ...
  </code></pre>
  
  <p>Alternative solutions to the problem also welcome, I am most certainly a GEF (and Eclipse in general) newbie.</p>