litesoft
@ 633
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / widget / input / fieldsupport / AbstractInputField.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
package com.temp.client.foundation.widget.input.fieldsupport; import com.google.gwt.user.client.ui.Panel; import com.google.gwt.user.client.ui.Widget; import com.temp.client.foundation.util.UtilsGwt; import com.temp.client.foundation.widget.input.InputField; import com.temp.shared.externalization.E13nData; import com.temp.shared.utils.Enableable; import com.temp.shared.utils.ObjectUtils; import java.util.HashSet; import java.util.Set; /** * Common abstract helper for both the generated Widget and the Proxied versions of the InputField. */ public abstract class AbstractInputField<T, C extends AbstractInputField<T, C>> implements InputField<T> { // Optionally set private Set<ChangeListener<T>> changeListeners = new HashSet<ChangeListener<T>>(); protected boolean enabled = true; private State visibility = State.Visible; private StateInputField currentStyleState; @Override public final State getVisibility() { return visibility; } @Override public final void setVisibility(State visibility) { visibility = ObjectUtils.deNull(visibility, State.Visible); Panel container = getContainer(); if (container != null) { this.visibility = visibility; container.setVisible(visibility != State.Invisible); UtilsGwt.setHidden(container, visibility == State.Cloaked); } } // Configuration Methods @Override public final InputField<T> add(ChangeListener<T> changeListener) { if (changeListener != null) { changeListeners.add(changeListener); } return this; } @Override public final boolean remove(ChangeListener<T> changeListener) { return (changeListener == null) ? false : changeListeners.remove(changeListener); } @Override public final void removeAllChangeListeners() { changeListeners.clear(); } abstract protected Enableable getEnableable(); // Anytime Methods // For Enableable @Override public final boolean isEnabled() { Enableable enableable = getEnableable(); return (enableable != null) ? enableable.isEnabled() : enabled; } @Override public final void setEnabled(boolean enable) { enabled = enable; Enableable enableable = getEnableable(); if (enableable != null) { enableable.setEnabled(enable); } } @Override public final InputField<T> enable() { setEnabled(true); return this; } @Override public final InputField<T> disable() { setEnabled(false); return this; } // For Visible @Override public final boolean isVisible() { return State.Visible == getVisibility(); } @Override public final boolean isCloaked() { return State.Cloaked == getVisibility(); } @Override public final boolean isInvisible() { return State.Invisible == getVisibility(); } @Override public final InputField<T> visible() { setVisibility(State.Visible); return this; } @Override public final InputField<T> cloak() { setVisibility(State.Visible); return this; } @Override public final InputField<T> invisible() { setVisibility(State.Invisible); return this; } // Only callable in Run Mode protected final void updateStyle(StateInputField state) { state = ObjectUtils.deNull(state, StateInputField.BASE); if (state != currentStyleState) { Panel panel = getContainer(); if (panel != null) { if (currentStyleState != null) { panel.removeStyleName(currentStyleState.toCSS()); } panel.addStyleName(state.toCSS()); } currentStyleState = state; } } protected final void notifyChangeListeners() { for (ChangeListener<T> zListener : changeListeners) { zListener.changed(this); } } protected final void assertBuildMode(String method) { assertMode(method, false); } protected final void assertRunMode(String method) { assertMode(method, true); } private void assertMode(String method, boolean expectedRunMode) { if (isRunMode() != expectedRunMode) { throw new IllegalStateException("Unable to access component/method '" + method + "' of InputField Named '" + getName() + // (expectedRunMode ? "', because not in Run Mode (init NOT called)" : "', because no longer in Build Mode (init has already been called)")); } } protected final C inheritanceLeaf() { return ObjectUtils.cast(this); } abstract protected Panel getContainer(); abstract protected void updateErrorLabel(Widget errorLabel, E13nData error); } |