Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How do I go about implementing paste at position
How do I go about implementing paste at position [message #191841] Tue, 10 June 2008 10:03 Go to next message
Kristian O'Connor is currently offline Kristian O'ConnorFriend
Messages: 29
Registered: July 2009
Junior Member
Hi all -

I hope someone can help - currently developing something akin to a bookshelf
with an ordered list of books on it... the bookshelf is a compartment and
the books are added into that compartment as a list - i.e. they have
position...

When copying and pasting between compartments - the book always gets added
to the end of the list... but I would like to paste at a specific position
in the list...

Currently we have a ripped up some of the GMF codebase to allow for pasting
within containers... but how would I go about determining the position the
paste occured in the compartment - and pass that along in a modified version
of PasteRequest! or can I gain access to that location when executing a
paste command.?!

Any thoughts - is this possible.?!

Thanks in advance -
Kristian O'Connor
Re: How do I go about implementing paste at position [message #193441 is a reply to message #191841] Thu, 19 June 2008 08:15 Go to previous message
Kristian O'Connor is currently offline Kristian O'ConnorFriend
Messages: 29
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.

------=_NextPart_000_0020_01C8D1ED.076E42A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all -

I have come up with a solution whereby I put the 'to be pasted' books =
notational and semantical positions into a 'hints' map - then use that =
later in the copy and paste process to paste those elements at the =
specific positions...

ie. had to hack out the ClipboardSupportUtil and change the =
appendEObjectAt method to take a position argument...

eg.
public static EObject appendEObjectAt(int position, EObject eObject, =
EReference reference, EObject referencedObject)
{
if (isOkToAppendEObjectAt(eObject, reference, referencedObject) =
=3D=3D false)
{
return null;
}
if (reference.isContainment())
{
((InternalEObject) referencedObject).eSetResource(null, null);
sendCreateEvent(referencedObject);
}

// if pasting into a list...
if (((Collection) eObject.eGet(reference)) instanceof BasicEList && =
position >=3D 0)
{
((BasicEList) eObject.eGet(reference)).add(position, =
referencedObject);
}
else
{
// default behaviour...
((Collection) eObject.eGet(reference)).add(referencedObject);
}
return referencedObject;
}

Its a bit hacky but seems to work... the only issue left is that the =
pasted elements (i.e. when more than one book was copied) occur in the =
reverse order of the selection...

Thanks all..
K.



"Kristian O'Connor" <kristian.oconnor@gmail.com> wrote in message =
news:g2ljgl$fdt$1@build.eclipse.org...
> Hi all -
>=20
> I hope someone can help - currently developing something akin to a =
bookshelf=20
> with an ordered list of books on it... the bookshelf is a compartment =
and=20
> the books are added into that compartment as a list - i.e. they have=20
> position...
>=20
> When copying and pasting between compartments - the book always gets =
added=20
> to the end of the list... but I would like to paste at a specific =
position=20
> in the list...
>=20
> Currently we have a ripped up some of the GMF codebase to allow for =
pasting=20
> within containers... but how would I go about determining the position =
the=20
> paste occured in the compartment - and pass that along in a modified =
version=20
> of PasteRequest! or can I gain access to that location when executing =
a=20
> paste command.?!
>=20
> Any thoughts - is this possible.?!
>=20
> Thanks in advance -
> Kristian O'Connor=20
>=20
>
------=_NextPart_000_0020_01C8D1ED.076E42A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16640" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi all -</FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have come up with a solution whereby =
I put the=20
'to be pasted' books notational and semantical positions into a 'hints' =
map -=20
then use that later in the copy and paste process to paste those =
elements at the=20
specific positions...</FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>ie. had to hack out the =
ClipboardSupportUtil and=20
change the appendEObjectAt method to take a position =
argument...</FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>eg.</FONT></DIV>
<DIV align=3Djustify><B><FONT color=3D#7f0055><FONT face=3DArial=20
size=3D2>public</FONT></B></FONT><FONT size=3D2><FONT face=3DArial> =
<B><FONT=20
color=3D#7f0055>static</B></FONT></FONT></FONT><FONT size=3D2><FONT =
face=3DArial>=20
EObject appendEObjectAt(<B><FONT =
color=3D#7f0055>int</B></FONT></FONT></FONT><FONT=20
face=3DArial size=3D2> position, EObject eObject, </FONT><FONT =
face=3DArial=20
size=3D2>EReference reference, EObject referencedObject)</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV align=3Djustify><B><FONT color=3D#7f0055><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp; if</FONT></B></FONT><FONT size=3D2><FONT =
face=3DArial>=20
(<I>isOkToAppendEObjectAt</I>(eObject, reference, referencedObject) =
=3D=3D <B><FONT=20
color=3D#7f0055>false</B></FONT></FONT></FONT><FONT face=3DArial=20
size=3D2>)</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
{</FONT></DIV>
<DIV align=3Djustify><B><FONT color=3D#7f0055><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
return</FONT></B></FONT><FONT=20
size=3D2><FONT face=3DArial> <B><FONT=20
color=3D#7f0055>null</B></FONT></FONT></FONT><FONT face=3DArial=20
size=3D2>;</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
}</FONT></DIV>
<DIV align=3Djustify><B><FONT color=3D#7f0055><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp; if</FONT></B></FONT><FONT face=3DArial =
size=3D2>=20
(reference.isContainment())</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
{</FONT></DIV>
<DIV align=3Djustify><FONT size=3D2><FONT =
face=3DArial>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; ((InternalEObject) =
referencedObject).eSetResource(<B><FONT=20
color=3D#7f0055>null</B></FONT></FONT></FONT><FONT size=3D2><FONT =
face=3DArial>,=20
<B><FONT color=3D#7f0055>null</B></FONT></FONT></FONT><FONT face=3DArial =

size=3D2>);</FONT></DIV>
<DIV align=3Djustify><FONT size=3D2><FONT =
face=3DArial><I>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; =
sendCreateEvent</I>(referencedObject);</FONT></FONT></DIV >
<DIV align=3Djustify><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
}</FONT></DIV>
<DIV align=3Djustify><FONT size=3D2><FONT size=3D2><FONT face=3DArial=20
size=3D2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV align=3Djustify><FONT color=3D#3f7f5f><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp; // if pasting into a =
list...</FONT></DIV></FONT>
<DIV align=3Djustify><B><FONT color=3D#7f0055><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;if</FONT> </B></FONT><FONT =
size=3D2><FONT=20
face=3DArial> (((Collection) eObject.eGet(reference)) <B><FONT=20
color=3D#7f0055>instanceof</B></FONT></FONT></FONT><FONT face=3DArial =
size=3D2>=20
BasicEList </FONT><FONT face=3DArial size=3D2>&amp;&amp; position =
&gt;=3D=20
0)</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
{</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
((BasicEList) eObject.eGet(reference)).add(position,=20
referencedObject);</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></DIV >
<DIV align=3Dleft><B><FONT color=3D#7f0055><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp; else</FONT></DIV></B></FONT><FONT size=3D2>
<DIV align=3Dleft><FONT face=3DArial>&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV align=3Dleft></FONT><FONT color=3D#3f7f5f size=3D2><FONT=20
face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // default=20
behaviour...</FONT></DIV></FONT><FONT size=3D2>
<DIV align=3Dleft><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
((Collection) =
eObject.eGet(reference)).add(referencedObject);</FONT></DIV >
<DIV align=3Dleft><FONT face=3DArial>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV align=3Dleft></FONT><B><FONT color=3D#7f0055 size=3D2><FONT=20
face=3DArial>&nbsp;&nbsp;&nbsp; return</FONT></B></FONT><FONT =
size=3D2><FONT=20
face=3DArial> referencedObject;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Its a bit hacky but seems to work... =
the only issue=20
left is that the pasted elements (i.e. when more than one book was =
copied) occur=20
in the reverse order of the selection...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks all..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>K.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"Kristian O'Connor" &lt;</FONT><A=20
href=3D"mailto:kristian.oconnor@gmail.com"><FONT face=3DArial=20
size=3D2>kristian.oconnor@gmail.com</FONT></A><FONT face=3DArial =
size=3D2>&gt; wrote=20
in message </FONT><A href=3D"news:g2ljgl$fdt$1@build.eclipse.org"><FONT =
face=3DArial=20
size=3D2>news:g2ljgl$fdt$1@build.eclipse.org</FONT></A><FONT =
face=3DArial=20
size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt; Hi all =
-<BR>&gt; <BR>&gt; I=20
hope someone can help - currently developing something akin to a =
bookshelf=20
<BR>&gt; with an ordered list of books on it...&nbsp; the bookshelf is a =

compartment and <BR>&gt; the books are added into that compartment as a =
list -=20
i.e. they have <BR>&gt; position...<BR>&gt; <BR>&gt; When copying and =
pasting=20
between compartments - the book always gets added <BR>&gt; to the end of =
the=20
list... but I would like to paste at a specific position <BR>&gt; in the =

list...<BR>&gt; <BR>&gt; Currently we have a ripped up some of the GMF =
codebase=20
to allow for pasting <BR>&gt; within containers... but how would I go =
about=20
determining the position the <BR>&gt; paste occured in the compartment - =
and=20
pass that along in a modified version <BR>&gt; of PasteRequest! or can I =
gain=20
access to that location when executing a <BR>&gt; paste =
command.?!<BR>&gt;=20
<BR>&gt; Any thoughts - is this possible.?!<BR>&gt; <BR>&gt; Thanks in =
advance=20
-<BR>&gt; Kristian O'Connor <BR>&gt; <BR>&gt;</FONT></BODY></HTML>

------=_NextPart_000_0020_01C8D1ED.076E42A0--
Previous Topic:Problem with proxies in resources, that reference other editor's files
Next Topic:Getting related diagrams in different files
Goto Forum:
  


Current Time: Thu Sep 26 03:59:58 GMT 2024

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

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

Back to the top