このエントリーをはてなブックマークに追加

公式 UI Editors(英語)

Editorメリット

Uiとコードが綺麗にわかれる。リファクタリングの代わりに。単調な、get,setコーディングから開放。コードの再利用が高まる

関連クラス

HasEditorDelegate

項目が足りないなど、エラーメッセージを出したい時に使う

ValueAwareEditor

書き出し時にflush()、最初の初期化時にsetValue()が呼ばれる。

HasEditorDelegateでエラー出したい時や、最初の値を別途所持したい時に使う。

IsEditor,LeafValueEditor

WidgetをEditor対応する時に使う

例 Integerに対応する

implements IsEditor<LeafValueEditor<Integer>>,TakesValue<Integer>

    private LeafValueEditor<Integer> editor;
    @Override
    public LeafValueEditor<Integer> asEditor() {
        if (editor == null) {
              editor = TakesValueEditor.of(this);
            }
            return editor;
    }
    public Integer getValue(){
        return range.getValue();
     }
    @Override
    public void setValue(Integer value) {
         range.setValue(value);
    }

タイプ別

String int double boolean Object
SimpleEditor SimpleEditor SimpleEditor SimpleEditor SimpleEditor
ValueListBox ValueListBox ValueListBox ValueListBox ValueListBox
TextBox IntBox DoubleBox CheckBox
TextArea

SimpleEditorは編集できませんが

FAQ

値が全く反応されない。

Editorのスコープをprivateにしている。 スコープをなしにする

よくあるエラー

実行時にエラー

editorにData側にない、余計なフィールドがある。

ignoreのアノテーションを追加で回避、フィールドだけでなく、メソッドにも必要

@Ignore CheckBox xxx;

@Ignore public ColorBox getColorEditor(){
        return colorEditor;
    }
Creating Editor model for ***.***.Driver
[ERROR] Could not find a getter for path xxx in proxy type com.akjava.gwt.inpaint.client.MaskData
[ERROR] Unable to create Editor model due to previous errors

GWT Editor例