Okay, so I had some free time today, and this will be a nice to have for my application so I dug in a little bit more.
Turns out that if you have the Tag Browse Tree mode configured as a Readtime Tag Tree then you get a different Transferable type.
If your mode is set to ‘Realtime Tag Tree’ then the transferable that is used is a ListOfNodeBrowseInfo
If your mode is set to ‘Historical Tag Tree’ the the transferable that is used is a ListOfQualifiedPath
I am sure there are reasons for that in the background.
That means your code needs to change slightly to use the correct Transferable Flavor
NOTE: If you have added the listener in the InternalFramActivated event you will need to close the window in the designer and re-open it once the change has been made.
from java.awt.dnd import DropTargetAdapter, DropTarget
from com.inductiveautomation.ignition.client.tags.dnd import ListOfNodeBrowseInfo
class customDragDropListener(DropTargetAdapter):
_comp = None
def __init__(self,comp):
DropTargetAdapter.__init__(self)
self._comp = comp
def drop(self,e):
e.acceptDrop(e.getDropAction())
paths = [[node.getFullPath()] for node in e.getTransferable().getTransferData(ListOfNodeBrowseInfo.FLAVOR) if not node.hasChildren() and node.getObjectType().toString() != 'Provider']
self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
ddl = customDragDropListener(self)
DropTarget(self,ddl)
Note that his will not accept a Folder or Provider, I didn’t take the time to handle that.
To properly handle these you will need to write a function which utilizes a recursive browse to gather the paths on a thread other than the GUI thread, should you want to handle a folder or provider in any way other than doing nothing. I have chosen to ‘ignore’ those items with this code.
simple when i drag and drop tag i dont want the string after the dot
i only want tag upto consumption_KWTON… if any person try to drag and drop with engunit or some other think i want to show popup
hope now you understood
thanks
You can handle this in a couple of different ways.
You can just split the path and ignore the property specification in the transferable.
You can break apart the comprehension and show a message box, or pop up if you prefer.
In the second case you will need to determine if that means not excepting the entire drop or not.
Case 1
def drop(self,e):
e.acceptDrop(e.getDropAction())
paths = [[node.getFullPath().split('.')[0]] for node in e.getTransferable().getTransferData(ListOfNodeBrowseInfo.FLAVOR) if not node.hasChildren() and node.getObjectType().toString() != 'Provider']
self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
Case 2
def drop(self,e):
e.acceptDrop(e.getDropAction())
paths = []
addPaths = True
for node in e.getTransferable(e.getTransferData(ListOfNodeBrowseInfo.FLAVOR):
if not node.hasChildren() and node.getObjectType().toString() != 'Provider']:
path = node.getFullPath().split('.')
if len(path) == 1:
paths.append(path)
else:
addPaths = False #set flag to not add paths
break #if were not accepting the drop, no reason to continue the loop
if addPaths:
self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
else:
system.gui.messageBox('Your message here for invalid drops')