RetargetAction --- Custom requests --- Copy paste actions [message #184527] |
Tue, 14 June 2005 14:25 |
Eclipse User |
|
|
|
Originally posted by: raswinkumar.datamirror.com
Hi,
I am trying to implement copy and paste functionality in my application....
right now, i am able to get it to work but i am sure there is a beeter way
of doing this...
can anyone help me on this?
this is what i know so far....
whenever a object is selected, control is passed to the edit domain and the
suitable tool is invoked ( default being selection tool) then the tool sends
all the request and gets all the command and tabulates the menu with the
commands....
here is what i cant do.... i am not able to create custom request and get
the copy and paste command from the Component policy... is there a way of
doing this...
i realise there is a ACTION FACTORY. COPY and PASTE... but these things dont
seems to working... and they are deprecated as well....
what do i do??
thanks
Aswin
|
|
|
Re: RetargetAction --- Custom requests --- Copy paste actions [message #184617 is a reply to message #184527] |
Tue, 14 June 2005 20:35 |
Hallvard Traetteberg Messages: 673 Registered: July 2009 Location: Trondheim, Norway |
Senior Member |
|
|
On Tue, 14 Jun 2005 10:25:06 -0400, "Aswin"
<raswinkumar@datamirror.com> wrote:
>Hi,
>
>I am trying to implement copy and paste functionality in my application....
My strategy is to register my PasteAction as a "global action
handler", using the following code
setGlobalActionHandler(new CopyAction((IWorkbenchPart)this),
ActionFactory.COPY.getId());
setGlobalActionHandler(new CutAction((IWorkbenchPart)this),
ActionFactory.CUT.getId());
setGlobalActionHandler(new PasteAction((IWorkbenchPart)this),
ActionFactory.PASTE.getId());
}
private void setGlobalActionHandler(IAction action, String id) {
action.setId(id);
if (action instanceof SelectionAction) {
addEditPartAction((SelectionAction)action);
}
getEditorSite().getActionBars().setGlobalActionHandler(id, action);
}
The CopyAction, CutAction and PasteActions are all defined as
subclasses of SelectionAction. The method addEditPartAction used above
ensures that these actions are added to a list of actions that are
"refreshed" when the selection changes, thus ensuring the actions are
given a chance to enable/disable themselves.
Hallvard
|
|
|
Re: RetargetAction --- Custom requests --- Copy paste actions [message #184677 is a reply to message #184617] |
Wed, 15 June 2005 13:31 |
Eclipse User |
|
|
|
Originally posted by: raswinkumar.datamirror.com
Hi,
thanks for the help... but just a few clarifications....
in which class do i place this and what do i do inside the
addEditPartAction()
and getEditorSite()...
is there any methods i may need to implement in the CutAction, CopyAction
and PasteAction
thanks,
Aswin
|
|
|
Re: RetargetAction --- Custom requests --- Copy paste actions [message #184723 is a reply to message #184677] |
Wed, 15 June 2005 20:44 |
Hallvard Traetteberg Messages: 673 Registered: July 2009 Location: Trondheim, Norway |
Senior Member |
|
|
My understanding of this is based on the "RedBook" about using GEF and
EMF together. This problem is only related to GEF, however.
The code is part of the EditorPart implementation, e.g. a subclass of
MultiPageEditorPart.
On Wed, 15 Jun 2005 09:31:07 -0400, "Aswin"
<raswinkumar@datamirror.com> wrote:
>Hi,
>thanks for the help... but just a few clarifications....
>in which class do i place this and what do i do inside the
>addEditPartAction()
>and getEditorSite()...
When creating the actions, you have to make sure that those that are
affected by the selection (those that subclass SelectionAction) later
get updated when the selection changes. One way of doing that is
storing all these actions in a list, and then pass this list to a
method like the one below (updateAction) when a selectionChanged event
is received. Of course, you have to handle selection changes, too.
/**
* Updates the specified actions.
*
* @param actions the list of ids of actions to update
*/
private void updateActions(List actions)
{
for (Iterator it = actions.iterator(); it.hasNext();)
{
IAction action =
getActionRegistry().getAction(it.next());
if (action instanceof UpdateAction) {
((UpdateAction)action).update();
}
}
}
The addEditPartAction method just stores the action in a list that is
later passed to updateActions.
>is there any methods i may need to implement in the CutAction, CopyAction
>and PasteAction
Look at the SelectionAction class for both handling enablement and
getting the selection when performing the action.
|
|
|
Powered by
FUDForum. Page generated in 0.02736 seconds