I have a big plug-in eclipse Indigo RCP program. Trying to migrate to Oxygen and Java 8 (from 7) I get problems with all om my setExpanded(false) regarding GridLayouts.
I get a response similar to ...GridLayout can not be casted to FillLayout. The strange thing is that this worked in Indigo. No changes to the code-base between the two versions. Apart from this Compact/Extend the program seems to work.
Any ideas??
Of course I can add the error-message but my question is if there are changes between indigo and Oxygen or even Neon and Oxygen that concern setExtend?
There is a bug report out there from 2014 but seems never to have been resoved.
stack trace:
!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)
Code:
@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);
}
The line:
baseComp.setLayoutData(new GridData(GridData.FILL_BOTH));
is setting layout data on the base composite. This data is used by the parent
control layout. The parent control is using FillLayout
so GridData
is not correct. You should just remove this line as you don't need any layout data for FillLayout
.
setExpanded
causes a reflow
which redoes the layout of all controls so you are hitting this when you call setExpanded
.
Also note:
layout = new GridLayout();
layout.horizontalSpacing = 0;
layout.verticalSpacing = 10;
layout.marginHeight = 0;
layout.marginWidth = 0;
m_searchRoiSection.setLayout(layout);
Section
does not support setLayout
and is just ignoring this call.