Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Suppressing menus, menu entries and toolbuttons
Suppressing menus, menu entries and toolbuttons [message #459014] Mon, 27 November 2006 14:49 Go to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
Platform: Eclipse 3.2.0/3.2.1
Java 2 SDK 1.5.0

I'm trying to figure out the simplest and cleanest way to suppress
irrelevant menus, menu entries and toolbuttons, for an RCP
application. "Cut the clutter", so to speak.

I've looked into both product level config/code (preferred) and
runtime configuring.

The most promising candidate is defining a new perspective, but it
looks like a perspective is mostly considered with views and their
layout, and that it can add new menus, and/or menu entries. It can't
suppress/replace existing ones, unless I'm mistaken (which I actually
hope I am).

I've googled a bit and found this old bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=29179
which refer to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=36967
which is said to be fixed with the introduction of the 3.0 platform.
This indicates that the functionality is in there somewhere...?

I've also googled this:
http://wiki.eclipse.org/index.php/Product_Customization#Supp ressing_An_Action

But I'm not comfortable with the solution propsed there (basically
rebuilding loaded plugin.xml files on the fly, before using them, if I
understood it correctly...).

Does anyone have any pointers or solutions, or pointers to solutions?

Thanx!


- Steinar
Re: Suppressing menus, menu entries and toolbuttons [message #459016 is a reply to message #459014] Mon, 27 November 2006 15:43 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

http://wiki.eclipse.org/index.php/Product_Customization#Supp ressing_An_Action
refers to work that's being investigate for 3.3.

In 3.1.x/3.2.x you can mask out *most* menu/toolbar items using
activities/capabilities.

Check out your Help>Help Contents>Platform Plug-in Developer
Guide>Programmer's Guide>Advanced workbench concepts for information on
filtering large user interfaces, which covers Capabilities and Activities.

There is also some information in the Actions, Commands, and Activities
section of http://wiki.eclipse.org/index.php/The_Official_Eclipse_FAQs

Later,
PW


Re: Suppressing menus, menu entries and toolbuttons [message #459042 is a reply to message #459016] Mon, 27 November 2006 20:18 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Paul Webster <pwebster@ca.ibm.com>:

> http://wiki.eclipse.org/index.php/Product_Customization#Supp ressing_An_Action
> refers to work that's being investigate for 3.3.

Ah, Ok. I thought bug 154099 referred to from the top of that page,
and the "Generalized OSGi Transformations" was the future stuff, and
the XSLT transformations of plugin.xml were current workarounds.

> In 3.1.x/3.2.x you can mask out *most* menu/toolbar items using
> activities/capabilities.

> Check out your Help>Help Contents>Platform Plug-in Developer
> Guide>Programmer's Guide>Advanced workbench concepts for information
> on filtering large user interfaces, which covers Capabilities and
> Activities.

Thanx! Looks like there is some filtering possibilites here, but the
only capabilities I can disable are "Development" and "Team" (in
Window->Preferences... and then General->Capabilities).

The docs I have to study some more. Can I create activities that
suppress system commands? Or are activities meant for grouping new
commands, so that they can be disabled or enabled like "Development"
and "Team", above?

> There is also some information in the Actions, Commands, and
> Activities section of
> http://wiki.eclipse.org/index.php/The_Official_Eclipse_FAQs

Hm... action sets seems like a promising concept. Can they be
overriden/replaced, I wonder...? Yes, they are the ones that can be
customized on a runtime/workspace basis. There the menus can be
slimmed down quite a bit. But not very useful for creating product
configurations, I'm afraid.

Thanx for the info!


- Steinar
Re: Suppressing menus, menu entries and toolbuttons [message #459044 is a reply to message #459042] Mon, 27 November 2006 20:42 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
Here's something that looks promising, "Retargetable actions":
http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/guide/wrkAdv_retarget.htm
Re: Suppressing menus, menu entries and toolbuttons [message #459047 is a reply to message #459044] Mon, 27 November 2006 21:03 Go to previous messageGo to next message
Andreas Goetz is currently offline Andreas GoetzFriend
Messages: 110
Registered: July 2009
Senior Member
Steinar,

could you post your final solution? Same issue for me- would like to get rid
of working sets...

Thanks,
Andi

"Steinar Bang" <sb@dod.no> wrote in message
news:87ac2cfwpo.fsf@bang.priv.no...
> Here's something that looks promising, "Retargetable actions":
> http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/guide/wrkAdv_retarget.htm
>
Is File->Open File... retargetable? (Was: Suppressing menus, menu entries and toolbuttons) [message #459119 is a reply to message #459044] Tue, 28 November 2006 08:58 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

> Here's something that looks promising, "Retargetable actions":
> http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/guide/wrkAdv_retarget.htm

Is, or is not, the "Open File..." action retargetable?

Some earlier responses on the eclipse newsgroups indicates that it is, eg.
http://dev.eclipse.org/newslists/news.eclipse.platform/msg44 590.html
http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/m sg08439.html

However, it isn't listed under neither the file menu entries, nor the
global actions, in IWorkbenchActionConstants:
http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/ui/IWorkbenchActionConstants .html
(the wrkAdv_retarget URL says only the global actions are
retargetable).

No "Open File" entries are listed under "File Menu" either. The
newsgroup messages above are from about one year ago, and I guess that
would be the time of eclipse 3.1. But the eclipse 3.1 documentation
looks about the same as the 3.2 documentation for this.

Does anyone know?

Thanx!


- Steinar
Re: Suppressing menus, menu entries and toolbuttons [message #459124 is a reply to message #459047] Tue, 28 November 2006 13:06 Go to previous messageGo to next message
Andreas Goetz is currently offline Andreas GoetzFriend
Messages: 110
Registered: July 2009
Senior Member
Not sure this is what you're looking for, but I've found this code in KNIME
for modifying the resource navigator's context menu:

/**

* Fills the context menu with the actions contained in this group and its

* subgroups. Additionally the close project item is removed as not intended

* for the kinme projects. Note: Projects which are closed in the default

* navigator are not shown in the knime navigator any more.

*

* @param menu the context menu

*/

@Override

public void fillContextMenu(final IMenuManager menu) {

// fill the menu

super.fillContextMenu(menu);


// remove the close project item

menu.remove(CloseResourceAction.ID);


// remove some more items (this is more sophisticated, as these

// items do not have an id

for (IContributionItem item : menu.getItems()) {


if (item instanceof ActionContributionItem) {


ActionContributionItem aItem = (ActionContributionItem)item;

// remove the gointo item

if (aItem.getAction() instanceof GoIntoAction) {


menu.remove(aItem);

} else if (aItem.getAction() instanceof OpenInNewWindowAction) {


menu.remove(aItem);

}


}

}


// TODO: this is hardcoded the copy item. should be retreived more

// dynamically

String id = menu.getItems()[2].getId();


// add an open action which is not listed as the project is normally

// not openable.

menu.insertBefore(id, new Separator());

menu.insertBefore(id, new OpenKnimeProjectAction(this));

menu.insertBefore(id, new Separator());

}



"Andreas Goetz" <cpuidle@gmx.de> wrote in message
news:ekfjoc$1ed$1@utils.eclipse.org...
> Steinar,
>
> could you post your final solution? Same issue for me- would like to get
> rid of working sets...
>
> Thanks,
> Andi
>
> "Steinar Bang" <sb@dod.no> wrote in message
> news:87ac2cfwpo.fsf@bang.priv.no...
>> Here's something that looks promising, "Retargetable actions":
>> http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/guide/wrkAdv_retarget.htm
>>
>
>
Re: Suppressing menus, menu entries and toolbuttons [message #459126 is a reply to message #459124] Tue, 28 November 2006 13:24 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> "Andreas Goetz" <cpuidle@gmx.de>:

> Not sure this is what you're looking for, but I've found this code
> in KNIME for modifying the resource navigator's context menu:
[snip!]

Thanx for the information, but it's not quite what I'm looking for.

Adding new new toolbuttons, and menus and menu entries, are pretty
well covered by the documentation.

It's slimming down the menus provided by the framework that gives me
problems.

Ie. what do I do when our usability people ask me what a command is
for, and I reply "er... it's something eclipse put in. It has no
meaning here, but I don't know how to get rid of it", and then they
tell me that that isn't really a good answer. :-)

Another problem I have, is replacing the "Open File..." action with a
brand new action. Currently we have both the "Open File..." action
which doesn't do what we'd like it to, and an "Open XML File..."
action which does (it parses the XML into a DOM, sniffs the DOM and
decides the editor on the basis of what it finds).

So what I'm looking at are the possibilities of either losing the
standard "Open File..." action and naming the "Open Xml File.." to be
"Open File...", or changing "Open File..." using retargeting to use
the mechanism currently used by the "Open Xml File..." action.
Re: Suppressing menus, menu entries and toolbuttons [message #459128 is a reply to message #459042] Tue, 28 November 2006 13:37 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Steinar Bang wrote:
>
> Thanx! Looks like there is some filtering possibilites here, but the
> only capabilities I can disable are "Development" and "Team" (in
> Window->Preferences... and then General->Capabilities).
>
> The docs I have to study some more. Can I create activities that
> suppress system commands? Or are activities meant for grouping new
> commands, so that they can be disabled or enabled like "Development"
> and "Team", above?

The advanced workbench section I pointed to contains information on how
you would create your own activites and activity bindings. Then you
could disable them and make the bound-UI elements disappear.

The other things you mentioned don't work for what you want (unless I
misunderstood your question).

ActionSets allow you to create groups of actions that can be visible or
not as a group. But not everything is in ActionSets, you can't modify
existing ones only create new ones, and you can see (or not) the entire
ActionSet.

Retargetable actions are global actions (contributed by the workbench
window) whose behaviour can be overriden by individual views or editors.
But you can't control their visibility.

Later,
PW


Re: Suppressing menus, menu entries and toolbuttons [message #459183 is a reply to message #459126] Tue, 28 November 2006 17:33 Go to previous messageGo to next message
Andreas Goetz is currently offline Andreas GoetzFriend
Messages: 110
Registered: July 2009
Senior Member
The sample shows some removing from context menu?

"Steinar Bang" <sb@dod.no> wrote in message
news:87odqremam.fsf@bang.priv.no...
>>>>>> "Andreas Goetz" <cpuidle@gmx.de>:
>
>> Not sure this is what you're looking for, but I've found this code
>> in KNIME for modifying the resource navigator's context menu:
> [snip!]
....
> It's slimming down the menus provided by the framework that gives me
> problems.
....
Re: Suppressing menus, menu entries and toolbuttons [message #459187 is a reply to message #459128] Tue, 28 November 2006 21:09 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Paul Webster <pwebster@ca.ibm.com>:

> The advanced workbench section I pointed to contains information on
> how you would create your own activites and activity bindings. Then
> you could disable them and make the bound-UI elements disappear.

Yes, that's what I figured.

> The other things you mentioned don't work for what you want (unless I
> misunderstood your question).

What I'm looking for is to be able to filter away some standard
eclipse menus and/or replace the actions of some standard eclipse menu
entries with my own.

> ActionSets allow you to create groups of actions that can be visible
> or not as a group. But not everything is in ActionSets, you can't
> modify existing ones only create new ones, and you can see (or not)
> the entire ActionSet.

That's also what I figured.

> Retargetable actions are global actions (contributed by the workbench
> window) whose behaviour can be overriden by individual views or
> editors. But you can't control their visibility.

But I could do stuff like replace the action underlying "Open File..."
with my own. That is; I could _if_ "Open File..." was a retargetable
action which it doesn't look like it is...:-)

Thanx for the info!
Re: Suppressing menus, menu entries and toolbuttons [message #459188 is a reply to message #459183] Tue, 28 November 2006 21:28 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> "Andreas Goetz" <cpuidle@gmx.de>:

> The sample shows some removing from context menu?

Yes, but the context menu is sort of a special case. It's meant to be
rebuilt depending on the context (whatever the context may be).

That said, it may be possible to do things with the menus from
code...? What's available from the IWorkbench interface, I wonder...?
http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/ui/IWorkbench.html

From the IWorkbench it's possible to get an ICommandService reference,
and it may be possible to use it to rebuild menus on the fly...?
http://wiki.eclipse.org/index.php/Platform_Command_Framework
Re: Suppressing menus, menu entries and toolbuttons [message #459189 is a reply to message #459188] Tue, 28 November 2006 21:46 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

>>>>> "Andreas Goetz" <cpuidle@gmx.de>:
>> The sample shows some removing from context menu?

> Yes, but the context menu is sort of a special case. It's meant to be
> rebuilt depending on the context (whatever the context may be).

> That said, it may be possible to do things with the menus from
> code...? What's available from the IWorkbench interface, I wonder...?
> http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/ui/IWorkbench.html

> From the IWorkbench it's possible to get an ICommandService reference,
> and it may be possible to use it to rebuild menus on the fly...?
> http://wiki.eclipse.org/index.php/Platform_Command_Framework

Here's something promising in that direction. Unfortuately it's just
a proposed design for 3.3:
http://wiki.eclipse.org/index.php/Menu_Item_Placement_Exampl es
Retargeting the "Open File..." action (Was: Suppressing menus, menu entries and toolbutton [message #459703 is a reply to message #459187] Wed, 06 December 2006 13:39 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

> But I could do stuff like replace the action underlying "Open
> File..." with my own. That is; I could _if_ "Open File..." was a
> retargetable action which it doesn't look like it is...:-)

To repeat my platform:
Platform: Eclipse 3.2.0/3.2.1
Java 2 SDK 1.5.0

To summarize my problem here:
- I need to handle several different XML formats, all of which have
the extension .xml, with different editors for each format
- we currently have a factory which we use on input XML files to try to
determine their actual format, and create an object implementing
IEditorInput based on that
- when we get the editor input, we use it to find the id of the
editorpart class in question (we've extended the IEditorInput
interface to have an getEditorId() method)
- we call IWorkbenchPage#openEditor() with the editor input and the
appropriate editor id

To do this we've created a new editor action, which is added to the
file menu with the text "Open XML File...".

I would like that action to end up behind "Open File..." instead.

But that doesn't seem straightforward.

There is a registry from file name extension to IEditorPart, but that
won't work here. I would have needed a registry for a factory that
could return a tuple of IEditorInput and editor id, and this factory
would have needed to be used by the system "Open File..." action.

If the "Open File..." action had been retargetable, I could have
replaced it with the action currently going under the entry "Open XML
File..." (our RCP app will only ever have to open XML files, but as I
said, XML files with several formats/vocabularies/schemas).

One way that will work, is to create our own ActionBarAdviser and
populate the menus and toolbars using code. That will work, but
possibly isn't The Eclipse Way(TM)...?

Is there some possible approach I'm missing here?

Thanx!


- Steinar
Re: Retargeting the "Open File..." action (Was: Suppressing menus, menu entries and toolbu [message #459704 is a reply to message #459703] Wed, 06 December 2006 13:48 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Steinar Bang wrote:
>>>>>> Steinar Bang <sb@dod.no>:
>
>> But I could do stuff like replace the action underlying "Open
>> File..." with my own. That is; I could _if_ "Open File..." was a
>> retargetable action which it doesn't look like it is...:-)
>
> To repeat my platform:
> Platform: Eclipse 3.2.0/3.2.1
> Java 2 SDK 1.5.0
>
> To summarize my problem here:
> - I need to handle several different XML formats, all of which have
> the extension .xml, with different editors for each format

I think this is the problem that Content Type is supposed to solve.

Content type already has XML as a subset of Text. You would create
sub-types of XML. Content Types allow you to examine the .xml files to
further classify them.

Then you can tie your editor definitions to a content type.

Later,
PW


Re: Retargeting the "Open File..." action [message #459750 is a reply to message #459704] Thu, 07 December 2006 09:14 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Paul Webster <pwebster@ca.ibm.com>:

> I think this is the problem that Content Type is supposed to solve.

> Content type already has XML as a subset of Text. You would create
> sub-types of XML. Content Types allow you to examine the .xml files
> to further classify them.

> Then you can tie your editor definitions to a content type.

Thanx for the heads-up! I googled this bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=37668
which seems to be exactly what I'm talking about.

I'll study up on the framework (and probably get back with more
questions :-) ).
Re: Retargeting the "Open File..." action [message #459752 is a reply to message #459750] Thu, 07 December 2006 09:39 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

>>>>> Paul Webster <pwebster@ca.ibm.com>:
>> I think this is the problem that Content Type is supposed to solve.

>> Content type already has XML as a subset of Text. You would create
>> sub-types of XML. Content Types allow you to examine the .xml files
>> to further classify them.

>> Then you can tie your editor definitions to a content type.

> Thanx for the heads-up! I googled this bug
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=37668
> which seems to be exactly what I'm talking about.

> I'll study up on the framework (and probably get back with more
> questions :-) ).

This seems like the place to start reading:
http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/reference/extension-points/org_eclipse_core_runtime_co ntentTypes.html
Re: Retargeting the "Open File..." action [message #459758 is a reply to message #459752] Thu, 07 December 2006 12:04 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

[snip! Determining editor on the basis of content type]
> This seems like the place to start reading:
> http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/reference/extension-points/org_eclipse_core_runtime_co ntentTypes.html

Let's see... what I need to do, is:

- Write an implementation of the ITextContentDescriber interface
http://help.eclipse.org/help32/nftopic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/core/runtime/content/IText ContentDescriber.html

- Register the class that implements ITextContentDescriber in with one
content type <extension> in plugin.xml, for each separate XML
format (described in the quoted URL above)

- Implement the ITextContentDescriber#describe() method, to look at
the contents of the file, and determine if it is one of the
supported file formats, and if it is, fill out an
IContentDescription for the format

- The IContentDescription#getContentType() method will return an
IContentType that can be used to get the correct editor

- I will need to refer to the content type ID in the editor
extensions:
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/extension-points/org_eclipse_ui_e ditors.html

The only part that's missing is where, how, and if, IEditorInput
figures into this, when using the regular "Open File..." action...?

Thanx!


- Steinar
Re: Retargeting the "Open File..." action [message #459831 is a reply to message #459758] Thu, 07 December 2006 13:03 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Steinar Bang wrote:
> [... snip ...]
> - I will need to refer to the content type ID in the editor
> extensions:
> http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/extension-points/org_eclipse_ui_e ditors.html
>
> The only part that's missing is where, how, and if, IEditorInput
> figures into this, when using the regular "Open File..." action...?
>

It sounds like you've covered all the bases. It should mean that the
IEditorInput returned by the project explorer or Package Explorer will
work fine with your editors.

i.e. double-clicking on your .xml file should generate an IEditorInput
(usually a FileEditorInput) and the system will match it with the
correct editor ID for you, using your content types as well as the
standard file associations.

Later,
PW


Re: Retargeting the "Open File..." action [message #459832 is a reply to message #459831] Thu, 07 December 2006 13:24 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Paul Webster <pwebster@ca.ibm.com>:

> It sounds like you've covered all the bases. It should mean that
> the IEditorInput returned by the project explorer or Package
> Explorer will work fine with your editors.

> i.e. double-clicking on your .xml file should generate an
> IEditorInput (usually a FileEditorInput) and the system will match
> it with the correct editor ID for you, using your content types as
> well as the standard file associations.

Ok. Thanx!

Hm... sounds like I have a bit of refactoring to do then, since our
custom IEditorInput is currently a container for the model resulting
from the XML parsing, and contains the functionality for reserializing
the model into a DOM.
Re: Retargeting the "Open File..." action [message #459876 is a reply to message #459758] Thu, 07 December 2006 20:35 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

> Let's see... what I need to do, is:

> - Write an implementation of the ITextContentDescriber interface
> http://help.eclipse.org/help32/nftopic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/core/runtime/content/IText ContentDescriber.html

Turns out this isn't needed because of the XMLRootElementContentDescriber:
http://help.eclipse.org/help32/nftopic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/core/runtime/content/XMLRo otElementContentDescriber.html

There's even an example in
http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/reference/extension-points/org_eclipse_core_runtime_co ntentTypes.html

<extension point="org.eclipse.core.runtime.contentTypes">
<content-type id="ABC"
base-type="org.eclipse.core.runtime.xml"
file-extensions="a,b,c">
<describer class=" org.eclipse.core.runtime.content.XMLRootElementContentDescri ber ">
<parameter name="element" value="abc"/>
</describer>
</content-type>
</extension>

The "element" is the top level element name of a particular document
type.
Re: Retargeting the "Open File..." action [message #459892 is a reply to message #459831] Fri, 08 December 2006 12:03 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Paul Webster <pwebster@ca.ibm.com>:

> It sounds like you've covered all the bases. It should mean that
> the IEditorInput returned by the project explorer or Package
> Explorer will work fine with your editors.

> i.e. double-clicking on your .xml file should generate an
> IEditorInput (usually a FileEditorInput) and the system will match
> it with the correct editor ID for you, using your content types as
> well as the standard file associations.

When I used the getAdapter() call on the editor's input to get an
IStorageEditorInput everything seemed to work as expected. Ie. I
successfully loaded an XML file in the expected editor.
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/ui/IStorageEditor Input.html

But save or save as didn't do anything.

And the opened files weren't persisted.

So I looked at the return of IEditorInput#getPersistable(), and it was
null.

I debugged down into it, and found that the actual implementation was
JavaFileEditorInput. So why on earth do I get JavaFileEditorInput on
a file with .xml?

Is it because "File->Open File..." doesn't support content types? Is
it because my RCP somehow have Java files as the default type?

Thanx!


- Steinar
Re: Retargeting the "Open File..." action [message #459893 is a reply to message #459892] Fri, 08 December 2006 12:22 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

>>>>> Paul Webster <pwebster@ca.ibm.com>:
>> It sounds like you've covered all the bases. It should mean that
>> the IEditorInput returned by the project explorer or Package
>> Explorer will work fine with your editors.

>> i.e. double-clicking on your .xml file should generate an
>> IEditorInput (usually a FileEditorInput) and the system will match
>> it with the correct editor ID for you, using your content types as
>> well as the standard file associations.

> When I used the getAdapter() call on the editor's input to get an
> IStorageEditorInput everything seemed to work as expected. Ie. I
> successfully loaded an XML file in the expected editor.
> http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/ui/IStorageEditor Input.html

> But save or save as didn't do anything.

> And the opened files weren't persisted.

> So I looked at the return of IEditorInput#getPersistable(), and it was
> null.

> I debugged down into it, and found that the actual implementation was
> JavaFileEditorInput. So why on earth do I get JavaFileEditorInput on
> a file with .xml?

> Is it because "File->Open File..." doesn't support content types? Is
> it because my RCP somehow have Java files as the default type?

It's because OpenExternalFileAction#createEditorInput() returns a
JavaFileEditorInput for all files that aren't inside the workspace.

private IEditorInput createEditorInput(IFileStore fileStore) {
IFile workspaceFile= getWorkspaceFile(fileStore);
if (workspaceFile != null)
return new FileEditorInput(workspaceFile);
return new JavaFileEditorInput(fileStore);
}

This sounds like a,... rather strange thing to do.

Is it a bug? Is there a workaround I can apply? Can I replace the
IEditorInput given in the init() method, with a FileEditorInput?
OpenExternalFileAction returns JavaFileEditorInput (Was: Retargeting the "Open File..." ac [message #459895 is a reply to message #459893] Fri, 08 December 2006 13:08 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

>>>>> Steinar Bang <sb@dod.no>:

>> When I used the getAdapter() call on the editor's input to get an
>> IStorageEditorInput everything seemed to work as expected. Ie. I
>> successfully loaded an XML file in the expected editor.
>> http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/ui/IStorageEditor Input.html

>> But save or save as didn't do anything.

>> And the opened files weren't persisted.

>> So I looked at the return of IEditorInput#getPersistable(), and it was
>> null.

>> I debugged down into it, and found that the actual implementation was
>> JavaFileEditorInput. So why on earth do I get JavaFileEditorInput on
>> a file with .xml?

>> Is it because "File->Open File..." doesn't support content types? Is
>> it because my RCP somehow have Java files as the default type?

> It's because OpenExternalFileAction#createEditorInput() returns a
> JavaFileEditorInput for all files that aren't inside the workspace.

> private IEditorInput createEditorInput(IFileStore fileStore) {
> IFile workspaceFile= getWorkspaceFile(fileStore);
> if (workspaceFile != null)
> return new FileEditorInput(workspaceFile);
> return new JavaFileEditorInput(fileStore);
> }

> This sounds like a,... rather strange thing to do.

> Is it a bug? Is there a workaround I can apply? Can I replace the
> IEditorInput given in the init() method, with a FileEditorInput?

Trying to create a FileEditorInput from a JavaFileEditorInput failed
because there is no way to get an IFile reference from
JavaFileEditorInput, and the only way to create a FileEditorInput is
using a constructor that takes an IFile argument.

Other workaround approaches highly appreciated.
Re: OpenExternalFileAction returns JavaFileEditorInput [message #459896 is a reply to message #459895] Fri, 08 December 2006 13:21 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
As a summary of all above: I get JavaFileEditorInput instead of
FileEditorInput from the "File->Open File..." command when files are
outside of the workspace.

That would have been fine, except JavaFileEditorInput isn't
persistable, so it won't persist in the recently used files list when
the app is stopped and restarted.

Is there a way I could make the editor input be persistable?

I tried replacing the JavaFileEditorInput with FileEditorInput in the
editor's init() method, but I was unsuccessful in getting an IFile
from JavaFileEditorInput.
Re: OpenExternalFileAction returns JavaFileEditorInput [message #459901 is a reply to message #459896] Fri, 08 December 2006 14:26 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Steinar Bang wrote:
> As a summary of all above: I get JavaFileEditorInput instead of
> FileEditorInput from the "File->Open File..." command when files are
> outside of the workspace.



That's the way this works. IFileEditorInput represents a workspace file
and is a 1st class citizen. JavaFileEditorInput represents an external
file ... it's there so you can open external files into eclipse, but
it's not a 1st class citizen, since it's not in the workspace. We'll
never get resource deltas for it, for example.

There was some talk of providing the "external file editor input"
functionality in the platform somewhere, but I don't know the state of
that enhancement. As part of that, maybe it could play better ...

Later,
PW


Re: OpenExternalFileAction returns JavaFileEditorInput [message #459918 is a reply to message #459901] Fri, 08 December 2006 17:59 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Paul Webster <pwebster@ca.ibm.com>:

> That's the way this works. IFileEditorInput represents a workspace
> file and is a 1st class citizen. JavaFileEditorInput represents an
> external file ... it's there so you can open external files into
> eclipse, but it's not a 1st class citizen, since it's not in the
> workspace. We'll never get resource deltas for it, for example.

But it would be rilly-rilly-nice if they could end up in the most
recently used files list in a persistent manner.

You wouldn't happen to have a workaround for that, by any chance...? :-)

Right now I'm trying to write a persistable IPathEditorInput (I've
based open, doSave, and doSaveAs around IPathEditorInput, which is one
of the interfaces implemented by JavaFileEditorInput, and probably the
easiest one to persist), but I haven't figured out how
IPersistableElement is supposed to work yet, and still don't know if
substituting an editor's IEditorInput in the init() method will work.

Time will show.
Re: OpenExternalFileAction returns JavaFileEditorInput [message #459921 is a reply to message #459918] Fri, 08 December 2006 21:08 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

> But it would be rilly-rilly-nice if they could end up in the most
> recently used files list in a persistent manner.

> You wouldn't happen to have a workaround for that, by any chance...? :-)

> Right now I'm trying to write a persistable IPathEditorInput (I've
> based open, doSave, and doSaveAs around IPathEditorInput, which is
> one of the interfaces implemented by JavaFileEditorInput, and
> probably the easiest one to persist), but I haven't figured out how
> IPersistableElement is supposed to work yet, and still don't know if
> substituting an editor's IEditorInput in the init() method will
> work.

> Time will show.

It worked for restoring editor state. But it didn't work for keeping
persitent recently used file entries in the File menu. So either the
trick for that is something other than making the IEditorInput
persistable, or the original IEditorInput is stored separately from
via the editor.

I'm guessing on the latter. It's debugging time again.
Re: OpenExternalFileAction returns JavaFileEditorInput [message #459923 is a reply to message #459921] Fri, 08 December 2006 21:35 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

> It worked for restoring editor state. But it didn't work for
> keeping persitent recently used file entries in the File menu. So
> either the trick for that is something other than making the
> IEditorInput persistable, or the original IEditorInput is stored
> separately from via the editor.

> I'm guessing on the latter. It's debugging time again.

If I'd been able to access Workbench#getEditorHistory(), remove
references to the original IEditorInput and adding a tuple for the
editor and its new IEditorInput, I could have fixed it.

But that method's protected.

This is starting to look hopeless...
Re: OpenExternalFileAction returns JavaFileEditorInput [message #459990 is a reply to message #459901] Sun, 10 December 2006 19:28 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Paul Webster <pwebster@ca.ibm.com>:

> That's the way this works. IFileEditorInput represents a workspace
> file and is a 1st class citizen. JavaFileEditorInput represents an
> external file ... it's there so you can open external files into
> eclipse, but it's not a 1st class citizen, since it's not in the
> workspace. We'll never get resource deltas for it, for example.

> There was some talk of providing the "external file editor input"
> functionality in the platform somewhere, but I don't know the state
> of that enhancement. As part of that, maybe it could play better
> ...

Well, I put my desired behaviour into bugzilla, and hope for the
best...:-)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=167352
How to delete File > Open File.. menu item? [message #460800 is a reply to message #459990] Fri, 29 December 2006 18:00 Go to previous messageGo to next message
Le Hong Phuong is currently offline Le Hong PhuongFriend
Messages: 8
Registered: July 2009
Junior Member
I have the same problem as Steinar. My application has 2 system menu items Open File... and Open and I cannot remove them out.

I worked around in the Eclipse documentation

http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/wrkAdv_retarget.htm

and found that File > Open File... is not retargetable action. So I cannot retarget it to my own implementation.

I read all the posts in this thread but I didn't find a solution. :(

Actually I have to define an action set that contains an Open XML File... action in the plugin.xml.

My File menu now has 3 Open actions, 2 system open actions do not work but I cannot delete them!!!
Re: How to delete File > Open File.. menu item? [message #460853 is a reply to message #460800] Sun, 31 December 2006 09:28 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> phuonglh <phuonglh@gmail.com>:

> I have the same problem as Steinar. My application has 2 system menu
> items Open File... and Open and I cannot remove them out.

> I worked around in the Eclipse documentation

> http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/wrkAdv_retarget.htm

> and found that File > Open File... is not retargetable action. So I
> cannot retarget it to my own implementation.

> I read all the posts in this thread but I didn't find a solution. :(

Well, there _is_ a solution, but it isn't pretty. Something like
this:

- Create a class that extends ActionBarAdvisor
- Override the ActionBarAdvisor#fillMenuBar() method and use a
MenuManager to build _all_ of your app's menus manually (this is
what makes it not pretty in my opinion, especially when all you
want to do, is to remove a single entry from the file menu...)
- Create a class that extends WorkbenchWindowAdvisor
- Override the WorkbenchWindowAdvisor#createActionBarAdvisor()
method, and have it return an instance of your ActionBarAdvisor
class
- Create a class that extends WorkbenchAdvisor
- Override the WorkbenchAdvisor#createWorkbenchWindowAdvisor() method
to create, and return an instance of your WorkbenchWindowAdvisor
subclass
- Create a class that implements IPlatformRunnable
- In this class' run() method, call the static method
PlatformUI#createAndRunWorkbench() giving an instance of your
WorkbenchAdvisor subclass as the second argument
- Register this class with an application extension in the
org.eclipse.core.runtime.applications extension point

I may have missed a class or two that needs implementing, and there
may be more required methods, and registration of the application
extension may not be enough, but... this is hopefully enough to give
you a pointer for where to look to lose your undesired "open file"
entries...:-)
Re: How to delete File > Open File.. menu item? [message #460855 is a reply to message #460853] Sun, 31 December 2006 13:46 Go to previous messageGo to next message
Le Hong Phuong is currently offline Le Hong PhuongFriend
Messages: 8
Registered: July 2009
Junior Member
Thanks for your detailed explanation. I'll try your solution while waiting for a new version of RCP. :)

Happy new year!
Re: How to delete File > Open File.. menu item? [message #460878 is a reply to message #460853] Mon, 01 January 2007 08:49 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

> Well, there _is_ a solution, but it isn't pretty. Something like
> this:

> - Create a class that extends ActionBarAdvisor
> - Override the ActionBarAdvisor#fillMenuBar() method and use a
> MenuManager to build _all_ of your app's menus manually (this is
> what makes it not pretty in my opinion, especially when all you
> want to do, is to remove a single entry from the file menu...)

This is the core thing to implement. The rest of the classes below,
are just leading up to calling this method at the appropriate point.
Javadoc for ActionBarAdvisor:
http://help.eclipse.org/help32/nftopic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/ui/application/ActionBarAd visor.html

A code fragment for the start of the fillMenuBar() method:

protected void fillMenuBar(IMenuManager menuBar)
{
super.fillMenuBar(menuBar);
IMenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
fileMenu.add(this.newAction);
fileMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
fileMenu.add(new Separator());
fileMenu.add(this.closeAction);
fileMenu.add(this.closeAllAction);
...
menuBar.add(fileMenu);
...
}

Ie. create a MenuManager for each menu, fill it up with the
appropriate actions, and add it to the IMenuManager given as the
method argument.

> - Create a class that extends WorkbenchWindowAdvisor
> - Override the WorkbenchWindowAdvisor#createActionBarAdvisor()
> method, and have it return an instance of your ActionBarAdvisor
> class
> - Create a class that extends WorkbenchAdvisor
> - Override the WorkbenchAdvisor#createWorkbenchWindowAdvisor() method
> to create, and return an instance of your WorkbenchWindowAdvisor
> subclass
> - Create a class that implements IPlatformRunnable
> - In this class' run() method, call the static method
> PlatformUI#createAndRunWorkbench() giving an instance of your
> WorkbenchAdvisor subclass as the second argument
> - Register this class with an application extension in the
> org.eclipse.core.runtime.applications extension point

> I may have missed a class or two that needs implementing, and there
> may be more required methods, and registration of the application
> extension may not be enough, but... this is hopefully enough to give
> you a pointer for where to look to lose your undesired "open file"
> entries...:-)

This last comment still holds. :-)
Re: How to delete File > Open File.. menu item? [message #460880 is a reply to message #460878] Mon, 01 January 2007 09:02 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
Some ActionBar advisor examples.

In the below URL, search for "ActionBar Advisor", and find a
skeletion listing, and short description of some methods:
http://www.eclipse.org/articles/Article-RCP-2/tutorial2.html

In the below URL, search for "Menus and Toolbars", and find an
example implementation with annotations:
http://www.eclipse.org/articles/Article-RCP-3/tutorial3.html
Re: How to delete File > Open File.. menu item? [message #460887 is a reply to message #460880] Mon, 01 January 2007 17:05 Go to previous message
Le Hong Phuong is currently offline Le Hong PhuongFriend
Messages: 8
Registered: July 2009
Junior Member
Thanks again for your valuable direction.

We need a really tricky procedure to accomplish a simple demand in a RCP application ! A strange story? :-)

Phuong.
Previous Topic:Browser location
Next Topic:StyledRanges
Goto Forum:
  


Current Time: Fri Apr 19 22:51:29 GMT 2024

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

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

Back to the top