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 04:58  |
Eclipse User |
|
|
|
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 07:35] by Moderator
|
|
| | | |
Re: How to pass Keyboard Events to the MPart? [message #986493 is a reply to message #986381] |
Tue, 20 November 2012 11:04   |
Eclipse User |
|
|
|
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 11:19] by Moderator
|
|
|
Re: How to pass Keyboard Events to the MPart? [message #986622 is a reply to message #986493] |
Wed, 21 November 2012 03:57   |
Eclipse User |
|
|
|
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 #986698 is a reply to message #986622] |
Wed, 21 November 2012 06:29   |
Eclipse User |
|
|
|
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 :)
|
|
| | | | |
Goto Forum:
Current Time: Wed Jul 23 03:48:24 EDT 2025
Powered by FUDForum. Page generated in 0.26383 seconds
|