-1

I create a ScrollingGraphicalViewer to show my figures, but no figure displays. I debugged the source and it seems all object (figures, editparts, models) are created, no exceptions. Why the figures do not display?

Since the code is larege and spread many Java files, I briefly depict what I did.

  1. creating model objects. In my model, there are two kinds of elements, directory and file. A directory may contain other directories or files.

  2. figure objects. I create two kinds of figures, one for directory, the other for file. the directory figure can have nested figures for nested directories and files.

  3. editpart objects. for each kind of model elements, i.e., directory and file, to connect relation between model and figures.

  4. an editpart factory object, for create each editpart object.

  5. create a ScrollingGraphicalViewer object (viewer). and invoke the following methods on viewer: viewer.createControl(), viewer.setRootEditPart(), viewer.setEditPartFactory, and viewer.setContents().

Anything missing? Any clues and comments will be appriciated.

Thanks.

zjg.robin
  • 95
  • 1
  • 5
  • After several days' trial, I found the figures can diaplay when I set size on these figures, e.g., in the method of createFigure(). But does it really need to do so? The example code of GEF does not. BTW: I set a preferredSize on the figure object during its construction. – zjg.robin Jun 12 '14 at 03:42
  • For questions related to GEF and display problems, it is very helpful to see the full code for at least the `EditPart`s that are affected. – s.d Jun 12 '14 at 07:52

1 Answers1

0

Overriding refreshVisuals() in your EditParts will do the trick. This is the correct place to react to constraint changes as dictated by your model. You will have to set the figures constraint relative to the parent EditPart (and its figure's FreeformLayout) as well, so for FileEditPart (cf. cross-posting on the Eclipse GEF Forum) do something like the following in refreshVisuals().

getParent().setLayoutConstraint(this, figure, layout);

layout here will have to be a draw2d Rectangle. You can calculate that by giving it x and y values, and getFigure().getPreferredSize().width for the layout.width, and dto. for height.

For basic GEF usage - of which this is a case - I'd suggest you have a look at Rubel et al.'s GEF Book.

s.d
  • 4,017
  • 5
  • 35
  • 65