javaeclipseeclipse-plugineclipse-rcprcp

There is no handler to execute for command / WorkbenchContext localValues no longer references handler classes


we currently doing migration from eclipse Juno to Eclipse 4.24 so we have some issues on it. We are in a Eclipse RCP environment using eclipse e4, with e4xmi file correctly setup.

The WorkbenchContext of our Eclipse RCP application no longer our handler in the localValues attributes, so our HIM is ko because she cannot execute the command she detect. If we tried to execute the command through the EHandlerService it's raise a

org.eclipse.core.commands.NotHandledException: There is no handler to execute for command rf.command.configuration.addconfigurationsystem

lHandlerService.executeHandler(lCmd);

This is how we dynamically populate our FirstPage HIM :

  final EHandlerService lHandlerService = pContext.get(EHandlerService.class);
        final ECommandService lCommandService = pContext.get(ECommandService.class);
        EModelService lModelService = pContext.get(EModelService.class);
        ImageRegistry lImageRegistry = pContext.get(ImageRegistry.class);
        
        for (IConfigurationElement lElt : lReg
            .getConfigurationElementsFor(EXTENSION_ID)) {
            logger.info("Extension ID: {}", EXTENSION_ID);
            List<MHandledToolItem> lItems = lModelService.findElements(lWindow,
                lElt.getAttribute(TOOLITEM_ID), MHandledToolItem.class, null);
            logger.info("ToolItem Id {}",lElt.getAttribute(TOOLITEM_ID));
          
            for (final MHandledToolItem lItem : lItems) {
                logger.info("Processing tool item ID: {}", lItem.getElementId());
                
                logger.info("Processing tool item Class : {}", lItem.getClass());
                logger.info("Processing tool item, Command ID: {}", lItem.getCommand().getElementId());
                Object handler = pContext.getActiveLeaf().get("handler::" + lItem.getCommand().getElementId());
                logger.info("Object handler : {}", handler);   
                ToolItem lToolItem = new ToolItem(lToolBar, SWT.NONE);
                lToolItem.setImage(lImageRegistry.get(lElt.getAttribute(IMAGE_URI)));
                lToolItem.setToolTipText(lItem.getTooltip());
                lToolItem.addSelectionListener(new SelectionListener() {
                 
                    @Override
                    public void widgetSelected(SelectionEvent pEvent) {
                        executeCommand(lItem);
                    }

                    @Override
                    public void widgetDefaultSelected(SelectionEvent pEvent) {
                        executeCommand(lItem);
                    }

                    private void executeCommand(MHandledToolItem pItem) {
                        MCommand lCommand = pItem.getCommand();
                        ParameterizedCommand lCmd = lCommandService.createCommand(
                            lCommand.getElementId(), null);
                            if (lHandlerService.canExecute(lCmd)) {
                            lHandlerService.executeHandler(lCmd);
                        }
                    }
                });
            }
        }
    }
The result of my log on Eclipse Juno : 
INFO [main] [FirstPage.java:95] Processing tool item ID: rf.handledtoolitem.configuration.addconfigurationsystem
INFO [main] [FirstPage.java:97] Processing tool item Class : class org.eclipse.e4.ui.model.application.ui.menu.impl.HandledToolItemImpl
INFO [main] [FirstPage.java:98] Processing tool item, Command ID: rf.command.configuration.addconfigurationsystem
INFO [main] [FirstPage.java:101] Object handler : rf.configuration.administrator.handlers.system.AddConfigSystemHandler@847f3e7

New Log on Eclipse 4.24 :

INFO [main] [FirstPage.java:95] Extension ID: rf.plateform.tools.firstPage
INFO [main] [FirstPage.java:98] ToolItem Id rf..handledtoolitem.configuration.addconfigurationsystem
INFO [main] [FirstPage.java:101] Processing tool item ID: rf.handledtoolitem.configuration.addconfigurationsystem
INFO [main] [FirstPage.java:103] Processing tool item Class : class org.eclipse.e4.ui.model.application.ui.menu.impl.HandledToolItemImpl
INFO [main] FirstPage [FirstPage.java:104] Processing tool item, Command ID: rf.command.configuration.addconfigurationsystem
INFO [main] FirstPage [FirstPage.java:106] Object handler : null

I've check my fragment.e4xmi who is perfectly param

<elements xsi:type="commands:Command" xmi:id="_HTKGMPdqEeG-14Xhj6dtog" elementId="rf.command.configuration.addconfigurationsystem" commandName="Nouvelle configuration syst&#xe8;me"/>
<elements xsi:type="commands:Handler" xmi:id="_GxVLgPdqEeG-14Xhj6dtog" elementId="rf.handler.configuration.addconfigurationsystem" contributionURI="bundleclass://rf.configuration.view.administrator/rf.configuration.administrator.handlers.system.AddConfigSystemHandler" command="_HTKGMPdqEeG-14Xhj6dtog"/>

I also tried to implement IHandler or extend AbstractHandler to my Handler with no success :


@SuppressWarnings("restriction")
public class AddConfigSystemHandler {

    /**
     * Execution of the Command
     * 
     * @param pPartManager
     *            PartByModel Service
     * @param pConfigurationService
     *            Configuration Service
     */
    @Execute
    public void execute(IModelService pConfigurationService, EPartManager pPartManager) {
        
        // Creation of a new element
        try {
            Configuration lNewElement = (Configuration) pConfigurationService
                .create((EObject) null, ConfigPackage.Literals.CONFIGURATION);

            // Display the part
            MPart lPart = pPartManager.showPart(
                ConfigurationPartId.administrator, lNewElement);
            lPart.setDirty(true);
        } catch (ConfigurationException lException) {
            MessageDialog.openError(null,
                "Impossible to create the element of configuration",
                lException.getMessage());
        }
    }

What is the process to add it againt to the WorkbenchContext ?


Solution

  • Everything was correctly param in our handler classes and fragment.e4xmi. The probleme came from our Application.e4xmi who was missing the Handler ProcessingAddon.

    Before our migration Application.e4xmi just had processing for Command and Binding

    <addons xmi:id="_2fQh2MauEeGMWL3OiqAGkw" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
    <addons xmi:id="_2fQh2cauEeGMWL3OiqAGkw" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
    

    But in Eclipse 4.24 we had to add this Addons to the context so the EclipseContext can correctly read and find the Handler classes.

    <addons xmi:id="_6wlLdsgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>