4

I have been trying to solve this for the past 2 days with no luck. I went through pages upon pages of solutions that all look correct, but either my implementation is wrong or they aren't they right solutions.

I have created a new Toolbar called AddEditDelete. Then I proceeded to add Actions to it:

Here is the AddAction.java

@ActionID(category = "Edit",
id = "com.waudware.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) {
        //TODO: Code here
    }
}

I also have EditAction.java and DeleteAction.java - they were all created as "Always Enabled".

What I have been trying to do is this: When you click on the Add button on the toolbar, it will execute the code in the AddAction.java AND disable EditAction.java (Gray out the action buttons so they are unclickable).

After 2 days of trying to figure out how to do this, I am completely lost and almost sure its impossible. NetBeans dev forums have been unhelpful so far.

Edit: My question is quite specific and simple: What would be the correct (even if it is a bad practice) approach to disabling EditAction.java from AddAction.java -So far I have tried using Lookup, CookieSet, Direct calls, Action instantiation, and the only thing I got that was remotely what I wanted is

ToolbarPool.getDefault().findToolbar("AddEditDelete").setEnabled(false);

which hides the whole toolbar, but not individual actions(icons) on it.

Metal Wing
  • 525
  • 1
  • 11
  • 22
  • @AndrewThompson My question is quite specific and simple: What would be the correct approach to disabling EditAction.java from AddAction.java -So far I have tried using Lookup, CookieSet, Direct calls, Action instantiation, and the only thing I got that was remotely what I wanted it ToolbarPool.getDefault().findToolbar("AddEditDelete").setEnabled(false) - which hides the whole toolbar. – Metal Wing May 18 '12 at 15:37

1 Answers1

3

See Toolbar.getComponents() instead.

Component components = ToolbarPool.getDefault().
    findToolbar("AddEditDelete").getComponents();
for (Component component : components) {
    component.setEnabled(false);
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • !! I was so close! My last attempt I tried printing out a list of components by doing ToolbarPool.getDefault(). findToolbar("AddEditDelete").list(); - but I didn't realize I could use Component array to disable the buttons. To be honest, it is probably because I never thought of the AddAction, EditAction as being Components. I kept thinking that it is either an Action (which didn't seem right when I tried putting it into Action array). Your solution works! I assume now I can just reference components by their index number and disable selectively! – Metal Wing May 18 '12 at 15:54