Search code examples
javaeclipseswteclipse-pdeeclipse-neon

WorkbenchWindowControlContribution isn't fully shown in Eclipse Neon


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?


Solution

  • 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());