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);
}
}
.
特定のスタックをチェックするためにParterServiceを利用する必要があります。
これはEclipse E4でかなり簡単です:
-
EPARTSERVICE
を注入する
-
その後、ApperServiceからアクティブな部分を取得します。
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