Skip to main content



      Home
Home » Modeling » EMF » [EMF Compare] How to provide a ModelComparison for custom refactorings?
[EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1067560] Tue, 09 July 2013 06:33 Go to next message
Eclipse UserFriend
Hello,
with the new EMF Compare version some API changes ocurred. In my project
I provide a lot of custom model refactorings which integrated very well
into the Eclipse LTK. So it was possible to provide a Change object and
the refactoring was integrated into the Refactoring History and so on.
The nice thing was that if the Change object implemented the
org.eclipse.emf.compare.ui.IModelCompareInputProvider interface then a
structure-based comparison of the original and refactored model could be
provided very easy. The only method which is required to be implemented
from this interface was

ModelCompareInput getModelCompareInput()

A ModelCompareInput just needed a match and a diff and a nice preview
could be displayed. My problem now is that IModelCompareInputProvider is
not provided anymore. How can I achieve this with the current EMF
Compare API?

best regards,
Jan
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1067696 is a reply to message #1067560] Wed, 10 July 2013 03:36 Go to previous messageGo to next message
Eclipse UserFriend
Without this I only get an empty preview saying that no preview is
available. How can I achieve this?

best regards,
Jan
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1067959 is a reply to message #1067696] Thu, 11 July 2013 08:41 Go to previous messageGo to next message
Eclipse UserFriend
No one here who can help?

best regards,
Jan
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1068192 is a reply to message #1067560] Fri, 12 July 2013 11:27 Go to previous messageGo to next message
Eclipse UserFriend
Ok guys, I played around a little bit but until now I wasn't
successfull. This is what I did.

At first I found an extension point where one can register a new previewer:

<extension
point="org.eclipse.ltk.ui.refactoring.changePreviewViewers">
<changePreviewViewer
class="MyPreviewer"
id="myPreviewerID">
<enablement>
<instanceof value="MyChange"/>
</enablement>
</changePreviewViewer>
</extension>

Ok, doing this MyPreviewer must implement the interface
IChangePreviewViewer (code follows shortly).
Then I found this article:
http://wiki.eclipse.org/EMF_Compare/How_To_Open_Compare_Dialog_With_Comparison#With_pre-computed_comparison
There you can see how to open a modal Compare Dialog. This just works
fine, but I wanted to integrate it into the refactoring wizard as
preview. Thus, my MyPreviewer implementation looks like this:

public class MyPreviewer implements IChangePreviewViewer {

private ViewForm control;

public void createControl(Composite parent) {
control = new ViewForm(parent, SWT.BORDER);
}

public Control getControl() {
return control;
}

public void setInput(ChangePreviewViewerInput input) {
if(!(input.getChange() instanceof MyChange)){
return;
}
MyChange change = (MyChange) input.getChange();
EObject originalModel = change.getRefactorer().getOriginalModel();
EObject fakeRefactoredModel =
change.getRefactorer().getFakeRefactoredModel();

EMFCompare comparator = EMFCompare.builder().build();
Comparison comparison =
comparator.compare(EMFCompare.createDefaultScope(originalModel,
fakeRefactoredModel));
ICompareEditingDomain editingDomain =
EMFCompareEditingDomain.create(originalModel, fakeRefactoredModel, null);
AdapterFactory adapterFactory = new
ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
CompareEditorInput compareEditorInput = new
ComparisonEditorInput(new CompareConfiguration(), comparison,
editingDomain, adapterFactory);
compareEditorInput.run(new NullProgressMonitor());

AbstractModelCompareDialog dialog = new
AbstractModelCompareDialog(control, compareEditorInput);
Control compareControl = dialog.initializeControl();
}
}

My class AbstractModelCompareDialog is a subclass of
org.eclipse.compare.internal.CompareDialog because the method
CompareUI.openCompareDialog(compareEditorInput) seen under the above
link does exactly this: opening a CompareDialog. My intension of doing
this is that I can reuse the dialog without opening it. The created
control then should be integrated into the preview. Therefore
AbstractModelCompareDialog simply looks like this:

