Eclipse E4の特定のパートスタックでアクティブな部分を取得する方法

StackOverflow https://stackoverflow.com//questions/24017374

  •  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();
.

他のヒント

部品の親を使って、その選択された要素も私のために働きました。私たちのアプリケーションではいくつかの部品スタックがあるため、ParterVice.getActivePart()が機能しませんでした。 MPARTはMUIElementから拡張されているため、MPARTを返却する必要があるため、MUIElementを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);
            }
        }
.

特定のスタックをチェックするためにParterServiceを利用する必要があります。

これはEclipse E4でかなり簡単です:

  1. EPARTSERVICE

  2. を注入する

  3. その後、ApperServiceからアクティブな部分を取得します。

  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