Drag and drop to list component

It is filtered to only show on a “Right” click.

OK I have to right click the tag correct?

Oh, I was thinking of an example I made years ago:

You’re welcome to do that, but @lrose is absolutely correct - skipping drag and drop is going to be a lot more maintainable.

1 Like

You should be able to right click on any item in the tag tree and it show the popup menu. In the designer you will need to be in preview mode.

1 Like

I tired your project file in my local host, i cant able to move tags from tag tree browser to list in your project file. is there any changes need to be done. can you check and tell me know please

getting error in 7th line in script

one doubt whether you drag and drop tags from tag browser tree to list component ???

Perhaps you were correct?

This turned out to be a bit simpler than I was originally thinking. Not trivial, but not really painful either.

Add an extension function to your list component, I called mine addDropListener. Then in the script add the following script:

from java.awt.dnd import DropTargetAdapter, DropTarget
from com.inductiveautomation.ignition.client.tags.dnd import ListOfQualifiedPath
	
class customDragDropListener(DropTargetAdapter):
	_comp = None
	def __init__(self,comp):
		DropTargetAdapter.__init__(self)
		self._comp = comp
			
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[path] for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR)]
		self._comp.data = system.dataset.addRows(self._comp.data,paths)
			
ddl = customDragDropListener(self)
DropTarget(self,ddl)

Then in the internalFrameActivated Event Handler on the window use the following script

NOTE: You will need to change the path for the component to be valid for your system.

tagList = system.gui.getParentWindow(event).getComponentForPath('Root Container.List')

if not tagList.getDropTarget():
    tagList.addDropListener()

Select any number of tags in the Tag Browse Tree component drop them on the list and they will be appended to the list’s dataset. It doesn’t validate incoming paths against pre-existing paths so you can add duplicates, if you want this functionality you’ll need to add it to the drop function.

1 Like

I will check this scripts and revert you back



I tired your script. when i drag and drop tags from tag tree browser to list.

its not showing tag path in list, "list is empty"

Is there any thing to add in script???

please let me know

I assumed that you were adding this code to an existing window.

In order for the code to work the List’s dataset needs to have a defined column, which doesn’t happen until you either bind it to something or add a column.

Adding a String Column to your List’s dataset, should correct your issue.

Of course you could check the data property and either create the dataset or add rows to it.

Code which includes a check:

from java.awt.dnd import DropTargetAdapter, DropTarget
from com.inductiveautomation.ignition.client.tags.dnd import ListOfQualifiedPath
		
class customDragDropListener(DropTargetAdapter):
	_comp = None
	def __init__(self,comp):
		DropTargetAdapter.__init__(self)
		self._comp = comp
				
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[path] for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR)]
		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)

If you make a change to this code, you will need to close the window in the designer in order to re-register the listener to the list component. Another, potentially easier option is to add a temporary button and add script there to register the listener. Otherwise the changes in the script will not take effect.

i used this script and i opened in client window.

still same issue list is empty when i drag and drop the tags

is there anything to change?

can you share me the project backup with you done this scripting ?

Did you add a column to the List’s Data property?

yes

Since you have done that, have you saved, closed the window, and re-opened it?

Does the cursor change to the drop icon when you are over the List?

yes its changing to drop icon but tag path is not showing in list. pervious script also same issue list is empty even i drag and drop

yes i saved and closed client and opened again and checked too.

I’m not sure, it works for me. Note, this is from Ignition 8.0.8. If you’re not getting any errors, then I’m not sure, you could try putting a Print statement in the drop function to insure you are getting the data transfered.

def drop(self,e):
    e.acceptDrop(e.getDropAction())
    paths = [[path] for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR)]
    print paths
    self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)

DnD_Test.zip (12.1 KB)

its showing this error when i print paths

i am using ignition 8.0.15

That error is saying that the object returned from getTransferable() is None.

I would expect you to get that error with or without the print paths

Because of this error tag path its not showing in list component?
So what is the solution for now
Is there any thing to change?

I don’t know, you’re going to have to do some troubleshooting of your own. The code works for me in my version, and so I would expect it to work in yours.