Thread Rating:
  • 469 Vote(s) - 2.77 Average
  • 1
  • 2
  • 3
  • 4
  • 5
セル単位での色指定
06-17-2013, 07:57 PM,
#6
RE: セル単位での色指定
とりあえず、フィールドで持ってみました

Code:
||セルの振舞いを定義する Mixinクラス
{define-class public abstract CellReacterMixin
  field public cell-reacter-proc:#{proc-type {RecordGridCell}:void}
  {constructor public {default
                          cell-reacter-proc:#{proc-type {RecordGridCell}:void} = null,
                          ... }
      set self.cell-reacter-proc = cell-reacter-proc
  }
  ||セルの振舞いを処理する 振舞いは独自に指定できるようにプロシージャで定義
  {method public {set-custom-react cell:RecordGridCell}:void
    {if-non-null react-proc = self.cell-reacter-proc then
        {react-proc cell}
    }
  }
  {getter public {as-RecordGridCell}:#RecordGridCell
    {type-switch self
     case rgc:RecordGridCell do
        {return rgc}
     else
        {return null}
    }
  }
  {method public {get-cell-react-option option-name:String}:any
    {if-non-null cell = self.as-RecordGridCell then
        {if-non-null record = cell.record, rf = cell.field then
            {return {cell.record.get rf.name & option-name}}
        }
    }
    {return null}
  }
}

||読み取り専用背景色
{def public READONLY_BACKGROUND_COLOR :String =  "#D0D0D0"}
||エラー用背景色
{def public ERROR_BACKGROUND_COLOR:String  = "#FFB0B0"}
||必須入力用背景色
{def public REQUIRED_BACKGROUND_COLOR:String  = "#FFFFCC"}
||カスタムレコードフィールドのコード名
{def public ERROR-FIELD-NAME:String = "_error?"}
{def public READ-ONLY-FIELD-NAME:String = "_read-only?"}
{def public REQUIRED-FIELD-NAME:String = "_required?"}
||エラー、表示のみ、必須 のプロパティを指定するための実装
{define-class public DefaultCellReactMixin {inherits CellReacterMixin}
  field constant error?:String = ERROR-FIELD-NAME
  field constant read-only?:String = READ-ONLY-FIELD-NAME
  field constant required?:String = REQUIRED-FIELD-NAME
  {constructor public {default ...}
    {construct-super {splice...}}
  }
  ||セルの振舞いを定義するためのフィールドを追加するプロシージャ
  {define-proc public {get-cusotmed-field fields:RecordFields}:RecordFields
    def ary-rf:{Array-of RecordField} = {{Array-of RecordField}}
    {for rf in fields do
        {ary-rf.append rf}
        let read-only-def-val:bool = false
        let required-def-val:bool = false
        {ary-rf.append {RecordField rf.name & ERROR-FIELD-NAME,
                           domain = bool, default-value = false}}
        {ary-rf.append {RecordField rf.name & READ-ONLY-FIELD-NAME,
                           domain = bool, default-value = read-only-def-val}}
        {ary-rf.append {RecordField rf.name & REQUIRED-FIELD-NAME,
                           domain = bool, default-value = required-def-val}}
    }
    {return {RecordFields {splice ary-rf}}}
  }

  {define-proc public {default-cell-reacter cell:RecordGridCell}:void
    {type-switch cell
     case react-mxin:DefaultCellReactMixin do
        ||選択されている場合は、背景色、文字色が設定済みなので、後続の処理を行わない
        {if not cell.selected?  then
            {if-non-null record = cell.record then
                || 表示のみの反映が高位なので、最初に判断
                {if {react-mxin.get-cell-react-option react-mxin.read-only?}  then
                    set cell.editable? = false
                    set cell.background = READONLY_BACKGROUND_COLOR
                 elseif {react-mxin.get-cell-react-option react-mxin.error?} then
                    ||エラー時は背景を赤色にする
                    set cell.background = ERROR_BACKGROUND_COLOR
                 elseif {react-mxin.get-cell-react-option react-mxin.required?} then
                    ||必須時は背景を黄色にする
                    set cell.background = REQUIRED_BACKGROUND_COLOR
                 else
                    {unset cell.background}
                }
            }
        }
    }
  }
}
||セルの振舞いを独自に指定したセル
{define-class public open CustomReactCell
  {inherits StandardStringCell, DefaultCellReactMixin }
  {constructor public {default ...}
    {construct-super.StandardStringCell}
    {construct-super.DefaultCellReactMixin
        cell-reacter-proc = DefaultCellReactMixin.default-cell-reacter,
        {splice ...}}
  }
  {method public open {refresh-data}:void
    {super.refresh-data}
    {self.set-custom-react self}
  }
}

{let people:RecordSet =
    {RecordSet
        {DefaultCellReactMixin.get-cusotmed-field
            {RecordFields  {RecordField "First", domain = String} }
        },
        {RecordData First = "John"},
        {RecordData First = "Jane"},
        {RecordData First = "Jane"}
    }
}
{def grid =
    {RecordGrid
        height = 1.5in,
        automatic-columns? = false,
        {RecordGridColumn cell-spec = CustomReactCell, "First" },
        record-source = people
    }
}
{def real-grid =
    {RecordGrid
        width = 6in,
        height = 1in,
        record-source = people
    }
}
{VBox
    grid,
    real-grid
}





Messages In This Thread
セル単位での色指定 - by umemura - 05-28-2013, 03:56 PM
RE: セル単位での色指定 - by dyoshida - 05-31-2013, 12:46 AM
RE: セル単位での色指定 - by umemura - 05-31-2013, 10:49 AM
RE: セル単位での色指定 - by dyoshida - 05-31-2013, 12:38 PM
RE: セル単位での色指定 - by michaeljee - 06-13-2013, 01:43 PM
RE: セル単位での色指定 - by umemura - 06-17-2013, 07:57 PM
RE: セル単位での色指定 - by umemura - 10-28-2013, 01:11 PM
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('905')