Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » using the compare API
using the compare API [message #294206] Mon, 07 November 2005 10:53 Go to next message
vijaishanker is currently offline vijaishankerFriend
Messages: 60
Registered: July 2009
Member
hi,
In my plugin I would like to compare 2 files, for this purpose I would
like to use the org.eclipse.compare API.I searched on the internet for
some proper examples or tutorials for this purpose but couldnt find any. I
also found that for this purpose I need to use the "ContentMergeViewer" or
the "TextMergeViewer". Can someone please shed more light on these or
direct me to some examples on this topic.

thanks,

vijai
Re: using the compare API [message #294214 is a reply to message #294206] Mon, 07 November 2005 13:30 Go to previous messageGo to next message
vijaishanker is currently offline vijaishankerFriend
Messages: 60
Registered: July 2009
Member
hi,

is it possible to compare 2 files/IFiles using the eclipse compare API
and if so, how can it be done.

thanks

Vijai
Re: using the compare API [message #294216 is a reply to message #294206] Mon, 07 November 2005 13:35 Go to previous messageGo to next message
Michael Valenta is currently offline Michael ValentaFriend
Messages: 560
Registered: July 2009
Senior Member
Vijai,

One class you can extend to get a two or three way compare is the
CompareEditorInput class. Have a look at the ResourceCompareInput class
in the org.eclipse.compare plugin for an example.

Michael

Vijai wrote:
> hi,
> In my plugin I would like to compare 2 files, for this purpose I would
> like to use the org.eclipse.compare API.I searched on the internet for
> some proper examples or tutorials for this purpose but couldnt find any.
> I also found that for this purpose I need to use the
> "ContentMergeViewer" or the "TextMergeViewer". Can someone please shed
> more light on these or direct me to some examples on this topic.
>
> thanks,
>
> vijai
>
Re: using the compare API [message #294229 is a reply to message #294216] Mon, 07 November 2005 15:18 Go to previous messageGo to next message
vijaishanker is currently offline vijaishankerFriend
Messages: 60
Registered: July 2009
Member
hi michael,
thanx for the reply...I am trying to implement the compare feature by
subclassing CompareEditorInput()

The class which extends CompareEditorInput is as follows,

class CompareInput extends CompareEditorInput {

public CompareInput(CompareConfiguration arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}

protected Object prepareInput(IProgressMonitor arg0)
throws InvocationTargetException, InterruptedException {
// TODO Auto-generated method stub
return null;
}

}

When i try to create a CompareEditorInput object out of the class,
passing a CompareConfiguration to its constructor, it throws a
nullpointerException at the place where i create the CompareConfiguration,
Can someone tell me what went wrong, I am still a newbie in Plugin
development...

private void testTextMerge() {
try {
-> CompareConfiguration config=new CompareConfiguration();
CompareEditorInput compare=new CompareInput(config);
} catch (Exception e) {
e.printStackTrace();
}
}

The line indicated by the arrow throws the nullpointerexception,

thanks

Vijai
Re: using the compare API [message #294255 is a reply to message #294229] Tue, 08 November 2005 10:48 Go to previous messageGo to next message
vijaishanker is currently offline vijaishankerFriend
Messages: 60
Registered: July 2009
Member
Vijai wrote:

> hi michael,
> thanx for the reply...I am trying to implement the compare feature by
> subclassing CompareEditorInput()

> The class which extends CompareEditorInput is as follows,

> class CompareInput extends CompareEditorInput {

> public CompareInput(CompareConfiguration arg0) {
> super(arg0);
> // TODO Auto-generated constructor stub
> }

> protected Object prepareInput(IProgressMonitor arg0)
> throws InvocationTargetException, InterruptedException {
> // TODO Auto-generated method stub
> return null;
> }

> }

> When i try to create a CompareEditorInput object out of the class,
> passing a CompareConfiguration to its constructor, it throws a
> nullpointerException at the place where i create the CompareConfiguration,
> Can someone tell me what went wrong, I am still a newbie in Plugin
> development...

> private void testTextMerge() {
> try {
> -> CompareConfiguration config=new CompareConfiguration();
> CompareEditorInput compare=new CompareInput(config);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }

> The line indicated by the arrow throws the nullpointerexception,

> thanks

> Vijai

I guess i figured out that anything thats got to do with CompareUIPlugin
throws a NullPointerException, for example creating a new
CompareConfiguration(), gets redirected to the method, new
CompareConfiguration(CompareUIPlugin.getPreferenceStore()); and this
statement throws a null pointer exception
Are there any prerequisites that need to be done before calling the
CompareUIPlugin.getPreferenceStore() method, like for example(creating an
empty file somewhere on the file system or calling some other method
before it)

I am attaching the Stack trace of the exception

java.lang.NullPointerException
at
com.vijai.matrix.plugin.ui.Views.JPOCommitView.testTextMerge (JPOCommitView.java:268)
at
com.vijai.matrix.plugin.ui.Views.JPOCommitView.access$0(JPOC ommitView.java:265)
at
com.vijai.matrix.plugin.ui.Views.JPOCommitView$6.widgetSelec ted(JPOCommitView.java:239)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2713)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:367)

The start of the exception points to the super() in the following code,

class CompareInput extends CompareEditorInput {

public CompareInput(CompareConfiguration arg0) {
super(new CompareConfiguration());
// TODO Auto-generated constructor stub
}

protected Object prepareInput(IProgressMonitor arg0)
throws InvocationTargetException, InterruptedException {
// TODO Auto-generated method stub
return null;
}

}


Any help or tips is appreciated,

thanks

Vijai
[75% RESOLVED]Re: using the compare API [message #294307 is a reply to message #294255] Wed, 09 November 2005 13:25 Go to previous messageGo to next message
vijaishanker is currently offline vijaishankerFriend
Messages: 60
Registered: July 2009
Member
hi,
I have finally managed to compare 2 pieces of text and have managed to
diplay it on a dialog. For this I have used the TextViewMerger, but I
would like to open it on a editor page or the page similar to which
eclipse opens up "compare" results...Do i need to use some extension point
or is there any other way to display the result of the TextMergeViewer...

Thanq

vijai
Re: [75% RESOLVED]Re: using the compare API [message #294312 is a reply to message #294307] Wed, 09 November 2005 16:29 Go to previous messageGo to next message
Michael Valenta is currently offline Michael ValentaFriend
Messages: 560
Registered: July 2009
Senior Member
You'll want to use a CompareEditorInput for that. As I mentioned in my
previous post you should have a look at the ResourceCompareInput in the
compare plugin. If you search for references to that class you will see
how to open an editor as well.

Michael

Vijai wrote:
> hi,
> I have finally managed to compare 2 pieces of text and have managed to
> diplay it on a dialog. For this I have used the TextViewMerger, but I
> would like to open it on a editor page or the page similar to which
> eclipse opens up "compare" results...Do i need to use some extension
> point or is there any other way to display the result of the
> TextMergeViewer...
>
> Thanq
>
> vijai
>
[RESOLVED finally]Re: using the compare API [message #294339 is a reply to message #294312] Thu, 10 November 2005 10:59 Go to previous messageGo to next message
vijaishanker is currently offline vijaishankerFriend
Messages: 60
Registered: July 2009
Member
Michael Valenta wrote:

> You'll want to use a CompareEditorInput for that. As I mentioned in my
> previous post you should have a look at the ResourceCompareInput in the
> compare plugin. If you search for references to that class you will see
> how to open an editor as well.

> Michael

> Vijai wrote:
>> hi,
>> I have finally managed to compare 2 pieces of text and have managed to
>> diplay it on a dialog. For this I have used the TextViewMerger, but I
>> would like to open it on a editor page or the page similar to which
>> eclipse opens up "compare" results...Do i need to use some extension
>> point or is there any other way to display the result of the
>> TextMergeViewer...
>>
>> Thanq
>>
>> vijai
>>

thanks Michael,

I finally managed to get the compare editor open and show me the
differences, at first I was trying to use TextMergeViewer(subclass of
ContentMergeViewer) and it showed me differences good enough but it
wouldnt maximize and was always the size of a thumbnail,
Now I used the CompareEditorInput and it works fine now, but the colors
that were present in the TextMergeViewer are missing,but thats ok...
The code i used is as following,


class EditorInput extends CompareEditorInput {

public EditorInput(CompareConfiguration configuration) {
super(configuration);
}

protected Object prepareInput(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
Differencer d = new Differencer();
Object diff = d.findDifferences(false, new NullProgressMonitor(), null,
null, new Input("difference1"), new Input(
"difference2"));
return diff;
}

}

class Input implements ITypedElement, IStreamContentAccessor {

String fContent;

public Input(String s) {
fContent = s;
}

public String getName() {
// TODO Auto-generated method stub
return "name";
}

public Image getImage() {
// TODO Auto-generated method stub
return null;
}

public String getType() {
// TODO Auto-generated method stub
return "txt";
}

public InputStream getContents() throws CoreException {
// TODO Auto-generated method stub
return new ByteArrayInputStream(fContent.getBytes());
}

}



and the command that opens the Compare Editor,
CompareUI.openCompareDialog(new EditorInput(
new CompareConfiguration()));

thanks for the help,

Vijai
Re: [RESOLVED finally]Re: using the compare API [message #987103 is a reply to message #294339] Fri, 23 November 2012 13:46 Go to previous message
sam mn is currently offline sam mnFriend
Messages: 25
Registered: August 2010
Junior Member
new CompareConfiguration() is still giving me NoClassDefFoundError.

I have implemented this in our RCP app. Added the org.eclipse.compare dependency in pom file and have installed it into local maven repo as well.

However one thing i see in the Manifest.MF (Dependency tab) is its not showing up in 'Available versions to match" section when we right click and select 'Properties' on the org.eclipse.compare plugin.

Am i missing something here ?, could someone guide me here.

Previous Topic:Unable to create object of SAXBuilder.
Next Topic:example of opening an IFolder and a filesystem directory in a CompareEditor?
Goto Forum:
  


Current Time: Thu Nov 27 03:01:59 GMT 2014

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

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