public class AbstractModelCompareDialog extends CompareDialog {

private Composite parent;
private CompareEditorInput input;

public AbstractModelCompareDialog(Composite parent, CompareEditorInput
input) {
super(parent.getShell(), input);
this.parent = parent;
}

protected Control initializeControl(){
return createContents(parent);
}
}

And now my problem is that the lower part of the preview still stays
empty only containing a label "No preview available". This is very
annoying. I assume that I'm not the only one having this desire. Can
annybody help me in finding out what I'm doing wrong?

I would appreciate it a lot.

best regards,
Jan
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1069235 is a reply to message #1068192] Mon, 15 July 2013 09:26 Go to previous messageGo to next message
Eclipse UserFriend
Is this the wrong newsgroup or why doesn't someone answer?

best regards,
Jan
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1069260 is a reply to message #1069235] Mon, 15 July 2013 10:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jan,

Sorry for the late reply. Currently, EMF Compare's committers are either on vacation (it's summer time yet!) or busy on other topics. It may help you understand why your messages have stayed unanswered.

I've never tried to reuse the compare dialog components instead of opening it. BTW, you may have noticed that all the GUI (either the one displayed in the compare editor or the compare dialog) is build in the method org.eclipse.compare.CompareEditorInput.createContents(Composite). So, you should create your own subclass of CompareEditorInput (of ComparisonEditorInput actually to reuse the EMF Compare specific code) instead of your own CompareDialog...

Hope this helps.
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1069281 is a reply to message #1069260] Mon, 15 July 2013 11:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mikael,
thanks for your answer! It gave me the right pointer to
ComparisonEditorInput. Now, I got it working as expected. Great!
I did four small things to achieve my goal.

1) I changed my createControl method of MyPreviewer:

public void createControl(Composite parent) {
this.parent = parent;
}

2) I added a new field to MyPreviewer:

private Control previewControl;

3) I removed the last three lines in setInput of MyPreviewer, regarding
AbstractModelCompareDialog and replaced it with:

previewControl = compareEditorInput.createContents(parent);

4) I replaced getControl of MyPreviewer with this impl:

public Control getControl() {
return previewControl;
}

Now everything works fine and I'm happy ;) Thank you a lot Mikael!

best regards,
Jan
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1069587 is a reply to message #1069281] Tue, 16 July 2013 03:37 Go to previous messageGo to next message
Eclipse UserFriend
Jan,

Again, sorry for the late replies, glad to see Mikael's input was enough to lead you in the right direction Smile. For further questions, you might want to use the Modeling/Compare part of this forum, or the eclipse.modeling.emf newsgroup, which we monitor more frequently.

Laurent Goubet
Obeo
Re: [EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1069621 is a reply to message #1069587] Tue, 16 July 2013 04:51 Go to previous message
Eclipse UserFriend
Hi Laurent,
I was wondering about your pointer to the eclipse.modeling.emf
newsgroup. I didn't know about this newsgroup. I use Thunderbird as
newsgroup reader but it doesn't offer me eclipse.modeling.emf on the
news server news.eclipse.org. Strange.

Well, anyways, thanks for the pointer.

best regards,
Jan


Laurent Goubet wrote:
> Jan,
>
> Again, sorry for the late replies, glad to see Mikael's input was enough
> to lead you in the right direction :). For further questions, you might
> want to use the http://www.eclipse.org/forums/eclipse.modeling.emf part
> of this forum, or the eclipse.modeling.emf newsgroup, which we monitor
> more frequently.
>
> Laurent Goubet
> Obeo
Previous Topic:Changing EObject identification mechanism
Next Topic:Re: Registering a resource factory on a file name
Goto Forum:
  


Current Time: Fri Jul 18 04:40:56 EDT 2025

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

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

Back to the top