Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345468 - Translations not occurring for handled menu items
Summary: Translations not occurring for handled menu items
Status: RESOLVED FIXED
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 4.1 RC2   Edit
Assignee: Brian de Alwis CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-11 12:44 EDT by Brian de Alwis CLA
Modified: 2011-05-17 07:07 EDT (History)
3 users (show)

See Also:
pwebster: review?


Attachments
patch to MenuHelper (922 bytes, patch)
2011-05-11 14:32 EDT, Brian de Alwis CLA
no flags Details | Diff
MenuHelper patch v2 (1.55 KB, patch)
2011-05-11 14:51 EDT, Brian de Alwis CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian de Alwis CLA 2011-05-11 12:44:47 EDT
I hope I'm missing something here, but I fear I am not.

The Eclipse SDK IDE for Cocoa adds menu items for Window > Minimize, Window > Zoom, Window > Bring All To Front.  These are responsible for the following warnings seen on startup, as the org.eclipse.e4.ui.workbench.renderers.swt.cocoa fragment doesn't (yet) provide definitions:

   !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.880
   !MESSAGE Unable to create menu item "null", command
   "org.eclipse.ui.cocoa.minimizeWindow" not defined

   !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.881
   !MESSAGE Unable to create menu item "null", command
   "org.eclipse.ui.cocoa.zoomWindow" not defined

   !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.881
   !MESSAGE Unable to create menu item "null", command
   "org.eclipse.ui.cocoa.arrangeWindowsInFront" not defined

I'm creating some Eclipse 4-based implementations, but having to define them programmatically (I can't define them in a fragment.e4xmi as we don't know the applicable application element ids).

I'm trying to ensure that these definitions use translatable strings, if present.  My initial attempt fails, however:

    MCommand zoom = MCommandsFactory.INSTANCE.createCommand();
    zoom.setElementId(commandId);
    zoom.setCommandName("%command.zoom.name");
    zoom.setDescription("%command.zoom.desc");
    zoom.setContributorURI("platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa");
    app.getCommands().add(zoom);

    MHandler handler = MCommandsFactory.INSTANCE.createHandler();
    handler.setContributionURI("platform:/plugin/org.eclipse.e4.ui.workbench.renderers.swt.cocoa/" + ZoomWindowHandler.class.getName());
    handler.setContributorURI("platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa");
    handler.setElementId(ZoomWindowHandler.class.getName());
    handler.setCommand(zoom);
    app.getHandlers().add(handler);

But the menu items show up as "%command.zoom.name".  It works if I instead use the injected TranslationService and explicitly perform the translation:

    command.setCommandName(translator == null ? name : 
        translator.translate("%command.zoom.name",
            "platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa"));
    command.setDescription(description == null ? description : 
        translator.translate("%command.zoom.desc",
            "platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa"));

The BundleTranslationProvider does get called, except its contributorURI is null, and so no translation is attempted:

    BundleTranslationProvider.translate(String, String) line: 46	
    LocalizationHelper.getLocalized(String, MApplicationElement, IEclipseContext) line: 132	
    LocalizationHelper.getLocalized(String, MApplicationElement) line: 112	
    LocalizationHelper.getLocalizedLabel(MUIElement) line: 72	
    HandledMenuItemImpl(ItemImpl).getLocalizedLabel() line: 314	

The problem is, I think, that the HandledMenuItem created takes its name from the command ("%command.zoon.name") but doesn't take the command's contributorURI, and instead has a null contributorURI.  

One solution might be to amend ItemImpl#getLocalizedLabel() and getLocalizedTooltip() to do something like this:

    public String getLocalizedLabel() {
        if(getContributorURI() == null
                && getLabel().equals(getCommand().getLabel()) {
            return LocalizationHelper.getLocalized(getLabel(), getCommand().getContributor());
        }
        return LocalizationHelper.getLocalizedLabel(this);
    }

(untested; it's a bit icky)

Or alternatively, org.eclipse.ui.workbench's org.eclipse.ui.internal.menus.MenuHelper#createItem() should also set the newly-created menu item's contributorURI to the command's contributorURI?

Or MHandledItem's implementation of #getContributorURI() should, if its contributorURI is null, return the command's contributorURI instead?
Comment 1 Brian de Alwis CLA 2011-05-11 14:21:05 EDT
These menu items are defined in org.eclipse.ui.ide's org.eclipse.ui.internal.ide.WorkbenchActionBuilder.java:


CommandContributionItemParameter minimizeParam = new CommandContributionItemParameter(window, null,
    "org.eclipse.ui.cocoa.minimizeWindow", CommandContributionItem.STYLE_PUSH); //$NON-NLS-1$
minimizeItem = new CommandContributionItem(minimizeParam);
CommandContributionItemParameter zoomParam = new CommandContributionItemParameter(window, null,
    "org.eclipse.ui.cocoa.zoomWindow", CommandContributionItem.STYLE_PUSH); //$NON-NLS-1$
zoomItem = new CommandContributionItem(zoomParam);
CommandContributionItemParameter arrangeWindowsParam = new CommandContributionItemParameter(window, null,
    "org.eclipse.ui.cocoa.arrangeWindowsInFront", CommandContributionItem.STYLE_PUSH); //$NON-NLS-1$
arrangeWindowsItem = new CommandContributionItem(arrangeWindowsParam);
Comment 2 Brian de Alwis CLA 2011-05-11 14:32:25 EDT
Created attachment 195408 [details]
patch to MenuHelper

Change MenuHelper#createItem(MApplication, CommandContributionItem) to set the new item's contributorURI to the command instance's contributorURI.
Comment 3 Brian de Alwis CLA 2011-05-11 14:51:09 EDT
Created attachment 195412 [details]
MenuHelper patch v2

Fix other applicable locations too (createItem() and createToolItem())
Comment 4 Paul Webster CLA 2011-05-16 18:46:55 EDT
Released to HEAD
PW
Comment 5 Paul Webster CLA 2011-05-17 07:07:45 EDT
I didn't switch it to REOPENED, and can't find the record in the history :-)  Maybe when I switched assignee?

If anybody would like to REOPEN, please feel free.

PW