Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Copy/Paste shape text (Read 4044 times)
cpmjones
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Aug 4th, 2008
Copy/Paste shape text
Jun 3rd, 2010 at 2:40pm
Print Post  
Hi,

I have my own shape class which extends ShapeNode.

I am implementing copy/paste using the readExternal/writeExternal methods.

All works fine. However, I need to be able to update the text of the pasted shapes each time it is pasted.

For example, if you have a shape with text "MindFusion" then on the first paste, the new shape should be "MindFusion 2" and then next paste "MindFusion 3" and so on.

I tried using the readExternal() to read the text of all the current diagram shapes to determine the suffix. However the getParent() returns null instead of the Diagram object.

I also tried using the shape's constructor which is used for the copy/paste but the suffix is added twice - as it is called on both copy and paste?

I then thought about using one of the diagram listener methods. The nodeCreating() event does not get caught when pasting however.

Is there another event which will be triggered on each paste?

Or is there a better method of achieving this?

Thanks,

Chris
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy/Paste shape text
Reply #1 - Jun 3rd, 2010 at 2:55pm
Print Post  
Hi,

Since the pasted items are selected after calling pasteFromClipboard(), it should be possible to loop over diagram.getSelection().getNodes() and update their texts. We could also add a nodePasted() event for this, we have the same in the .NET versions of the control.

Stoyan
  
Back to top
 
IP Logged
 
cpmjones
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Aug 4th, 2008
Re: Copy/Paste shape text
Reply #2 - Jun 3rd, 2010 at 3:27pm
Print Post  
Hi Stoyan,

I tried as you suggested and it works perfectly!

Thanks again for your help.

Regards,

Chris Smiley
  
Back to top
 
IP Logged
 
cpmjones
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Aug 4th, 2008
Re: Copy/Paste shape text
Reply #3 - Jun 4th, 2010 at 2:39pm
Print Post  
One more question.

I also have my own class which extends DiagramLink.

Is it possible to copy/paste a combination of shapes which extend ShapeNode together with the DiagramLink extended objects which connect them?

For example to copy/paste the whole diagram?

Thanks,

Chris
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy/Paste shape text
Reply #4 - Jun 4th, 2010 at 2:56pm
Print Post  
It should be possible - override the "public DiagramItem clone(boolean clipboard)" method in your custom link class and return an instance of the same class.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
cpmjones
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Aug 4th, 2008
Re: Copy/Paste shape text
Reply #5 - Jun 4th, 2010 at 3:25pm
Print Post  
How will it handle the origin and destination, as these will need to be the newly pasted origin and destination?

Thanks,

Chris
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy/Paste shape text
Reply #6 - Jun 4th, 2010 at 3:30pm
Print Post  
The control calls setOrigin and setDestination on the links after cloning all items. The built-in clone method looks as shown below btw. If you have any problems, try implementing a constructor that takes two node arguments and calls the respective super class constructor, and then implement clone in the same way:

Code
Select All
public DiagramItem clone(boolean clipboard)
{
	return new DiagramLink(this, getDummyNode(), getDummyNode());
} 


I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
cpmjones
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Aug 4th, 2008
Re: Copy/Paste shape text
Reply #7 - Jun 4th, 2010 at 3:58pm
Print Post  
Got it working.

Thanks again for all your help!

Chris
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint