Code:
{define-class public DoroppableListGrid {inherits RecordGrid} {constructor public {default
record-source:#RecordSet = null,
sort:#RecordSort = null,
filter:#RecordFilter = null,
key-spec:any = null,
header-options:RecordGridRowOptions = {RecordGridRowOptions},
ui-object:#RecordGridUI = null,
...
}
{construct-super
record-source = record-source,
sort = sort,
filter = filter,
key-spec = key-spec,
header-options = header-options,
ui-object = ui-object,
{splice ...} ,
{on e:DragOver at grid:RecordGrid do
{e.will-accept-drop?
{proc {type:Type, x:Distance, y:Distance,
effect:#DragEffect}:DragEffect def (cell:#RecordGridCell, record-index:int, column-index:int )= {grid.ui.grid-objects-at e.x, e.y}
set self.rollover-cell = cell {return drag-effect-copy}
}
}
}
} } {method public {on-drop e:Drop}:void
{super.on-drop e} ||ドロップイベントが完了したら、ロールオーバ色をリセットする
set self.rollover-cell = null
}
field _rollover-cell:#RecordGridCell = null
{setter private {rollover-cell cell:#RecordGridCell } ||同一レコードの塗り直しは無視
{if self._rollover-cell == cell then
{return}
}
||すでにロールバック色を塗ってある行を元に戻す
{if-non-null self._rollover-cell , r = self._rollover-cell.record then {for col in self.columns do
{if-non-null c = {self.ui.get-cell-at r, col} then
{if c.selected? then
set c.background = self.selected-background
else
{unset c.background}
}
}
} } ||ロールバック色を設定する
{if-non-null cell , r = cell.record then {for col in self.columns do
{if-non-null c = {self.ui.get-cell-at r, col} then
set c.background = "orange"
{output {c.get-data}}
}
} } set self._rollover-cell = cell }}{define-proc public {notified rg:RecordGrid, r:Record, i:int}:#Background
{if {r.compare-field "select", true} == 0 then
{return {Background.from-string "silver"}}
else
{return null}
}
}
{let people:RecordSet =
{RecordSet
{RecordFields
{RecordField "select", domain = bool,default-value = false},
{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, select = true},
{RecordData First = "John", Last = "Smith", Age = 25, select = true},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "John", Last = "Smith", Age = 25, select = true},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "John", Last = "Smith", Age = 25, select = true},
{RecordData First = "John", Last = "Smith", Age = 25, select = true},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "Jane", Last = "Jones", Age = 28}
}
}
{value
{DoroppableListGrid
record-source = people ,alternate-row-background = "#cceecc" ,row-background-spec = notified ,
{on e:Drop at grid:RecordGrid do
{e.accept-drop
{proc {a:any, x:Distance, y:Distance,
effect:#DragEffect}:DropResult
{return {DropResultCopy
action = {proc {}:void
def (cell:#RecordGridCell, record-index:int, column-index:int )= {grid.ui.grid-objects-at e.x, e.y} {if-non-null cell then
{popup-message
cell.record-index + 1 & "行目にドロップされました。",
modal? = true}
}
}
}
}
} }
}
}
}{def fr:Frame = {Frame border-width=1pt, "アイテム", dragee={ImageDragee}}}{value fr}