eclipse - 如何限制Eclipse e4窗口的最小尺寸

标签 eclipse window size minimum e4

我正在制作一个基于Eclipse e4框架的应用程序。我想知道如何控制应用程序窗口的最小尺寸。似乎没有可以在 e4xmi 文件中为此目的定义属性。

有人知道怎么做吗?

我在 Eclipse 社区论坛 ( http://www.eclipse.org/forums/index.php/t/244875/ ) 中发现了一个帖子,说可以通过创建我自己的渲染器来实现。我怎样才能准确地做到这一点?

非常感谢:)

最佳答案

假设您正在使用内置的 SWT 渲染器,您还可以监听 E4 MWindow 元素的创建并获得对底层 SWT Shell 的访问。在此示例中,监听器在 AddOn 中注册,您可以将其添加到 e4xmi。

import javax.annotation.PostConstruct;

import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.swt.widgets.Shell;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

public class MinSizeAddon {
    @PostConstruct
    public void init(final IEventBroker eventBroker) {
        EventHandler handler = new EventHandler() {
            @Override
            public void handleEvent(Event event) {
                if (!UIEvents.isSET(event))
                    return;

                Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
                if (!(objElement instanceof MWindow))
                    return;

                MWindow windowModel = (MWindow)objElement;
                Shell theShell = (Shell)windowModel.getWidget();
                if (theShell == null)
                    return;

                theShell.setMinimumSize(400, 300);
            }
        };
        eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, handler);
    }
}

请注意,这将为应用程序中的任何 MWindow 执行,并且可以有更多个 MWindow(即,当 MPart 从 MPartStack 分离到单独的窗口时)。如果你想限制执行到特定的MWindows,我建议在e4xmi中的窗口中添加一个标签,并在设置最小大小之前检查这个标签。

关于eclipse - 如何限制Eclipse e4窗口的最小尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15894393/

相关文章:

java - Eclipse IDE : How to know exact jar file for classes loaded at runtime?

c++ - 在cpp中创建Maya UI窗口

ios - 如何降低 UILabel 文本字体的重量?

python-3.x - 在安装python 3.5时调用此安装程序时,必须提供获取targetdir变量

delphi - Delphi中如何获取屏幕的可用坐标

assembly - 汇编语言的自动代码去重?

eclipse - 如何在dockerfile中包含本地语言服务器并从中构建docker镜像?

eclipse - 通过Eclipse连接手机调试时如何安全断开手机?

python - 无法在 Eclipse 中创建 python View

c++ - Qt - MDI Child 未正确关闭