Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:40:57+00:00 2026-06-02T04:40:57+00:00

I have a handler in an Eclipse plugin (developed on Indigo) that I want

  • 0

I have a handler in an Eclipse plugin (developed on Indigo) that I want to run every time a Java file in a text editor is saved (or opened, ideally). As far as I can gather, there are two ways of achieving this:

  1. Programattically via the CommandService API.
  2. Using the configuration in plugin.xml

I’ve tried both of these. Method 1 like this:

public class Activator extends AbstractUIPlugin {
    @Override
    public void start(final BundleContext context) throws Exception {
        super.start(context);
        ICommandService commandService = (ICommandService) PlatformUI
              .getWorkbench().getService(ICommandService.class);
        commandService.addExecutionListener(new MyListener());
        plugin = this;
    }
    ...
}

public class MyListener implements IExecutionListener {
    @Override
    public void postExecuteSuccess(final String commandId, final Object returnValue) {
        System.out.println("PostEventSuccess:" + commandId);
    }

    @Override
    public void preExecute(final String commandId, final ExecutionEvent event) {}

    @Override
    public void notHandled(String commandId, NotHandledException exception) {}

    @Override
    public void postExecuteFailure(String commandId, ExecutionException exception) {}
}

and method 2. like this:

<extension point="org.eclipse.ui.handlers">
    <handler 
        commandId="org.eclipse.ui.file.save"
        class="mypackage.MyHandler">
        <activeWhen>
            <with variable="activeWorkbenchWindow">
                <instanceof value="org.eclipse.ui.IWorkbenchWindow"/>
            </with>
        </activeWhen>
    </handler>
</extension> 

Method 1. doesn’t run my listener at all. Method 2. works, in that the handler is executed, but my handler seems to replace the default handler. When the user tries to save the file my handler runs but the file doesn’t get saved. The handler itself seems to be fine (I’ve tested it by creating a menu item that runs it).

Is Method 1. deprecated now or have I implemented the service incorrectly? How do I get method 2. to save a file? Can the default handler be run from my handler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:40:58+00:00Added an answer on June 2, 2026 at 4:40 am

    These two do not differ just in that one is programmatic and the other declarative. I think defining the command handler is wrong as this handles the command execution instead of just being notified that the command was executed. Your first approach seems fine, but your code doesn’t get executed until the plugin has been activated, which happens lazily, when the first class from your bundle is loaded. There is a workaround in Eclipse: contribute to the org.eclipse.ui.startup extension point. Make e.g. your Activator class implement IStartup, you can use an empty implementation — the only point is to get the framework to load any class from your bundle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Java webapp that I developed locally with m2eclipse + Jetty + eclipse,
I have recently developed an Eclipse plugin, however the plugin does not seem to
I have a handler and a runnable, Handler has a loop that runs from
I have a Handler class that looks like this: class Handler{ public $group; public
We have a requirment which requires to have an Handler that is extended from
I have a message handler, which consumes from a JMS queue and that sends
I have an event handler that needs to determine a type and execute code
I have an event handler that will remove an element from a list of
I have a plug-in to an Eclipse RCP application that has a view. After
I'm trying to use this Sonatype Eclipse plugin for the first time to handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.