1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui; 20 21 import org.netbeans.modules.xml.multiview.ItemEditorHelper; 22 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer; 23 24 27 public abstract class TextItemEditorModel extends ItemEditorHelper.ItemEditorModel { 28 29 XmlMultiViewDataSynchronizer synchronizer; 30 private boolean emptyAllowed; 31 private boolean emptyIsNull; 32 String origValue; 33 34 protected TextItemEditorModel(XmlMultiViewDataSynchronizer synchronizer, boolean emptyAllowed) { 35 this(synchronizer, emptyAllowed, false); 36 37 } 38 protected TextItemEditorModel(XmlMultiViewDataSynchronizer synchronizer, boolean emptyAllowed, boolean emptyIsNull) { 39 this.synchronizer = synchronizer; 40 this.emptyAllowed = emptyAllowed; 41 this.emptyIsNull = emptyIsNull; 42 origValue = getValue(); 43 } 44 45 protected boolean validate(String value) { 46 return emptyAllowed ? true : value != null && value.length() > 0; 47 } 48 49 protected abstract void setValue(String value); 50 51 protected abstract String getValue(); 52 53 public final boolean setItemValue(String value) { 54 if (emptyAllowed && emptyIsNull && value != null) { 55 while (value.length() > 0 && value.charAt(0) == ' ') { 56 value = value.substring(1); 57 } 58 if (value.length() == 0) { 59 value = null; 60 } 61 } 62 if (validate(value)) { 63 String currentValue = getValue(); 64 if (!(value == currentValue || value != null && value.equals(currentValue))) { 65 setValue(value); 66 synchronizer.requestUpdateData(); 67 } 68 return true; 69 } else { 70 return false; 71 } 72 } 73 74 public final String getItemValue() { 75 String value = getValue(); 76 return value == null ? "" : value; 77 } 78 79 public void documentUpdated() { 80 setItemValue(getEditorText()); 81 } 82 } 83 | Popular Tags |