1

I have a callback action called AddAction. When AddAction is pressed I want it to enable all the components on the TopComponent as well as disable several of the other actions on the toolbar. Then when the SaveAction is pressed it saves the data to the database, enables the other actions and disables all the components on the TC.

Right now I have AddAction setup to enable all the components but I can't figure out how to disable the other actions as well.

AddAction

@ActionID(
    category = "1",
id = "com.waudware.Actions.AddAction")
@ActionRegistration(
    iconBase = "com/waudware/Actions/Icons/add.png",
    displayName = "#CTL_AddAction",
    key = "AddAction")
@ActionReferences({
    @ActionReference(path = "Menu/Record", position = 3333),
    @ActionReference(path = "Toolbars/AddEditDelete", position = 100)
})
@Messages("CTL_AddAction=Add")
public final class EditAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
    }
}

TopComponent

public RouteTopComponent() {
        initComponents();
        setName(Bundle.CTL_RouteTopComponent());
        setToolTipText(Bundle.HINT_RouteTopComponent());

        getActionMap().put("AddAction", new AbstractAction(){
            @Override
            public void actionPerformed(ActionEvent e) {
                addRoute(true);
            }
        });
}

private void addRoute(boolean add) {
        txtRoute.setEnabled(add);
    }
4

2 回答 2

2
于 2013-01-17T21:48:13.260 回答
0

我所做的:

getActionMap().get("AddAction").setEnabled(true | false);

您还可以启用/禁用/隐藏整个工具栏

Toolbar toolbar;

toolbar = ToolbarPool.getDefault().findToolbar("toolbarName");
if (toolbar != null) {
    toolbar.setVisible(true | false);    // show / hide
    toolbar.setEnabled(true | false);    // enable / disable
}
于 2013-07-04T20:23:38.160 回答