Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Disabled Tool- and Menu-Items when adding programmatically
Disabled Tool- and Menu-Items when adding programmatically [message #1239873] Wed, 05 February 2014 08:41 Go to next message
Stefan Weiser is currently offline Stefan WeiserFriend
Messages: 55
Registered: February 2012
Member
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.
Re: Disabled Tool- and Menu-Items when adding programmatically [message #1239883 is a reply to message #1239873] Wed, 05 February 2014 09:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I'm a bit suprised that you don't have an Application.e4xmi are you sure
you are using e(fx)clipse and don't want the e4?

Tom

On 05.02.14 09:41, Stefan Weiser wrote:
> I try to migrate an existing e3-Application, where ToolItems and
> MenuItems are added programmatically to a part. In another
> http://www.eclipse.org/forums/index.php/t/550344/ 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.
Re: Disabled Tool- and Menu-Items when adding programmatically [message #1239892 is a reply to message #1239883] Wed, 05 February 2014 09:20 Go to previous messageGo to next message
Stefan Weiser is currently offline Stefan WeiserFriend
Messages: 55
Registered: February 2012
Member
It's the aim that the application has the same functionality after the migration process and the compatibility-layer should not be required. So I know that I require the Application.e4xmi later. Now I migrate all my parts with the and DIViewPart, which works really good. I hope to migrate everything without loosing any features and then introduce the Application.e4xmi.

Is there another or better way for migration??

By the way I experiment with the Application.e4xmi in an own SampleE4Project.

[Updated on: Wed, 05 February 2014 09:23]

Report message to a moderator

Re: Disabled Tool- and Menu-Items when adding programmatically [message #1239893 is a reply to message #1239892] Wed, 05 February 2014 09:23 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I repeat my question and I'm now 100% sure that you are at the wrong forum!

You want the e4 forum but are asking at the efxclipse one which deals
about e4 on JavaFX and JavaFX at Eclipse in general.

Tom

On 05.02.14 10:20, Stefan Weiser wrote:
> It's the aim that the application has the same functionality after the
> migration process and the compatibility-layer should not be required. So
> I know that I require the Application.e4xmi later. Now I migrate all my
> parts with the and DIViewPart, which works really good. I hope to
> migrate everything without loosing any features and then introduce the
> Application.e4xmi.
> Is there another or better way for migration??
Re: Disabled Tool- and Menu-Items when adding programmatically [message #1240295 is a reply to message #1239893] Thu, 06 February 2014 06:27 Go to previous messageGo to next message
Stefan Weiser is currently offline Stefan WeiserFriend
Messages: 55
Registered: February 2012
Member
Oh, I'm sorry that I placed my question into the wrong forum. I hope someone can move my topic into the correct forum.
Re: Disabled Tool- and Menu-Items when adding programmatically [message #1240353 is a reply to message #1240295] Thu, 06 February 2014 09:29 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You need to repo to the e4 forum!

Tom

On 06.02.14 07:27, Stefan Weiser wrote:
> Oh, I'm sorry that I placed my question into the wrong forum. I hope
> someone can move my topic into the correct forum.
Re: Disabled Tool- and Menu-Items when adding programmatically [message #1240858 is a reply to message #1240353] Fri, 07 February 2014 06:29 Go to previous message
Stefan Weiser is currently offline Stefan WeiserFriend
Messages: 55
Registered: February 2012
Member
I was looking now, if there is a newer Kepler-Eclipse available, but there isn't. So I hope someone has a hint, how programmatically adding tool and menuitems in e4.

Previous Topic:Migration an Eclipse 3.x RCP application to E4: product problem
Next Topic:Re: Proposed improvement to Eclipse
Goto Forum:
  


Current Time: Tue Mar 19 05:39:39 GMT 2024

Powered by FUDForum. Page generated in 0.02640 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top