如何限制Eclipse e4的最小窗口大小 [英] How to restrict the minimum size of the window for Eclipse e4

查看:69
本文介绍了如何限制Eclipse e4的最小窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个基于Eclipse e4框架的应用程序.我想知道如何控制应用程序窗口的最小大小.为此,似乎无法在e4xmi文件中定义属性.

I am making an application based on Eclipse e4 framework. I was wondering how the minimal size of the application window can be controlled. There seems no properties can be defined in e4xmi file for this purpose.

有人知道怎么做吗?

我在Eclipse社区论坛中找到了一个主题( http://www.eclipse.org/forums/index.php/t/244875/)表示,可以通过创建自己的渲染器来实现.我该怎么做呢?

I found a thread in Eclipse Community Forum (http://www.eclipse.org/forums/index.php/t/244875/) saying it can be achieved by creating my own renderer. How can I do that exactly?

非常感谢:)

推荐答案

假定您正在使用内置的SWT渲染器,您还可以侦听E4 MWindow元素的创建并获得对基础SWT Shell的访问权限.在此示例中,侦听器在一个AddOn中注册,您可以将其添加到e4xmi.

Assuming you are using the built-in SWT Renderers, you can also listen for the creation of your E4 MWindow elements and gain access to the underlying SWT Shell. In this example the listener is registered in an AddOn, which you can add to your 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执行,并且可以有更多(例如,当MPart从MPartStack分离到单独的窗口中时).如果要将执行限制为特定的MWindows,建议您在e4xmi的窗口中添加一个标签,并在设置最小大小之前检查该标签.

Note, that this will be executed for any MWindow in your application, and there can be more of them (i.e. when an MPart is detached from the MPartStack into a seperate window). If you want to limit the execution to specific MWindows, I recommend to add a tag to the window in the e4xmi and check for this tag before setting the minimum size.

这篇关于如何限制Eclipse e4的最小窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