Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Strange behaviour with contributed Handler(Handler called on startup and shutdown or not at all)
icon5.gif  Strange behaviour with contributed Handler [message #1017874] Tue, 12 March 2013 17:13 Go to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
I managed to contribute some commands, handlers and MenuItems etc. to my host application as described here and here.
BTW: Thanks guys, you regularly save my day.

The head of my execute method looks like the following:
@Execute
@Inject
public void openAndProcessSequencerFile(IEclipseContext ctx,
	@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
	EModelService modelService,
	MApplication application){
 // some code here: opens a FileDialog
}


I've read somewhere that the @Inject isn't necessary when you have @Execute, because it's somehow included. But if it's there it seems, that this Handler is called on startup of my host application for every Handled*Item I have (two times for me, because I have one HandledMenuItem and one HandledToolItem for this Command). I know this because the FileDialog is opened twice. Afterwards those Handled*Items are deactivated (not enabled). Does @Inject do more than injecting?

If I remove the @Inject, this behaviour is gone and my MenuItem is enabled. But in turn, if I click it, nothing happens, not even an exception is thrown.

In addition it is called twice for every Handled*Item on shutdown of the application. 4 FileDialogs opening Evil or Very Mad

Any ideas on what is happening here?
I already tried to set the "enabled" property of the HandledMenuItem and HandledToolItem in my fragment to false, but that didn't help either.

I tried with and without a canExecute() method. Doesn't make any difference in both cases.

Here is my fragment.e4xmi (there are some more Commands and Handlers, but only one is implemented right now):

<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_IQ5MMIsXEeKSObafD6BggQ">
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Fp3wgIsgEeKSObafD6BggQ" featurename="commands" parentElementId="com.vknie.comma.app">
    <elements xsi:type="commands:Command" xmi:id="_Zu-dkIsgEeKSObafD6BggQ" elementId="com.vknie.comma.core.importFile.command.openSequencerFile" commandName="Import Sequencer File"/>
    <elements xsi:type="commands:Command" xmi:id="_S08_0IsiEeKSObafD6BggQ" elementId="com.vknie.comma.core.importFile.command.mergePieces" commandName="Merge Pieces"/>
    <elements xsi:type="commands:Command" xmi:id="_YvSQQIsiEeKSObafD6BggQ" elementId="com.vknie.comma.core.importFile.command.splitPiece" commandName="Split Piece"/>
  </fragments>
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_lW14kIsgEeKSObafD6BggQ" featurename="handlers" parentElementId="com.vknie.comma.app">
    <elements xsi:type="commands:Handler" xmi:id="_qAinkIsgEeKSObafD6BggQ" elementId="com.vknie.comma.core.importFile.handler.openSequencerFileHandler" contributionURI="bundleclass://com.vknie.comma.core.importFile/com.vknie.comma.core.importfile.handler.OpenSequencerFileHandler" command="_Zu-dkIsgEeKSObafD6BggQ"/>
    <elements xsi:type="commands:Handler" xmi:id="_h0GfsIsiEeKSObafD6BggQ" elementId="com.vknie.comma.core.importFile.handler.mergePieces" command="_S08_0IsiEeKSObafD6BggQ"/>
    <elements xsi:type="commands:Handler" xmi:id="_kxMi8IsiEeKSObafD6BggQ" elementId="com.vknie.comm.core.importFile.handler.splitPiece" command="_YvSQQIsiEeKSObafD6BggQ"/>
  </fragments>
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_8PY9oIsgEeKSObafD6BggQ" featurename="children" parentElementId="com.vknie.comma.app.menu.file">
    <elements xsi:type="menu:HandledMenuItem" xmi:id="_D6gPMIshEeKSObafD6BggQ" label="Import Sequencer File" command="_Zu-dkIsgEeKSObafD6BggQ"/>
  </fragments>
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_mnImUIshEeKSObafD6BggQ" featurename="children" parentElementId="com.vknie.comma.app.toolbar.mainToolbar">
    <elements xsi:type="menu:HandledToolItem" xmi:id="_0MtrMIshEeKSObafD6BggQ" label="Import Sequencer File" command="_Zu-dkIsgEeKSObafD6BggQ"/>
  </fragments>
</fragment:ModelFragments>



Re: Strange behaviour with contributed Handler [message #1018118 is a reply to message #1017874] Wed, 13 March 2013 07:37 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
If you put @Inject on it the DI container calls is upon creation of the
handler instance (hence called twice on startup.) and whenever the
values in the context changes (hence on shutdown)

If it is not called upon clicking when you only have @Execute it means
one of the values you request is not available. Can you try putting
@Optional on the arguments an see which one of the those guys is NULL -
I know none of them should be but it helps tracking it down.

Tom

Am 12.03.13 18:13, schrieb Marina Knieling:
> I managed to contribute some commands, handlers and MenuItems etc. to my
> host application as described
> http://www.vogella.com/articles/Eclipse4Modularity/article.html#contribute_fragment
> and
> http://www.bestsolution.at/en/download.php?cat=01_Services&file=Eclipse4Tutorial_WritingApplicationWithE4_BestSolution.pdf.
>
> BTW: Thanks guys, you regularly save my day.
>
> The head of my execute method looks like the following:
>
> @Execute
> @Inject
> public void openAndProcessSequencerFile(IEclipseContext ctx,
> @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
> EModelService modelService,
> MApplication application){
> // some code here: opens a FileDialog
> }
>
>
> I've read somewhere that the @Inject isn't necessary when you have
> @Execute, because it's somehow included. But if it's there it seems,
> that this Handler is called on startup of my host application for every
> Handled*Item I have (two times for me, because I have one
> HandledMenuItem and one HandledToolItem for this Command). I know this
> because the FileDialog is opened twice. Afterwards those Handled*Items
> are deactivated (not enabled). Does @Inject do more than injecting?
>
> If I remove the @Inject, this behaviour is gone and my MenuItem is
> enabled. But in turn, if I click it, nothing happens, not even an
> exception is thrown.
>
> In addition it is called twice for every Handled*Item on shutdown of the
> application. 4 FileDialogs opening :evil:
> Any ideas on what is happening here?
> I already tried to set the "enabled" property of the HandledMenuItem and
> HandledToolItem in my fragment to false, but that didn't help either.
>
> I tried with and without a canExecute() method. Doesn't make any
> difference in both cases.
>
> Here is my fragment.e4xmi (there are some more Commands and Handlers,
> but only one is implemented right now):
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <fragment:ModelFragments xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands"
> xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment"
> xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu"
> xmi:id="_IQ5MMIsXEeKSObafD6BggQ">
> <fragments xsi:type="fragment:StringModelFragment"
> xmi:id="_Fp3wgIsgEeKSObafD6BggQ" featurename="commands"
> parentElementId="com.vknie.comma.app">
> <elements xsi:type="commands:Command"
> xmi:id="_Zu-dkIsgEeKSObafD6BggQ"
> elementId="com.vknie.comma.core.importFile.command.openSequencerFile"
> commandName="Import Sequencer File"/>
> <elements xsi:type="commands:Command"
> xmi:id="_S08_0IsiEeKSObafD6BggQ"
> elementId="com.vknie.comma.core.importFile.command.mergePieces"
> commandName="Merge Pieces"/>
> <elements xsi:type="commands:Command"
> xmi:id="_YvSQQIsiEeKSObafD6BggQ"
> elementId="com.vknie.comma.core.importFile.command.splitPiece"
> commandName="Split Piece"/>
> </fragments>
> <fragments xsi:type="fragment:StringModelFragment"
> xmi:id="_lW14kIsgEeKSObafD6BggQ" featurename="handlers"
> parentElementId="com.vknie.comma.app">
> <elements xsi:type="commands:Handler"
> xmi:id="_qAinkIsgEeKSObafD6BggQ"
> elementId="com.vknie.comma.core.importFile.handler.openSequencerFileHandler"
> contributionURI="bundleclass://com.vknie.comma.core.importFile/com.vknie.comma.core.importfile.handler.OpenSequencerFileHandler"
> command="_Zu-dkIsgEeKSObafD6BggQ"/>
> <elements xsi:type="commands:Handler"
> xmi:id="_h0GfsIsiEeKSObafD6BggQ"
> elementId="com.vknie.comma.core.importFile.handler.mergePieces"
> command="_S08_0IsiEeKSObafD6BggQ"/>
> <elements xsi:type="commands:Handler"
> xmi:id="_kxMi8IsiEeKSObafD6BggQ"
> elementId="com.vknie.comm.core.importFile.handler.splitPiece"
> command="_YvSQQIsiEeKSObafD6BggQ"/>
> </fragments>
> <fragments xsi:type="fragment:StringModelFragment"
> xmi:id="_8PY9oIsgEeKSObafD6BggQ" featurename="children"
> parentElementId="com.vknie.comma.app.menu.file">
> <elements xsi:type="menu:HandledMenuItem"
> xmi:id="_D6gPMIshEeKSObafD6BggQ" label="Import Sequencer File"
> command="_Zu-dkIsgEeKSObafD6BggQ"/>
> </fragments>
> <fragments xsi:type="fragment:StringModelFragment"
> xmi:id="_mnImUIshEeKSObafD6BggQ" featurename="children"
> parentElementId="com.vknie.comma.app.toolbar.mainToolbar">
> <elements xsi:type="menu:HandledToolItem"
> xmi:id="_0MtrMIshEeKSObafD6BggQ" label="Import Sequencer File"
> command="_Zu-dkIsgEeKSObafD6BggQ"/>
> </fragments>
> </fragment:ModelFragments>
>
>
>
>
Re: Strange behaviour with contributed Handler [message #1018161 is a reply to message #1018118] Wed, 13 March 2013 09:37 Go to previous message
Eclipse UserFriend
What version of the platform are you on? If post Kepler M4 you should add the HandlerProcessingAddon to the addons.
Previous Topic:Prompting before closing Stopped working
Next Topic:subversive - Unable to read repository under Eclipse 4.2.2
Goto Forum:
  


Current Time: Fri Apr 19 12:17:07 GMT 2024

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

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

Back to the top