final Composite bottomComposite = new Composite(parent, SWT.NONE);
final GridData gd_bottomComposite = new GridData(SWT.FILL, SWT.FILL, true, true);
bottomComposite.setLayoutData(gd_bottomComposite);
bottomComposite.setLayout(new FillLayout());
graphicalViewer = new ScrollingGraphicalViewer();
graphicalViewer.createControl(bottomComposite);
graphicalViewer.setRootEditPart(new ScalableRootEditPart());
graphicalViewer.setEditPartFactory(new PartFactory());
//
FigureCanvas canvas = (FigureCanvas) graphicalViewer.getControl();
canvas.setBackground(ColorConstants.cyan);
canvas.setScrollBarVisibility(FigureCanvas.ALWAYS);
//
EditDomain domain = new EditDomain();
//domain.setActiveTool(new SelectionTool());
graphicalViewer.setEditDomain(domain);
File f=new File("。。。/11/11.gef");
InputStream is=null;
try {
is = new FileInputStream(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ContainerModel container = (ContainerModel) Xml.readXML(is);
graphicalViewer.setContents(container);
总结一下步骤:
1:需要创建ScrollingGraphicalViewer graphicalViewer = new ScrollingGraphicalViewer();
2:设置ScrollingGraphicalViewer的part工厂。 ( 核心。。。。)graphicalViewer.setEditPartFactory(new PartFactory());
3:设置EditDomain graphicalViewer.setEditDomain(domain);
4:设置Contents graphicalViewer.setContents(container);