Search code examples
javaeclipsepluginsstatusbar

In Eclipse statusbar is there a way to include a new statusfield (say the file's line delimiters )?


Iam writing an eclipse plugin with a customized text editor. The status bar contibutor iam using is is the default one. and these fields displayed are Standard Eclipse statusbar

i believe they are because of the following in org.eclipse.ui.part.EditorActionBarContributor

/**
 * The status fields to be set to the editor
 * @since 3.0
 */
private final static StatusFieldDef[] STATUS_FIELD_DEFS= {
    new StatusFieldDef(ITextEditorActionConstants.STATUS_CATEGORY_FIND_FIELD, null, false, EditorMessages.Editor_FindIncremental_reverse_name.length() + 15),
    new StatusFieldDef(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE, null, true, StatusLineContributionItem.DEFAULT_WIDTH_IN_CHARS + 1),
    new StatusFieldDef(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE, ITextEditorActionDefinitionIds.TOGGLE_OVERWRITE, true, StatusLineContributionItem.DEFAULT_WIDTH_IN_CHARS),
    new StatusFieldDef(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION, ITextEditorActionConstants.GOTO_LINE, true, StatusLineContributionItem.DEFAULT_WIDTH_IN_CHARS)
};

my question is how to add a new status field for linedelimiter type


Solution

  • You should define you own editor action bar contributor which extends BasicTextEditorActionContributor to get the standard status fields.

    Override contributeToStatusLine and add new status line contribution items for your extra items:

    @Override
    public void contributeToStatusLine(IStatusLineManager statusLineManager) {
      super.contributeToStatusLine(statusLineManager);
    
      statusLineManager.add(item);
    }
    

    where item is a StatusLineContributionItem which you should create in the action bar contributor construtor:

    item = new StatusLineContributionItem("id", true, width in characters);
    

    In the setActiveEditor method you should set the action for the item and tell the editor about the status field:

    @Override
    public void setActiveEditor(IEditorPart part) {
    
      // TODO check this is your editor
    
      item.setActionHandler(... get action handler from editor...);
    
      ITextEditorExtension extension = (ITextEditorExtension)part;
      extension.setStatusField(item, "id");
    }
    

    In your main editor code extending TextEditor you can then call

    IStatusField statusField = getStatusField("id");
    
    statusField.setText("text");
    statusField.setImage(image);