2

I'm developing a plug-in for a Eclipse RCP application. In this plug-in I want to set a text message and an icon in the trim status bar.

Considering my circumstances, I think I can scrap the following approaches:

  • The ActionBarAdvisor approach seems to require the main application to set the status bar content. This is not suitable as the plug-in should be able to be independent to the application and vice versa.

  • The StatusLineContributionItem seems to be bound to a certain view. In my case, the content has to be set globally for the whole application regardless of the currently selected view.

This leaves us to the Contributing to the Status Bar/Trim in Eclipse RCP approach. I've set up a small sample implementation following this approach:

The plugin.xml implementation:

  <menuContribution
        allPopups="false"
        locationURI="toolbar:org.eclipse.ui.trim.status">
     <toolbar
           id="mypackage.toolbarContribution">
        <control
              class="mypackage.StatusBarContribution">
        </control>
     </toolbar>
  </menuContribution>

And the class implementation:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;

public class StatusBarContribution extends WorkbenchWindowControlContribution {

  protected Composite composite = null;

  @Override
  protected Control createControl(Composite parent) {
    FillLayout layout = new FillLayout(SWT.HORIZONTAL);
    layout.marginHeight = 0;
    layout.marginWidth = 0;        

    composite = new Composite(parent, SWT.NO_TRIM | SWT.BORDER);
    composite.setLayout(layout);  

    Text text = new Text(composite, SWT.NONE);
    text.setText("foo");

    return composite;
  }  
}

But this only gives me a small slice of text in the status bar:

enter image description here

I purposely set

composite = new Composite(parent, SWT.NO_TRIM  | SWT.BORDER);

to be able to see the layout margins:

As you can see, the created composite height is way to low to display the text correctly: status bar's composite borders

So, am I missing here something - e.g. using another margin property or SWT bit style?

Baz
  • 36,440
  • 11
  • 68
  • 94
Niklas
  • 102
  • 10
  • You could try using GridLayout rather than FillLayour. Use GridData with a width and height hint on the Text. – greg-449 May 09 '18 at 12:06
  • 2
    Hi Greg, I tried the following without any success after changing the layout to GridLayout: `GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, false, true); gridData.heightHint = text.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; text.setLayoutData(gridData);` – Niklas May 11 '18 at 10:05
  • @Niklas did you have any success with this problem? I have just upgraded my RCP app from Kepler to 2020-03 and now have the same problem as you have described. – paul May 27 '20 at 06:57

1 Answers1

0

If you add a dummy command contribution in addition to the control, layout works.

tander
  • 1