Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to get a specific MPart in a command handler with DI
How to get a specific MPart in a command handler with DI [message #1706588] Thu, 27 August 2015 22:51 Go to next message
Paul Roubekas is currently offline Paul RoubekasFriend
Messages: 207
Registered: March 2012
Location: Chattanooga, TN USA
Senior Member
I have a pure e4 application I am trying to build. I am somewhat new to eclipse and e4 so not being able to find an answer with an internet search because I was not using the correct search term(s).

I have a command and handler defined in the e4xmi file. I have my POJO handler. I can inject the IServiceConstants.ACTIVE_PART into the @Execute method. Depending on what the "Active Part" is when the end user press my "Reset" button the execute(Mpart aPart) can have a object or be null.

My e4 application has many sections/windows many of which can have a MPart and there are a lot of subInterface of MPart like MApplicationElement, MBindings, MContext, MContribution, MDirtyable, MHandlerContainer, MLocalizable, MPartSashContainerElement, MStackElement, MUIElement, MUILabel and MWindowElement. So my command handler could get any random MPart when invoked. But I need to go into one specific MPart, a JavaFX ScrollPane, and change some data in the scene graph.

How do I get the MPart I need when any random MPart will come in through DI?


package software;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;

import javax.inject.Named;

public class Reset {
	@Execute
	public void execute(
			@Named(IServiceConstants.ACTIVE_PART) MPart aPart
			) {
		System.out.println("aPart: " + aPart);
	}
}


<?xml version="1.0" encoding="UTF-8"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_KTDxQUz1EeW7Qp-pzyj-PA" elementId="org.eclipse.e4.application" bindingContexts="_KTDxQEz1EeW7Qp-pzyj-PA">
  <children xsi:type="basic:TrimmedWindow" xmi:id="_gGN7kEz1EeW7Qp-pzyj-PA" elementId="commandhandler.app.trimmedwindow.0">
    <children xsi:type="basic:Part" xmi:id="_8DELgEz2EeW7Qp-pzyj-PA" elementId="commandhandler.app.part.0" contributionURI="bundleclass://commandHandler.app/software.CommandHandlerPart"/>
    <trimBars xmi:id="_ojXHAEz1EeW7Qp-pzyj-PA" elementId="commandhandler.app.trimbar.0">
      <children xsi:type="menu:ToolBar" xmi:id="_rBNpgEz1EeW7Qp-pzyj-PA" elementId="commandhandler.app.toolbar.0">
        <children xsi:type="menu:HandledToolItem" xmi:id="_uSkskEz1EeW7Qp-pzyj-PA" elementId="commandhandler.app.handledtoolitem.reset" label="Reset" command="_4tEVgEz1EeW7Qp-pzyj-PA">
          <parameters xmi:id="_khvH0Ez5EeW7Qp-pzyj-PA" elementId="commandhandler.app.parameter.0" name="commandhandler.app.commandparameter.reset"/>
        </children>
      </children>
    </trimBars>
  </children>
  <handlers xmi:id="_6o-okEz1EeW7Qp-pzyj-PA" elementId="commandhandler.app.handler.reset" contributionURI="bundleclass://commandHandler.app/software.Reset" command="_4tEVgEz1EeW7Qp-pzyj-PA"/>
  <rootContext xmi:id="_KTDxQEz1EeW7Qp-pzyj-PA" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
    <children xmi:id="_KTDxQkz1EeW7Qp-pzyj-PA" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
    <children xmi:id="_KTDxQ0z1EeW7Qp-pzyj-PA" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
  </rootContext>
  <commands xmi:id="_4tEVgEz1EeW7Qp-pzyj-PA" elementId="commandhandler.app.command.reset" commandName="Reset">
    <parameters xmi:id="_hgbS8Ez5EeW7Qp-pzyj-PA" elementId="commandhandler.app.commandparameter.reset" name="Reset"/>
  </commands>
  <addons xmi:id="_KTDxREz1EeW7Qp-pzyj-PA" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
  <addons xmi:id="_KTDxRUz1EeW7Qp-pzyj-PA" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
  <addons xmi:id="_KTDxRkz1EeW7Qp-pzyj-PA" elementId="org.eclipse.fx.ui.keybindings.e4.service" contributionURI="bundleclass://org.eclipse.fx.ui.keybindings.e4/org.eclipse.fx.ui.keybindings.e4.BindingServiceAddon"/>
  <addons xmi:id="_KTDxR0z1EeW7Qp-pzyj-PA" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
  <addons xmi:id="_KTDxSEz1EeW7Qp-pzyj-PA" 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="_KTDxSUz1EeW7Qp-pzyj-PA" elementId="org.eclipse.fx.ui.keybindings.e4.model" contributionURI="bundleclass://org.eclipse.fx.ui.keybindings.e4/org.eclipse.fx.ui.keybindings.e4.BindingProcessingAddon"/>
  <addons xmi:id="_KTDxSkz1EeW7Qp-pzyj-PA" elementId="org.eclipse.e4.ui.workbench.addons.HandlerProcessingAddon" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
</application:Application>





Oxygen 3a
Windows 10
Re: How to get a specific MPart in a command handler with DI [message #1706611 is a reply to message #1706588] Fri, 28 August 2015 07:31 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 28.08.15 00:51, Paul Roubekas wrote:
> I have a pure e4 application I am trying to build. I am somewhat new to
> eclipse and e4 so not being able to find an answer with an internet
> search because I was not using the correct search term(s).
> I have a command and handler defined in the e4xmi file. I have my POJO
> handler. I can inject the IServiceConstants.ACTIVE_PART into the
> @Execute method. Depending on what the "Active Part" is when the end
> user press my "Reset" button the execute(Mpart aPart) can have a object
> or be null.
>
> My e4 application has many sections/windows many of which can have a
> MPart and there are a lot of subInterface of MPart like
> MApplicationElement, MBindings, MContext, MContribution, MDirtyable,
> MHandlerContainer, MLocalizable, MPartSashContainerElement,
> MStackElement, MUIElement, MUILabel and MWindowElement. So my command
> handler could get any random MPart when invoked. But I need to go into
> one specific MPart, a JavaFX ScrollPane, and change some data in the
> scene graph.
> How do I get the MPart I need when any random MPart will come in through
> DI?
>

Let the system inject the MApplication instance and search for the
specific part.

class Handler {

@Execute
void zoom(MApplication app, EModelService s) {
s.findElement(MPart.class,....);
}
}

But IMHO this is not the way to go but you should better send an event
and in the handler and let your part subscribe to the event.

class Handler {

@Execute
void zoom(IEventBroker b) {
b.post("/my/application/zoom/increase", 1);
}

}

class MyPart {
@UIEventTopic("/my/application/zoom/increase")
void handleZoom(Integer value) {
// ...
}
}

Tom
Previous Topic:Migration from E3 + compat to Pure E4 application
Next Topic:How to configure e4xmi for a radio button menu
Goto Forum:
  


Current Time: Sat Apr 20 04:06:32 GMT 2024

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

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

Back to the top