javaeclipseuser-interfaceeclipse-gmf

Customizing Editor Workbench by Adding Title Eclipse GMF


I want to add a title at the top of the canvas in my editor, that I generated using GMF in Eclipse. Can someone please direct me as to what changes I need to make to the generated code so as to achieve that? Thanks


Solution

  • Here is the code snippet for you that adds an SWT label at the top of Graphical Viewer for GEF's Logic Example editor. Yopu can easily do the same for the GMF editor because GMF's DiagramEditor has been created based on GEF's LogicEditor.

    I have modified the following methods in GEF's LogicEditor:

    private Composite graphicalControl;
    
    /*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.gef.ui.parts.GraphicalEditor#createGraphicalViewer(org.eclipse
     * .swt.widgets.Composite)
     */
    protected void createGraphicalViewer(Composite parent) {
        graphicalControl = new Composite(parent, SWT.None);
        graphicalControl.setLayout(new GridLayout());
    
        Label label = new Label(graphicalControl, SWT.None);
        label.setText("MY DIAGRAM NAME!!!");
        label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    
        rulerComp = new RulerComposite(graphicalControl, SWT.NONE);
        super.createGraphicalViewer(rulerComp);
        rulerComp
                .setGraphicalViewer((ScrollingGraphicalViewer) getGraphicalViewer());
        rulerComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    
    protected Control getGraphicalControl() {
        return graphicalControl;
    }
    

    In addition to that change i removed the previous implementations of these methods in LogicEditor and replaced call to getGraphicalControl() with rulerComp for LogicEditor#configureGraphicalViewer() method (a the end there are 2 SWT listeners added)

    Result on the screenshot below.

    enter image description here