1

SWTbot API を使用して、Eclipse でコンポジットからテキストを取得しようとしています。メイン グループを含むコンポジットと、そのメイン グループに子グループを含むコンポジットがあります。
私が直面している問題は、コンポジット内のテキストを取得できないことです。Eclipse でそのテキストを取得する方法はありますか。
名前、最小バージョンなどのすべてのテキストを取得したいコンポジットの画像を添付しました。
助けてください。私のプロジェクトの一種のブロッカーです。 ここに画像の説明を入力

4

1 に答える 1

1

直接ではありませんが、次の方法で実行できます。

public getContainedText(Control c) {
    return getContainedText(c, new ArrayList<String>());
}

private getContainedText(Control c, List<String> strings) {
    if (c instanceof Label) {
        strings.add(((Label) c).getText();
    } else if (c instanceof Text) {
        strings.add(((Text) c).getText();
    }
    // and so on for other control types you want to handle
    // and for text you are interested in.
    // Or as an approximation, use reflection to check if
    // c has getText method and call it, but this will miss
    // List, Combo, etc.

    if (c instanceof Composite) {
        for (Control child : ((Composite) c).getChildren()) {
            getContainedText(child, strings);
        }
    }
}
于 2013-02-05T13:58:07.617 に答える