0

申請書の作成に 1 か月を費やした後、私は奇妙なことを発見しました。すべての TopComponents がある Viewer モジュールと、すべてのツールバー アクションを保持する MenuToolbar モジュールがあります。これが私の追加です:

package com.demo.toolbar;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionID;
import org.openide.util.NbBundle.Messages;

@ActionID(category = "Edit",
id = "com.demo.toolbar.AddAction")
@ActionRegistration(iconBase = "com/demo/toolbar/icons/add.png",
displayName = "#CTL_AddAction")
@ActionReferences({
    @ActionReference(path = "Toolbars/AddEditDelete", position = 1),
    @ActionReference(path = "Shortcuts", name = "D-A")
})
@Messages("CTL_AddAction=Add")
public final class AddAction implements ActionListener {

    public void actionPerformed(ActionEvent e) {
        //code here
    }
}

このショートカットは CTRL+A でアクティブになり、TopComponent を追加モードにします。CTRL+D コマンドでアクティブ化される DeleteAction もあります。人が CTRL + A を押すと、次のことが起こります。

List<Component> c = new ArrayList<Component>();
        c.addAll(Arrays.asList(ToolbarPool.getDefault().findToolbar("AddEditDelete").getComponents()));
if (mode.equals("add")) {
    for (Component component : c) {
        component.setEnabled(false);
        }
        c.get(13).setEnabled(true);
        c.get(14).setEnabled(true);
}

基本的に、ユーザーがツールバーの [追加] ボタンをクリックすると、他のすべてのボタン (削除を含む) が無効になるため、ユーザーは追加モードでこれらのアクションを実行できません。

ただし、CTRL+D を押して削除することはできます。これは大きなノーノーです...

この動作を修正するにはどうすればよいですか?

4

1 に答える 1

1

アクションを直接有効/無効にしないでください。アクション APIを見てください。CookieActionあなたが望むものかもしれません。アイデアは、Cookie (何らかのコンテキスト) をグローバル ルックアップに公開することです。Cookie 対応アクションは、Cookie の存在に応じて自動的に有効/無効になります。

実際、これが IDE の保存ボタンの仕組みです。エディターがSaveCookieグローバル コンテキストに a を置くと、ツールバー ボタンと Ctrl+S が有効になります。ここで説明したように

ステート マシンを使用して、Cookie の存在をクリーンな方法で制御することを検討してください。

于 2012-06-24T18:31:09.973 に答える