2

Eclipse プラグイン ビュー チュートリアルに基づいて、簡単なビューを作成しました。プラグインがデバッガーの変更をリッスンできるようにする機能を追加しました。私の問題は、デバッガーで何かが発生するたびに、ビューを更新して新しい情報で更新することです。ここに私が持っているもの/私が試しているものがあります:

    public void createPartControl(Composite parent) {

        listener = new DebugContextListener(this);
        DebugUITools.getDebugContextManager().addDebugContextListener(listener);

        // Check if there is an already started debug context
        IAdaptable dc = DebugUITools.getDebugContext();
        if (dc != null) {
                dataCollection.add(new ProxyScope("hi")); // manually injecting data 
                Object o = dc.getAdapter(IStackFrame.class);
                if (o instanceof IStackFrame)
                        setStackFrame((IStackFrame) o);

                viewer.refresh(); // this doesn't work
        }       


        viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);

        // Set column lines visible, and create two columns
        Tree tree = viewer.getTree();
        tree.setHeaderVisible(true);
        tree.setLinesVisible(true);

        TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
        column1.setText("Name");
        column1.setWidth(400);
        TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
        column2.setText("Value");
        column2.setWidth(200);

        drillDownAdapter = new DrillDownAdapter(viewer);
        viewer.setContentProvider(new VariableViewContentProvider());
        viewer.setLabelProvider(new VariableViewLabelProvider());
        viewer.setSorter(new ViewerSorter());
        viewer.setInput(getViewSite());

....

}

基本的に、このデバッグ リスニング ロジックはすべて上部にあり、if ステートメント内で発生します。私のプログラムがそこに入るという事実を私は知っています。何かが変わるたびに、ビューを更新したいのですが、viewer.refresh を実行しようとしましたが、うまくいきません。ビューに表示される情報は、dataCollection オブジェクトに基づいているため、dataCollection.add... の行は、デバッガーが何かを行ったかのように手動でデータを追加するだけです。その行を if ステートメントの外に置くと、ビューは機能します (これは、プラグインを最初に起動したときのビューの元の構成にすぎないと思います) が、if ステートメントの中に入れると機能しません。 、私のビューが更新されないことを意味します。

助けてくれてありがとう。

4

3 に答える 3

4

createPartControls is that time of the life cycle of a view, where its contained widgets are created (when the view becomes visible initially). This code is only executed once during the view life cycle, therefore you cannot add anything here directly to refresh your view.

Eclipse parts typically update their content as a reaction to a changed selection inside of the workbench (e.g. the user might click on another stack frame in the debug view). I'm not sure if that already completely fulfills your needs, but it's a good start for sure and described well in the Eclipse FAQ.

于 2012-07-06T03:52:29.280 に答える
0

tableViewerでも同様の問題があります。あるケースでは、単純なviewer.refresh()が機能しましたが、別のケースでは、それほど「美しく」ないソリューションを取得する必要がありました。

私が今持っている解決策は、viewer.setInput(null)で入力をnullに設定してから、更新されたデータを再度設定することではありません。大量のデータがないため、これは一時的に発生します。そうしないと、すべての変更での作成のオーバーヘッドが実現できない可能性があります。

よりクリーンな解決策を見つけたら、投稿します。

于 2012-07-06T22:11:11.637 に答える
0

Bananeweizen の回答のおかげで、おそらくもっと良い方法があるかもしれませんが、必要なことと同様のコードをハックすることができました。選択イベントが発生したときにリッスンする ISelectionListener を追加しました (これはグローバル変数として ViewPart クラスに入ります)。

ISelectionListener selectionListener = new ISelectionListener() {
    public void selectionChanged(IWorkbenchPart part, ISelection sel) {
       if (!(sel instanceof IStructuredSelection))
           return;
       IStructuredSelection ss = (IStructuredSelection) sel;

       if(sel.toString().contains("org.eclipse.jdt.internal.debug.core.model")){
           viewer.setInput(getSite());
       }
    }
 };

したがって、デバッグ ボタンのいずれかをクリックすると、ビューが更新されます。setInput は基本的に、ビュー内でテーブルを形成する方法の特定の実装を提供する ContentProvider で getElements() を呼び出します。

于 2012-07-06T23:04:07.087 に答える