문제

부품을 만드는 버튼이 있습니다.나는 현재 가치있는 부분에 현재 볼 수있는 활성 부분을 가져와야하며 일부 가치의 키로 저장하고 있습니다.어떻게 활성 부분을 얻어야합니까? 나는 다음과 같은 코드를 사용했지만, 그것은 파트 스타 켓의 모든 부분을 얻고있다.

            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 ()는 우리의 응용 프로그램에서 여러 개의 파트 스택을 가지고 있으며, 그 순간에 초점이없는 부품 스택에서 부품이 필요했습니다. MPART는 MuiElement에서 확장되기 때문에 MPART를 반환해야하기 때문에 MPART를 반환해야하기 때문에 MUIEEEMEMENE을 MPART로 던져야했습니다. 다음은 내 코드가 있습니다.

나는 그 대답을 발견했다.지금 그것의 일하고 있습니다.

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

특정 스택을 확인하기 위해 부품 서비스를 사용해야합니다.

이것은 Eclipse E4와 함께 꽤 간단합니다.

  1. epartservice

  2. 를 주입합니다.

  3. 그런 다음 Paresservice에서 활성 부분을 얻습니다.

  4. Hier는 새로 고침 핸들러의 샘플입니다.

    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