Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Provide custom IMarker Action in Problem View.
Provide custom IMarker Action in Problem View. [message #335536] Mon, 13 April 2009 21:00 Go to next message
Adil Fulara is currently offline Adil Fulara
Messages: 14
Registered: July 2009
Junior Member
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 #335549 is a reply to message #335536] Tue, 14 April 2009 13:20 Go to previous messageGo to next message
Ben Vitale is currently offline Ben Vitale
Messages: 247
Registered: July 2009
Senior Member
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 #335555 is a reply to message #335536] Tue, 14 April 2009 17:15 Go to previous messageGo to next message
Hitesh  is currently offline 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 Go to previous messageGo to next message
Adil Fulara is currently offline 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 Go to previous messageGo to next message
Adil Fulara is currently offline 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
>
>
>
>
>
Re: Provide custom IMarker Action in Problem View. [message #335646 is a reply to message #335628] Sat, 18 April 2009 00:46 Go to previous message
Ben Vitale is currently offline Ben Vitale
Messages: 247
Registered: July 2009
Senior Member
Adil Fulara wrote:
> "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
>

Try IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID.

-Ben
Previous Topic:Re: Painting in a composite
Next Topic:Configuring standard views as menu items
Goto Forum:
  


Current Time: Thu Oct 02 16:32:04 GMT 2014

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

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