2

EclipseとSWTを使用して、私は現在、CommandContributionItem(CCI)を2つのテキストフィールドを持つButtonに取得しようとしています。ViewPartボタンを押すParameterizedCommandと、テキストフィールドの現在のテキスト値をパラメータとして使用して呼び出されるはずです。

次のように、テキストフィールドの初期値をCCIに渡すことができました。

public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    text = new Text(parent, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    text_1 = new Text(parent, SWT.BORDER);
    text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Map<String, String> params = new HashMap<String, String>();
    params.put("myString", text.getText());
    params.put("mySecondString", text_1.getText());

    CommandContributionItemParameter p = new CommandContributionItemParameter(getSite(),
            "commandSyso","com.voo.example.commandparameter.simple.sysoCommand",  CommandContributionItem.STYLE_PUSH);
    p.label = "My Label";
    p.parameters = params;
    CommandContributionItem item = new CommandContributionItem(p);
    item.fill(parent);
}

ただし、これは静的な1回限りのパスです。CCIが呼び出されるたびにこれを動的に更新する方法はありますか?

4

1 に答える 1

1

CommandContributionItemパラメータは本質的に静的です。それらを変更することはできません。の新しいインスタンスを作成するだけですCommandContributionItem

コマンドを操作する場合、の実装は。IHandlerを使用して現在の選択を探す必要がありますExecutionEvent.getApplicationContext()。の場合IEvaluationContext、選択は次を使用して取得できますorg.eclipse.ui.handlers.HandlerUtil

しかし、あなたの例では、2つのテキストフィールドの値をフレームワークに提供する方法が必要になります。これは、、、(新しい名前で各テキストフィールドを提供できる場合)を実装するか、ハンドラーに次のことを確認させることによって行いますISelectionProvider。次に、アクセサを介して情報にアクセスしますISourceProviderIViewPart

于 2012-08-20T19:42:16.323 に答える