Skip to Content
Eclipse Cookbook
book

Eclipse Cookbook

by Steve Holzner
June 2004
Beginner to intermediate
364 pages
7h 38m
English
O'Reilly Media, Inc.
Content preview from Eclipse Cookbook

12.10. Coding a Plug-in Action

Problem

You have an action, and you need to make it actually do something.

Solution

Edit its .java file, and implement the support you need.

Discussion

Continuing the example developed over the previous three recipes, open Action1.java now if it’s not already open. This file contains plenty of TODOs, such as adding code to the action’s constructor to customize it, which we’ll ignore in this example. Here, we’ll display a message box when the user selects our menu item or clicks our toolbar button, as the plug-in developed earlier in this chapter did.

To do that, we’ll need an object that implements the Workbench window interface, IWorkbenchWindow. The object we need is passed to the init method in Action1.java, so we’ll begin by creating a private class variable, window, to hold it:

public class Action1 implements IWorkbenchWindowActionDelegate {
    private IWorkbenchWindow window;
        .
        .
        .

Then we’ll store the Workbench window passed to us in the init method in this variable like so:

public void init(IWorkbenchWindow window)  {
    this.window = window;
}

We can use this variable and the openInformation method of the MessageDialog class to display a message box with the message This plug-in is functional. in the action’s run method. To use the MessageDialog class, we first import it and then call it in the run method:

               import org.eclipse.jface.dialogs.MessageDialog;
        .
        .
        .
public void run(IAction action)  {
    MessageDialog.openInformation(
               window.getShell( ),
    "New Plug-in" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Eclipse

Eclipse

Steve Holzner
Official Eclipse 3.0 FAQs

Official Eclipse 3.0 FAQs

John Arthorne, Chris Laffra

Publisher Resources

ISBN: 0596007108Catalog PageErrata