[EMF Compare] How to provide a ModelComparison for custom refactorings? [message #1067560] |
Tue, 09 July 2013 06:33  |
Eclipse User |
|
|
|
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 #1068192 is a reply to message #1067560] |
Fri, 12 July 2013 11:27   |
Eclipse User |
|
|
|
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 #1069621 is a reply to message #1069587] |
Tue, 16 July 2013 04:51  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.33174 seconds