我有一个创建零件的按钮。我需要获取当前在他零件堆栈中可见的活动部分,我将其存储为某个值的键。我应该如何获得活跃的部分? 我使用了以下代码,但它是在零件中获取所有部分。

            MPart graphpart = partService
                    .createPart("com.abc.xyz.project.partDescriptor.1");
            MPartStack stack = (MPartStack) modelService.find(
                    "com.abc.xyz.project.partstack.2", application);

            for (int i = 0; i < stack.getChildren().size(); i++) {
                if (stack.getChildren().get(i).isVisible()) {
                    System.out.println("values"
                            + ((MPart) stack.getChildren().get(i)).getLabel());
                    application.getTransientData().put(
                            ((MPart) stack.getChildren().get(i)).getLabel(),
                            selectedFiles);
                }
            }
.

有帮助吗?

解决方案

从一个MPart,您可以直接使用:

final MElementContainer<MUIElement> container = part.getParent();
.

(这将是MPartStack

然后,您可以使用:

获取当前所选的堆栈
MUIElement selected = container.getSelectedElement();
.

其他提示

使用部分的父级及其所选元素也为我工作。Partservice.getActivePart()不起作用,因为在我们的应用程序中,我们有几个部分堆栈,我需要一个部分堆栈的零件堆栈,这些堆栈在那一刻没有焦点。 我也必须将MuiElement投入MPART,因为我需要返回一个MPART,这不是问题,因为MPART从MUIElement扩展。 这是我的代码:

我找到了答案。它现在的工作。

for (int i = 0; i < stack.getChildren().size(); i++) {
                        if (partService.isPartVisible((MPart) stack.getChildren().get(i))) {

                System.out.println("Storage of values"
                        + ((MPart) stack.getChildren().get(i)).getLabel());
                application.getTransientData().put(
                        ((MPart) stack.getChildren().get(i)).getLabel(),
                        selectedFiles);
            }
        }
.

我们应该使用零件服务来检查特定堆栈是否可见。

这非常简单,E2:

  1. 注入epartservice

  2. 然后

    然后从零件服务部分获得。

    HIER是我的refreshHandler的样本。

    public class RefreshHandler {
    
        @Inject
        EModelService modelService;
        @Inject
        MWindow window;
        @Inject
        IEventBroker broker;
        @Inject
        EPartService partService;
    
    
        @Execute
        public void execute() {
            System.out.println(this.getClass().getSimpleName() + " called");
            MPart activePart = partService.getActivePart();
    
            if(activePart != null) {
                System.out.println("--->" + activePart.getElementId());
            }
        }
    
        @CanExecute
        public boolean canExecute() {
            MPerspective activePerspective = modelService.getActivePerspective(window);
            if (activePerspective != null && activePerspective.getElementId()
                    .equals(IApplicationUIElementID.PERSPECTIVE_WORKINGSTORE_ID)) {
                return true;
            }
            return false;
        }
    
    }
    
    .

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top