Disabled Tool- and Menu-Items when adding programmatically [message #1239873] |
Wed, 05 February 2014 03:41  |
Eclipse User |
|
|
|
I try to migrate an existing e3-Application, where ToolItems and MenuItems are added programmatically to a part. In another post of I've found the solution to add the HandlerProcessingAddon to the Model but did not have success. The items are still disabled. As I don't have an Application.e4xmi know, because of migration, I have to add it programmatically.
I tried it as follows:
/**
* Register the HandlerProcessingAddon programmatically, because I don't have one yet.
*/
private void registerHandlerProcessingAddon() {
MAddon addon = MApplicationFactory.INSTANCE.createAddon();
addon.setElementId("org.eclipse.e4.ui.workbench.handler.model");
addon.setContributionURI("bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon");
application.getAddons().add(addon);
}
/**
* Create and register the command and the handler.
*
* @return the command
*/
private MCommand createAndRegisterCopyCommandAndHandler() {
MCommand command = MCommandsFactory.INSTANCE.createCommand();
command.setElementId("theCommandId");
command.setCommandName("theCommandName");
application.getCommands().add(command);
MHandler handler = MCommandsFactory.INSTANCE.createHandler();
handler.setElementId(IWorkbenchCommandConstants.EDIT_COPY);
handler.setCommand(command);
handler.setContributorURI("bundleclass://org.eclipse.ui.ide/org.eclipse.ui.internal.views.markers.MarkerCopyHandler");
application.getHandlers().add(handler);
return command;
}
private void addCopyToolItem(MCommand command) {
MHandledToolItem toolElement = MMenuFactory.INSTANCE.createHandledToolItem();
toolElement.setElementId("theElementToTest");
toolElement.setIconURI("platform:/plugin/pluginName/icons/detail.png");
toolElement.setCommand(command);
toolElement.setVisible(true);
toolElement.setEnabled(true);
toolElement.setToBeRendered(true);
MToolBar toolbar = part.getToolbar();
toolbar.getChildren().add(toolElement);
toolbar.setVisible(true);
toolbar.setOnTop(true);
toolbar.setToBeRendered(true);
}
Is there anything wrong in the code??? I thought adding the addon solves the problem. Tool- and MenuItems added directly in the model are working fine.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07351 seconds