Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Invoking Find/Replace
Invoking Find/Replace [message #333890] Mon, 12 January 2009 19:54 Go to next message
Bret Schuhmacher is currently offline Bret SchuhmacherFriend
Messages: 26
Registered: July 2009
Junior Member
Hi all,

I'm trying to create a simple Find/Replace dialog by reusing the standard
Ctrl+F dialog. I have a SourceViewer and I'm catching the Ctrl+F now. I
call doFindReplace(), below. I've tried to create an action, like this:
protected void doFindReplace() {
ActionFactory.FIND.create( getActiveWorkbenchWindow());
FindReplaceAction fandrAction = new FindReplaceAction(getPRB(),
"Editor.FindReplace.", getActiveWorkbenchPart());

fandrAction.runWithEvent(new Event());
// fandrAction.run();

}

None of that code works - nothing ever pops up. What am I doing wrong?
FWIW, getPRB() returns an empty resource bundle. Do I need to instantiate
the FindReplaceDialog class myself? Do I need to subclass
FindReplaceAction, overriding run() myself? I just want a simple
find/replace dialog to pop up, targeted at my editor (from which I pressed
Ctrl+F).

I cannot find any examples, though. I'm targeting v3.2 in case the API
has changed in the last year or so.

Thanks in advance!

Bret
Re: Invoking Find/Replace [message #333895 is a reply to message #333890] Tue, 13 January 2009 08:36 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Bret Schuhmacher wrote:
> Hi all,
>
> I'm trying to create a simple Find/Replace dialog by reusing the
> standard Ctrl+F dialog. I have a SourceViewer and I'm catching the
> Ctrl+F now. I call doFindReplace(), below. I've tried to create an
> action, like this:
> protected void doFindReplace() {
> ActionFactory.FIND.create( getActiveWorkbenchWindow());
> FindReplaceAction fandrAction = new FindReplaceAction(getPRB(),
> "Editor.FindReplace.", getActiveWorkbenchPart());
>
> fandrAction.runWithEvent(new Event());
> // fandrAction.run();
>
> }
>
> None of that code works - nothing ever pops up. What am I doing
> wrong? FWIW, getPRB() returns an empty resource bundle. Do I need to
> instantiate the FindReplaceDialog class myself? Do I need to subclass
> FindReplaceAction, overriding run() myself? I just want a simple
> find/replace dialog to pop up, targeted at my editor (from which I
> pressed Ctrl+F).
Make sure your active workbench part provides an IFindReplaceTarget adapter.

Dani
>
> I cannot find any examples, though. I'm targeting v3.2 in case the
> API has changed in the last year or so.
>
> Thanks in advance!
>
> Bret
>
Re: Invoking Find/Replace [message #333899 is a reply to message #333895] Tue, 13 January 2009 14:56 Go to previous messageGo to next message
Bret Schuhmacher is currently offline Bret SchuhmacherFriend
Messages: 26
Registered: July 2009
Junior Member
Thanks for the reply, Dani. I'm confused, though, since my SourceViewer
is a TextViewer, which appears to have all the right methods required of a
IFindReplaceTarget, although it doesn't say it implements that interface
on this page:
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/extension-points/index.html


If I try to implement IFindReplaceTarget in my subclassed SourceViewer I
get a message that TextViewer.findAndSelect(...) cannot hide the public
abstract method in IFindReplaceTarget. I can do this:
fSourceViewer.getFindReplaceTarget(), but I cannot pass that to the
FindReplaceAction constructor, which wants a WorkbenchPart, not a
FindReplaceTarget.

Ideas?

Thanks again,

Bret
Re: Invoking Find/Replace [message #333906 is a reply to message #333899] Tue, 13 January 2009 16:56 Go to previous messageGo to next message
Bret Schuhmacher is currently offline Bret SchuhmacherFriend
Messages: 26
Registered: July 2009
Junior Member
Dani,

Were you suggesting this?

FindReplaceAction fandrAction = new FindReplaceAction(getPRB(), null,
(IWorkbenchPart)
getActiveWorkbenchPart().getAdapter(IFindReplaceTarget.class .getClass()));


I tried that and I still don't get a popup.

I found out the ActiveWorkbenchPart() is returning a tab at the bottom of
my IDE called "Properties". My Editor is *inside* the body of that tab.
My editor extends a SourceViewer, which would have an IFindReplaceTarget
(because SourceViewer extends a TextEditor).

I'm open to suggestions if you have a minute.

Thanks!

Bret
Re: Invoking Find/Replace [message #333910 is a reply to message #333906] Tue, 13 January 2009 17:49 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Bret Schuhmacher wrote:
> Dani,
>
> Were you suggesting this?
>
> FindReplaceAction fandrAction = new FindReplaceAction(getPRB(), null,
> (IWorkbenchPart)
> getActiveWorkbenchPart().getAdapter(IFindReplaceTarget.class .getClass()));
>
>
>
> I tried that and I still don't get a popup.
>
> I found out the ActiveWorkbenchPart() is returning a tab at the bottom
> of my IDE called "Properties". My Editor is *inside* the body of that
> tab. My editor extends a SourceViewer, which would have an
> IFindReplaceTarget (because SourceViewer extends a TextEditor).
SourceViewer does not extend TextEditor.

Either the part from getActiveWorkbenchPart() must return a valid
IFindReplaceTarget (which the Properties view probably won't) or you
must use the 3.3 API:
FindReplaceAction.FindReplaceAction(ResourceBundle, String, Shell,
IFindReplaceTarget) where you pass in
yourTextViewer.getFindReplaceDocumentAdapter().

Dani
>
> I'm open to suggestions if you have a minute.
>
> Thanks!
>
> Bret
>
Re: Invoking Find/Replace [message #333956 is a reply to message #333910] Wed, 14 January 2009 16:39 Go to previous messageGo to next message
Bret Schuhmacher is currently offline Bret SchuhmacherFriend
Messages: 26
Registered: July 2009
Junior Member
Daniel Megert wrote:

>> IFindReplaceTarget (because SourceViewer extends a TextEditor).
> SourceViewer does not extend TextEditor.

My mistake - I thought it did. Thanks.




> Either the part from getActiveWorkbenchPart() must return a valid
> IFindReplaceTarget (which the Properties view probably won't) or you
> must use the 3.3 API:
> FindReplaceAction.FindReplaceAction(ResourceBundle, String, Shell,
> IFindReplaceTarget) where you pass in
> yourTextViewer.getFindReplaceDocumentAdapter().


Hmmmm... I added both the v3.3 and the v3.4
org.eclipse.ui.workbench.texteditor.jar to my Eclipse project and I get no
complaints from Eclipse when I use that constructor, but they both cause
problems further down the line when I try to start my app due to their
upgraded version requirements (i.e. they want upgraded jface and other
jars).

Thanks for your assistance, Dani, but it looks like I'm stuck :-(. I
wonder if I can reimplement my editor to implement the IFindReplaceTarget
interface...

Rgds,

Bret
Re: Invoking Find/Replace [message #333960 is a reply to message #333956] Wed, 14 January 2009 17:19 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Bret Schuhmacher wrote:
> Daniel Megert wrote:
>
>>> IFindReplaceTarget (because SourceViewer extends a TextEditor).
>> SourceViewer does not extend TextEditor.
>
> My mistake - I thought it did. Thanks.
>
>
>
>
>> Either the part from getActiveWorkbenchPart() must return a valid
>> IFindReplaceTarget (which the Properties view probably won't) or you
>> must use the 3.3 API:
>> FindReplaceAction.FindReplaceAction(ResourceBundle, String, Shell,
>> IFindReplaceTarget) where you pass in
>> yourTextViewer.getFindReplaceDocumentAdapter().
>
>
> Hmmmm... I added both the v3.3 and the v3.4
> org.eclipse.ui.workbench.texteditor.jar to my Eclipse project and I
> get no complaints from Eclipse when I use that constructor, but they
> both cause problems further down the line when I try to start my app
> due to their upgraded version requirements (i.e. they want upgraded
> jface and other jars).
Sure. You can't just go and grab a single JAR from one version and put
it into the other one.

Dani
>
> Thanks for your assistance, Dani, but it looks like I'm stuck :-(. I
> wonder if I can reimplement my editor to implement the
> IFindReplaceTarget interface...
>
> Rgds,
>
> Bret
>
Previous Topic:Undo does not work in 3.4?
Next Topic:[Databinding] Resetting targets after removing binding
Goto Forum:
  


Current Time: Sat Aug 17 08:08:53 GMT 2024

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

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

Back to the top