我有一个很大的Eclipse Indigo RCP插件程序。
尝试迁移到Oxygen和Java 8(从7开始)时,我所有关于GridLayouts的setExpanded(false)都出现了问题。

我得到类似于...的响应 GridLayout无法转换为FillLayout
奇怪的是,这在Indigo中有效。两个版本之间的代码库均未更改。除了此压缩/扩展程序外,该程序似乎还可以工作。

有任何想法吗??

当然我可以添加错误消息,但是我的问题是靛蓝和氧气之间,甚至霓虹灯和氧气之间是否存在与setExtend有关的变化?

2014年有一个错误报告,但似乎从未得到解决。

堆栈跟踪:

!ENTRY org.eclipse.ui 4 0 2017-09-15 08:44:54.915
!MESSAGE Unhandled event loop exception
!STACK 0
    java.lang.ClassCastException: org.eclipse.swt.layout.GridData cannot be cast to org.eclipse.swt.layout.FillData
    at org.eclipse.swt.layout.FillLayout.flushCache(FillLayout.java:173)
    at org.eclipse.swt.widgets.Composite.layout(Composite.java:831)
    at org.eclipse.swt.widgets.Control.requestLayout(Control.java:2427)
    at org.eclipse.ui.forms.widgets.ExpandableComposite.reflow(ExpandableComposite.java:1139)
    at org.eclipse.ui.forms.widgets.Section.reflow(Section.java:122)
    at org.eclipse.ui.forms.widgets.ExpandableComposite.internalSetExpanded(ExpandableComposite.java:893)
    at org.eclipse.ui.forms.widgets.Section.internalSetExpanded(Section.java:108)
    at org.eclipse.ui.forms.widgets.ExpandableComposite.toggleState(ExpandableComposite.java:1068)
    at org.eclipse.ui.forms.widgets.ExpandableComposite.access$5(ExpandableComposite.java:1065)
    at org.eclipse.ui.forms.widgets.ExpandableComposite$1.linkActivated(ExpandableComposite.java:576)
    at org.eclipse.ui.forms.widgets.AbstractHyperlink.handleActivate(AbstractHyperlink.java:213)
    at org.eclipse.ui.forms.widgets.AbstractHyperlink.handleMouseUp(AbstractHyperlink.java:307)
    at org.eclipse.ui.forms.widgets.AbstractHyperlink.lambda$3(AbstractHyperlink.java:115)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4428)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4238)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3817)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1044)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
    at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
    at com.myCompany.rcp.console.product.Application.start(Application.java:167)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1472)

码:

    @Override
    public void createPartControl(Composite parent)

{
// Toolkit
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
toolkit.setBorderStyle(SWT.NO);

// Base component
baseComp = toolkit.createComposite(parent);
GridLayout layout = new GridLayout();
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight=0;
layout.marginWidth=0;
baseComp.setLayout(layout);
baseComp.setLayoutData(new GridData(GridData.FILL_BOTH));
m_searchRoiSection = toolkit.createSection(baseComp, Section.DESCRIPTION | Section.TWISTIE | Section.EXPANDED);
m_searchRoiSection.setActiveToggleColor(toolkit.getHyperlinkGroup().getActiveForeground());
m_searchRoiSection.setToggleColor(toolkit.getColors().getColor(IFormColors.SEPARATOR));
toolkit.createCompositeSeparator(m_searchRoiSection);
layout = new GridLayout();
layout.horizontalSpacing = 0;
layout.verticalSpacing = 10;
layout.marginHeight = 0;
layout.marginWidth = 0;
m_searchRoiSection.setLayout(layout);
m_searchRoiSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
m_searchRoiSection.addExpansionListener(new ExpansionAdapter()
{
public void expansionStateChanged(ExpansionEvent e)
{
updateRoiSection();
}
});
m_searchRoiSection.setText("ROI");
m_searchRoiSection.setDescription("Select region of interest. Leave blank for any area.");
Composite searchRoiComp = toolkit.createComposite(m_searchRoiSection);
layout = new GridLayout();
layout.horizontalSpacing = 3;
layout.verticalSpacing = 3;
layout.marginHeight = 5;
layout.marginWidth = 5;
layout.numColumns = 3;
searchRoiComp.setLayout(layout);
// Create ROI search section contents
createRoiSearch(searchRoiComp);
m_searchRoiSection.setClient(searchRoiComp);
m_searchRoiSection.setExpanded(false);
}

最佳答案

该行:

baseComp.setLayoutData(new GridData(GridData.FILL_BOTH));

在基础复合材料上设置布局数据。此数据由parent控件布局使用。父控件使用的是FillLayout,因此GridData不正确。您只需要删除此行,因为FillLayout不需要任何布局数据。
setExpanded会导致生成一个reflow,它会重做所有控件的布局,因此您在调用setExpanded时将其击中。

另请注意:
layout = new GridLayout();
layout.horizontalSpacing = 0;
layout.verticalSpacing = 10;
layout.marginHeight = 0;
layout.marginWidth = 0;
m_searchRoiSection.setLayout(layout);
Section不支持setLayout,只是忽略了此调用。

10-08 19:39