Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Why figures do not display?
Why figures do not display? [message #1385756] Wed, 11 June 2014 02:32 Go to next message
Jingang Zhou is currently offline Jingang ZhouFriend
Messages: 57
Registered: December 2010
Member
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 #1385883 is a reply to message #1385756] Thu, 12 June 2014 03:50 Go to previous messageGo to next message
Jingang Zhou is currently offline Jingang ZhouFriend
Messages: 57
Registered: December 2010
Member
After several days' trial, I found the figures can diaplay when I set size on these figures, e.g., in the method of editpart's 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.

Thanks.
Re: Why figures do not display? [message #1385896 is a reply to message #1385883] Thu, 12 June 2014 07:44 Go to previous messageGo to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

Overriding refreshVisuals() in your EditParts will do the trick. You will probably have to set the figures constraint relative to the parent EditPart as well, so for FileEditPart 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 width, and dto. for height.

[Updated on: Thu, 12 June 2014 07:45]

Report message to a moderator

Re: Why figures do not display? [message #1385930 is a reply to message #1385896] Thu, 12 June 2014 10:11 Go to previous messageGo to next message
Jingang Zhou is currently offline Jingang ZhouFriend
Messages: 57
Registered: December 2010
Member
Thank you Stephan.

I extends the addChildVisual() to layout my figures.

Best regards.

Re: Why figures do not display? [message #1386045 is a reply to message #1385930] Fri, 13 June 2014 07:49 Go to previous message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
Robin Zhou wrote on Thu, 12 June 2014 12:11
Thank 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.
Previous Topic:How to select figures in a ViewPart?
Next Topic:Add button to palette
Goto Forum:
  


Current Time: Tue Mar 19 06:40:40 GMT 2024

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

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

Back to the top