WorkbenchWindowControlContribution 未在 Eclipse Neon 中完全显示
WorkbenchWindowControlContribution isn't fully shown in Eclipse Neon
切换到 Eclipse Neon 后,我注意到 WorkbenchWindowControlContribution
没有完全显示。在 Eclipse Mars.
中没有任何问题
由 Label
和 Text
组成的简单项目在 Neon 中看起来如此:
商品代码如下:
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;
}
}
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>
会不会是 Neon 中的错误?
是的,这是一个错误,在此处报告:
Bug 471313 - toolbar:org.eclipse.ui.trim.status is not displayed correctly in Eclipse Mars
也看看这个,它更适合你的描述,因为它是关于工具栏的:
Bug 471326 - main toolbar control contributions is cut off
这里有一个解决方法:
class 应该扩展 ControlContribution
而不是 WorkbenchWindowControlContribution
。
在 YourApplicationNameActionBarAdvisor.fillCoolBar()
(替换 YourApplicationName)中添加:toolbar.add(new YourControlContribution());
切换到 Eclipse Neon 后,我注意到 WorkbenchWindowControlContribution
没有完全显示。在 Eclipse Mars.
由 Label
和 Text
组成的简单项目在 Neon 中看起来如此:
商品代码如下:
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;
}
}
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>
会不会是 Neon 中的错误?
是的,这是一个错误,在此处报告:
Bug 471313 - toolbar:org.eclipse.ui.trim.status is not displayed correctly in Eclipse Mars
也看看这个,它更适合你的描述,因为它是关于工具栏的:
Bug 471326 - main toolbar control contributions is cut off
这里有一个解决方法:
class 应该扩展 ControlContribution
而不是 WorkbenchWindowControlContribution
。
在 YourApplicationNameActionBarAdvisor.fillCoolBar()
(替换 YourApplicationName)中添加:toolbar.add(new YourControlContribution());