e4 - removing elements from the application model

主宰稳场 提交于 2019-12-25 03:27:19

问题


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.

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();
                }
            }
            ...
    }

回答1:


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

findElement finds a single element with a given id:

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

There are several flavors of findElements, the simplest is:

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

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);

you may also need to call element.setToBeRendered(false)

Note for an MPart you can use EPartService.hidePart.



来源:https://stackoverflow.com/questions/28040312/e4-removing-elements-from-the-application-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!