Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Technology Project and PMC » How does one monitor events in Eclipse (run, save, refactor, etc.)?
How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72351] Fri, 02 June 2006 00:37 Go to next message
Eclipse UserFriend
Originally posted by: pschlesi.NOSPAM.uci.edu

Hi! I'm building a plug-in that must monitor user events in Eclipse
(run, save, refactor, etc.). How does one do that? What is the API
call? Is there an example out there that I can model myself after?

Any help would be greatly appreciated...

Thanks, Phil
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72368 is a reply to message #72351] Fri, 02 June 2006 12:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

AFAIK, there's no general event bus that captures all actions.

In 3.2, you can register an IExecutionListener with the ICommandService.
That would notify any commands that are executing, which is most
actions (but not all).

Later,
PW


Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72387 is a reply to message #72368] Fri, 02 June 2006 16:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pschlesi.NOSPAM.uci.edu

Hi Paul - I will try this this weekend or early next week and will post
back my results.

Thanks!

- Phil

Paul Webster wrote:
> AFAIK, there's no general event bus that captures all actions.
>
> In 3.2, you can register an IExecutionListener with the ICommandService.
> That would notify any commands that are executing, which is most
> actions (but not all).
>
> Later,
> PW
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72531 is a reply to message #72368] Sun, 11 June 2006 08:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pschlesi.NOSPAM.uci.edu

Paul - that appears to have done the trick. Thanks for the pointer.

Once this plugin's done, I'm going to post the code somewhere - there's
no examples of how to use any of this stuff...

- Phil

Paul Webster wrote:
> AFAIK, there's no general event bus that captures all actions.
>
> In 3.2, you can register an IExecutionListener with the ICommandService.
> That would notify any commands that are executing, which is most
> actions (but not all).
>
> Later,
> PW
CODE for all to use - Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72584 is a reply to message #72368] Sun, 11 June 2006 21:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pschlesi.NOSPAM.uci.edu

This will come out messy, sorry. Use this with the Eclipse default
plug-in for a View.

ArrayList<String> events = new ArrayList<String> ();

ICommandService commandService = (ICommandService)
PlatformUI.getWorkbench().getAdapter(ICommandService.class);

commandService.readRegistry();

Collection categories = commandService.getDefinedCategoryIds();
Object[] catString = categories.toArray();

Collection commandIds = commandService.getDefinedCommandIds();
Object[] comString = commandIds.toArray();

PrintWriter out = null;
try {
out = new PrintWriter( new BufferedWriter( new FileWriter( "c:/foo2.out"
) ) );

out.write("Categories\n");
for (int i = 0; i < catString.length; ++i)
out.write(i + ": " + catString[i].toString() + "\n");
out.write("\n\nCommandIds\n");
for (int i = 0; i < comString.length; ++i)
out.write(i + ": " + comString[i].toString() + "\n");

out.close();
} catch (IOException e) {
e.printStackTrace();
}

ExecutionListener executionListener = new ExecutionListener();

commandService.addExecutionListener(executionListener);

public class ExecutionListener implements IExecutionListener {

public void notHandled(String arg0, NotHandledException arg1) {
events.add("NotHandled: " + arg0);
viewer.refresh();
}

public void postExecuteFailure(String arg0, ExecutionException arg1) {
// do nothing - we watch preExecute and notHandled
}

public void postExecuteSuccess(String arg0, Object arg1) {
// do nothing - we watch preExecute and notHandled
}

public void preExecute(String arg0, ExecutionEvent arg1) {
events.add("preExecute: " + arg0);
viewer.refresh();
}

}
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72689 is a reply to message #72368] Thu, 15 June 2006 04:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pschlesi.NOSPAM.uci.edu

Paul,

Little problem: the IExecutionListener / ICommandService pairing only
reports what KEYBOARD shortcuts are used.

So Ctrl-S will show up.

However, if I click File/Save, or click the Disk button in the toolbar,
nothing is picked up.

What is the class for listening to commands via mouse or menus?

- Phil

Paul Webster wrote:
> AFAIK, there's no general event bus that captures all actions.
>
> In 3.2, you can register an IExecutionListener with the ICommandService.
> That would notify any commands that are executing, which is most
> actions (but not all).
>
> Later,
> PW
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72699 is a reply to message #72689] Thu, 15 June 2006 11:09 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Philip Schlesinger wrote:
> Paul,
>
> Little problem: the IExecutionListener / ICommandService pairing only
> reports what KEYBOARD shortcuts are used.
>
> So Ctrl-S will show up.
>
> However, if I click File/Save, or click the Disk button in the toolbar,
> nothing is picked up.
>
> What is the class for listening to commands via mouse or menus?

