Skip Navigation

Adding Status Lines for Editors

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

  1. In the Package Explorer, expand the project name of the editor project to receive a status line contribution.

  2. Expand the src folder, and then expand the package name of the editor.

  3. Open your Java source file in a Java editor. The file you open must have the AbstractAppEditor class that you extended when you created the sample editor. (See the Name field for AbstractAppEditor.)

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

import com.sabre.edge.platform.core.editor.editors.AbstractAppEditor;

public class SampleEditor extends AbstractAppEditor {

  public SampleEditor() {
    super();
  }
}
  1. Create the initializeStatusLine() method. In this method, include the code in Steps 6 through 9 below.

private void initializeStatusLine() {

}
  1. Include the following code to retrieve a reference to IStatusLineManager.

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

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

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

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

  1. 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 Editor 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.

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

actionBars.updateActionBars();

  1. Call the initializeStatusLine() method from the createPartControl() method.

public void createPartControl(Composite parent)
    {
        Label label = new Label(parent, SWT.NONE);
        label.setText("Sample Editor");
        parent.setLayout(new FillLayout());

        initializeStatusLine();
    }

Your AbstractAppEditor 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.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IActionBars;
import  com.sabre.edge.platform.core.editor.editors.AbstractAppEditor;

public class SampleEditor extends AbstractAppEditor
{

    public void createPartControl(Composite parent)
    {
        Label label = new Label(parent, SWT.NONE);
        label.setText("Sample Editor");
        parent.setLayout(new FillLayout());

        initializeStatusLine();
    }

    private void initializeStatusLine()
    {
        IActionBars actionBars = getEditorSite().getActionBars();

        IStatusLineManager statusLineManager =
            actionBars.getStatusLineManager();
        statusLineManager.setMessage("Simple Editor status message");

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

        actionBars.updateActionBars();
    }
}