简体   繁体   中英

Eclipse RCP: Height of a search text in the toolbar in Eclipse 4.6

I have an Eclipse 3.8 RCP application that runs on the Eclipse 4.4 platform using the compatibility layer . In the toolbar there is a search text which looks like this:

工具栏4.4

But when I run the application on Eclipse 4.6 it looks like this:

工具栏4.6

The search text is added via the following extension point in the plugin.xml :

<extension point="org.eclipse.ui.menus">
<menuContribution
    locationURI="toolbar:org.eclipse.ui.trim.command2">
    <toolbar id="search.toolbar">
    <control 
        class="app.SearchText"
        id="app.SearchText">
    </control>
    </toolbar>
</menuContribution>
</extension>

The SearchText class looks like this:

public class SearchText extends WorkbenchWindowControlContribution {

// ...

@Override
protected Control createControl(Composite parent) {
    parent.setLayout(new FillLayout());
    log.trace("create search text control");
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = 5;
    layout.marginHeight = 0;
    layout.marginWidth = 5;
    layout.verticalSpacing = 0;
    composite.setLayout(layout);
    text = new Text(composite, SWT.BORDER | SWT.SEARCH);
    // ...
    return composite;
}

// ...

I played with the layout parameters but with no success and I have no idea how this could be fixed. Thanks for any help on this!

I reported a bug a while ago: main toolbar control contributions is cut off

Here is a workaround:

The class should extend ControlContribution instead of WorkbenchWindowControlContribution .

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



Here the print screens of the reported bug, must be the same issue.

Test with Eclipse Luna (4.4.2) 使用Eclipse Luna(4.4.2)进行测试

Test with Eclipse Mars (4.5.0) 使用Eclipse Mars进行测试(4.5.0)

For Eclipse Oxygen (4.7) the following workaround posted on this issue worked for me:

public class MyWorkbenchWindowControlContribution extends
    WorkbenchWindowControlContribution {

  @Override
  protected Control createControl(Composite parent) {
    parent.getParent().setRedraw(true);
    ....
  }

  @Override
  public boolean isDynamic() {
    return true;
  }
  ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM