Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » EditorParts, doSave(), commands, and key bindings
EditorParts, doSave(), commands, and key bindings [message #459904] Fri, 08 December 2006 10:09 Go to next message
Eclipse UserFriend
Originally posted by: bsimpson.mstc.state.ms.us

I'd like to create a fairly simple IEditorPart implementation that
executes code to save the editor input when the user clicks a save
button in the toolbar, chooses a save menu item, or types Ctrl+S. I've
been reading in the Eclipse Help about commands and key binding
extensions and how to tie those to actions in my plugin.xml. That makes
sense to me. I'm already using actions and action delegates for a bunch
of other things in the app. However, I'm puzzled because in the docs on
IEditorPart and EditorPart, all it mentions is putting your save code in
doSave() and using the progress monitor to provide progress feedback. I
would think you'd want to put the save code in an action or action
delegate that is triggered by Ctrl+S or the buttons, but there is no
mention of that, as far as I have seen. So my question is, are the
commands & save actions supposed to interact somehow with doSave() in my
IEditorPart implementation, or is this an either-or situation where I
should use either actions & commands to save or put my save code in
doSave()? What am I missing here?

Barry
Re: EditorParts, doSave(), commands, and key bindings [message #459906 is a reply to message #459904] Fri, 08 December 2006 10:44 Go to previous messageGo to next message
Eclipse UserFriend
your command should work with IWorkbenchPage#saveEditor(IEditorPart,
boolean)

Later,
PW
Re: EditorParts, doSave(), commands, and key bindings [message #459910 is a reply to message #459906] Fri, 08 December 2006 11:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bsimpson.mstc.state.ms.us

Do you mean my *action* should use IWorkbenchPage#saveEditor? Do you
mean that I need to call IWorkbenchPage#saveEditor from the run method
of my IEditorActionDelegate? I want to use the built-in
org.eclipse.ui.file.save command as my action's definitionID. I won't be
defining my own command implementation, will I?

Paul Webster wrote:
> your command should work with IWorkbenchPage#saveEditor(IEditorPart,
> boolean)
>
> Later,
> PW
Re: EditorParts, doSave(), commands, and key bindings [message #459911 is a reply to message #459910] Fri, 08 December 2006 11:23 Go to previous messageGo to next message
Eclipse UserFriend
So, in theory your implement doSave(*) (and potentially doSaveAs()).
Then you get the eclipse save action for free.

In an RCP app you would create and install ActionFactory.SAVE, the same
way that WorkbenchActionBuilder does ... it puts it in the menu and toolbar.

Is that what you are asking? How to get Save to appear and make sure it
calls doSave(*) on your editor?

Later,
PW
Re: EditorParts, doSave(), commands, and key bindings [message #459916 is a reply to message #459911] Fri, 08 December 2006 12:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bsimpson.mstc.state.ms.us

Yes, I believe that is what I'm asking.

On the plugin.xml side, I've got something like this:

<extension
point="org.eclipse.ui.editors">
<editor
class="my.plugin.editors.PaymentFormEditor"
default="false"
icon="icons/payment_edit.png"
id="my.plugin.editors.payment"
name="PaymentFormEditor"/>
</extension>
<extension
point="org.eclipse.ui.editorActions">
<editorContribution
id="my.plugin.paymentEditorActions"
targetID="my.plugin.editors.payment">
<action
class="my.plugin.actions.PaymentSaveActionDelegate"
definitionId="org.eclipse.ui.file.save"
enablesFor="1"
id="my.plugin.paymentEditorActions.PaymentSaveAction"
label="Save Payment"
menubarPath="additions"
style="push"
tooltip="Save the changes to the current payment."/>
</editorContribution>
</extension>

The org.eclipse.ui.file.save command and the Ctrl+S key binding are
declared in the org.eclipse.ui plugin's plugin.xml file.

I might also need to create an org.eclipse.ui.actionSets extension to
get my action into the menu and toolbar, but I'm not sure about that
yet. (This would be the alternative to doing it programmatically in the
ApplicationActionBarAdvisor using ActionFactory.SAVE, I suppose.)

Anyways, basically what I want to know is how to make
my.plugin.actions.PaymentSaveActionDelegate.run() trigger
my.plugin.editors.PaymentFormEditor.doSave().

Is that the correct way to go about this? I would think this would be a
fairly common requirement in an RCP, so I feel like I'm missing some
small piece of info that would make the proverbial light bulb come on.

Paul Webster wrote:
> So, in theory your implement doSave(*) (and potentially doSaveAs()).
> Then you get the eclipse save action for free.
>
> In an RCP app you would create and install ActionFactory.SAVE, the same
> way that WorkbenchActionBuilder does ... it puts it in the menu and
> toolbar.
>
> Is that what you are asking? How to get Save to appear and make sure it
> calls doSave(*) on your editor?
>
> Later,
> PW
Re: EditorParts, doSave(), commands, and key bindings [message #459972 is a reply to message #459916] Sat, 09 December 2006 12:28 Go to previous messageGo to next message
Eclipse UserFriend
The specific answer is to get the active editor. The below is from the
SaveAction run() code. This is the save code run by using the
programmatic approach ActionFactory.SAVE.

public void run() {
if (getWorkbenchWindow() == null) {
// action has been disposed
return;
}

[...stuff deleted here for views...]

IEditorPart part = getActiveEditor();
if (part != null) {
IWorkbenchPage page = part.getSite().getPage();
page.saveEditor(part, false);
}
}

The WorkbenchPage implementation calls doSave() if the part (e.g. a view
part or editor part) implements ISaveablePart. ISaveablePart specifies
the doSave() method. ISaveablePart is an interface implemented by
EditorPart which is how it gets to your editor part you have created.

I am not sure what the file save action does but I would probably use
this save action which already knows about editors. The standard code
path pops up a question dialog box to confirm your save.


Barry Simpson wrote:
> Yes, I believe that is what I'm asking.
>
> On the plugin.xml side, I've got something like this:
>
> <extension
> point="org.eclipse.ui.editors">
> <editor
> class="my.plugin.editors.PaymentFormEditor"
> default="false"
> icon="icons/payment_edit.png"
> id="my.plugin.editors.payment"
> name="PaymentFormEditor"/>
> </extension>
> <extension
> point="org.eclipse.ui.editorActions">
> <editorContribution
> id="my.plugin.paymentEditorActions"
> targetID="my.plugin.editors.payment">
> <action
> class="my.plugin.actions.PaymentSaveActionDelegate"
> definitionId="org.eclipse.ui.file.save"
> enablesFor="1"
> id="my.plugin.paymentEditorActions.PaymentSaveAction"
> label="Save Payment"
> menubarPath="additions"
> style="push"
> tooltip="Save the changes to the current payment."/>
> </editorContribution>
> </extension>
>
> The org.eclipse.ui.file.save command and the Ctrl+S key binding are
> declared in the org.eclipse.ui plugin's plugin.xml file.
>
> I might also need to create an org.eclipse.ui.actionSets extension to
> get my action into the menu and toolbar, but I'm not sure about that
> yet. (This would be the alternative to doing it programmatically in the
> ApplicationActionBarAdvisor using ActionFactory.SAVE, I suppose.)
>
> Anyways, basically what I want to know is how to make
> my.plugin.actions.PaymentSaveActionDelegate.run() trigger
> my.plugin.editors.PaymentFormEditor.doSave().
>
> Is that the correct way to go about this? I would think this would be a
> fairly common requirement in an RCP, so I feel like I'm missing some
> small piece of info that would make the proverbial light bulb come on.
>
> Paul Webster wrote:
>> So, in theory your implement doSave(*) (and potentially doSaveAs()).
>> Then you get the eclipse save action for free.
>>
>> In an RCP app you would create and install ActionFactory.SAVE, the
>> same way that WorkbenchActionBuilder does ... it puts it in the menu
>> and toolbar.
>>
>> Is that what you are asking? How to get Save to appear and make sure
>> it calls doSave(*) on your editor?
>>
>> Later,
>> PW
Re: EditorParts, doSave(), commands, and key bindings [message #460008 is a reply to message #459972] Mon, 11 December 2006 10:17 Go to previous message
Eclipse UserFriend
Originally posted by: bsimpson.mstc.state.ms.us

That seems to be working. Thanks so much for clarifying.

aappddeevv wrote:
> The specific answer is to get the active editor. The below is from the
> SaveAction run() code. This is the save code run by using the
> programmatic approach ActionFactory.SAVE.
>
> public void run() {
> if (getWorkbenchWindow() == null) {
> // action has been disposed
> return;
> }
>
> [...stuff deleted here for views...]
>
> IEditorPart part = getActiveEditor();
> if (part != null) {
> IWorkbenchPage page = part.getSite().getPage();
> page.saveEditor(part, false);
> }
> }
>
> The WorkbenchPage implementation calls doSave() if the part (e.g. a view
> part or editor part) implements ISaveablePart. ISaveablePart specifies
> the doSave() method. ISaveablePart is an interface implemented by
> EditorPart which is how it gets to your editor part you have created.
>
> I am not sure what the file save action does but I would probably use
> this save action which already knows about editors. The standard code
> path pops up a question dialog box to confirm your save.
>
>
> Barry Simpson wrote:
>> Yes, I believe that is what I'm asking.
>>
>> On the plugin.xml side, I've got something like this:
>>
>> <extension
>> point="org.eclipse.ui.editors">
>> <editor
>> class="my.plugin.editors.PaymentFormEditor"
>> default="false"
>> icon="icons/payment_edit.png"
>> id="my.plugin.editors.payment"
>> name="PaymentFormEditor"/>
>> </extension>
>> <extension
>> point="org.eclipse.ui.editorActions">
>> <editorContribution
>> id="my.plugin.paymentEditorActions"
>> targetID="my.plugin.editors.payment">
>> <action
>> class="my.plugin.actions.PaymentSaveActionDelegate"
>> definitionId="org.eclipse.ui.file.save"
>> enablesFor="1"
>> id="my.plugin.paymentEditorActions.PaymentSaveAction"
>> label="Save Payment"
>> menubarPath="additions"
>> style="push"
>> tooltip="Save the changes to the current payment."/>
>> </editorContribution>
>> </extension>
>>
>> The org.eclipse.ui.file.save command and the Ctrl+S key binding are
>> declared in the org.eclipse.ui plugin's plugin.xml file.
>>
>> I might also need to create an org.eclipse.ui.actionSets extension to
>> get my action into the menu and toolbar, but I'm not sure about that
>> yet. (This would be the alternative to doing it programmatically in
>> the ApplicationActionBarAdvisor using ActionFactory.SAVE, I suppose.)
>>
>> Anyways, basically what I want to know is how to make
>> my.plugin.actions.PaymentSaveActionDelegate.run() trigger
>> my.plugin.editors.PaymentFormEditor.doSave().
>>
>> Is that the correct way to go about this? I would think this would be
>> a fairly common requirement in an RCP, so I feel like I'm missing some
>> small piece of info that would make the proverbial light bulb come on.
>>
>> Paul Webster wrote:
>>> So, in theory your implement doSave(*) (and potentially doSaveAs()).
>>> Then you get the eclipse save action for free.
>>>
>>> In an RCP app you would create and install ActionFactory.SAVE, the
>>> same way that WorkbenchActionBuilder does ... it puts it in the menu
>>> and toolbar.
>>>
>>> Is that what you are asking? How to get Save to appear and make sure
>>> it calls doSave(*) on your editor?
>>>
>>> Later,
>>> PW
Previous Topic:Best Practices
Next Topic:RCP 3.2.1 windowMenu has no contents
Goto Forum:
  


Current Time: Wed Mar 26 01:51:35 EDT 2025

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

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

Back to the top