Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » selection after adding child programmatically
selection after adding child programmatically [message #132962] Wed, 19 May 2004 13:00 Go to next message
steven melzer is currently offline steven melzerFriend
Messages: 38
Registered: July 2009
Member
i have a ClipboardAction and ClipboardCommand which does a basic
cut/copy/paste. it is a SelectionAction so it supports multiple
editparts. it works fine. but i want to "select" the new editparts after
i paste them. the paste routine does a parentModel.add(childModel) which
in turn fires an event to the parentEditPart, which in turn calls
refreshChildren. refreshChildren is the standard method, i have not
subclassed it.

how do i do the selection?

thanks,
steve
Re: selection after adding child programmatically [message #132988 is a reply to message #132962] Wed, 19 May 2004 13:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Find the editpart via its model. viewer.getEditPartRegsitry() will tell
you.
"Steven Melzer" <smelzer@paymentech.com> wrote in message
news:c8flqb$coo$1@eclipse.org...
> i have a ClipboardAction and ClipboardCommand which does a basic
> cut/copy/paste. it is a SelectionAction so it supports multiple
> editparts. it works fine. but i want to "select" the new editparts after
> i paste them. the paste routine does a parentModel.add(childModel) which
> in turn fires an event to the parentEditPart, which in turn calls
> refreshChildren. refreshChildren is the standard method, i have not
> subclassed it.
>
> how do i do the selection?
>
> thanks,
> steve
>
Re: selection after adding child programmatically [message #133051 is a reply to message #132962] Wed, 19 May 2004 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

Hi,

I'm not a specialist of gef so don't trust my advices too much.

When the method parentModel.add(childModel) returns, the change events =

have been fired by the model, the refreshChildren methods have been =

called, and so the EditPart hierarchy is now up to date with the new sta=
te =

of the model, if I make no mistakes. So at the end of the paste routine,=
=

by calling the method getEditPartRegistry() on the EditPartViewer, you c=
an =

get a map between the model objects you just have added and the EditPart=
s =

wich have just been created for them. In this map, the model objects are=
=

the keys to the EditParts, so you can get the EditParts. Once you have t=
he =

EditParts, maybe you could call on them the method setSelection(...) ? I=
=

know that method fires events to notify the selection change so everythi=
ng =

would work fine.

Let me know if this was the good solution,

with best regards,

r=E9gis

On Wed, 19 May 2004 13:00:59 +0000 (UTC), Steven Melzer =

<smelzer@paymentech.com> wrote:

> i have a ClipboardAction and ClipboardCommand which does a basic
> cut/copy/paste. it is a SelectionAction so it supports multiple
> editparts. it works fine. but i want to "select" the new editparts =

> after
> i paste them. the paste routine does a parentModel.add(childModel) wh=
ich
> in turn fires an event to the parentEditPart, which in turn calls
> refreshChildren. refreshChildren is the standard method, i have not
> subclassed it.
>
> how do i do the selection?
>
> thanks,
> steve
Re: selection after adding child programmatically [message #133064 is a reply to message #132988] Wed, 19 May 2004 14:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

oops
didn't see your answer
sorry

On Wed, 19 May 2004 09:52:39 -0400, Randy Hudson <none@us.ibm.com> wrote=
:

> Find the editpart via its model. viewer.getEditPartRegsitry() will te=
ll
> you.
> "Steven Melzer" <smelzer@paymentech.com> wrote in message
> news:c8flqb$coo$1@eclipse.org...
>> i have a ClipboardAction and ClipboardCommand which does a basic
>> cut/copy/paste. it is a SelectionAction so it supports multiple
>> editparts. it works fine. but i want to "select" the new editparts =
=

>> after
>> i paste them. the paste routine does a parentModel.add(childModel) =

>> which
>> in turn fires an event to the parentEditPart, which in turn calls
>> refreshChildren. refreshChildren is the standard method, i have not
>> subclassed it.
>>
>> how do i do the selection?
>>
>> thanks,
>> steve
>>
>
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: selection after adding child programmatically [message #133184 is a reply to message #132988] Wed, 19 May 2004 23:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: phil.williams.toadmail.com

This is a multi-part message in MIME format.
--------------090702020102030609070701
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

I simply keep track of the model elements in my copy action and then
call a method within my editor which calls the getEditPartRegistry for
each and build a list of Edit Parts and then do the following for the
edit part list

StructuredSelection selection = new StructuredSelection( parts );
getGraphicalViewer().setSelection( selection );

HTH,
Phil

Randy Hudson wrote:

>Find the editpart via its model. viewer.getEditPartRegsitry() will tell
>you.
>"Steven Melzer" <smelzer@paymentech.com> wrote in message
>news:c8flqb$coo$1@eclipse.org...
>
>
>>i have a ClipboardAction and ClipboardCommand which does a basic
>>cut/copy/paste. it is a SelectionAction so it supports multiple
>>editparts. it works fine. but i want to "select" the new editparts after
>>i paste them. the paste routine does a parentModel.add(childModel) which
>>in turn fires an event to the parentEditPart, which in turn calls
>>refreshChildren. refreshChildren is the standard method, i have not
>>subclassed it.
>>
>>how do i do the selection?
>>
>>thanks,
>>steve
>>
>>
>>
>
>
>
>

--------------090702020102030609070701
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body>
I simply keep track of the model elements in my copy action and then
call a method within my editor which calls the getEditPartRegistry for
each and build a list of Edit Parts and then do the following for the
edit part list<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StructuredSelection selection = new StructuredSelection( parts
);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; getGraphicalViewer().setSelection( selection );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
HTH,<br>
Phil<br>
<br>
Randy Hudson wrote:<br>
<blockquote cite="midc8fodl$gf4$1@eclipse.org" type="cite">
<pre wrap="">Find the editpart via its model. viewer.getEditPartRegsitry() will tell
you.
"Steven Melzer" <a class="moz-txt-link-rfc2396E" href="mailto:smelzer@paymentech.com">&lt;smelzer@paymentech.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:c8flqb$coo$1@eclipse.org">news:c8flqb$coo$1@eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">i have a ClipboardAction and ClipboardCommand which does a basic
cut/copy/paste. it is a SelectionAction so it supports multiple
editparts. it works fine. but i want to "select" the new editparts after
i paste them. the paste routine does a parentModel.add(childModel) which
in turn fires an event to the parentEditPart, which in turn calls
refreshChildren. refreshChildren is the standard method, i have not
subclassed it.

how do i do the selection?

thanks,
steve

</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------090702020102030609070701--
Re: selection after adding child programmatically [message #134079 is a reply to message #133184] Tue, 25 May 2004 12:57 Go to previous messageGo to next message
steven melzer is currently offline steven melzerFriend
Messages: 38
Registered: July 2009
Member
thanks phil (and everyone else). i got it working now.

phil, my paste command does a clone of the model object that were copied
or cut since the pasted object needs to be its own thing. so i keep track
of the cloned models, not the copied models. you make reference to
keeping track of the copied models in the action. i am just curious how
other people are implementing concepts. are you doing something similar
to myself, or something different?

thanks,
steve

Phil Williams wrote:

> I simply keep track of the model elements in my copy action and then
> call a method within my editor which calls the getEditPartRegistry for
> each and build a list of Edit Parts and then do the following for the
> edit part list

> StructuredSelection selection = new StructuredSelection( parts );
> getGraphicalViewer().setSelection( selection );

> HTH,
> Phil

> Randy Hudson wrote:

> >Find the editpart via its model. viewer.getEditPartRegsitry() will tell
> >you.
> >"Steven Melzer" <smelzer@paymentech.com> wrote in message
> >news:c8flqb$coo$1@eclipse.org...
> >
> >
> >>i have a ClipboardAction and ClipboardCommand which does a basic
> >>cut/copy/paste. it is a SelectionAction so it supports multiple
> >>editparts. it works fine. but i want to "select" the new editparts after
> >>i paste them. the paste routine does a parentModel.add(childModel) which
> >>in turn fires an event to the parentEditPart, which in turn calls
> >>refreshChildren. refreshChildren is the standard method, i have not
> >>subclassed it.
> >>
> >>how do i do the selection?
> >>
> >>thanks,
> >>steve
> >>
> >>
> >>
> >
> >
> >
> >
Re: selection after adding child programmatically [message #134687 is a reply to message #134079] Fri, 28 May 2004 11:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: phil.williams.toadmail.com

This is a multi-part message in MIME format.
--------------020507030002080008060700
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Perhaps I misspoke. Here is what I am doing. My copy action has the
following run():

public void run() {
List copiableObjects = getCopiableObject( getSelectedObjects() );
if ( !copiableObjects.isEmpty() ) {
Clipboard.getDefault().setContents( copiableObjects );
}
}

The getCopiableObject() does a check based on the rules of my model to
determine if the objects that the user has selected in the editor are
indeed copiable. For instance, I filter out connections since they
don't make sense to copy and paste. I place the EditParts in the clipboard.

My paste action then has the following in its run():

public void run() {
List parts = new ArrayList();
List commands = getCommands( getClipboardContents() );
for (Iterator iter = commands.iterator(); iter.hasNext();) {
Command cmd = (Command) iter.next();

// cache the editpart for later selection
if ( cmd instanceof CompoundCommand ) {
CompoundCommand compoundCmd = (CompoundCommand) cmd;
AddCommand add =
(AddCommand)compoundCmd.getCommands().get( 0 );
parts.add( add.getChild() );
}

execute( cmd );

}
((MyEditor)getEditorPart()).selectProcessors( parts );
}

The getCommands() method then walks through the contents of the
clipboard and creates the appropriate commands. These include commands
to add a new object (AddCommand), link two objects (if their sources
were linked), and place objects (I shift them by a set amount relative
to the source). Since the command that creates them is a
CompoundCommand (AddCommand and SetConstraintCommand) I check for those
and cache the new model (even though the list isn't named properly at
the moment).

HTH,
Phil

Steven Melzer wrote:

>thanks phil (and everyone else). i got it working now.
>
>phil, my paste command does a clone of the model object that were copied
>or cut since the pasted object needs to be its own thing. so i keep track
>of the cloned models, not the copied models. you make reference to
>keeping track of the copied models in the action. i am just curious how
>other people are implementing concepts. are you doing something similar
>to myself, or something different?
>
>thanks,
>steve
>
>Phil Williams wrote:
>
>
>
>>I simply keep track of the model elements in my copy action and then
>>call a method within my editor which calls the getEditPartRegistry for
>>each and build a list of Edit Parts and then do the following for the
>>edit part list
>>
>>
>
>
>
>> StructuredSelection selection = new StructuredSelection( parts );
>> getGraphicalViewer().setSelection( selection );
>>
>>
>
>
>
>>HTH,
>>Phil
>>
>>
>
>
>
>>Randy Hudson wrote:
>>
>>
>
>
>
>>>Find the editpart via its model. viewer.getEditPartRegsitry() will tell
>>>you.
>>>"Steven Melzer" <smelzer@paymentech.com> wrote in message
>>>news:c8flqb$coo$1@eclipse.org...
>>>
>>>
>>>
>>>
>>>>i have a ClipboardAction and ClipboardCommand which does a basic
>>>>cut/copy/paste. it is a SelectionAction so it supports multiple
>>>>editparts. it works fine. but i want to "select" the new editparts after
>>>>i paste them. the paste routine does a parentModel.add(childModel) which
>>>>in turn fires an event to the parentEditPart, which in turn calls
>>>>refreshChildren. refreshChildren is the standard method, i have not
>>>>subclassed it.
>>>>
>>>>how do i do the selection?
>>>>
>>>>thanks,
>>>>steve
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>
>
>
>

--------------020507030002080008060700
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body>
Perhaps I misspoke.
Re: selection after adding child programmatically [message #135068 is a reply to message #134687] Mon, 31 May 2004 01:35 Go to previous messageGo to next message
steven melzer is currently offline steven melzerFriend
Messages: 17
Registered: July 2009
Junior Member
phil,

that is very interesting. i appreciate the insight. you do an add
command on the clipboard objects. doesn't that imply that you will have 2
models in the diagram actually tied to the same "real" model? that is why
i clone the model before doing an add command. am i missing something?

also, what do you mean by "linking" two objects? i am not familiar with
this.

again thanks,
steve

Phil Williams wrote:

> Perhaps I misspoke. Here is what I am doing. My copy action has the
> following run():

> public void run() {
> List copiableObjects = getCopiableObject( getSelectedObjects() );
> if ( !copiableObjects.isEmpty() ) {
> Clipboard.getDefault().setContents( copiableObjects );
> }
> }

> The getCopiableObject() does a check based on the rules of my model to
> determine if the objects that the user has selected in the editor are
> indeed copiable. For instance, I filter out connections since they
> don't make sense to copy and paste. I place the EditParts in the clipboard.

> My paste action then has the following in its run():

> public void run() {
> List parts = new ArrayList();
> List commands = getCommands( getClipboardContents() );
> for (Iterator iter = commands.iterator(); iter.hasNext();) {
> Command cmd = (Command) iter.next();

> // cache the editpart for later selection
> if ( cmd instanceof CompoundCommand ) {
> CompoundCommand compoundCmd = (CompoundCommand) cmd;
> AddCommand add =
> (AddCommand)compoundCmd.getCommands().get( 0 );
> parts.add( add.getChild() );
> }

> execute( cmd );

> }
> ((MyEditor)getEditorPart()).selectProcessors( parts );
> }

> The getCommands() method then walks through the contents of the
> clipboard and creates the appropriate commands. These include commands
> to add a new object (AddCommand), link two objects (if their sources
> were linked), and place objects (I shift them by a set amount relative
> to the source). Since the command that creates them is a
> CompoundCommand (AddCommand and SetConstraintCommand) I check for those
> and cache the new model (even though the list isn't named properly at
> the moment).

> HTH,
> Phil

> Steven Melzer wrote:

> >thanks phil (and everyone else). i got it working now.
> >
> >phil, my paste command does a clone of the model object that were copied
> >or cut since the pasted object needs to be its own thing. so i keep track
> >of the cloned models, not the copied models. you make reference to
> >keeping track of the copied models in the action. i am just curious how
> >other people are implementing concepts. are you doing something similar
> >to myself, or something different?
> >
> >thanks,
> >steve
> >
> >Phil Williams wrote:
> >
> >
> >
> >>I simply keep track of the model elements in my copy action and then
> >>call a method within my editor which calls the getEditPartRegistry for
> >>each and build a list of Edit Parts and then do the following for the
> >>edit part list
> >>
> >>
> >
> >
> >
> >> StructuredSelection selection = new StructuredSelection( parts );
> >> getGraphicalViewer().setSelection( selection );
> >>
> >>
> >
> >
> >
> >>HTH,
> >>Phil
> >>
> >>
> >
> >
> >
> >>Randy Hudson wrote:
> >>
> >>
> >
> >
> >
> >>>Find the editpart via its model. viewer.getEditPartRegsitry() will tell
> >>>you.
> >>>"Steven Melzer" <smelzer@paymentech.com> wrote in message
> >>>news:c8flqb$coo$1@eclipse.org...
> >>>
> >>>
> >>>
> >>>
> >>>>i have a ClipboardAction and ClipboardCommand which does a basic
> >>>>cut/copy/paste. it is a SelectionAction so it supports multiple
> >>>>editparts. it works fine. but i want to "select" the new editparts
after
> >>>>i paste them. the paste routine does a parentModel.add(childModel) which
> >>>>in turn fires an event to the parentEditPart, which in turn calls
> >>>>refreshChildren. refreshChildren is the standard method, i have not
> >>>>subclassed it.
> >>>>
> >>>>how do i do the selection?
> >>>>
> >>>>thanks,
> >>>>steve
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>>
> >
> >
> >
> >
Re: selection after adding child programmatically [message #135268 is a reply to message #135068] Tue, 01 June 2004 01:36 Go to previous message
Eclipse UserFriend
Originally posted by: phil.williams.toadmail.com

This is a multi-part message in MIME format.
--------------090506070409060507090504
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

No, I do not have two objects tied to the same model. I have a copy
constructor in my model that does the "cloning." That is all done in
the getCommands() method.

linking = connecting. Basically, if two elements in the diagram that
are connected are copied, the pasted elements are also connected.

steven melzer wrote:

>phil,
>
>that is very interesting. i appreciate the insight. you do an add
>command on the clipboard objects. doesn't that imply that you will have 2
>models in the diagram actually tied to the same "real" model? that is why
>i clone the model before doing an add command. am i missing something?
>
>also, what do you mean by "linking" two objects? i am not familiar with
>this.
>
>again thanks,
>steve
>
>Phil Williams wrote:
>
>
>
>>Perhaps I misspoke. Here is what I am doing. My copy action has the
>>following run():
>>
>>
>
>
>
>> public void run() {
>> List copiableObjects = getCopiableObject( getSelectedObjects() );
>> if ( !copiableObjects.isEmpty() ) {
>> Clipboard.getDefault().setContents( copiableObjects );
>> }
>> }
>>
>>
>
>
>
>>The getCopiableObject() does a check based on the rules of my model to
>>determine if the objects that the user has selected in the editor are
>>indeed copiable. For instance, I filter out connections since they
>>don't make sense to copy and paste. I place the EditParts in the clipboard.
>>
>>
>
>
>
>>My paste action then has the following in its run():
>>
>>
>
>
>
>> public void run() {
>> List parts = new ArrayList();
>> List commands = getCommands( getClipboardContents() );
>> for (Iterator iter = commands.iterator(); iter.hasNext();) {
>> Command cmd = (Command) iter.next();
>>
>>
>
>
>
>> // cache the editpart for later selection
>> if ( cmd instanceof CompoundCommand ) {
>> CompoundCommand compoundCmd = (CompoundCommand) cmd;
>> AddCommand add =
>>(AddCommand)compoundCmd.getCommands().get( 0 );
>> parts.add( add.getChild() );
>> }
>>
>>
>
>
>
>> execute( cmd );
>>
>>
>
>
>
>> }
>> ((MyEditor)getEditorPart()).selectProcessors( parts );
>> }
>>
>>
>
>
>
>>The getCommands() method then walks through the contents of the
>>clipboard and creates the appropriate commands. These include commands
>>to add a new object (AddCommand), link two objects (if their sources
>>were linked), and place objects (I shift them by a set amount relative
>>to the source). Since the command that creates them is a
>>CompoundCommand (AddCommand and SetConstraintCommand) I check for those
>>and cache the new model (even though the list isn't named properly at
>>the moment).
>>
>>
>
>
>
>>HTH,
>>Phil
>>
>>
>
>
>
>>Steven Melzer wrote:
>>
>>
>
>
>
>>>thanks phil (and everyone else). i got it working now.
>>>
>>>phil, my paste command does a clone of the model object that were copied
>>>or cut since the pasted object needs to be its own thing. so i keep track
>>>of the cloned models, not the copied models. you make reference to
>>>keeping track of the copied models in the action. i am just curious how
>>>other people are implementing concepts. are you doing something similar
>>>to myself, or something different?
>>>
>>>thanks,
>>>steve
>>>
>>>Phil Williams wrote:
>>>
>>>
>>>
>>>
>>>
>>>>I simply keep track of the model elements in my copy action and then
>>>>call a method within my editor which calls the getEditPartRegistry for
>>>>each and build a list of Edit Parts and then do the following for the
>>>>edit part list
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>> StructuredSelection selection = new StructuredSelection( parts );
>>>> getGraphicalViewer().setSelection( selection );
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>>HTH,
>>>>Phil
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>>Randy Hudson wrote:
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>>>Find the editpart via its model. viewer.getEditPartRegsitry() will tell
>>>>>you.
>>>>>"Steven Melzer" <smelzer@paymentech.com> wrote in message
>>>>>news:c8flqb$coo$1@eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>i have a ClipboardAction and ClipboardCommand which does a basic
>>>>>>cut/copy/paste. it is a SelectionAction so it supports multiple
>>>>>>editparts. it works fine. but i want to "select" the new editparts
>>>>>>
>>>>>>
>after
>
>
>>>>>>i paste them. the paste routine does a parentModel.add(childModel) which
>>>>>>in turn fires an event to the parentEditPart, which in turn calls
>>>>>>refreshChildren. refreshChildren is the standard method, i have not
>>>>>>subclassed it.
>>>>>>
>>>>>>how do i do the selection?
>>>>>>
>>>>>>thanks,
>>>>>>steve
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>

--------------090506070409060507090504
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body>
No, I do not have two objects tied to the same model.
Previous Topic:Problems in running my GEF Logic Designer
Next Topic:figure in Swing or awt container ?
Goto Forum:
  


Current Time: Thu Apr 25 21:42:10 GMT 2024

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

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

Back to the top