我正在制作一个基于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/