Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Eclipse4中获取特定部件堆栈中的活动部件?_Java_Eclipse_Eclipse Rcp_E4 - Fatal编程技术网

Java 如何在Eclipse4中获取特定部件堆栈中的活动部件?

Java 如何在Eclipse4中获取特定部件堆栈中的活动部件?,java,eclipse,eclipse-rcp,e4,Java,Eclipse,Eclipse Rcp,E4,我有一个创建零件的按钮。我需要获取当前在部件堆栈中可见的活动部件,并将其存储为某个值的键。我应该如何获得活动部件? 我使用了下面的代码,但是它得到了partstack中的所有部分 MPart graphpart = partService .createPart("com.abc.xyz.project.partDescriptor.1"); MPartStack stack = (MPartStack) m

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

            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 graphpart=partService
.createPart(“com.abc.xyz.project.partDescriptor.1”);
MPartStack=(MPartStack)modelService.find(
“com.abc.xyz.project.partstack.2”,应用程序);
for(int i=0;i
我找到了答案。现在开始工作了

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);
            }
        }
for(int i=0;i

我们应该使用partservice来检查特定堆栈是否可见。

MPart
您可以直接使用以下工具获取其容器:

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

使用零件的父级及其所选元素也对我有效。partService.getActivePart()无法工作,因为在我们的应用程序中,我们有几个部件堆栈,我需要一个部件堆栈中的一个部件,而该部件堆栈当时不在焦点中。 我还必须将MUIElement转换为一个MPart,因为我需要返回一个MPart,这不是问题,因为MPart从MUIElement扩展而来。 这是我的密码:

这对于Eclipse E4来说非常简单:

  • 注入EPartService

  • 然后从零件服务获取活动零件

  • 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;
        }
    
    }
    
    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;
        }
    
    }