Code:
{define-class public open CustomPaste {inherits RecordGridPaste}
{constructor public {default context:RecordGrid}
{construct-super context}
}
{method public {do-command allow-prompt?:bool = true}:void
{if not self.context.editable? then
def ret-val = {popup-question "対象のグリッドは編集不可ですが、強制的に貼り付けますか?"}
{if ret-val == Dialog.yes then
{with self.context.editable? = true do
{super.do-command allow-prompt? = allow-prompt?}
}
}
else
{super.do-command allow-prompt? = allow-prompt?}
}
}
}
{define-class public CustomPasteControlRecordGrid {inherits RecordGrid}
{constructor public {default ...}
{construct-super {splice ...}}
}
{method public {create-command name:String}:#Command
{switch name
case "paste" do
def paste-command = {CustomPaste self}
{return paste-command}
else
{return {super.create-command name}}
}
}
}
{let rs: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}
}
}
{def paste-grid =
{CustomPasteControlRecordGrid
record-source = rs,
editable? = false
}
}
{value paste-grid}
{CommandButton
label = "貼り付け",
{on Action do
{if paste-grid.records.size == 0 then
{if-non-null rs-tmp = paste-grid.record-source then
{rs-tmp.append {rs-tmp.new-record}}
}
}
{paste-grid.select-all}
{paste-grid.do-command "paste"}
{paste-grid.select-nothing}
}
}
{CommandButton
label = "全削除",
{on Action do
{rs.delete-all}
}
}
{CommandButton
label = "追加",
{on Action do
{rs.append {RecordData First = "John", Last = "Smith", Age = 25}}
}
}