Bug 510777 - [Themes] Switch from default or Dark Theme to Themes without css for forms throw an exception
Summary: [Themes] Switch from default or Dark Theme to Themes without css for forms th...
Status: CLOSED DUPLICATE of bug 484506
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: PC Windows All
: P3 normal (vote)
Target Milestone: 4.7 M6   Edit
Assignee: Ralf Petter CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-20 11:48 EST by Ralf Petter CLA
Modified: 2017-02-22 07:59 EST (History)
2 users (show)

See Also:


Attachments
Screenshot of a form based view after a theme change (33.21 KB, image/png)
2017-01-20 11:48 EST, Ralf Petter CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Petter CLA 2017-01-20 11:48:36 EST
Created attachment 266386 [details]
Screenshot of a form based view after a theme change

If you switch from a theme like the default, or the dark one which contains css for FormHeading and Section titlebars, to a theme without css properties for FormHeading and Section, the UI will not be rendered properly and an IllegalArgumentExecption will be thrown. The reason is, that the CSSEngine diposes the color which are set on the Formheading and Section during theme switch and as there are no new colors for FormHeading and Section in the new theme no new colors are set in the widgets and then every repaint of open FormHeadings and Section will throw the Exception because the use a disposed Color.

Steps to reproduce:

Start eclipse oxygen either with Dark or the default theme activated. 
Open some form based views or editors.
Switch to a theme like Win XP blue.

See attached screenshot for how it looks and how it should look after theme switch.

The Stacktrace of the Exception is:

java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4514)
	at org.eclipse.swt.SWT.error(SWT.java:4448)
	at org.eclipse.swt.SWT.error(SWT.java:4419)
	at org.eclipse.swt.graphics.GC.setForeground(GC.java:4639)
	at org.eclipse.ui.internal.forms.widgets.FormHeading.onPaint(FormHeading.java:826)
	at org.eclipse.ui.internal.forms.widgets.FormHeading.lambda$0(FormHeading.java:576)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4431)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1103)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1088)
	at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1665)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4887)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:359)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5194)
	at org.eclipse.swt.internal.win32.OS.RedrawWindow(Native Method)
	at org.eclipse.swt.widgets.Control.update(Control.java:4647)
	at org.eclipse.swt.widgets.Control.update(Control.java:4637)
	at org.eclipse.e4.ui.workbench.renderers.swt.SashLayout.lambda$0(SashLayout.java:97)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:213)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4431)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4241)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3820)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1133)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:684)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
	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)

There are two possible solutions to solve this problem. The easiest would be to add the missing css to all themes, and the more compicated would be to enahnce the CSSStylingcode, that if there is no css for FormHeading or Section in the new theme, that the stylingengine set the default colors like the ones in a FormToolkit.
Comment 1 Lars Vogel CLA 2017-02-01 04:39:59 EST
Where are the colors disposed? The org.eclipse.ui.internal.forms.css.dom.SectionElement reset method tries to switch to the last color. Maybe these colors simply needs some default values?
Comment 2 Ralf Petter CLA 2017-02-01 05:01:14 EST
Lars  i have seen that code for the section is already implemented in org.eclipse.ui.internal.forms.css.dom.SectionElement, but for FormElement the code to reset is missing and so it uses the code for the composite. I have a new version of FormElement in the works which prevents the exception, but i need additional time for further tests.

public class FormElement extends CompositeElement {
	private Map<String, Color> headerColors = new HashMap<>();
	private static final String[] headerColorKeys = { IFormColors.H_BOTTOM_KEYLINE1, IFormColors.H_BOTTOM_KEYLINE2,
			IFormColors.H_GRADIENT_END, IFormColors.H_GRADIENT_START, IFormColors.H_HOVER_FULL,
			IFormColors.H_HOVER_LIGHT, IFormColors.H_PREFIX };
	public FormElement(Form formHeading, CSSEngine engine) {
		super(formHeading, engine);
		for (String headerColorKey : headerColorKeys) {
			headerColors.put(headerColorKey, formHeading.getHeadColor(headerColorKey));
		}
	}

	@Override
	public void reset() {
		super.reset();
		Form formHeading = (Form) getWidget();
		for (String headerColorKey : headerColorKeys) {
			formHeading.setHeadColor(headerColorKey, headerColors.get(headerColorKey));
		}
	}
}

If you want i can upload a WIP review with the changes i have made so far.
Comment 3 Lars Vogel CLA 2017-02-01 05:08:19 EST
(In reply to Ralf Petter from comment #2)
> Lars  i have seen that code for the section is already implemented in
> org.eclipse.ui.internal.forms.css.dom.SectionElement, but for FormElement
> the code to reset is missing and so it uses the code for the composite. I
> have a new version of FormElement in the works which prevents the exception,
> but i need additional time for further tests.

+1 Sounds like the correct approach to me.

> If you want i can upload a WIP review with the changes i have made so far.

Not necessary to upload WIP for me.
Comment 4 Ralf Petter CLA 2017-02-22 07:59:40 EST

*** This bug has been marked as a duplicate of bug 484506 ***