Skip Navigation

Adding Status Lines for Views

Before you can add status line contributions for a view, your plug-in must include a view.

  1. Open your project in your Eclipse workspace.

  2. From Package Explorer, expand the project name of the view project to receive a status line contribution.

  3. Expand the src folder, and then expand the package name of the view.

  4. Open your Java source file in a Java editor. The file you open must have the ViewPart class that you extended when you created the sample view.

        In the code for the sample view, these lines are the following:

import org.eclipse.ui.part.ViewPart;
public class BasicViewPart extends ViewPart {
}
  1. Create the initializeStatusLine() method.

private void initializeStatusLine() {

}
  1. In initializeStatusLine(), include the code that is shown below.

        Include the following code to retrieve a reference to IStatusLineManager .

        This lets you get an instance of IStatusLineManager for which you can call other methods.

IActionBars actionBars = getViewSite().getActionBars();
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();

        Include the following code to define the message text that you want to display on the status line:

statusLineManager.setMessage("Simple View status message");

        Include the following code to add a new item to the status line and to define the text.

StatusLineContributionItem modeContributionItem = new StatusLineContributionItem("mode");
modeContributionItem.setText("Simple View mode");
statusLineManager.add(modeContributionItem);
statusLineManager.add(new Separator());

        In this sample, modeContributionItem is an element that displays the message text on the status line.

        You can provide your own name.

        You can add new items with the StatusLineContributionItem class.

        Include the following code to propagate the changes throughout the workbench:

actionBars.updateActionBars();

  1. In createPartControl(), add the following code:

@Override
public void createPartControl(Composite parent)
{
      initializeStatusLine();
}

        Extend createPartControl() and setFocus() . You defined the behavior for the setFocus() method when you created your view, so you can complete this method accordingly.

Your Java code should be similar to the following:

package com.sabre.redapp.example.statusbar;

import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;

public class SampleView extends ViewPart
{

    /**
     * {@inheritDoc}
     */
    @Override
    public void createPartControl(Composite parent)
    {
        initializeStatusLine();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setFocus() {
    }
    private void initializeStatusLine()
    {
        IActionBars actionBars = getViewSite().getActionBars();
        IStatusLineManager statusLineManager = actionBars.getStatusLineManager();

        statusLineManager.setMessage("Simple View status message");
        StatusLineContributionItem modeContributionItem = newStatusLineContributionItem("mode");
        modeContributionItem.setText("Simple View mode");
        statusLineManager.add(modeContributionItem);
        statusLineManager.add(new Separator());
        actionBars.updateActionBars();
    }
}