try
{
if (content.isDataFlavorSupported(ClientFlavors.ITEM))
{
// We need to copy the item from the clipboard, since we are about to modify it.
Item source = (Item) content.getTransferData(ClientFlavors.ITEM);
// Serialize to a byte array
ByteArrayOutputStream os = new ByteArrayOutputStream(4096);
XMLDriver.getInstance().serialize(source, os);
byte[] bytes = os.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
Item item = (Item) XMLDriver.getInstance().deserializeStream(null, is);
item.setGeneratorInfo(source.getGeneratorInfo());
// TODONOW Item item = (Item) source.clone();
Model model = getSelectedModel(ItemBrowserPlugin.GUESS_MODEL | ItemBrowserPlugin.USE_CURRENT_MODEL);
item.setModel(model);
item.maintainReferences(ModelObject.SYNC_GLOBAL_REFNAMES | ModelObject.RESOLVE_LOCAL_REFS);
// Find a new name for the item; we generate the name by appending a running number to the item type
String oldName = item.getName();
ItemUtil.ensureUniqueItemName(item, model);
String newName = item.getName();
if (item instanceof JavaActivityItem)
{
// In case of activity items, change the name of the action
// implementation class also when renaming the activity
JavaActivityItem activity = (JavaActivityItem) item;
String oldClassName = activity.getHandlerDefinition().getHandlerClassName();
if (oldClassName != null && oldName != null)
{
// ...substitute ".OldName" to ".NewName"
String className = StringUtil.substitute(oldClassName, "." + oldName, "." + newName);
// Update the object
activity.getHandlerDefinition().setHandlerClassName(className);
}
}
// Get the item type editor associated with this item
ItemEditor editor = ItemEditorRegistry.getInstance().lookupItemEditor(item.getItemType());
if (editor != null)
{
// For compatibility with pre-2.0 process items
StandardItemEditor.ensureProcessType(item);
// Open the item wizard for the item
final Item newItem = editor.openItem(item, EditedItemStatus.COPIED);
if (newItem != null)
{
if (ModelConnector.getInstance().saveItem(item, true))
{
SwingUtilities.invokeLater(new Runnable()