Eclipse E4의 특정 부분적으로 활성 부분을 얻는 방법은 무엇입니까?
-
21-12-2019 - |
문제
부품을 만드는 버튼이 있습니다.나는 현재 가치있는 부분에 현재 볼 수있는 활성 부분을 가져와야하며 일부 가치의 키로 저장하고 있습니다.어떻게 활성 부분을 얻어야합니까? 나는 다음과 같은 코드를 사용했지만, 그것은 파트 스타 켓의 모든 부분을 얻고있다.
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();
. 다른 팁
나는 그 대답을 발견했다.지금 그것의 일하고 있습니다.
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와 함께 꽤 간단합니다.
-
epartservice
를 주입합니다.
-
그런 다음 Paresservice에서 활성 부분을 얻습니다.
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;
}
}
.제휴하지 않습니다 StackOverflow