e4-从应用程序模型中删除元素 [英] e4 - removing elements from the application model

查看:83
本文介绍了e4-从应用程序模型中删除元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改现有的 e4应用程序模型。在我的修改中,我想删除应用程序模型中的一些元素。例如。零件,菜单等。我有唯一的UI-Element-Id。我该如何最好地利用此信息从应用程序模型中删除某些元素。

I want to modify an existing e4 Application Model. In my modification I want to remove some elements inside the Application Model. E.g. Parts, Menu and so on. I am having the unique UI-Element-Id. How can I best remove some elements from the Application Model with this information.

目前,我将使用 MApplication 类,并查看每个子代以及子代中的每个子代,如果有很多带有UI-Element-Id的匹配项。

At this time, I am going to use the MApplication class, and look at every children and children of the children, if there are many matches with an UI-Element-Id. But this approach is nasty I think.

    public void modifyApplikationModel(String uiElementId) {
            if (uiElementId == null || uiElementId.trim().equals("")) {
                return;
            }       
            //application is injected
            List<MAddon> addons = application.getAddons();
            Iterator<MAddon> addonIterator = addons.iterator();
            while (addonIterator.hasNext()) {
                MAddon addon = addonIterator.next();
                if (uiElementId.equals(addon.getElementId())) {
                    addonIterator.remove();
                }
            }
            ...
    }


推荐答案

您可以使用 EModelService findElement findElements 方法来搜索模型元素。

You can use the EModelService findElement or findElements methods to search for model elements.

findElement 查找带有一个元素的单个元素。给定的ID:

findElement finds a single element with a given id:

MUIElement element = modelService.findElement("id", application);

findElements 有几种风格,最简单的方法是:

There are several flavors of findElements, the simplest is:

List<MPart> parts = modelService.findElements(application, "id", MPart.class, Collections.emptyList());

在两种情况下应用程序都可以是 MApplication 或您要从中开始搜索的任何其他元素。

in both case application can be the MApplication or any other element you want to start the search from.

找到元素后,可以将其删除

Once you have found your element you can remove it from the parent:

MElementContainer<MUIElement> parent = element.getParent();

parent.getChildren().remove(element);

您可能还需要调用 element.setToBeRendered(false)

对于 MPart 的注释,可以使用 EPartService.hidePart

Note for an MPart you can use EPartService.hidePart.

这篇关于e4-从应用程序模型中删除元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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