Why figures do not display? [message #1385756] |
Tue, 10 June 2014 22:32  |
Eclipse User |
|
|
|
Hi, all,
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?
I briefly depict what I did, then paste my code.
1. model objects. In my model, there are two kinds of elements, directory and file. A directory may contain other directories or files. I default use Java File class for this purpose.
2. one figure object. I create one kind of figure for file, which can have nested figures for its chidren if the file is a directory. (This figure can display in a standalone Java application).
3. two editpart objects. one for file, the other for root.
public class FileEditPart extends AbstractGraphicalEditPart{
public FileEditPart(File file){
setModel(file);
}
@Override
protected IFigure createFigure() {
FileFigure figure = new FileFigure(((File)getModel()).getName(), null, null);
return figure;
}
@Override
public IFigure getContentPane() {
return ((FileFigure)getFigure()).getContentPane();
}
@Override
protected List<File> getModelChildren() {
if (getModel().isDirectory()){
return Arrays.asList(getModel().listFiles());
}
return new ArrayList<File>();
}
public File getModel(){
return (File)super.getModel();
}
}
public class RootEditPart extends AbstractGraphicalEditPart {
//root denotes the directory under which to show the file elements.
public RootEditPart(String root){
setModel(root);
}
@Override
protected IFigure createFigure() {
Figure figure = new FreeformLayer();
figure.setBorder(new MarginBorder(3));
figure.setLayoutManager(new FreeformLayout());
return figure;
}
@Override
protected List<File> getModelChildren() {
List<File> children = Arrays.asList(new File(getModel()).listFiles());
return children;
}
@Override
public String getModel() {
return (String) super.getModel();
}
}
4. an editpart factory object, for create each editpart object.
public class FileEditPartFactory implements EditPartFactory {
@Override
public EditPart createEditPart(EditPart context, Object model) {
if (model instanceof File){
return new FileEditPart((File)model);
}else if (model instanceof String){
return new RootEditPart((String)model);
}
return null;
}
}
5. a view to display the elements (figures). I use a DirectoryDialog for users to select a directory as the root.
public class GEFView extends ViewPart {
private Shell shell;
private ScrollingGraphicalViewer viewer;
@Override
public void createPartControl(Composite parent) {
viewer = new ScrollingGraphicalViewer();
viewer.createControl(parent);
viewer.getControl().setBackground(ColorConstants.white);
viewer.setRootEditPart(new ScalableFreeformRootEditPart());
viewer.setEditPartFactory(new FileEditPartFactory());
shell = parent.getShell();
shell.getDisplay().asyncExec(new Runnable(){
@Override
public void run() {
String file = new DirectoryDialog(shell).open();
if (file != null){
viewer.setContents(file);
}
}
});
}
@Override
public void setFocus() {
}
}
Anything missing? Any clues and comments will be appriciated.
Thanks.
|
|
|
|
|
|
Re: Why figures do not display? [message #1386045 is a reply to message #1385930] |
Fri, 13 June 2014 03:49  |
Eclipse User |
|
|
|
Robin Zhou wrote on Thu, 12 June 2014 12:11Thank you Stephan.
I extends the addChildVisual() to layout my figures.
Best regards.
This is not the right place, if the constraints might change dependent on your model. As already indicated, refreshVisuals() is intended for this purpose.
|
|
|
Powered by
FUDForum. Page generated in 0.03524 seconds