As I said, there isn't one. Hopefully in 3.3.

Later,
PW


Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #72800 is a reply to message #72689] Tue, 20 June 2006 06:47 Go to previous message
Eclipse UserFriend
Originally posted by: jekutsch.inf.fu-berlin.de

Hi Philip,

I had a similiar problem some weeks ago and posted my solution in
eclipse.platform. See the posting attached. Maybe the same technique is
useful for you as well. It requires that you'd like to catch events on
(Text)Editors. I didn't explore it in more details.

If you want to fetch Save operations, you may listen to the dirtyStateChange
of an IFileBufferListener which must be registrered as this:

FileBuffers.getTextFileBufferManager().addFileBufferListener (new
MyFileBufferListener());

where MyFileBufferListener implements IFileBufferListener. Dirty Flag state
callup methods are also provided by JDT's ElementStateListeners and
ResourceListeners.

Generally, I don't know any basic mechanism to catch user activities apart
from the basic SWT's Display.handleEvent().

I'm interested in your project. What are you about to implement? I'm
currently implementing a plugin to store meaningful user actions while
programming with Eclipse (for research purposes). Fuyy: The first version of
this (called ECG: http://www.inf.fu-berlin.de/ecg) has been compiled by a
student with surname "Schlesinger" :-)

Cheers,
Sebastian (http://www.inf.fu-berlin.de/~jekutsch)



"Philip Schlesinger" <pschlesi@NOSPAM.uci.edu> wrote in message
news:e6qn28$bpq$1@utils.eclipse.org...
> Paul,
>
> Little problem: the IExecutionListener / ICommandService pairing only
> reports what KEYBOARD shortcuts are used.
>
> So Ctrl-S will show up.
>
> However, if I click File/Save, or click the Disk button in the toolbar,
> nothing is picked up.
>
> What is the class for listening to commands via mouse or menus?
>
> - Phil
>
> Paul Webster wrote:
>> AFAIK, there's no general event bus that captures all actions.
>>
>> In 3.2, you can register an IExecutionListener with the ICommandService.
>> That would notify any commands that are executing, which is most actions
>> (but not all).
>>
>> Later,
>> PW
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #600638 is a reply to message #72351] Fri, 02 June 2006 12:22 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

AFAIK, there's no general event bus that captures all actions.

In 3.2, you can register an IExecutionListener with the ICommandService.
That would notify any commands that are executing, which is most
actions (but not all).

Later,
PW


Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #600647 is a reply to message #72368] Fri, 02 June 2006 16:24 Go to previous message
Philip Schlesinger is currently offline Philip SchlesingerFriend
Messages: 7
Registered: July 2009
Junior Member
Hi Paul - I will try this this weekend or early next week and will post
back my results.

Thanks!

- Phil

Paul Webster wrote:
> AFAIK, there's no general event bus that captures all actions.
>
> In 3.2, you can register an IExecutionListener with the ICommandService.
> That would notify any commands that are executing, which is most
> actions (but not all).
>
> Later,
> PW
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #600700 is a reply to message #72368] Sun, 11 June 2006 08:13 Go to previous message
Philip Schlesinger is currently offline Philip SchlesingerFriend
Messages: 7
Registered: July 2009
Junior Member
Paul - that appears to have done the trick. Thanks for the pointer.

Once this plugin's done, I'm going to post the code somewhere - there's
no examples of how to use any of this stuff...

- Phil

Paul Webster wrote:
> AFAIK, there's no general event bus that captures all actions.
>
> In 3.2, you can register an IExecutionListener with the ICommandService.
> That would notify any commands that are executing, which is most
> actions (but not all).
>
> Later,
> PW
CODE for all to use - Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #600720 is a reply to message #72368] Sun, 11 June 2006 21:25 Go to previous message
Philip Schlesinger is currently offline Philip SchlesingerFriend
Messages: 7
Registered: July 2009
Junior Member
This will come out messy, sorry. Use this with the Eclipse default
plug-in for a View.

ArrayList<String> events = new ArrayList<String> ();

ICommandService commandService = (ICommandService)
PlatformUI.getWorkbench().getAdapter(ICommandService.class);

commandService.readRegistry();

Collection categories = commandService.getDefinedCategoryIds();
Object[] catString = categories.toArray();

Collection commandIds = commandService.getDefinedCommandIds();
Object[] comString = commandIds.toArray();

PrintWriter out = null;
try {
out = new PrintWriter( new BufferedWriter( new FileWriter( "c:/foo2.out"
) ) );

out.write("Categories\n");
for (int i = 0; i < catString.length; ++i)
out.write(i + ": " + catString[i].toString() + "\n");
out.write("\n\nCommandIds\n");
for (int i = 0; i < comString.length; ++i)
out.write(i + ": " + comString[i].toString() + "\n");

out.close();
} catch (IOException e) {
e.printStackTrace();
}

ExecutionListener executionListener = new ExecutionListener();

commandService.addExecutionListener(executionListener);

public class ExecutionListener implements IExecutionListener {

public void notHandled(String arg0, NotHandledException arg1) {
events.add("NotHandled: " + arg0);
viewer.refresh();
}

public void postExecuteFailure(String arg0, ExecutionException arg1) {
// do nothing - we watch preExecute and notHandled
}

public void postExecuteSuccess(String arg0, Object arg1) {
// do nothing - we watch preExecute and notHandled
}

public void preExecute(String arg0, ExecutionEvent arg1) {
events.add("preExecute: " + arg0);
viewer.refresh();
}

}
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #600765 is a reply to message #72368] Thu, 15 June 2006 04:18 Go to previous message
Philip Schlesinger is currently offline Philip SchlesingerFriend
Messages: 7
Registered: July 2009
Junior Member
Paul,

Little problem: the IExecutionListener / ICommandService pairing only
reports what KEYBOARD shortcuts are used.

So Ctrl-S will show up.

However, if I click File/Save, or click the Disk button in the toolbar,
nothing is picked up.

What is the class for listening to commands via mouse or menus?

- Phil

Paul Webster wrote:
> AFAIK, there's no general event bus that captures all actions.
>
> In 3.2, you can register an IExecutionListener with the ICommandService.
> That would notify any commands that are executing, which is most
> actions (but not all).
>
> Later,
> PW
Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #600772 is a reply to message #72689] Thu, 15 June 2006 11:09 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Philip Schlesinger wrote:
> Paul,
>
> Little problem: the IExecutionListener / ICommandService pairing only
> reports what KEYBOARD shortcuts are used.
>
> So Ctrl-S will show up.
>
> However, if I click File/Save, or click the Disk button in the toolbar,
> nothing is picked up.
>
> What is the class for listening to commands via mouse or menus?

As I said, there isn't one. Hopefully in 3.3.

Later,
PW


Re: How does one monitor events in Eclipse (run, save, refactor, etc.)? [message #600811 is a reply to message #72689] Tue, 20 June 2006 06:47 Go to previous message
Eclipse UserFriend
Originally posted by: jekutsch.inf.fu-berlin.de

Hi Philip,

I had a similiar problem some weeks ago and posted my solution in
eclipse.platform. See the posting attached. Maybe the same technique is
useful for you as well. It requires that you'd like to catch events on
(Text)Editors. I didn't explore it in more details.

If you want to fetch Save operations, you may listen to the dirtyStateChange
of an IFileBufferListener which must be registrered as this:

FileBuffers.getTextFileBufferManager().addFileBufferListener (new
MyFileBufferListener());

where MyFileBufferListener implements IFileBufferListener. Dirty Flag state
callup methods are also provided by JDT's ElementStateListeners and
ResourceListeners.

Generally, I don't know any basic mechanism to catch user activities apart
from the basic SWT's Display.handleEvent().

I'm interested in your project. What are you about to implement? I'm
currently implementing a plugin to store meaningful user actions while
programming with Eclipse (for research purposes). Fuyy: The first version of
this (called ECG: http://www.inf.fu-berlin.de/ecg) has been compiled by a
student with surname "Schlesinger" :-)

Cheers,
Sebastian (http://www.inf.fu-berlin.de/~jekutsch)



"Philip Schlesinger" <pschlesi@NOSPAM.uci.edu> wrote in message
news:e6qn28$bpq$1@utils.eclipse.org...
> Paul,
>
> Little problem: the IExecutionListener / ICommandService pairing only
> reports what KEYBOARD shortcuts are used.
>
> So Ctrl-S will show up.
>
> However, if I click File/Save, or click the Disk button in the toolbar,
> nothing is picked up.
>
> What is the class for listening to commands via mouse or menus?
>
> - Phil
>
> Paul Webster wrote:
>> AFAIK, there's no general event bus that captures all actions.
>>
>> In 3.2, you can register an IExecutionListener with the ICommandService.
>> That would notify any commands that are executing, which is most actions
>> (but not all).
>>
>> Later,
>> PW
Previous Topic:RAP & Thin-client UIs
Next Topic:Hi
Goto Forum:
  


Current Time: Fri Apr 19 14:28:28 GMT 2024

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

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

Back to the top