Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Cut Copy and paste Implementation
Cut Copy and paste Implementation [message #223880] Fri, 06 October 2006 05:49 Go to next message
Eclipse UserFriend
Originally posted by: siddharth.star.gmail.com

Hi,

I have been grappling with the Cut Copy and Paste implementaion in GEF for
the past few days and was just hoping if someone could help me find a
better solution.

As of now when performing Cut (say in Cut Action) I create a list of model
elements corresponding to the selected elements and place it in the
Clipboard [in say CutCommand so that I can undo and redo Cut operation].
Similarly in the Copy Action I place in the Clipboard a copy of all the
selected model elements. Now in the Paste Action say I execute a paste
Command which takes whatever is in the Clipboard and pastes it. So far so
good, everything works fine including undo and redo.
The problem is that say the user presses simultaneous Paste how do i cope
with that. Right now what I am doing is after every paste i create a copy
of the pasted elements and store it in the clipboard so that on doing a
successive paste without either of cut or copy the correct behavior is
observed. However, the obvious drawback woth this approach is that the
Clipboard contains an unnecessary copy. So if someone can please
give/suggest me a better idea.

Basically, I believe all my problems would be solved if in the paste
Action I have the handle as to which of them[Cut Copy] was the action last
invoked in a series of actions [example actions A, B, Copy, C, D, Cut, F,
G ], so in my paste if I would know that Cut was last invoked [as per
example] I'll simply paste the elements of the Clipboard or else if its
Copy I'll create a copy and paste it in the clipboard. So the logic of
Copy would be with paste action and it would suit my needs. At least i
hope so:-)

Thanks for your help in advance,
Siddharth
Re: Cut Copy and paste Implementation [message #223887 is a reply to message #223880] Fri, 06 October 2006 09:03 Go to previous message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
I've implemented cut, copy and paste and have struggled with the same
problems. My strategy was as follows:
- I used the XMI serialisation as the clipboard content, to make sure
it is independent of the actual objects in the editor. This makes it
possible to paste it somewhere else, too, e.g. in notepad, fix the
objects and paste it back. I essentially implemented a new transfer
type (I think that's what it is called). Note that not all object
structures may be handled this way, it works best with hierarchies and
well-defined cross-references.
- Copy generated the serialisation
- Paste re-created the objects by reading it in. Note that this
strategy looses the identity of objects, which must instead be handled
by using id-fields. My reasoning is that the identity cannot be the
same when pasting, since we must support several pastes of the same
objects. I guess this is the problem you're struggling with.
- Cut is copy followed by delete.

Hallvard

On Fri, 6 Oct 2006 05:49:37 +0000 (UTC), siddharth.star@gmail.com
(Siddharth) wrote:

>Hi,
>
>I have been grappling with the Cut Copy and Paste implementaion in GEF for
>the past few days and was just hoping if someone could help me find a
>better solution.
>
>As of now when performing Cut (say in Cut Action) I create a list of model
>elements corresponding to the selected elements and place it in the
>Clipboard [in say CutCommand so that I can undo and redo Cut operation].
>Similarly in the Copy Action I place in the Clipboard a copy of all the
>selected model elements. Now in the Paste Action say I execute a paste
>Command which takes whatever is in the Clipboard and pastes it. So far so
>good, everything works fine including undo and redo.
>The problem is that say the user presses simultaneous Paste how do i cope
>with that. Right now what I am doing is after every paste i create a copy
>of the pasted elements and store it in the clipboard so that on doing a
>successive paste without either of cut or copy the correct behavior is
>observed. However, the obvious drawback woth this approach is that the
>Clipboard contains an unnecessary copy. So if someone can please
>give/suggest me a better idea.
>
>Basically, I believe all my problems would be solved if in the paste
>Action I have the handle as to which of them[Cut Copy] was the action last
>invoked in a series of actions [example actions A, B, Copy, C, D, Cut, F,
>G ], so in my paste if I would know that Cut was last invoked [as per
>example] I'll simply paste the elements of the Clipboard or else if its
>Copy I'll create a copy and paste it in the clipboard. So the logic of
>Copy would be with paste action and it would suit my needs. At least i
>hope so:-)
>
>Thanks for your help in advance,
>Siddharth
Previous Topic:Drawing custom decorations in Compartment-Nodes
Next Topic:EMF property source provider in GEF?
Goto Forum:
  


Current Time: Wed Dec 08 14:06:56 GMT 2021

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

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

Back to the top