Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to pass Keyboard Events to the MPart?
How to pass Keyboard Events to the MPart? [message #986381] Tue, 20 November 2012 09:58 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
I have the following situation:

Situation:
In my application I need to redirect the keyboard events to the active part,
so that the content inside the acive MPart can handle the events.


What did I try:
What I wanted to do was monitoring the active Part:

//Monitoring the active part.
class Delegator{
 MPart activePart;

 public Delegator{
  this.addListener(SWT.KeyDown, new Listener{
    //pass the Keyboard Events to the activePart here
    activePart.getListeners.PASS_EVENTS_HERE
  });

}

@Inject
    private void getActivePart(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
        if (part != null) {
            activePart = part;
        }
    }


Inside of the MParts-Contributions i would like to listen for the Events, which will be passed to the MPart (when the MPart is active) from the Delegator.class:
class PartContribution{

 //the part which the PartContribution is in will be injected here
 @Inject
 MPart part;

 public PartContribution{
   //Listen to the events, passed to the active part.
   part.addListener...
 }

}



Problem:
Now the problem is, that the MPart can not have any Listeners registered to it,
so I have no Idea how to pass the events to the acive part and read it from there.
The SWT Widget doesn't exist yet, when I am creating the listeners.

Question:
Is there some functionality, which would allow to pass KeyBoardEvents to a MParts?

[Updated on: Tue, 20 November 2012 12:35]

Report message to a moderator

Re: How to pass Keyboard Events to the MPart? [message #986440 is a reply to message #986381] Tue, 20 November 2012 12:36 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
It's possible to define KeyBindings in the application model. Simple put: KeyBindings trigger Commands when a defined key sequence is pressed. These Commands could then have an appropriate Handler inside of the Parts that are interested in these Commands.
Re: How to pass Keyboard Events to the MPart? [message #986449 is a reply to message #986440] Tue, 20 November 2012 13:11 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Thnx Christoph, but the problem is in redirecting ALL Keyboard Events into the active MPart,

so that every part should not check, if it is currently active on every event.

To implement that by Key-Bindings I would have to register a keyBinding for every key, and I would still have to check if the part is currently active inside the part.
Re: How to pass Keyboard Events to the MPart? [message #986488 is a reply to message #986449] Tue, 20 November 2012 15:55 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

sorry I don't understand what you are trying to achieve. AFAIK all key strokes / events are passed to the active part. Why should the framework pass key events to an inactive part?

Why should the part listen to key events? What is the goal?

Sorry for the questions, but I don't get the big picture you are trying to achieve. Maybe an example would be helpful. In the meantime, maybe the event broker is some kind of help.

Greez,
Dirk
Re: How to pass Keyboard Events to the MPart? [message #986493 is a reply to message #986381] Tue, 20 November 2012 16:04 Go to previous messageGo to next message
Frank Langanke is currently offline Frank LangankeFriend
Messages: 7
Registered: October 2012
Junior Member
You have to add the listener within the lifecycle method of your part-contribution. Send an event through the event broker and have your contribution part listen to. Add the code below to your part-contributions:
@PostConstruct
public void createControls(Composite parent, MPart part) {

        // don't use this in prod, just as a hint
	parent.getShell().getDisplay().addFilter(SWT.KeyUp, new Listener() {
		
		@Override
		public void handleEvent(Event event) {
			System.out.println("key:" + event.keyCode);
                        broker.post("foo/bar/topic", event.keyCode);
			
		}
	});
}

@Inject
@Optional
public void handleKeyEvent(
		@UIEventTopic("foo/bar/topic") int keyCode,
		MPart part,
		@Active MPart activePart) {
	if (part.getElementId().equals(activePart.getElementId())) {
		System.out.println("active part handles: " + keyCode);
	}
}


However, it is actually nonsense, because every key input is always on the active part? How would an user be able to push a key in non-active part?

[Updated on: Tue, 20 November 2012 16:19]

Report message to a moderator

Re: How to pass Keyboard Events to the MPart? [message #986622 is a reply to message #986493] Wed, 21 November 2012 08:57 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Thnx for trying to help, guyz! Maybe I should try to explain my goal more preceisely:

Statement 1
First of all: the active-part in my application does not match the active part in e4.

Term 1:
There is an application, which cotains some parts
Plugins will contribute the content to theses parts.
I have no control over the content, which will be contributed by the plugins to the parts.

Term 2:
In SWT the Mouse-Events are not propagated through the composite hierarchy,
so clicking into a part with content (contributed by other plugins) - do not activeate the part.
The part simply do not know, that there was a mouseclick, because it is smallowed by the content,
over which (content) I do not have any control.

Term 3:
A part, of course SHOULD be activable by clicking inside of the part, since this is a common behaviour.

My solution:
Listen to all Events and pass them to the part, which have been active recently and which is not active anymore (e.g. because the focus is on the menu, toolbar etc.)

If the part could have listeners on it - the parts-content could register the listeners on the part. My Delegator would then trigger the listeners of the active parts.
This would avoid the check by the part-content, whether the current part is active or not, as proposed by Frank. I can not require this check, since I have no control over the part-content.

Idea:
Maybe it would be easier to listen for the Events,
map all mouseclicks to parts,
and really activate the parts by requesting focus Smile
Re: How to pass Keyboard Events to the MPart? [message #986698 is a reply to message #986622] Wed, 21 November 2012 11:29 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Are you describing SWT.Activate?

Tom

Am 21.11.12 09:57, schrieb Alex Kipling:
> Thnx for trying to help, guyz! Maybe I should try to explain my goal
> more preceisely:
>
> Statement 1
> First of all: the active-part in my application does not match the
> active part in e4.
>
> Term 1: There is an application, which cotains some parts
> Plugins will contribute the content to theses parts.
> I have no control over the content, which will be contributed by the
> plugins to the parts.
>
> Term 2: In SWT the Mouse-Events are not propagated through the composite
> hierarchy, so clicking into a part with content (contributed by other
> plugins) - do not activeate the part.
> The part simply do not know, that there was a mouseclick, because it is
> smallowed by the content,
> over which (content) I do not have any control.
>
> Term 3:
> A part, of course SHOULD be activable by clicking inside of the part,
> since this is a common behaviour.
>
> My solution:
> Listen to all Events and pass them to the part, which have been active
> recently and which is not active anymore (e.g. because the focus is on
> the menu, toolbar etc.)
>
> If the part could have listeners on it - the parts-content could
> register the listeners on the part. My Delegator would then trigger the
> listeners of the active parts.
> This would avoid the check by the part-content, whether the current part
> is active or not, as proposed by Frank. I can not require this check,
> since I have no control over the part-content.
>
> Idea:
> Maybe it would be easier to listen for the Events, map all mouseclicks
> to parts,
> and really activate the parts by requesting focus :)
Re: How to pass Keyboard Events to the MPart? [message #986726 is a reply to message #986698] Wed, 21 November 2012 13:20 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Iam describing the following issue:

the parts are not activated, when you click into a part,
if there are some composites inside the part.

The composites consume the event, as usual in SWT.

I am looking for a workaround, to activate Parts by clicking onto one of the composites inside a part.

[Updated on: Wed, 21 November 2012 13:21]

Report message to a moderator

Re: How to pass Keyboard Events to the MPart? [message #986739 is a reply to message #986726] Wed, 21 November 2012 13:57 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You should be able to activate your part by using EPartService.showPart(part, PartState.ACTIVATE)
Re: How to pass Keyboard Events to the MPart? [message #986757 is a reply to message #986726] Wed, 21 November 2012 14:45 Go to previous messageGo to next message
Frank Langanke is currently offline Frank LangankeFriend
Messages: 7
Registered: October 2012
Junior Member
Alex Kipling wrote on Wed, 21 November 2012 08:20
Iam describing the following issue:

the parts are not activated, when you click into a part,
if there are some composites inside the part.

The composites consume the event, as usual in SWT.

I am looking for a workaround, to activate Parts by clicking onto one of the composites inside a part.


Works for me. Did you implement setFocus() for your part-contributions?

@Focus
private void setFocus() {
  composite.setFocus();
} 

Re: How to pass Keyboard Events to the MPart? [message #986810 is a reply to message #986757] Wed, 21 November 2012 17:50 Go to previous message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Indeed, @Focus is triggered on part-click.
I can work this it - thnx!
Previous Topic:How to execute a Handler by id?
Next Topic:Difference between org. .. .observable and org. .. .observable.source
Goto Forum:
  


Current Time: Fri Apr 19 07:52:10 GMT 2024

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

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

Back to the top