3

After switching to Eclipse Neon I noticed that WorkbenchWindowControlContribution's aren't fully shown. There weren't any problems with them in Eclipse Mars.

A simple item consisting of a Label and a Text looks so in Neon:

enter image description here

The code of the item is below:

package experiments;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;

public class ControlContributionItem extends WorkbenchWindowControlContribution {
    public static final String ID = "MyControlContributionItem"; //$NON-NLS-1$

    @Override
    protected Control createControl(Composite parent) {
        Composite rootComp = new Composite(parent, SWT.NONE);

        GridLayout gridLayout = new GridLayout(2, false);
        gridLayout.marginHeight = 0;
        gridLayout.verticalSpacing = 0;
        rootComp.setLayout(gridLayout);

        Label label = new Label(rootComp, SWT.NONE);
        label.setText("Label"); //$NON-NLS-1$

        Text text = new Text(rootComp, SWT.BORDER | SWT.READ_ONLY);
        text.setText("Text");
        GridData data = new GridData(SWT.FILL, SWT.CENTER, false, true);
        FontData fontData = text.getFont().getFontData()[0];
        Font boldFont = new Font(parent.getDisplay(), fontData.getName(), fontData.getHeight(), fontData.getStyle() | SWT.BOLD);
        text.setFont(boldFont);
        data.widthHint = 120;
        text.setLayoutData(data);

        rootComp.pack();

        return rootComp;
    }

}

The related part in plugin.xml

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.main.toolbar">
         <toolbar
               id="MyControlContributionItem">
            <control
                  class="experiments.ControlContributionItem"
                  id="MyControlContributionItem">
            </control>
         </toolbar>
        </menuContribution>
    </extension>

Can it be a bug in Neon?

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
ka3ak
  • 2,435
  • 2
  • 30
  • 57

1 Answers1

4

Yes this is a bug, reported here:

Bug 471313 - toolbar:org.eclipse.ui.trim.status is not displayed correctly in Eclipse Mars

Also have a look at this one, which suits more your description since it's about the toolbar:

Bug 471326 - main toolbar control contributions is cut off

Printscreen of Error in Mars

Here is a workaround:

The class should extend ControlContribution instead of WorkbenchWindowControlContribution.

In the YourApplicationNameActionBarAdvisor.fillCoolBar() (replace the YourApplicationName) add: toolbar.add(new YourControlContribution());

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
  • 1
    I've been wondering why the Workspace Mechanic icon started appearing like that in Neon. This explains a lot - thanks for the bug links! – avojak May 02 '17 at 14:55
  • 1
    Thanks. I've also raised a bug, which turned out to be a duplicate of 471313. However I've applied another workaround described here https://bugs.eclipse.org/bugs/show_bug.cgi?id=471313#c12 – ka3ak May 03 '17 at 16:30