没有要执行命令的处理程序/WorkbenchContext localValues 不再引用处理程序类

问题描述 投票:0回答:1

我们目前正在进行从 Eclipse Juno 到 Eclipse 4.24 的迁移,因此我们遇到了一些问题。我们处于使用 eclipse e4 的 Eclipse RCP 环境中,并且正确设置了 e4xmi 文件。

我们的 Eclipse RCP 应用程序的 WorkbenchContext 不再是 localValues 属性中的处理程序,因此我们的 HIM 是 ko,因为她无法执行她检测到的命令。 如果我们尝试通过 EHandlerService 执行命令,则会引发

org.eclipse.core.commands.NotHandledException:没有要执行命令 rf.command.configuration.addconfigurationsystem 的处理程序

lHandlerService.executeHandler(lCmd);

这就是我们动态填充 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 [FirstPage.java:95] Processing tool item ID: rf.handledtoolitem.configuration.addconfigurationsystem
INFO [main] FirstPage [FirstPage.java:97] Processing tool item Class : class org.eclipse.e4.ui.model.application.ui.menu.impl.HandledToolItemImpl
INFO [main] FirstPage [FirstPage.java:98] Processing tool item, Command ID: rf.command.configuration.addconfigurationsystem
INFO [main] FirstPage [FirstPage.java:101] Object handler : rf.configuration.administrator.handlers.system.AddConfigSystemHandler@847f3e7

Eclipse 4.24 上的新日志:

INFO [main] FirstPage [FirstPage.java:95] Extension ID: rf.plateform.tools.firstPage
INFO [main] FirstPage [FirstPage.java:98] ToolItem Id rf..handledtoolitem.configuration.addconfigurationsystem
INFO [main] FirstPage [FirstPage.java:101] Processing tool item ID: rf.handledtoolitem.configuration.addconfigurationsystem
INFO [main] FirstPage [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

我已经检查了我的fragment.e4xmi,他是完美的参数

<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"/>

我还尝试实现 IHandler 或将 AbstractHandler 扩展到我的 Handler 但没有成功:


@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());
        }
    }

将其重新添加到 WorkbenchContext 的过程是什么?

java eclipse eclipse-plugin eclipse-rcp rcp
1个回答
0
投票

问题来自我们的 Application.e4xmi,它缺少 HandlerProcessingAddon。

在迁移之前,Application.e4xmi 仅处理命令和绑定

<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"/>

但是在 Eclipse 4.24 中,我们必须将此 Addons 添加到上下文中,以便 EclipseContext 可以正确读取并找到 Handler 类。

<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"/>
© www.soinside.com 2019 - 2024. All rights reserved.