This Question is Assumed Answered

1 "correct" answer available (5 pts) 15 "helpful" answers available (3 pts)
1 Replies Last post: Jul 17, 2008 6:24 PM by carl

How to create drag able record of RecordGrid?

Jul 17, 2008 6:06 AM

Click to view RajivGu's profile Level 6 RajivGu 81 posts since
Apr 2, 2008

Hi,

I want to create records of the recordgrid drag able.

So that I could drag a record or selected multiple record and

Drop over the outside Image or any other object which accept
the

Drop. I tried to add the selected record on drag able frame
but

All the efforts are in vain.

I am sending my code for reference. Please let me know if something can be done

Just by altering the code.


{curl 7.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
{applet manifest = "manifest.mcurl",
{compiler-directives careful? = true}
}

{let people:RecordSet =
{RecordSet
{RecordFields
{RecordField "First", domain = String},
{RecordField "Last", domain = String},
{RecordField "Age", domain = int}
},
{RecordData First = "John", Last = "Smith", Age = 25},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "Jane", Last = "Jones", Age = 28}
}
}
{let rg:RecordGrid = {RecordGrid
record-source = people,
height = 3cm,
display-column-headers? = false,
display-filler-column? = true,
alternate-row-background = "#cceecc",
grid-line-color = "#ccccff",
horizontal-grid-line-width = 2px,
vertical-grid-line-width = 4px
}

}

{define-class DragableRecordSet {inherits Frame}
field vbox:VBox = {VBox}
{constructor {default arr-rec:#Record}
||{for r:Record in arr-rec asa {Array-of Record} do
{self.vbox.add arr-rec"First" asa String}
||}

{construct-super
background = "yellow",
dragee = {ImageDragee},
self.vbox

}
}
}
{let frm:Frame = {Frame}}
{rg.add-event-handler
{on DragEnter at rg:RecordGrid do
let fm:Frame = {new DragableRecordSet, rg.current-record} asa Frame
{popup-message fm}

}
}
{rg.add-event-handler
{on e:DragStarted at rg:RecordGrid do

let fm:Frame = {new DragableRecordSet, rg.current-record} asa Frame
{popup-message fm}

}
}

{rg.add-event-handler
{on GrabRelease at rg:RecordGrid do
let fm:Frame = {new DragableRecordSet, rg.current-record} asa Frame
{value fm}
}
}

{set frm = {Frame
width = 400pt,
height = 400pt,
rg
}
}

{value
frm
}

Thanks

Rajiv R Gupta

Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
1. Re: How to create drag able record of RecordGrid? Jul 17, 2008 6:24 PM
It's certainly possible to add DnD to RecordGrid, but it could be a difficult project to fit that in appropriately among all the existing gesture handling. Certainly one could take the OPEN-CONTROLS code and modify it extensively to support the desired operations.

If you are looking for more limited support, you could do something along the lines of the following example, where I've made individual cells dragable. Note that to vastly simplify things, I've turned off cells taking focus, since otherwise clicking on a cell to drag it would likely remove the selection that you were trying to drag. You sadly cannot drag from the row selector in the example either -- that would require OPEN-CONTROLS modification since the row selector is not a publicly accessible element. You could also spruce this example up with a better ImageDragee graphic, etc., but I've omitted all that to keep this manageable. As a general warning, you'd really never want to actually move any Graphics that you drag out of the Ul; rather, if you wanted to "drag out" Records, you should use RecordSet operations to indirectly do so.

In the example, dragging a cell, or a cell from a set of selected rows, will add the "First" data from those Record(s) to the VBox.

{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField "First", domain = String},
            {RecordField "Last", domain = String},
            {RecordField "Age", domain = int}
        },
        {RecordData First = "John", Last = "Smith", Age = 25},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Jones", Age = 28}
    }
}
 
{define-class public open DragStringCell {inherits StandardStringCell}
 
  {constructor public {default}
    {construct-super}
    set self.dragee = {ImageDragee}
  }
 
}
 
{let rg:RecordGrid =
    {RecordGrid
        record-source = people,
        height = 3cm,
        display-column-headers? = false,
        display-filler-column? = true,
        alternate-row-background = "#cceecc",
        grid-line-color = "#ccccff",
        horizontal-grid-line-width = 2px,
        vertical-grid-line-width = 4px,
        cell-spec = DragStringCell,
        cells-take-focus? = false
    }
 
}
 
{value rg}
 
{define-proc package {drop-action
                         vb:VBox,
                         a:any
                     }:{proc-type {}:void}
    {return
        {proc {}:void
            {type-switch a
             case dsc:DragStringCell do
                {vb.clear}
                {if-non-null grid = dsc.grid then
                    def selection = grid.selection
                    let passed-selection?:bool = false
                    {if selection.record-count >= 1 then
                        {if {selection.contains-record? dsc.record-index} then
                            set passed-selection? = true
                            {for one-record in grid.selection.records do
                                {vb.add grid.records[one-record]["First"]}
                            }
                        }
                    }
                    {if not passed-selection? then
                        {vb.add dsc.record["First"]}
                    }
                }
            }
        }
    }
}
 
{value
    def vb =
        {VBox
            margin = 5mm,
            border-color = "red",
            border-width = 2px,
            opaque-to-events? = true
        }
 
    {vb.add-event-handler
        {on e:DragOver do 
            {e.will-accept-drop?
                {proc {type:Type, x:Distance, y:Distance,
                       effect:#DragEffect}:DragEffect
                    {if type == DragStringCell then
                        {return drag-effect-copy}
                     else
                        {return drag-effect-none}
                    }
                }
            }
        }
    }
    
    {vb.add-event-handler
        {on e:Drop at vb:VBox do
            {e.accept-drop
                {proc {a:any, x:Distance, y:Distance,
                       effect:#DragEffect}:DropResult
                    {return
                        {DropResultCopy
                            action = {drop-action vb, a}
                        }
                    }
                }
            }
        }
    }
    
    vb
}