Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMFForms] ClassCastException while setting Validation Color after upgrading to EMFForms 1.9
[EMFForms] ClassCastException while setting Validation Color after upgrading to EMFForms 1.9 [message #1740517] Mon, 15 August 2016 10:45 Go to next message
Peter Hermsdorf is currently offline Peter HermsdorfFriend
Messages: 25
Registered: August 2011
Junior Member
hi,

I'm using a customized Version of the XMLDateControlSWTRenderer to make it look a little bit different and to add our own DatePicker.
Additionally i'm using a validation template to set a custom error color.

After upgrading to EMFForms 1.9 (from 1.7) I'm getting the following ClassCastException when builing the UI

Caused by: java.lang.ClassCastException: Cannot cast org.eclipse.swt.widgets.Text to org.eclipse.swt.widgets.Composite
	at java.lang.Class.cast(Class.java:3369) ~[na:1.8.0_74]
	at org.eclipse.emf.ecp.view.spi.core.swt.renderer.TextControlSWTRenderer.setValidationColor(TextControlSWTRenderer.java:452) ~[na:na]
	at org.eclipse.emf.ecp.view.internal.core.swt.renderer.XMLDateControlSWTRenderer.setValidationColor(XMLDateControlSWTRenderer.java:405) ~[na:na]
	at org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer.applyInnerValidation(SimpleControlSWTRenderer.java:486) ~[na:na]
	at org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer.access$3(SimpleControlSWTRenderer.java:453) ~[na:na]
	at org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer$1.run(SimpleControlSWTRenderer.java:448) ~[na:na]
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) ~[org.eclipse.swt.gtk.linux.x86_3.104.2.v20160212-1350.jar:na]
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135) ~[org.eclipse.swt.gtk.linux.x86_3.104.2.v20160212-1350.jar:na]


My Class P4XMLDateControlSWTRenderer extends from XMLDateControlSWTRenderer and creates the Controls in a similar way:

@Override
	protected Control createSWTControl(final Composite parent) {
		final Composite main = new Composite(parent, SWT.NONE);
		main.setBackground(parent.getBackground());
		GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).numColumns(2).applyTo(main);
		GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(main);

		text = createTextControl(main);
		GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(text);

		final Label calendarButton = new Label(main, SWT.BORDER);
		final Image image = P4Images.CATALOG_BUTTON.getEnabled();
		calendarButton.setImage(image);
		calendarButton.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_control_xmldate"); //$NON-NLS-1$
		GridDataFactory.fillDefaults().applyTo(calendarButton);

		return main;
	}

	private Text createTextControl(final Composite parent) {
		final Text text = new Text(parent, getTextWidgetStyle());
		text.setData(CUSTOM_VARIANT, getTextVariantID());
		text.setMessage(getTextMessage());
		text.addFocusListener(new FocusListener() {
			@Override
			public void focusLost(final FocusEvent e) {
			}

			@Override
			public void focusGained(final FocusEvent e) {
				text.selectAll();
			}
		});
		return text;
	}


Any hints on what the problem could be are more than welcome.

