|
|
Re: Open an editor and specify the line of the document [message #465034 is a reply to message #465022] |
Thu, 22 March 2007 07:27 |
Sebastien Pennec Messages: 31 Registered: July 2009 |
Member |
|
|
Hello Daniel,
I finally made it like this:
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
map.put(IDE.EDITOR_ID_ATTR, "org.eclipse.jdt.internal.ui.javaeditor.JavaEditor");
try {
IMarker marker = file.createMarker(IMarker.TEXT);
marker.setAttributes(map);
IDE.openEditor(page, marker);
marker.delete();
} catch (PartInitException e) {
e.printStackTrace();
} catch (CoreException e) {
e.printStackTrace();
}
Is that a good practice?
Also, to obtain the IFile based on the name of the Java class I want to open, I had
to use org.eclipse.jdt.internal.core.JavaProject and
org.eclipse.jdt.internal.corext.util.JavaModelUtil, which are internal classes. Is
there a way to do that task without calling these classes?
Thanks,
Sébastien
Daniel Megert wrote:
> Sebastien Pennec wrote:
>
>> Hello,
>>
>> I'm using the following line to open a file in an editor:
>>
>> IDE.openEditor(page, file);
>>
>> But I'd like to open the editor at a specific line... how can I do that?
>
> Check whether it's an ITextEditor and then exploit its API to select the
> line or text range.
>
> Dani
>
>>
>> Thanks for your help :)
>>
>> Sébastien
|
|
|
Re: Open an editor and specify the line of the document [message #465048 is a reply to message #465034] |
Thu, 22 March 2007 11:16 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
Sebastien Pennec wrote:
> Hello Daniel,
>
> I finally made it like this:
>
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> HashMap<String, Object> map = new HashMap<String, Object>();
> map.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
> map.put(IDE.EDITOR_ID_ATTR,
> "org.eclipse.jdt.internal.ui.javaeditor.JavaEditor");
> try {
> IMarker marker = file.createMarker(IMarker.TEXT);
> marker.setAttributes(map);
> IDE.openEditor(page, marker);
> marker.delete();
> } catch (PartInitException e) {
> e.printStackTrace();
> } catch (CoreException e) {
> e.printStackTrace();
> }
>
> Is that a good practice?
It is OK if the editor isn't a text editor. In your case it is and hence
you should use:
if (editor instanceof ITextEditor) {
((ITextEditor)editor).selectAndReveal(offset, length);
return;
}
>
> Also, to obtain the IFile based on the name of the Java class I want
> to open,
What do you know from that class? Just the name? The file's location?
Dani
> I had to use org.eclipse.jdt.internal.core.JavaProject and
> org.eclipse.jdt.internal.corext.util.JavaModelUtil, which are internal
> classes. Is there a way to do that task without calling these classes?
>
> Thanks,
>
> Sébastien
>
> Daniel Megert wrote:
>
>> Sebastien Pennec wrote:
>>
>>> Hello,
>>>
>>> I'm using the following line to open a file in an editor:
>>>
>>> IDE.openEditor(page, file);
>>>
>>> But I'd like to open the editor at a specific line... how can I do
>>> that?
>>
>>
>> Check whether it's an ITextEditor and then exploit its API to select
>> the line or text range.
>>
>> Dani
>>
>>>
>>> Thanks for your help :)
>>>
>>> Sébastien
>>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03706 seconds