| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.ui.client.configurable.mvc.binding; |
| 17 | |
|
| 18 | |
import org.kuali.student.common.assembly.data.QueryPath; |
| 19 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 20 | |
import org.kuali.student.common.ui.client.widgets.RichTextEditor; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | 0 | public class RichTextBinding extends ModelWidgetBindingSupport<RichTextEditor> { |
| 29 | 0 | public static RichTextBinding INSTANCE = new RichTextBinding(); |
| 30 | |
|
| 31 | 0 | private RichTextBinding() {} |
| 32 | |
|
| 33 | |
@Override |
| 34 | |
public void setModelValue(RichTextEditor object, DataModel model, String path) { |
| 35 | 0 | String richTextRoot = path + QueryPath.getPathSeparator(); |
| 36 | |
|
| 37 | 0 | QueryPath qPath = QueryPath.parse(richTextRoot + "plain"); |
| 38 | |
|
| 39 | 0 | String oldValue = model.get(qPath); |
| 40 | 0 | String newValue = object.getText(); |
| 41 | |
|
| 42 | 0 | if (!nullsafeEquals(oldValue, newValue)) { |
| 43 | 0 | model.set(qPath, newValue); |
| 44 | 0 | setDirtyFlag(model, qPath); |
| 45 | |
} |
| 46 | |
|
| 47 | 0 | qPath = QueryPath.parse(richTextRoot + "formatted"); |
| 48 | |
|
| 49 | 0 | oldValue = model.get(qPath); |
| 50 | 0 | newValue = object.getHTML(); |
| 51 | |
|
| 52 | 0 | if (!nullsafeEquals(oldValue, newValue)) { |
| 53 | 0 | model.set(qPath, newValue); |
| 54 | 0 | setDirtyFlag(model, qPath); |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 0 | } |
| 65 | |
|
| 66 | |
@Override |
| 67 | |
public void setWidgetValue(RichTextEditor object, DataModel model, String path) { |
| 68 | 0 | String richTextRoot = path + QueryPath.getPathSeparator(); |
| 69 | |
|
| 70 | 0 | QueryPath qPath = QueryPath.parse(richTextRoot + "plain"); |
| 71 | 0 | String formatted = model.get(qPath); |
| 72 | |
|
| 73 | 0 | qPath = QueryPath.parse(richTextRoot + "formatted"); |
| 74 | 0 | String plain = model.get(qPath); |
| 75 | |
|
| 76 | 0 | if (formatted != null) { |
| 77 | 0 | object.setHTML(formatted); |
| 78 | 0 | } else if (plain != null) { |
| 79 | 0 | object.setText(plain); |
| 80 | |
} else { |
| 81 | 0 | object.setHTML(""); |
| 82 | |
} |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
} |