indexalice
indexalice

Reputation: 119

How to call method in other plugin?

I'm developing a eclipse plugin named mainPage ,and want to call a method in a plugin named Terminal.

I have already add Terminal to Bundle-ClassPath and Require-Bundle,then I called the method in mainPage like this

new ShowToolStoreCommandHandler().execute(null);

This method is to open a window . But i have a java.lang.NullPointerException when call this method.

I found the method getDefault() returns null when getting the instance of the Terminal in the Activator of Terminal.

So,how to call this method to open a window?

Upvotes: 0

Views: 376

Answers (1)

greg-449
greg-449

Reputation: 111142

There is nothing special about calling methods in other plug-ins provided they are designed to be called that way.

The class you mention is probably a command handler so it will expect to be called from the command handler service with the environment set up correctly.

You can use the IHandlerService to execute command handlers:

String commandId = .... the command id 

IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);

handlerService.executeCommand(commandId, null);

This assumes the command handler doesn't need an event argument and doesn't require any command parameters. If it does the call will be more complex and requires more research.

The 'commandId' will probably be defined in the plugin.xml of the plug-in.

Upvotes: 1

Related Questions