I am trying to create a simple application using the Eclipse GEF that displays a chart inside the ScrollingGraphicalViewer. At startup, I want the chart to be centered inside the viewer (imagine a star model where the center of the star is in the center of the view).
Here's what I think of the relevant sections of code:
My opinion:
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());
}
Editing Part Code:
@Override
protected void refreshVisuals() {
Project project = (Project) getModel();
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()) {
Point centrePoint = new Point(0, 0);
getFigure().setLocation(centrePoint);
} else {
...
}
}
And the parent part of the specified editing part:
public class ProjectDependencyModelEditPart extends AbstractGraphicalEditPart {
@Override
protected IFigure createFigure() {
Figure f = new FreeformLayer();
f.setLayoutManager(new XYLayout());
return f;
}
...
Alternative solutions to the problem are also welcomed; I am certainly a newbie to GEF (and Eclipse in general).
source
share