Home » Eclipse Projects » Eclipse Platform » Provide custom IMarker Action in Problem View.
| |
Re: Provide custom IMarker Action in Problem View. [message #335555 is a reply to message #335536] |
Tue, 14 April 2009 17:15 |
Hitesh Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Adil Fulara wrote:
> Hello,
> Firstly, i am not sure if this question is applicable to the current
> group. My apologies if i got it wrong.
> Currently in my RCP, if i double click an IMarker entry (where the
> resource is a windows word document) in the Problems View, the file is
> opened with MS Office Word as an OLE editor inside eclipse. I wish to
> over ride this and instead open the file externally in MS Office as a
> separate application.
> I was able to do this if i change the default file editor
> preferences[Windows => Preferences => General => Editors => File
> Associations ]. Is there to set this option programmatically?
> I did try using the following but did not work.
>
PlatformUI.getWorkbench().getEditorRegistry().setDefaultEdit or( "*.doc",EditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
> and
>
PlatformUI.getWorkbench().getEditorRegistry().setDefaultEdit or( "*.doc","winword.exe");
> Both of the above didn't work.
> Am i doing something wrong? Any help would be appreciated.
> Thank you.
> ~Adil.
The default 'goto' may not suffice in case you would always like to open a
marker in an external editor. The default goto relies mainly on
IDE.openEditor (..marker..), which has its way of finding out the
appropriate editor. The first being a marker attribute IDE.EDITOR_ID_ATTR.
If that has not been set, it checks if the resources in question has a
persistent property EDITOR_KEY - this can be set for the resource in
question by calling IDE.setDefaultEditor(IFile file, String editorID), the
same happens when user chooses to "Open With" . If the above fails, it
finally looks up the EditorRegistry for OLE, and then external.
Look at the plugin org.eclipse.ui.ide to see code that contributes to
markersview's menu.
Plugin.xml :
<extension
Point="org.eclipse.ui.menus">
<menuContribution
LocationURI="popup:org.eclipse.ui.ide.MarkersView">
By default the command will appear on all marker based views. The
visibleWhen, enabledWhen,etc expression can be used to restrict the
commands visibility and enablement.
The Handler must extend MarkerViewHandler
<sample>
public class Testhandler extends MarkerViewHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
IMarker[] markers = getSelectedMarkers(event);
for (int i = 0; i < markers.length; i++) {
IResource resource = markers[i].getResource();
if (resource.getType() != IResource.FILE)
continue;
try {
IDE.openEditor(getView(event).getSite().getPage(),
(IFile) resource, "Microsoft Word");
} catch (PartInitException e) {
e.printStackTrace();
}
}
return null;
}
}
</sample>
Hitesh
|
|
|
Re: Provide custom IMarker Action in Problem View. [message #335628 is a reply to message #335549] |
Thu, 16 April 2009 23:27 |
Adil Fulara Messages: 14 Registered: July 2009 |
Junior Member |
|
|
Thanks Ben,
That did the trick for me. I do however get an warning mentioning
"Discouraged Access : The type EditorRegistry is not accessible due to
restriction on required library
C:\eclipse\plugins\org.eclipse.ui.workbench_3.3.2.M20080207- 0800.jar "
for
EditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID
I could add suppress warning but is there any other way of resolving
this warning ?
Thank you very much.
~Adil.
Ben Vitale wrote:
> If you can get a handle to the marker you are concerned about, you might
> be able to specify the editor to use:
>
> marker.setAttribute(IDE.EDITOR_ID_ATTR,
> EditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
>
> I don't know if that's exactly what you need but maybe it helps.
>
> Cheers
> Ben
>
> Adil Fulara wrote:
>> Hello,
>>
>> Firstly, i am not sure if this question is applicable to the current
>> group. My apologies if i got it wrong.
>>
>> Currently in my RCP, if i double click an IMarker entry (where the
>> resource is a windows word document) in the Problems View, the file is
>> opened with MS Office Word as an OLE editor inside eclipse. I wish to
>> over ride this and instead open the file externally in MS Office as a
>> separate application.
>>
>> I was able to do this if i change the default file editor
>> preferences[Windows => Preferences => General => Editors => File
>> Associations ]. Is there to set this option programmatically?
>>
>> I did try using the following but did not work.
>>
>> PlatformUI.getWorkbench().getEditorRegistry().setDefaultEdit or( "*.doc",EditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
>>
>>
>> and
>>
>> PlatformUI.getWorkbench().getEditorRegistry().setDefaultEdit or( "*.doc","winword.exe");
>>
>>
>> Both of the above didn't work.
>>
>> Am i doing something wrong? Any help would be appreciated.
>>
>> Thank you.
>>
>> ~Adil.
|
|
|
Re: Provide custom IMarker Action in Problem View. [message #335629 is a reply to message #335555] |
Thu, 16 April 2009 23:30 |
Adil Fulara Messages: 14 Registered: July 2009 |
Junior Member |
|
|
Hitesh,
Thank you very much for the explanation. Although Ben's marker attribute
technique did help me solve the problem, your explanation helped me
understand how the internals work.
Appreciate your help alot.
Cheers,
~Adil.
Hitesh wrote:
> Adil Fulara wrote:
>
>> Hello,
>
>> Firstly, i am not sure if this question is applicable to the current
>> group. My apologies if i got it wrong.
>
>> Currently in my RCP, if i double click an IMarker entry (where the
>> resource is a windows word document) in the Problems View, the file is
>> opened with MS Office Word as an OLE editor inside eclipse. I wish to
>> over ride this and instead open the file externally in MS Office as a
>> separate application.
>
>> I was able to do this if i change the default file editor
>> preferences[Windows => Preferences => General => Editors => File
>> Associations ]. Is there to set this option programmatically?
>
>> I did try using the following but did not work.
>
>>
> PlatformUI.getWorkbench().getEditorRegistry().setDefaultEdit or( "*.doc",EditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
>
>
>> and
>
>>
> PlatformUI.getWorkbench().getEditorRegistry().setDefaultEdit or( "*.doc","winword.exe");
>
>
>> Both of the above didn't work.
>
>> Am i doing something wrong? Any help would be appreciated.
>
>> Thank you.
>
>> ~Adil.
>
> The default 'goto' may not suffice in case you would always like to open
> a marker in an external editor. The default goto relies mainly on
> IDE.openEditor (..marker..), which has its way of finding out the
> appropriate editor. The first being a marker attribute
> IDE.EDITOR_ID_ATTR. If that has not been set, it checks if the resources
> in question has a persistent property EDITOR_KEY - this can be set for
> the resource in question by calling IDE.setDefaultEditor(IFile file,
> String editorID), the same happens when user chooses to "Open With" . If
> the above fails, it finally looks up the EditorRegistry for OLE, and
> then external.
>
> Look at the plugin org.eclipse.ui.ide to see code that contributes to
> markersview's menu.
>
> Plugin.xml :
> <extension
> Point="org.eclipse.ui.menus">
> <menuContribution
> LocationURI="popup:org.eclipse.ui.ide.MarkersView">
>
> By default the command will appear on all marker based views. The
> visibleWhen, enabledWhen,etc expression can be used to restrict the
> commands visibility and enablement.
> The Handler must extend MarkerViewHandler
> <sample>
> public class Testhandler extends MarkerViewHandler {
>
> public Object execute(ExecutionEvent event) throws ExecutionException {
> IMarker[] markers = getSelectedMarkers(event);
> for (int i = 0; i < markers.length; i++) {
> IResource resource = markers[i].getResource();
> if (resource.getType() != IResource.FILE)
> continue;
> try {
> IDE.openEditor(getView(event).getSite().getPage(),
> (IFile) resource, "Microsoft Word");
> } catch (PartInitException e) {
> e.printStackTrace();
> }
> }
> return null;
> }
> }
> </sample>
>
> Hitesh
>
>
>
>
>
|
|
| |
Goto Forum:
Current Time: Sun Jan 19 13:41:46 GMT 2025
Powered by FUDForum. Page generated in 0.04676 seconds
|