cheers, peter
Re: [EMFForms] ClassCastException while setting Validation Color after upgrading to EMFForms 1.9 [message #1740598 is a reply to message #1740517] Tue, 16 August 2016 06:28 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,

due to holiday season, we will get back to you by the end of this week.

Best regards

Jonas

On 15.08.2016 12:45, Peter Hermsdorf wrote:
> hi,
>
> I'm using a customized Version of the XMLDateControlSWTRenderer to make
> it look a little bit different and to add our own DatePicker.
> Additionally i'm using a validation template to set a custom error color.
>
> After upgrading to EMFForms 1.9 (from 1.7) I'm getting the following
> ClassCastException when builing the UI
>
> Caused by: java.lang.ClassCastException: Cannot cast
> org.eclipse.swt.widgets.Text to org.eclipse.swt.widgets.Composite
> at java.lang.Class.cast(Class.java:3369) ~[na:1.8.0_74]
> at
> org.eclipse.emf.ecp.view.spi.core.swt.renderer.TextControlSWTRenderer.setValidationColor(TextControlSWTRenderer.java:452)
> ~[na:na]
> at
> org.eclipse.emf.ecp.view.internal.core.swt.renderer.XMLDateControlSWTRenderer.setValidationColor(XMLDateControlSWTRenderer.java:405)
> ~[na:na]
> at
> org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer.applyInnerValidation(SimpleControlSWTRenderer.java:486)
> ~[na:na]
> at
> org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer.access$3(SimpleControlSWTRenderer.java:453)
> ~[na:na]
> at
> org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer$1.run(SimpleControlSWTRenderer.java:448)
> ~[na:na]
> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
> ~[org.eclipse.swt.gtk.linux.x86_3.104.2.v20160212-1350.jar:na]
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
> ~[org.eclipse.swt.gtk.linux.x86_3.104.2.v20160212-1350.jar:na]
>
>
> My Class P4XMLDateControlSWTRenderer extends from
> XMLDateControlSWTRenderer and creates the Controls in a similar way:
>
> @Override
> protected Control createSWTControl(final Composite parent) {
> final Composite main = new Composite(parent, SWT.NONE);
> main.setBackground(parent.getBackground());
> GridLayoutFactory.fillDefaults().spacing(0,
> LayoutConstants.getSpacing().y).numColumns(2).applyTo(main);
> GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL,
> SWT.BEGINNING).applyTo(main);
>
> text = createTextControl(main);
> GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL,
> SWT.CENTER).applyTo(text);
>
> final Label calendarButton = new Label(main, SWT.BORDER);
> final Image image = P4Images.CATALOG_BUTTON.getEnabled();
> calendarButton.setImage(image);
> calendarButton.setData(CUSTOM_VARIANT,
> "org_eclipse_emf_ecp_control_xmldate"); //$NON-NLS-1$
> GridDataFactory.fillDefaults().applyTo(calendarButton);
>
> return main;
> }
>
> private Text createTextControl(final Composite parent) {
> final Text text = new Text(parent, getTextWidgetStyle());
> text.setData(CUSTOM_VARIANT, getTextVariantID());
> text.setMessage(getTextMessage());
> text.addFocusListener(new FocusListener() {
> @Override
> public void focusLost(final FocusEvent e) {
> }
>
> @Override
> public void focusGained(final FocusEvent e) {
> text.selectAll();
> }
> });
> return text;
> }
>
> Any hints on what the problem could be are more than welcome.
>
> cheers, peter
Re: [EMFForms] ClassCastException while setting Validation Color after upgrading to EMFForms 1.9 [message #1740767 is a reply to message #1740598] Thu, 18 August 2016 12:09 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 130
Registered: May 2015
Senior Member
Hi Peter,

The problem is, that the setValidationColor method of the XMLDateControlSWTRenderer knows that the createSwtControl method creates a composite as a wrapper around the result from the super call and thus pulls out this result and uses it in the super call to the setValidationColor of the TextControlSWTRenderer.
Now in the setValidationColor of the TextControlSWTRenderer we also "know" that the renderer encapsulated the actual control we want the validation color on into a composite. Thus it also takes the first element of this composite.
In your case this assumptions do not hold true and thus you get a ClassCast exception as you only have one Composite.

So in your case you simply could overwrite the setValidationColor method like this, as you have the Text element as a member variable:
protected void setValidationColor(Control control, Color validationColor) {
text.setBackground(validationColor);
}

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [EMFForms] ClassCastException while setting Validation Color after upgrading to EMFForms 1.9 [message #1740781 is a reply to message #1740767] Thu, 18 August 2016 13:52 Go to previous message
Peter Hermsdorf is currently offline Peter HermsdorfFriend
Messages: 25
Registered: August 2011
Junior Member
Thanks for the information, that fixed it.

Pretty easy at the end, just haven't seen that!

Thank you very much, as always Wink

Cheers, Peter
Previous Topic:Feature-based configuration for EMF Forms
Next Topic:[EMFForms] FeaturePathDomainModelReferenceConverter.getSetting throws DatabindingFailedException
Goto Forum:
  


Current Time: Tue Apr 24 23:23:59 GMT 2018

Powered by FUDForum. Page generated in 0.01626 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software