This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 152529 - NewAction.getToolbarPresenter() returns toolbar component with wrong text
Summary: NewAction.getToolbarPresenter() returns toolbar component with wrong text
Status: RESOLVED INVALID
Alias: None
Product: platform
Classification: Unclassified
Component: Actions (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: Stanislav Aubrecht
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-06 12:51 UTC by mgoe
Modified: 2009-09-23 15:53 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Module suite project showing the issue (6.00 KB, application/x-gzip)
2009-09-23 10:49 UTC, mgoe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mgoe 2008-11-06 12:51:59 UTC
The toolbar component returned from NewAction.getToolbarPresenter() does not always show the correct action name. I 
think the cause for this problem is, that NewAction does not overwrite the method getToolbarPresenter() from its base 
class CallableSystemAction like it does for the methods getMenuPresenter() and getPopupPresenter(). Since the type of 
object created by the NewAction can change, this has to be reflected by the texts shown for menu and toolbar. 
Currently it is only correct for the menu entry.
Comment 1 Stanislav Aubrecht 2008-12-04 12:38:20 UTC
the problem is that NewAction doesn't fire property change when its name changes so the default toolbar presenter
(JButton) doesn't change the display name either.
Comment 2 Jiri Rechtacek 2009-09-22 16:00:37 UTC
Could you attach a test case (or a symptom in IDE if any)? Thanks
Comment 3 mgoe 2009-09-23 10:48:19 UTC
I created a small module suite project (with Netbeans 6.8M1) which shows the strange handling of the Action.NAME 
property of a NewAction. The module suite has a TopComponent with a JToolBar. Three components (beside two explanation 
labels) have been added to the toolbar.
- The first component is a NewAction with an Action.Name property set. This property isn't honored at all (no text is 
displayed).
- The second component is the return value of NewAction.getToolbarPresenter(). For this component the text "Add" is 
displayed. The Action.Name property is used for the tooltip (which is questionable because for normal swing actions 
the property Action.SHORT_DESCRIPTION is used to set the tooltip text).
- The third component is an AbstractAction extension (SetNameAction) which allows to set the Action.Name property of 
the NewAction. The tooltip on the SetNameAction will show which string will be used next to set the Action.Name 
property. If you invoke the SetNameAction the only thing that changes is the tooltip text of the component returned by 
NewAction.getToolbarPresenter().

Best regards,
Martin

By the way: NewAction.setEnabled(true) isn't honored too
Comment 4 mgoe 2009-09-23 10:49:13 UTC
Created attachment 88170 [details]
Module suite project showing the issue
Comment 5 Jiri Rechtacek 2009-09-23 11:09:51 UTC
Thanks for information. I'm evaluating it...
Comment 6 Jiri Rechtacek 2009-09-23 15:17:44 UTC
Reassigned to Standa who known more about the problem.
Comment 7 Stanislav Aubrecht 2009-09-23 15:53:01 UTC
there are several problems in the attached sample module but none of them is a netbeans bug:)

- method JToolBar.add( Action ) creates a JButton and hides the button text if the action has both small and large
icons. which is the case for NewAction, even though the icons are just empty rectangles. therefore there nothing visible
for the first toolbar button. try JToolBar.add( new JButton( myNewAction ) ) instead

- NewAction.setEnabled( true ) has no effect because NewAction is a subclass of NodeAction whose enabled state depends
on currently activated Nodes. try adding the following piece of code to your sample TopComponent:

        Node myNode = new AbstractNode(Children.LEAF) {
            @Override
            public NewType[] getNewTypes() {
                return new NewType[] { new NewType() {
                    @Override
                    public void create() throws IOException {
                        System.out.println("create something new");
                    }
                }};
            }
        };
        setActivatedNodes(new Node[] { myNode });

- NewAction.putValue( Action.NAME, String ) does work if the action is added to the toolbar as a button instance (see
above). when using NewAction.getToolbarPresenter() then button's display name depends on activated nodes, see my example
above

also see javadoc for org.openide.util.actions.NodeAction