Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » Opening CompareUI Dialog based on tutorial(CompareConfiguration() init leads to NullPointerException)
Opening CompareUI Dialog based on tutorial [message #1469654] Tue, 11 November 2014 20:00 Go to next message
Márton Tunner is currently offline Márton TunnerFriend
Messages: 3
Registered: September 2014
Junior Member
Hi,

I would like to use the CompareUI Dialog, but CompareConfiguration() init leads to NullPointerException at this row:
CompareConfiguration ccfg = new CompareConfiguration();

Exception in thread "main" java.lang.NullPointerException
at org.eclipse.compare.CompareConfiguration.<init>(CompareConfiguration.java:279)


If I try to do it based on the tutorial, Eclipse makes me cast it to EMFCompareConfiguration and it leads to this:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.eclipse.compare.CompareEditorInput.<clinit>(CompareEditorInput.java:163)

CompareEditorInput input = new ComparisonEditorInput((EMFCompareConfiguration) new CompareConfiguration(), comparison, editingDomain, adapterFactory);


What is wrong, what should I do?

Thanks,
Márton
Re: Opening CompareUI Dialog based on tutorial [message #1471801 is a reply to message #1469654] Thu, 13 November 2014 10:47 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi Márton,

It seems like you are trying to use the compare configuration in a standalone environment, which cannot be done. You need to put your code in a plugin project and use it through a new Eclipse runtime.

Please see tutorials on how to create eclipse plugins for more information (this one's a little old but should get you started)

Laurent Goubet
Obeo
Re: Opening CompareUI Dialog based on tutorial [message #1471976 is a reply to message #1471801] Thu, 13 November 2014 13:46 Go to previous messageGo to next message
Márton Tunner is currently offline Márton TunnerFriend
Messages: 3
Registered: September 2014
Junior Member
Hi Laurent,

Thank you for your help, I will have a look at the tutorial.

Márton
Re: Opening CompareUI Dialog based on tutorial [message #1737050 is a reply to message #1471801] Tue, 05 July 2016 10:15 Go to previous messageGo to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 40
Registered: May 2012
Member
Hello,
I'm resuming this post because I had the exact same problem as the OP. My environment is as follows:
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600
Model comparison (EMF Compare) - 3.1.1.201509120604

According to your suggestion, I packaged all the code into a plugin. Now I'm running the code from a new Eclipse runtime instance, but it fails to execute with the following error message:
!ENTRY org.eclipse.ui 4 0 2016-07-05 11:48:57.084
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.compare.CompareConfiguration cannot be cast to org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration
  at ...
Caused by: java.lang.ClassCastException: org.eclipse.compare.CompareConfiguration cannot be cast to org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration
  at ...
... 38 more


This is the portion of code I'm using (note that, at line 3, the tutorial does not cast argument 1 to EMFCompareConfiguration):
// Instantiating an EMF Compare specific implementation of CompareEditorInput
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(scope.getLeft(), scope.getRight(), null);
AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
CompareEditorInput input = new ComparisonEditorInput((EMFCompareConfiguration) new CompareConfiguration(), comparison, editingDomain, adapterFactory);
CompareUI.openCompareDialog(input); // or CompareUI.openCompareEditor(input);


Maybe it's worth to remark that I get multiple warnings for this line:
CompareEditorInput input = new ComparisonEditorInput((EMFCompareConfiguration) new CompareConfiguration(), comparison, editingDomain, adapterFactory);


Here are the warnings:
- Discouraged access: The type 'ComparisonEditorInput' is not API (restriction on required library '<eclipse-dir>\plugins\org.eclipse.emf.compare.ide.ui_4.1.1.201509120604.jar')
- Discouraged access: The constructor 'ComparisonEditorInput(EMFCompareConfiguration, Comparison, ICompareEditingDomain, AdapterFactory)' is not API (restriction on required library '<eclipse-dir>\plugins\org.eclipse.emf.compare.ide.ui_4.1.1.201509120604.jar')
- Discouraged access: The type 'EMFCompareConfiguration' is not API (restriction on required library '<eclipse-dir>\plugins\org.eclipse.emf.compare.ide.ui_4.1.1.201509120604.jar')


It seems to me that the tutorial is not in-line with latest releases of EMF compare. How do I launch the CompareUI Dialog programmatically in EMF Compare 3.1.1?

Thanks in advance. Best,
--
Matteo

[Updated on: Tue, 05 July 2016 10:30]

Report message to a moderator

Re: Opening CompareUI Dialog based on tutorial [message #1737183 is a reply to message #1737050] Wed, 06 July 2016 09:10 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

Could you give us the full stack trace of the failure? this cannot be used to help you as-is.

Laurent Goubet
Obeo
Re: Opening CompareUI Dialog based on tutorial [message #1737184 is a reply to message #1737183] Wed, 06 July 2016 09:21 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Ho, the failure is in your code... yeah "(EMFCompareConfiguration) new CompareConfiguration()" cannot work. An EMFCompareConfiguration is a CompareConfiguration, but a CompareConfiguration is not an EMFCompareConfiguration.

Please use new EMFCompareConfiguration(new CompareConfiguration()) for a default config.

The documentation is indeed not up-to-date. We'll have to change this (bug 497371 opened for this).

Laurent Goubet
Obeo
Re: Opening CompareUI Dialog based on tutorial [message #1737186 is a reply to message #1737183] Wed, 06 July 2016 09:41 Go to previous message
Matteo M. is currently offline Matteo M.Friend
Messages: 40
Registered: May 2012
Member
Ok thanks, indeed I had tried something similar, i.e., using new EMFCompareConfiguration(). I didn't realize that I had to provide the new CompareConfiguration() as input argument.
Thanks
--
Matteo

[Updated on: Wed, 06 July 2016 09:46]

Report message to a moderator

Previous Topic:different xml file in different model but under the same folder
Next Topic:CompareUI Dialog: 'Cancel' after merging raises an exception
Goto Forum:
  


Current Time: Tue Mar 19 10:42:37 GMT 2024

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

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

Back to the top