001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.uilib.form.control;
016:
017: import org.araneaframework.http.HttpInputData;
018: import org.araneaframework.uilib.event.OnClickEventListener;
019: import org.araneaframework.uilib.event.StandardControlEventListenerAdapter;
020:
021: /**
022: * This class represents a button.
023: *
024: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
025: *
026: */
027: public class ButtonControl extends BaseControl {
028:
029: //*********************************************************************
030: // FIELDS
031: //*********************************************************************
032: protected StandardControlEventListenerAdapter eventHelper = new StandardControlEventListenerAdapter();
033:
034: /**
035: * Returns true
036: */
037: public boolean isRead() {
038: return true;
039: }
040:
041: /**
042: * @param onClickEventListener {@link OnClickEventListener} which is called when the control is clicked.
043: *
044: * @see StandardControlEventListenerAdapter#addOnClickEventListener(OnClickEventListener)
045: */
046: public void addOnClickEventListener(
047: OnClickEventListener onClickEventListener) {
048: eventHelper.addOnClickEventListener(onClickEventListener);
049: }
050:
051: /**
052: * Returns null.
053: * @return null.
054: */
055: public String getRawValueType() {
056: return null;
057: }
058:
059: //*********************************************************************
060: //* INTERNAL METHODS
061: //*********************************************************************
062:
063: protected void init() throws Exception {
064: super .init();
065:
066: setGlobalEventListener(eventHelper);
067: }
068:
069: /**
070: * Empty method
071: */
072: protected void readFromRequest(HttpInputData request) {
073: // Button control is not interested in what is submitted
074: }
075:
076: /**
077: * Empty method
078: */
079: public void convertAndValidate() {
080: // Button control is not interested in conversion and validation
081: }
082:
083: /**
084: * Does nothing
085: */
086: protected void prepareResponse() {
087: // Button control does not have data
088: }
089:
090: /**
091: * Returns {@link ViewModel}.
092: *
093: * @return {@link ViewModel}.
094: */
095: public Object getViewModel() {
096: return new ViewModel();
097: }
098:
099: //*********************************************************************
100: //* VIEW MODEL
101: //*********************************************************************
102:
103: /**
104: * Represents a <code>ButtonControl</code> view model.
105: *
106: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
107: *
108: */
109: public class ViewModel extends BaseControl.ViewModel {
110:
111: private boolean hasOnClickEventListeners;
112:
113: /**
114: * Takes an outer class snapshot.
115: */
116: public ViewModel() {
117: this .hasOnClickEventListeners = ButtonControl.this .eventHelper
118: .hasOnClickEventListeners();
119: }
120:
121: /**
122: * Returns whether any onClick events have been registered.
123: * @return whether any onClick events have been registered.
124: */
125: public boolean isOnClickEventRegistered() {
126: return hasOnClickEventListeners;
127: }
128: }
129: }
|