简体   繁体   English

通过添加Title Eclipse 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. 我想在编辑器的画布顶部添加一个标题,该标题是我在Eclipse中使用GMF生成的。 Can someone please direct me as to what changes I need to make to the generated code so as to achieve that? 有人可以指导我我需要对生成的代码进行哪些更改以实现该目标吗? Thanks 谢谢

Add the title using SWT controls rather than GEF/GMF constructs. 使用SWT控件而不是GEF / GMF构造添加标题。

Inside GEF's package org.eclipse.gef.ui.parts Look at classes: GraphicalEditor (no palette, just diagram viewer) GraphicalEditorWithPalette (diagram viewer + palette with a help of SWT Splitter) GraphicalEditorWithFlyoutPalette (same as above with ability to hide the palette) 在GEF的org.eclipse.gef.ui.parts包中查看类:GraphicalEditor(无调色板,仅是图表查看器)GraphicalEditorWithPalette(图表查看器+借助SWT Splitter进行的调色板)GraphicalEditorWithFlyoutPalette(与上述功能相同,可以隐藏调色板)

Note how palette is added to the editor. 注意如何将调色板添加到编辑器。 Something like that needs to be done to show the title. 需要执行类似的操作才能显示标题。

My advice is subclass GraphicalEditorWithFlyoutPalette, override #createPartControl(...) method to arrange diagram graphical viewer, palette viewer and title viewer. 我的建议是子类GraphicalEditorWithFlyoutPalette,重写#createPartControl(...)方法来安排图表图形查看器,调色板查看器和标题查看器。 TitleViewer can be a subclass of DiagramGraphicalViewer that just displays one editpart - the diagram, the figure for which is being a label. TitleViewer可以是DiagramGraphicalViewer的子类,该子类仅显示一个editpart-图表,该图表的图形是标签。 Alternatively you can just use SWT Label instead of TitleViewer (which you'd need to create yourself). 另外,您可以只使用SWT Label而不是TitleViewer(您需要自己创建)。 You'd have to provide model listening logic in this case to update the label's text for model changes if applicable. 在这种情况下,您必须提供模型侦听逻辑以更新标签的文本以进行模型更改(如果适用)。

Here is the code snippet for you that adds an SWT label at the top of Graphical Viewer for GEF's Logic Example editor. 这是为您提供的代码段,在GEF的Logic Example编辑器的Graphical Viewer的顶部添加了SWT标签。 Yopu can easily do the same for the GMF editor because GMF's DiagramEditor has been created based on GEF's LogicEditor. 由于GMF的DiagramEditor是基于GEF的LogicEditor创建的,因此Yopu可以轻松地对GMF编辑器执行相同的操作。

I have modified the following methods in GEF's LogicEditor: 我已经在GEF的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) 除了所做的更改外,我还删除了LogicEditor中这些方法的先前实现,并用ruleComp为LogicEditor#configureGraphicalViewer()方法替换了对getGraphicalControl()的调用(最后添加了2个SWT侦听器)

Result on the screenshot below. 结果显示在下面的屏幕截图中。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM