Home » Eclipse Projects » GEF » MultiPageEditorPart and Actions
MultiPageEditorPart and Actions [message #231972] |
Wed, 21 March 2007 11:09  |
Eclipse User |
|
|
|
Originally posted by: johan.piculell.ericsson.com
Hello. I have really tried to get my actions to work in my
MultiPageEditorPart for several hours and it drives me crazy. Could
someone give me a hint or point to some decent examples ion this?
My design seems quite common to me, a MultiPageEditorPart consisting of
two editors, one TextEditor and one subclassed GraphicalEditor. I want, as
one example, to have a delete button that deletes text in the TextEditor
(this works) and graphical objects in the GraphicalEditor. But I cannot
even get deletion of graphical objects to work at all. My problem seems to
boil down to that I have no idea about how to get the actions to work in
the GraphicalEditor once it is embedded in the MultiPageEditorPart.
|
|
| | | |
Re: MultiPageEditorPart and Actions [message #232026 is a reply to message #232018] |
Thu, 22 March 2007 07:03   |
Eclipse User |
|
|
|
Originally posted by: prashanto.chatterjee.softwareag.com
Hi Johan,
I have struggled a lot with Multi-page editors and I guess, since I have a
working application, I can share a few points with you.
1. Specify the following in your multi-page editor's ActionBarContributor:
------------------------------------------------------------ ------------------------------------------------------------ ----------
/* (non-JavaDoc)
* Method declared in AbstractMultiPageEditorActionBarContributor.
*/
public void setActivePage(IEditorPart part) {
IActionBars actionBars = getActionBars();
if (actionBars != null) {
actionBars.clearGlobalActionHandlers();
if(part instanceof GraphicalEditor){
ActionRegistry registry = (ActionRegistry)
part.getAdapter(ActionRegistry.class);
for (int i = 0; i < globalActionKeys.size(); i++) {
String id = (String) globalActionKeys.get(i);
actionBars.setGlobalActionHandler(id, registry.getAction(id));
}
}else if(part instanceof ITextEditor){
ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
: null;
actionBars.setGlobalActionHandler(
ActionFactory.DELETE.getId(),
getTextAction(editor, ITextEditorActionConstants.DELETE));
actionBars.setGlobalActionHandler(
ActionFactory.UNDO.getId(),
getTextAction(editor, ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(
ActionFactory.REDO.getId(),
getTextAction(editor, ITextEditorActionConstants.REDO));
actionBars.setGlobalActionHandler(
ActionFactory.CUT.getId(),
getTextAction(editor, ITextEditorActionConstants.CUT));
actionBars.setGlobalActionHandler(
ActionFactory.COPY.getId(),
getTextAction(editor, ITextEditorActionConstants.COPY));
actionBars.setGlobalActionHandler(
ActionFactory.PASTE.getId(),
getTextAction(editor, ITextEditorActionConstants.PASTE));
actionBars.setGlobalActionHandler(
ActionFactory.SELECT_ALL.getId(),
getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));
actionBars.setGlobalActionHandler(
ActionFactory.FIND.getId(),
getTextAction(editor, ITextEditorActionConstants.FIND));
actionBars.setGlobalActionHandler(
IDEActionFactory.BOOKMARK.getId(),
getTextAction(editor, IDEActionFactory.BOOKMARK.getId()));
}
//update the action bars
actionBars.updateActionBars();
}
}
------------------------------------------------------------ ------------------------------------------------------------ ----------
What you have above is basically standard code; only difference being that
you update actions based on the currently active editor?
If Undo-Redo works for you then you probably have this in your code.
2. Update your selection in the graphical editor as:
------------------------------------------------------------ ------------------------------------------------------------ ----------
/* (non-Javadoc)
* @see
org.eclipse.gef.ui.parts.GraphicalEditor#selectionChanged(or g.eclipse.ui.IWorkbenchPart,
org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// If not the active editor, ignore selection changed.
if(getSite().getPage().getActiveEditor() == myMPE &&
myMPE.getActiveEditor() == this){
updateActions(getSelectionActions());
}
}
------------------------------------------------------------ ------------------------------------------------------------ ----------
I found the above code while searching the newsgroup. This solved my
problem.
Hope this helps.
Regards,
Prashanto
"Johan" <johan.piculell@ericsson.com> wrote in message
news:4725aee8a782ccb042e07a115ec1a7dc$1@www.eclipse.org...
>I could also put my question like this:
> For some reason, undo/redo works just as I want it to from a contextmenu
> that I made. Functionality 100% correct in both text editor and graphical
> editor and they don't interfere with each other. But delete does not work
> at all apart from being able to delete from the text with the "del" button
> no matter which editor I'm looking at. How come redo/undo automagically
> works, but I cannot get delete to work at all (it is disabled in my
> graphical editor contextmenu)?
>
> regards
> /Johan
>
> Pratik Shah wrote:
>
>> There are known issues with getting actions to work in a MPEP. Search
>> this newsgroup.
>
>> "Johan" <johan.piculell@ericsson.com> wrote in message
>> news:41dc9efee689ae47c50c7ca5a3b3b3fc$1@www.eclipse.org...
>>> Hello. I have really tried to get my actions to work in my
>>> MultiPageEditorPart for several hours and it drives me crazy. Could
>>> someone give me a hint or point to some decent examples ion this?
>>>
>>> My design seems quite common to me, a MultiPageEditorPart consisting of
>>> two editors, one TextEditor and one subclassed GraphicalEditor. I want,
>>> as one example, to have a delete button that deletes text in the
>>> TextEditor (this works) and graphical objects in the GraphicalEditor.
>>> But I cannot even get deletion of graphical objects to work at all. My
>>> problem seems to boil down to that I have no idea about how to get the
>>> actions to work in the GraphicalEditor once it is embedded in the
>>> MultiPageEditorPart.
>>>
>>>
>>>
>
>
|
|
|
Re: MultiPageEditorPart and Actions [message #232033 is a reply to message #232026] |
Thu, 22 March 2007 09:04   |
Eclipse User |
|
|
|
Originally posted by: johan.piculell.ericsson.com
Thanks a ton Prashanto! Now I'm getting at least some progress.
A few more questions then,
I assume "myMPE" is an MultiPageEditorPart, but how can you call
myMPE.getActiveEditor()? This method is protected, what eclipse version
are you running?
Apart from this I have managed to get delete working, but the "del" key
only works in the graphical editor until I display the text editor, then
text editor overrides the key and all "del" key events goes to the text
editor. Guess I need to reset this somewhere when changing back to
graphical editor?
And I still cannot get copy/paste/cut to work in the graphical part, but
this might be out of the scope for this discussion since I probably miss
some fundamental stuff here.
thanks and regards
/Johan
Prashanto Chatterjee wrote:
> Hi Johan,
> I have struggled a lot with Multi-page editors and I guess, since I have a
> working application, I can share a few points with you.
> 1. Specify the following in your multi-page editor's ActionBarContributor:
>
------------------------------------------------------------ ------------------------------------------------------------ ----------
> /* (non-JavaDoc)
> * Method declared in AbstractMultiPageEditorActionBarContributor.
> */
> public void setActivePage(IEditorPart part) {
> IActionBars actionBars = getActionBars();
> if (actionBars != null) {
> actionBars.clearGlobalActionHandlers();
> if(part instanceof GraphicalEditor){
> ActionRegistry registry = (ActionRegistry)
> part.getAdapter(ActionRegistry.class);
> for (int i = 0; i < globalActionKeys.size(); i++) {
> String id = (String) globalActionKeys.get(i);
> actionBars.setGlobalActionHandler(id, registry.getAction(id));
> }
> }else if(part instanceof ITextEditor){
> ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
> : null;
> actionBars.setGlobalActionHandler(
> ActionFactory.DELETE.getId(),
> getTextAction(editor, ITextEditorActionConstants.DELETE));
> actionBars.setGlobalActionHandler(
> ActionFactory.UNDO.getId(),
> getTextAction(editor, ITextEditorActionConstants.UNDO));
> actionBars.setGlobalActionHandler(
> ActionFactory.REDO.getId(),
> getTextAction(editor, ITextEditorActionConstants.REDO));
> actionBars.setGlobalActionHandler(
> ActionFactory.CUT.getId(),
> getTextAction(editor, ITextEditorActionConstants.CUT));
> actionBars.setGlobalActionHandler(
> ActionFactory.COPY.getId(),
> getTextAction(editor, ITextEditorActionConstants.COPY));
> actionBars.setGlobalActionHandler(
> ActionFactory.PASTE.getId(),
> getTextAction(editor, ITextEditorActionConstants.PASTE));
> actionBars.setGlobalActionHandler(
> ActionFactory.SELECT_ALL.getId(),
> getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));
> actionBars.setGlobalActionHandler(
> ActionFactory.FIND.getId(),
> getTextAction(editor, ITextEditorActionConstants.FIND));
> actionBars.setGlobalActionHandler(
> IDEActionFactory.BOOKMARK.getId(),
> getTextAction(editor, IDEActionFactory.BOOKMARK.getId()));
> }
> //update the action bars
> actionBars.updateActionBars();
> }
> }
>
------------------------------------------------------------ ------------------------------------------------------------ ----------
> What you have above is basically standard code; only difference being that
> you update actions based on the currently active editor?
> If Undo-Redo works for you then you probably have this in your code.
> 2. Update your selection in the graphical editor as:
>
------------------------------------------------------------ ------------------------------------------------------------ ----------
> /* (non-Javadoc)
> * @see
>
org.eclipse.gef.ui.parts.GraphicalEditor#selectionChanged(or g.eclipse.ui.IWorkbenchPart,
> org.eclipse.jface.viewers.ISelection)
> */
> public void selectionChanged(IWorkbenchPart part, ISelection selection) {
> // If not the active editor, ignore selection changed.
> if(getSite().getPage().getActiveEditor() == myMPE &&
> myMPE.getActiveEditor() == this){
> updateActions(getSelectionActions());
> }
> }
>
------------------------------------------------------------ ------------------------------------------------------------ ----------
> I found the above code while searching the newsgroup. This solved my
> problem.
> Hope this helps.
> Regards,
> Prashanto
> "Johan" <johan.piculell@ericsson.com> wrote in message
> news:4725aee8a782ccb042e07a115ec1a7dc$1@www.eclipse.org...
>>I could also put my question like this:
>> For some reason, undo/redo works just as I want it to from a contextmenu
>> that I made. Functionality 100% correct in both text editor and graphical
>> editor and they don't interfere with each other. But delete does not work
>> at all apart from being able to delete from the text with the "del" button
>> no matter which editor I'm looking at. How come redo/undo automagically
>> works, but I cannot get delete to work at all (it is disabled in my
>> graphical editor contextmenu)?
>>
>> regards
>> /Johan
>>
>> Pratik Shah wrote:
>>
>>> There are known issues with getting actions to work in a MPEP. Search
>>> this newsgroup.
>>
>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>> news:41dc9efee689ae47c50c7ca5a3b3b3fc$1@www.eclipse.org...
>>>> Hello. I have really tried to get my actions to work in my
>>>> MultiPageEditorPart for several hours and it drives me crazy. Could
>>>> someone give me a hint or point to some decent examples ion this?
>>>>
>>>> My design seems quite common to me, a MultiPageEditorPart consisting of
>>>> two editors, one TextEditor and one subclassed GraphicalEditor. I want,
>>>> as one example, to have a delete button that deletes text in the
>>>> TextEditor (this works) and graphical objects in the GraphicalEditor.
>>>> But I cannot even get deletion of graphical objects to work at all. My
>>>> problem seems to boil down to that I have no idea about how to get the
>>>> actions to work in the GraphicalEditor once it is embedded in the
>>>> MultiPageEditorPart.
>>>>
>>>>
>>>>
>>
>>
|
|
|
Re: MultiPageEditorPart and Actions [message #232042 is a reply to message #232033] |
Thu, 22 March 2007 09:35   |
Eclipse User |
|
|
|
Originally posted by: prashanto.chatterjee.softwareag.com
Hi Johan,
About the method being protected; just override it and change the modifier
to public ;-)
About 'del' key not working once you switch to text-editor, I have a post to
the group for which I couldn't get any answer :-(. Maybe we can get cracking
at it now together.
About cut, copy and paste use the following code in your GraphicalEditor
implementation:
------------------------------------------------------------ -------------
/* (non-Javadoc)
* @see org.eclipse.gef.ui.parts.GraphicalEditor#createActions()
*/
protected void createActions() {
super.createActions();
ActionRegistry registry = getActionRegistry();
IAction actionCut;
actionCut = new CutAction(this);
actionCut.setId(ActionFactory.CUT.getId());
registry.registerAction(actionCut);
getSelectionActions().add(actionCut.getId());
IAction actionCopy;
actionCopy = new CopyAction(this);
actionCopy.setId(ActionFactory.COPY.getId());
registry.registerAction(actionCopy);
getSelectionActions().add(actionCopy.getId());
IAction actionPaste;
actionPaste = new PasteAction(this);
actionPaste.setId(ActionFactory.PASTE.getId());
registry.registerAction(actionPaste);
getSelectionActions().add(actionPaste.getId());
}
------------------------------------------------------------ -------------
You would need to write your own implementation for cut, copy and paste
depending on the model that you use.
Regards,
Prashanto
"Johan" <johan.piculell@ericsson.com> wrote in message
news:8b40c4b04da75232776d3260674a1298$1@www.eclipse.org...
> Thanks a ton Prashanto! Now I'm getting at least some progress. A few more
> questions then,
> I assume "myMPE" is an MultiPageEditorPart, but how can you call
> myMPE.getActiveEditor()? This method is protected, what eclipse version
> are you running?
> Apart from this I have managed to get delete working, but the "del" key
> only works in the graphical editor until I display the text editor, then
> text editor overrides the key and all "del" key events goes to the text
> editor. Guess I need to reset this somewhere when changing back to
> graphical editor?
> And I still cannot get copy/paste/cut to work in the graphical part, but
> this might be out of the scope for this discussion since I probably miss
> some fundamental stuff here.
>
> thanks and regards
> /Johan
>
> Prashanto Chatterjee wrote:
>
>> Hi Johan,
>> I have struggled a lot with Multi-page editors and I guess, since I have
>> a working application, I can share a few points with you.
>
>> 1. Specify the following in your multi-page editor's
>> ActionBarContributor:
>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>> /* (non-JavaDoc)
>> * Method declared in AbstractMultiPageEditorActionBarContributor.
>> */
>
>> public void setActivePage(IEditorPart part) {
>
>> IActionBars actionBars = getActionBars();
>> if (actionBars != null) {
>> actionBars.clearGlobalActionHandlers();
>
>> if(part instanceof GraphicalEditor){
>> ActionRegistry registry = (ActionRegistry)
>> part.getAdapter(ActionRegistry.class);
>> for (int i = 0; i < globalActionKeys.size(); i++) {
>> String id = (String) globalActionKeys.get(i);
>> actionBars.setGlobalActionHandler(id, registry.getAction(id));
>> }
>
>> }else if(part instanceof ITextEditor){
>> ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor)
>> part : null;
>> actionBars.setGlobalActionHandler(
>> ActionFactory.DELETE.getId(),
>> getTextAction(editor, ITextEditorActionConstants.DELETE));
>> actionBars.setGlobalActionHandler(
>> ActionFactory.UNDO.getId(),
>> getTextAction(editor, ITextEditorActionConstants.UNDO));
>> actionBars.setGlobalActionHandler(
>> ActionFactory.REDO.getId(),
>> getTextAction(editor, ITextEditorActionConstants.REDO));
>> actionBars.setGlobalActionHandler(
>> ActionFactory.CUT.getId(),
>> getTextAction(editor, ITextEditorActionConstants.CUT));
>> actionBars.setGlobalActionHandler(
>> ActionFactory.COPY.getId(),
>> getTextAction(editor, ITextEditorActionConstants.COPY));
>> actionBars.setGlobalActionHandler(
>> ActionFactory.PASTE.getId(),
>> getTextAction(editor, ITextEditorActionConstants.PASTE));
>> actionBars.setGlobalActionHandler(
>> ActionFactory.SELECT_ALL.getId(),
>> getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));
>> actionBars.setGlobalActionHandler(
>> ActionFactory.FIND.getId(),
>> getTextAction(editor, ITextEditorActionConstants.FIND));
>> actionBars.setGlobalActionHandler(
>> IDEActionFactory.BOOKMARK.getId(),
>> getTextAction(editor, IDEActionFactory.BOOKMARK.getId()));
>> }
>
>> //update the action bars
>> actionBars.updateActionBars();
>> }
>> }
>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>> What you have above is basically standard code; only difference being
>> that you update actions based on the currently active editor?
>> If Undo-Redo works for you then you probably have this in your code.
>
>> 2. Update your selection in the graphical editor as:
>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>> /* (non-Javadoc)
>> * @see
> org.eclipse.gef.ui.parts.GraphicalEditor#selectionChanged(or g.eclipse.ui.IWorkbenchPart,
>> org.eclipse.jface.viewers.ISelection)
>> */
>> public void selectionChanged(IWorkbenchPart part, ISelection selection)
>> {
>> // If not the active editor, ignore selection changed.
>> if(getSite().getPage().getActiveEditor() == myMPE &&
>> myMPE.getActiveEditor() == this){
>> updateActions(getSelectionActions());
>> }
>> }
>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>> I found the above code while searching the newsgroup. This solved my
>> problem.
>
>> Hope this helps.
>
>> Regards,
>> Prashanto
>
>> "Johan" <johan.piculell@ericsson.com> wrote in message
>> news:4725aee8a782ccb042e07a115ec1a7dc$1@www.eclipse.org...
>>>I could also put my question like this:
>>> For some reason, undo/redo works just as I want it to from a contextmenu
>>> that I made. Functionality 100% correct in both text editor and
>>> graphical editor and they don't interfere with each other. But delete
>>> does not work at all apart from being able to delete from the text with
>>> the "del" button no matter which editor I'm looking at. How come
>>> redo/undo automagically works, but I cannot get delete to work at all
>>> (it is disabled in my graphical editor contextmenu)?
>>>
>>> regards
>>> /Johan
>>>
>>> Pratik Shah wrote:
>>>
>>>> There are known issues with getting actions to work in a MPEP. Search
>>>> this newsgroup.
>>>
>>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>>> news:41dc9efee689ae47c50c7ca5a3b3b3fc$1@www.eclipse.org...
>>>>> Hello. I have really tried to get my actions to work in my
>>>>> MultiPageEditorPart for several hours and it drives me crazy. Could
>>>>> someone give me a hint or point to some decent examples ion this?
>>>>>
>>>>> My design seems quite common to me, a MultiPageEditorPart consisting
>>>>> of two editors, one TextEditor and one subclassed GraphicalEditor. I
>>>>> want, as one example, to have a delete button that deletes text in the
>>>>> TextEditor (this works) and graphical objects in the GraphicalEditor.
>>>>> But I cannot even get deletion of graphical objects to work at all. My
>>>>> problem seems to boil down to that I have no idea about how to get the
>>>>> actions to work in the GraphicalEditor once it is embedded in the
>>>>> MultiPageEditorPart.
>>>>>
>>>>>
>>>>>
>>>
>>>
>
>
|
|
|
Re: MultiPageEditorPart and Actions [message #232050 is a reply to message #232042] |
Thu, 22 March 2007 11:00   |
Eclipse User |
|
|
|
Originally posted by: johan.piculell.ericsson.com
Thank you, thank you, thank you!!
Now I'm back on track, now let's hope someone picks up our silent cry for
help on the key registration thing.
/Johan
Prashanto Chatterjee wrote:
> Hi Johan,
> About the method being protected; just override it and change the modifier
> to public ;-)
> About 'del' key not working once you switch to text-editor, I have a post to
> the group for which I couldn't get any answer :-(. Maybe we can get cracking
> at it now together.
> About cut, copy and paste use the following code in your GraphicalEditor
> implementation:
> ------------------------------------------------------------ -------------
> /* (non-Javadoc)
> * @see org.eclipse.gef.ui.parts.GraphicalEditor#createActions()
> */
> protected void createActions() {
> super.createActions();
> ActionRegistry registry = getActionRegistry();
> IAction actionCut;
> actionCut = new CutAction(this);
> actionCut.setId(ActionFactory.CUT.getId());
> registry.registerAction(actionCut);
> getSelectionActions().add(actionCut.getId());
> IAction actionCopy;
> actionCopy = new CopyAction(this);
> actionCopy.setId(ActionFactory.COPY.getId());
> registry.registerAction(actionCopy);
> getSelectionActions().add(actionCopy.getId());
> IAction actionPaste;
> actionPaste = new PasteAction(this);
> actionPaste.setId(ActionFactory.PASTE.getId());
> registry.registerAction(actionPaste);
> getSelectionActions().add(actionPaste.getId());
> }
> ------------------------------------------------------------ -------------
> You would need to write your own implementation for cut, copy and paste
> depending on the model that you use.
> Regards,
> Prashanto
> "Johan" <johan.piculell@ericsson.com> wrote in message
> news:8b40c4b04da75232776d3260674a1298$1@www.eclipse.org...
>> Thanks a ton Prashanto! Now I'm getting at least some progress. A few more
>> questions then,
>> I assume "myMPE" is an MultiPageEditorPart, but how can you call
>> myMPE.getActiveEditor()? This method is protected, what eclipse version
>> are you running?
>> Apart from this I have managed to get delete working, but the "del" key
>> only works in the graphical editor until I display the text editor, then
>> text editor overrides the key and all "del" key events goes to the text
>> editor. Guess I need to reset this somewhere when changing back to
>> graphical editor?
>> And I still cannot get copy/paste/cut to work in the graphical part, but
>> this might be out of the scope for this discussion since I probably miss
>> some fundamental stuff here.
>>
>> thanks and regards
>> /Johan
>>
>> Prashanto Chatterjee wrote:
>>
>>> Hi Johan,
>>> I have struggled a lot with Multi-page editors and I guess, since I have
>>> a working application, I can share a few points with you.
>>
>>> 1. Specify the following in your multi-page editor's
>>> ActionBarContributor:
>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>> /* (non-JavaDoc)
>>> * Method declared in AbstractMultiPageEditorActionBarContributor.
>>> */
>>
>>> public void setActivePage(IEditorPart part) {
>>
>>> IActionBars actionBars = getActionBars();
>>> if (actionBars != null) {
>>> actionBars.clearGlobalActionHandlers();
>>
>>> if(part instanceof GraphicalEditor){
>>> ActionRegistry registry = (ActionRegistry)
>>> part.getAdapter(ActionRegistry.class);
>>> for (int i = 0; i < globalActionKeys.size(); i++) {
>>> String id = (String) globalActionKeys.get(i);
>>> actionBars.setGlobalActionHandler(id, registry.getAction(id));
>>> }
>>
>>> }else if(part instanceof ITextEditor){
>>> ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor)
>>> part : null;
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.DELETE.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.DELETE));
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.UNDO.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.UNDO));
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.REDO.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.REDO));
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.CUT.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.CUT));
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.COPY.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.COPY));
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.PASTE.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.PASTE));
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.SELECT_ALL.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));
>>> actionBars.setGlobalActionHandler(
>>> ActionFactory.FIND.getId(),
>>> getTextAction(editor, ITextEditorActionConstants.FIND));
>>> actionBars.setGlobalActionHandler(
>>> IDEActionFactory.BOOKMARK.getId(),
>>> getTextAction(editor, IDEActionFactory.BOOKMARK.getId()));
>>> }
>>
>>> //update the action bars
>>> actionBars.updateActionBars();
>>> }
>>> }
>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>> What you have above is basically standard code; only difference being
>>> that you update actions based on the currently active editor?
>>> If Undo-Redo works for you then you probably have this in your code.
>>
>>> 2. Update your selection in the graphical editor as:
>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>> /* (non-Javadoc)
>>> * @see
>>
org.eclipse.gef.ui.parts.GraphicalEditor#selectionChanged(or g.eclipse.ui.IWorkbenchPart,
>>> org.eclipse.jface.viewers.ISelection)
>>> */
>>> public void selectionChanged(IWorkbenchPart part, ISelection selection)
>>> {
>>> // If not the active editor, ignore selection changed.
>>> if(getSite().getPage().getActiveEditor() == myMPE &&
>>> myMPE.getActiveEditor() == this){
>>> updateActions(getSelectionActions());
>>> }
>>> }
>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>> I found the above code while searching the newsgroup. This solved my
>>> problem.
>>
>>> Hope this helps.
>>
>>> Regards,
>>> Prashanto
>>
>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>> news:4725aee8a782ccb042e07a115ec1a7dc$1@www.eclipse.org...
>>>>I could also put my question like this:
>>>> For some reason, undo/redo works just as I want it to from a contextmenu
>>>> that I made. Functionality 100% correct in both text editor and
>>>> graphical editor and they don't interfere with each other. But delete
>>>> does not work at all apart from being able to delete from the text with
>>>> the "del" button no matter which editor I'm looking at. How come
>>>> redo/undo automagically works, but I cannot get delete to work at all
>>>> (it is disabled in my graphical editor contextmenu)?
>>>>
>>>> regards
>>>> /Johan
>>>>
>>>> Pratik Shah wrote:
>>>>
>>>>> There are known issues with getting actions to work in a MPEP. Search
>>>>> this newsgroup.
>>>>
>>>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>>>> news:41dc9efee689ae47c50c7ca5a3b3b3fc$1@www.eclipse.org...
>>>>>> Hello. I have really tried to get my actions to work in my
>>>>>> MultiPageEditorPart for several hours and it drives me crazy. Could
>>>>>> someone give me a hint or point to some decent examples ion this?
>>>>>>
>>>>>> My design seems quite common to me, a MultiPageEditorPart consisting
>>>>>> of two editors, one TextEditor and one subclassed GraphicalEditor. I
>>>>>> want, as one example, to have a delete button that deletes text in the
>>>>>> TextEditor (this works) and graphical objects in the GraphicalEditor.
>>>>>> But I cannot even get deletion of graphical objects to work at all. My
>>>>>> problem seems to boil down to that I have no idea about how to get the
>>>>>> actions to work in the GraphicalEditor once it is embedded in the
>>>>>> MultiPageEditorPart.
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
|
|
|
Re: MultiPageEditorPart and Actions [message #234214 is a reply to message #232050] |
Tue, 15 May 2007 11:35   |
Eclipse User |
|
|
|
Originally posted by: rudolf.hornig.gmail.com
put the following code in your GrahicalEditor.configureGrahicalViewer:
ActionRegistry registry = getActionRegistry();
String id = ActionFactory.UNDO.getId();
getEditorSite().getKeyBindingService().registerAction(regist ry.getAction(id));
id = ActionFactory.REDO.getId();
getEditorSite().getKeyBindingService().registerAction(regist ry.getAction(id));
id = ActionFactory.DELETE.getId();
getEditorSite().getKeyBindingService().registerAction(regist ry.getAction(id));
this will register the commands belonging ti UNDO/REDO/DELETE to the
graphical editor too. It seems that the text editor steals the key
bindings when activated, and does not restore the original state when
deactivated.
Rudolf
Johan wrote:
> Thank you, thank you, thank you!!
> Now I'm back on track, now let's hope someone picks up our silent cry
> for help on the key registration thing.
>
> /Johan
>
> Prashanto Chatterjee wrote:
>
>> Hi Johan,
>> About the method being protected; just override it and change the
>> modifier to public ;-)
>
>> About 'del' key not working once you switch to text-editor, I have a
>> post to the group for which I couldn't get any answer :-(. Maybe we
>> can get cracking at it now together.
>
>> About cut, copy and paste use the following code in your
>> GraphicalEditor implementation:
>> ------------------------------------------------------------ -------------
>> /* (non-Javadoc)
>> * @see org.eclipse.gef.ui.parts.GraphicalEditor#createActions()
>> */
>> protected void createActions() {
>> super.createActions();
>
>> ActionRegistry registry = getActionRegistry();
>
>> IAction actionCut;
>> actionCut = new CutAction(this);
>> actionCut.setId(ActionFactory.CUT.getId());
>> registry.registerAction(actionCut);
>> getSelectionActions().add(actionCut.getId());
>
>> IAction actionCopy;
>> actionCopy = new CopyAction(this);
>> actionCopy.setId(ActionFactory.COPY.getId());
>> registry.registerAction(actionCopy);
>> getSelectionActions().add(actionCopy.getId());
>
>> IAction actionPaste;
>> actionPaste = new PasteAction(this);
>> actionPaste.setId(ActionFactory.PASTE.getId());
>> registry.registerAction(actionPaste);
>> getSelectionActions().add(actionPaste.getId());
>> }
>> ------------------------------------------------------------ -------------
>
>> You would need to write your own implementation for cut, copy and
>> paste depending on the model that you use.
>
>> Regards,
>> Prashanto
>
>> "Johan" <johan.piculell@ericsson.com> wrote in message
>> news:8b40c4b04da75232776d3260674a1298$1@www.eclipse.org...
>>> Thanks a ton Prashanto! Now I'm getting at least some progress. A few
>>> more questions then,
>>> I assume "myMPE" is an MultiPageEditorPart, but how can you call
>>> myMPE.getActiveEditor()? This method is protected, what eclipse
>>> version are you running?
>>> Apart from this I have managed to get delete working, but the "del"
>>> key only works in the graphical editor until I display the text
>>> editor, then text editor overrides the key and all "del" key events
>>> goes to the text editor. Guess I need to reset this somewhere when
>>> changing back to graphical editor?
>>> And I still cannot get copy/paste/cut to work in the graphical part,
>>> but this might be out of the scope for this discussion since I
>>> probably miss some fundamental stuff here.
>>>
>>> thanks and regards
>>> /Johan
>>>
>>> Prashanto Chatterjee wrote:
>>>
>>>> Hi Johan,
>>>> I have struggled a lot with Multi-page editors and I guess, since I
>>>> have a working application, I can share a few points with you.
>>>
>>>> 1. Specify the following in your multi-page editor's
>>>> ActionBarContributor:
>>>>
>>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>
>>>> /* (non-JavaDoc)
>>>> * Method declared in AbstractMultiPageEditorActionBarContributor.
>>>> */
>>>
>>>> public void setActivePage(IEditorPart part) {
>>>
>>>> IActionBars actionBars = getActionBars();
>>>> if (actionBars != null) {
>>>> actionBars.clearGlobalActionHandlers();
>>>
>>>> if(part instanceof GraphicalEditor){
>>>> ActionRegistry registry = (ActionRegistry)
>>>> part.getAdapter(ActionRegistry.class);
>>>> for (int i = 0; i < globalActionKeys.size(); i++) {
>>>> String id = (String) globalActionKeys.get(i);
>>>> actionBars.setGlobalActionHandler(id, registry.getAction(id));
>>>> }
>>>
>>>> }else if(part instanceof ITextEditor){
>>>> ITextEditor editor = (part instanceof ITextEditor) ?
>>>> (ITextEditor) part : null;
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.DELETE.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.DELETE));
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.UNDO.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.UNDO));
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.REDO.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.REDO));
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.CUT.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.CUT));
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.COPY.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.COPY));
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.PASTE.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.PASTE));
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.SELECT_ALL.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));
>>>> actionBars.setGlobalActionHandler(
>>>> ActionFactory.FIND.getId(),
>>>> getTextAction(editor, ITextEditorActionConstants.FIND));
>>>> actionBars.setGlobalActionHandler(
>>>> IDEActionFactory.BOOKMARK.getId(),
>>>> getTextAction(editor, IDEActionFactory.BOOKMARK.getId()));
>>>> }
>>>
>>>> //update the action bars
>>>> actionBars.updateActionBars();
>>>> }
>>>> }
>>>>
>>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>
>>>> What you have above is basically standard code; only difference
>>>> being that you update actions based on the currently active editor?
>>>> If Undo-Redo works for you then you probably have this in your code.
>>>
>>>> 2. Update your selection in the graphical editor as:
>>>>
>>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>
>>>> /* (non-Javadoc)
>>>> * @see
>>>
> org.eclipse.gef.ui.parts.GraphicalEditor#selectionChanged(or g.eclipse.ui.IWorkbenchPart,
>
>>>> org.eclipse.jface.viewers.ISelection)
>>>> */
>>>> public void selectionChanged(IWorkbenchPart part, ISelection
>>>> selection) {
>>>> // If not the active editor, ignore selection changed.
>>>> if(getSite().getPage().getActiveEditor() == myMPE &&
>>>> myMPE.getActiveEditor() == this){
>>>> updateActions(getSelectionActions());
>>>> }
>>>> }
>>>>
>>>
> ------------------------------------------------------------ ------------------------------------------------------------ ----------
>
>>>> I found the above code while searching the newsgroup. This solved my
>>>> problem.
>>>
>>>> Hope this helps.
>>>
>>>> Regards,
>>>> Prashanto
>>>
>>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>>> news:4725aee8a782ccb042e07a115ec1a7dc$1@www.eclipse.org...
>>>>> I could also put my question like this:
>>>>> For some reason, undo/redo works just as I want it to from a
>>>>> contextmenu that I made. Functionality 100% correct in both text
>>>>> editor and graphical editor and they don't interfere with each
>>>>> other. But delete does not work at all apart from being able to
>>>>> delete from the text with the "del" button no matter which editor
>>>>> I'm looking at. How come redo/undo automagically works, but I
>>>>> cannot get delete to work at all (it is disabled in my graphical
>>>>> editor contextmenu)?
>>>>>
>>>>> regards
>>>>> /Johan
>>>>>
>>>>> Pratik Shah wrote:
>>>>>
>>>>>> There are known issues with getting actions to work in a MPEP.
>>>>>> Search this newsgroup.
>>>>>
>>>>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>>>>> news:41dc9efee689ae47c50c7ca5a3b3b3fc$1@www.eclipse.org...
>>>>>>> Hello. I have really tried to get my actions to work in my
>>>>>>> MultiPageEditorPart for several hours and it drives me crazy.
>>>>>>> Could someone give me a hint or point to some decent examples ion
>>>>>>> this?
>>>>>>>
>>>>>>> My design seems quite common to me, a MultiPageEditorPart
>>>>>>> consisting of two editors, one TextEditor and one subclassed
>>>>>>> GraphicalEditor. I want, as one example, to have a delete button
>>>>>>> that deletes text in the TextEditor (this works) and graphical
>>>>>>> objects in the GraphicalEditor. But I cannot even get deletion of
>>>>>>> graphical objects to work at all. My problem seems to boil down
>>>>>>> to that I have no idea about how to get the actions to work in
>>>>>>> the GraphicalEditor once it is embedded in the MultiPageEditorPart.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
>
|
|
|
Re: MultiPageEditorPart and Actions [message #235529 is a reply to message #234214] |
Wed, 13 June 2007 01:42  |
Eclipse User |
|
|
|
Originally posted by: johan.piculell.ericsson.com
Thanks Rudolf for replying on this, did not check this thread for a long
time since I thought it was dead more or less.
Anyway, I actually added the single line:
getEditorSite().getKeyBindingService();
in configureGraphicalViewer() the other week after some debugging internal
Eclipse classes and that resolved my problem. Now getKeybindingService is
deprecated so this feels like a temporary workaround for sure.
regards
/Johan
Rudolf Hornig wrote:
> put the following code in your GrahicalEditor.configureGrahicalViewer:
> ActionRegistry registry = getActionRegistry();
> String id = ActionFactory.UNDO.getId();
>
getEditorSite().getKeyBindingService().registerAction(regist ry.getAction(id));
> id = ActionFactory.REDO.getId();
>
getEditorSite().getKeyBindingService().registerAction(regist ry.getAction(id));
> id = ActionFactory.DELETE.getId();
>
getEditorSite().getKeyBindingService().registerAction(regist ry.getAction(id));
> this will register the commands belonging ti UNDO/REDO/DELETE to the
> graphical editor too. It seems that the text editor steals the key
> bindings when activated, and does not restore the original state when
> deactivated.
> Rudolf
> Johan wrote:
>> Thank you, thank you, thank you!!
>> Now I'm back on track, now let's hope someone picks up our silent cry
>> for help on the key registration thing.
>>
>> /Johan
>>
>> Prashanto Chatterjee wrote:
>>
>>> Hi Johan,
>>> About the method being protected; just override it and change the
>>> modifier to public ;-)
>>
>>> About 'del' key not working once you switch to text-editor, I have a
>>> post to the group for which I couldn't get any answer :-(. Maybe we
>>> can get cracking at it now together.
>>
>>> About cut, copy and paste use the following code in your
>>> GraphicalEditor implementation:
>>> ------------------------------------------------------------ -------------
>>> /* (non-Javadoc)
>>> * @see org.eclipse.gef.ui.parts.GraphicalEditor#createActions()
>>> */
>>> protected void createActions() {
>>> super.createActions();
>>
>>> ActionRegistry registry = getActionRegistry();
>>
>>> IAction actionCut;
>>> actionCut = new CutAction(this);
>>> actionCut.setId(ActionFactory.CUT.getId());
>>> registry.registerAction(actionCut);
>>> getSelectionActions().add(actionCut.getId());
>>
>>> IAction actionCopy;
>>> actionCopy = new CopyAction(this);
>>> actionCopy.setId(ActionFactory.COPY.getId());
>>> registry.registerAction(actionCopy);
>>> getSelectionActions().add(actionCopy.getId());
>>
>>> IAction actionPaste;
>>> actionPaste = new PasteAction(this);
>>> actionPaste.setId(ActionFactory.PASTE.getId());
>>> registry.registerAction(actionPaste);
>>> getSelectionActions().add(actionPaste.getId());
>>> }
>>> ------------------------------------------------------------ -------------
>>
>>> You would need to write your own implementation for cut, copy and
>>> paste depending on the model that you use.
>>
>>> Regards,
>>> Prashanto
>>
>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>> news:8b40c4b04da75232776d3260674a1298$1@www.eclipse.org...
>>>> Thanks a ton Prashanto! Now I'm getting at least some progress. A few
>>>> more questions then,
>>>> I assume "myMPE" is an MultiPageEditorPart, but how can you call
>>>> myMPE.getActiveEditor()? This method is protected, what eclipse
>>>> version are you running?
>>>> Apart from this I have managed to get delete working, but the "del"
>>>> key only works in the graphical editor until I display the text
>>>> editor, then text editor overrides the key and all "del" key events
>>>> goes to the text editor. Guess I need to reset this somewhere when
>>>> changing back to graphical editor?
>>>> And I still cannot get copy/paste/cut to work in the graphical part,
>>>> but this might be out of the scope for this discussion since I
>>>> probably miss some fundamental stuff here.
>>>>
>>>> thanks and regards
>>>> /Johan
>>>>
>>>> Prashanto Chatterjee wrote:
>>>>
>>>>> Hi Johan,
>>>>> I have struggled a lot with Multi-page editors and I guess, since I
>>>>> have a working application, I can share a few points with you.
>>>>
>>>>> 1. Specify the following in your multi-page editor's
>>>>> ActionBarContributor:
>>>>>
>>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>
>>>>> /* (non-JavaDoc)
>>>>> * Method declared in AbstractMultiPageEditorActionBarContributor.
>>>>> */
>>>>
>>>>> public void setActivePage(IEditorPart part) {
>>>>
>>>>> IActionBars actionBars = getActionBars();
>>>>> if (actionBars != null) {
>>>>> actionBars.clearGlobalActionHandlers();
>>>>
>>>>> if(part instanceof GraphicalEditor){
>>>>> ActionRegistry registry = (ActionRegistry)
>>>>> part.getAdapter(ActionRegistry.class);
>>>>> for (int i = 0; i < globalActionKeys.size(); i++) {
>>>>> String id = (String) globalActionKeys.get(i);
>>>>> actionBars.setGlobalActionHandler(id, registry.getAction(id));
>>>>> }
>>>>
>>>>> }else if(part instanceof ITextEditor){
>>>>> ITextEditor editor = (part instanceof ITextEditor) ?
>>>>> (ITextEditor) part : null;
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.DELETE.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.DELETE));
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.UNDO.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.UNDO));
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.REDO.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.REDO));
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.CUT.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.CUT));
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.COPY.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.COPY));
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.PASTE.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.PASTE));
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.SELECT_ALL.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));
>>>>> actionBars.setGlobalActionHandler(
>>>>> ActionFactory.FIND.getId(),
>>>>> getTextAction(editor, ITextEditorActionConstants.FIND));
>>>>> actionBars.setGlobalActionHandler(
>>>>> IDEActionFactory.BOOKMARK.getId(),
>>>>> getTextAction(editor, IDEActionFactory.BOOKMARK.getId()));
>>>>> }
>>>>
>>>>> //update the action bars
>>>>> actionBars.updateActionBars();
>>>>> }
>>>>> }
>>>>>
>>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>
>>>>> What you have above is basically standard code; only difference
>>>>> being that you update actions based on the currently active editor?
>>>>> If Undo-Redo works for you then you probably have this in your code.
>>>>
>>>>> 2. Update your selection in the graphical editor as:
>>>>>
>>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>
>>>>> /* (non-Javadoc)
>>>>> * @see
>>>>
>>
org.eclipse.gef.ui.parts.GraphicalEditor#selectionChanged(or g.eclipse.ui.IWorkbenchPart,
>>
>>>>> org.eclipse.jface.viewers.ISelection)
>>>>> */
>>>>> public void selectionChanged(IWorkbenchPart part, ISelection
>>>>> selection) {
>>>>> // If not the active editor, ignore selection changed.
>>>>> if(getSite().getPage().getActiveEditor() == myMPE &&
>>>>> myMPE.getActiveEditor() == this){
>>>>> updateActions(getSelectionActions());
>>>>> }
>>>>> }
>>>>>
>>>>
>>
------------------------------------------------------------ ------------------------------------------------------------ ----------
>>
>>>>> I found the above code while searching the newsgroup. This solved my
>>>>> problem.
>>>>
>>>>> Hope this helps.
>>>>
>>>>> Regards,
>>>>> Prashanto
>>>>
>>>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>>>> news:4725aee8a782ccb042e07a115ec1a7dc$1@www.eclipse.org...
>>>>>> I could also put my question like this:
>>>>>> For some reason, undo/redo works just as I want it to from a
>>>>>> contextmenu that I made. Functionality 100% correct in both text
>>>>>> editor and graphical editor and they don't interfere with each
>>>>>> other. But delete does not work at all apart from being able to
>>>>>> delete from the text with the "del" button no matter which editor
>>>>>> I'm looking at. How come redo/undo automagically works, but I
>>>>>> cannot get delete to work at all (it is disabled in my graphical
>>>>>> editor contextmenu)?
>>>>>>
>>>>>> regards
>>>>>> /Johan
>>>>>>
>>>>>> Pratik Shah wrote:
>>>>>>
>>>>>>> There are known issues with getting actions to work in a MPEP.
>>>>>>> Search this newsgroup.
>>>>>>
>>>>>>> "Johan" <johan.piculell@ericsson.com> wrote in message
>>>>>>> news:41dc9efee689ae47c50c7ca5a3b3b3fc$1@www.eclipse.org...
>>>>>>>> Hello. I have really tried to get my actions to work in my
>>>>>>>> MultiPageEditorPart for several hours and it drives me crazy.
>>>>>>>> Could someone give me a hint or point to some decent examples ion
>>>>>>>> this?
>>>>>>>>
>>>>>>>> My design seems quite common to me, a MultiPageEditorPart
>>>>>>>> consisting of two editors, one TextEditor and one subclassed
>>>>>>>> GraphicalEditor. I want, as one example, to have a delete button
>>>>>>>> that deletes text in the TextEditor (this works) and graphical
>>>>>>>> objects in the GraphicalEditor. But I cannot even get deletion of
>>>>>>>> graphical objects to work at all. My problem seems to boil down
>>>>>>>> to that I have no idea about how to get the actions to work in
>>>>>>>> the GraphicalEditor once it is embedded in the MultiPageEditorPart.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
|
|
|
Goto Forum:
Current Time: Sun Jul 27 11:24:35 EDT 2025
Powered by FUDForum. Page generated in 0.26028 seconds
|