Problem getting the event source properties onDrop

Questions, tips and tricks and techniques for scripting in Servoy

Problem getting the event source properties onDrop

Postby maria » Wed Jun 16, 2010 3:26 am

Hi All!

I am running an onDrop method in one of my table view forms and cannot access the properties of the object I'm dropping on.
event.getSource() gets me the label I'm dropping on and event.getSource().getDataProviderID() gets the right dataprovider id behind it.
But I can't get the value of that dataprovider though it does show up in the event properties. What would be the right method for that?

That's what I have got if I'm dropping on a label and on a field with the same dataprovider (I've tried using both a label and a field just in case):
1.jpg
Dropping on a label
1.jpg (21.72 KiB) Viewed 4691 times

2.jpg
Dropping on a field
2.jpg (29.56 KiB) Viewed 4691 times


What I need to get is the "BookMark1" string which is the dataprovider value of the target label/field.

Generally, it would be great to find out the index or the primary id of the row I'm dropping on in a table view.
Otherwise, how do I figure out what record is selected?

Please help! :?:
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Problem getting the event source properties onDrop

Postby maria » Wed Jun 23, 2010 8:23 am

Anyone? No one? :?:
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Problem getting the event source properties onDrop

Postby pbakker » Wed Jun 23, 2010 10:09 am

If you have the dataproviderid, you can use controller.getDataProviderValue(dataproviderid) to get it's value.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Problem getting the event source properties onDrop

Postby maria » Thu Jun 24, 2010 2:14 am

pbakker wrote:If you have the dataproviderid, you can use controller.getDataProviderValue(dataproviderid) to get it's value.

Paul

Yes, but it's not the primary key of the record.
Say, we have a list of customers and the grid would have a customer name, customer address fields, etc.
If I drop on a column with the city (as part of the customer address) it won't give me any useful information as the city would be the same for many customers.
How do I know on which one I dropped?

Cheers,
Maria

P.S. Either I'm not getting it or it's strange that no one has run into this problem before :?
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Problem getting the event source properties onDrop

Postby gerardo.gomez » Thu Jun 24, 2010 9:36 am

Hi!

You could do it storing data what you need (the pk in your case or the whole record) in event.data when dragging on your record. Later, in onDrop event, you can retrieve your data from event.data

This strategy is used in Servoy DnD sample solution (it's used to perform multiselection on dragging) and is what we are doing.

This is the code used in Servoy DnD sample solution (in this case, the whole selected record/s is/are stored in event.data):

Code: Select all
function onDrag(event) {
   if(!event.getSource()){
      return DRAGNDROP.NONE;
   }
   
   var data = [];
   var selection = foundset.getSelectedIndexes();
   for(i in selection){
      data.push(foundset.getRecord(selection[i]));
   }
   event.data = data;
   
   /* Returning both Copy & Move: the code in the onDrop method on the Order_Details form will perform a copy regardless,
    * but users do not know that normally, to perform a Copy action you need to use the Control modifier
    */
   return DRAGNDROP.COPY|DRAGNDROP.MOVE;
}


Code: Select all
function onDrop(event) {
   
   //Get the Product record objects (which were set in the onDrag method on the product_list form) from the event.data property of the event and process them
   for(i in event.data){
      var record = event.data[i];
                // Do what you want...


I hope this helps!
Best regards/Un saludo,

Gerardo Gómez
--
Servoy 5.1.4 build 964
Win7 - Java 1.6.0_20
Ubuntu 10.04 - Java 1.6.0_20
gerardo.gomez
 
Posts: 79
Joined: Thu Aug 20, 2009 1:15 am

Re: Problem getting the event source properties onDrop

Postby maria » Mon Jul 05, 2010 3:51 am

gerardo.gomez wrote:Hi!

You could do it storing data what you need (the pk in your case or the whole record) in event.data when dragging on your record. Later, in onDrop event, you can retrieve your data from event.data

This strategy is used in Servoy DnD sample solution (it's used to perform multiselection on dragging) and is what we are doing.

This is the code used in Servoy DnD sample solution (in this case, the whole selected record/s is/are stored in event.data):

Code: Select all
function onDrag(event) {
   if(!event.getSource()){
      return DRAGNDROP.NONE;
   }
   
   var data = [];
   var selection = foundset.getSelectedIndexes();
   for(i in selection){
      data.push(foundset.getRecord(selection[i]));
   }
   event.data = data;
   
   /* Returning both Copy & Move: the code in the onDrop method on the Order_Details form will perform a copy regardless,
    * but users do not know that normally, to perform a Copy action you need to use the Control modifier
    */
   return DRAGNDROP.COPY|DRAGNDROP.MOVE;
}


Code: Select all
function onDrop(event) {
   
   //Get the Product record objects (which were set in the onDrag method on the product_list form) from the event.data property of the event and process them
   for(i in event.data){
      var record = event.data[i];
                // Do what you want...


I hope this helps!


Thanks Gerardo but I think you're misunderstanding the problem.
There's no problem dragging the data, pks, whatever.
The problem is when I drop on another table view and it's impossible to figure out which record I'm on.

Say, we have two table views like below. The first one is a list of assignments, the other is a list of employees.
I'm dragging an assignment and drop it on an employee (to assign it to employee).
If I drag 'Assignment 1 from the first table I sure can get the whole record data and it's good.
But when I drop it on the employee table then the problem comes up.
If I'm dropping on the employee name and there are no duplicate names in the employee table then I can get the employee name from the data attribute of onDrop event.
But if I'm dropping on the 'city' column (and I have many-many columns in the employee table) then I'm in trouble because knowing that I dropped on 'Sydney' won't give me any chance to find out what the employee id is!
The target record is not becoming selected when I drop on it, so there's no way to figure out the target record in table view (no obvious way to me, that's why I'm asking - perhaps I'm overlooking something).

---------------------------
| Assignment 1 |
---------------------------
| Assignment 2 |
---------------------------
| Assignment 3 |
---------------------------


------------------------------
| John Smith | Sydney |
------------------------------
| Ben Austen | Brisbane |
------------------------------
| Laura Singh| Sydney |
------------------------------
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Problem getting the event source properties onDrop

Postby pbakker » Mon Jul 05, 2010 10:08 am

Unfortunately, determining the exact record in TableViews on which the drop took place is currently not possible.

It will be made possible in a future version

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Problem getting the event source properties onDrop

Postby maria » Tue Jul 06, 2010 5:09 am

pbakker wrote:Unfortunately, determining the exact record in TableViews on which the drop took place is currently not possible.

It will be made possible in a future version

Paul


Thanks Paul.
It's good to know I'm not making things up :)

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests