Como obter a parte ativa em um determinado partstack no eclipse e4?
-
21-12-2019 - |
Pergunta
Eu tenho um botão que cria peças.Eu precisa para obter a parte ativa que é visível no momento em que ele parte de pilha e eu estou armazenando-os como uma chave para algum valor.Como devo fazer a parte ativa?Eu tenho usado o seguinte código, mas ele está ficando todas as peças no 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);
}
}
Solução
A partir de uma MPart
você pode obter o seu recipiente diretamente com:
final MElementContainer<MUIElement> container = part.getParent();
(este será o MPartStack
)
Em seguida, você pode obter as pilhas atualmente selecionado criança com:
MUIElement selected = container.getSelectedElement();
Outras dicas
Usando o pai da peça e seu elemento selecionado também funcionou para mim.Partservice.getactivePart () não funcionou porque em nossa aplicação temos várias pilhas de parte e eu precisava de uma parte de uma pilha de parte que não estava em foco naquele momento. Eu também tive que lançar o Muielement para uma MPART porque eu precisava devolver um MPART, isso não era um problema, já que a MPART se estende do muielement. Aqui está o meu código:
Eu encontrei a resposta.Seu trabalho agora.
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);
}
}
Devemos fazer uso de partservice para verificar particular pilha está visível ou não.
Isso é muito simples, com o Eclipse E4:
Injetar o EPartService
Em seguida, começar a partir de partService a parte ativa.
Hier é uma amostra do meu 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;
}
}