001package org.gwtbootstrap3.client.ui.form.validator; 002 003import com.google.gwt.event.shared.EventHandler; 004import com.google.gwt.event.shared.GwtEvent; 005import com.google.gwt.event.shared.HasHandlers; 006import com.google.web.bindery.event.shared.HandlerRegistration; 007 008/* 009 * #%L 010 * GwtBootstrap3 011 * %% 012 * Copyright (C) 2015 GwtBootstrap3 013 * %% 014 * Licensed under the Apache License, Version 2.0 (the "License"); 015 * you may not use this file except in compliance with the License. 016 * You may obtain a copy of the License at 017 * 018 * http://www.apache.org/licenses/LICENSE-2.0 019 * 020 * Unless required by applicable law or agreed to in writing, software 021 * distributed under the License is distributed on an "AS IS" BASIS, 022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 023 * See the License for the specific language governing permissions and 024 * limitations under the License. 025 * #L% 026 */ 027 028/** 029 * Event fired when validation state changes. 030 * 031 * @author Steven Jardine 032 */ 033public class ValidationChangedEvent extends GwtEvent<ValidationChangedEvent.ValidationChangedHandler> { 034 035 /** 036 * HasValidationChangedHandlers. 037 */ 038 public interface HasValidationChangedHandlers extends HasHandlers { 039 040 /** 041 * Adds a validation changed handler. 042 * 043 * @param handler the handler 044 * @return the handler registration 045 */ 046 HandlerRegistration addValidationChangedHandler(ValidationChangedHandler handler); 047 } 048 049 /** 050 * ValidationChangedHandler. 051 */ 052 public interface ValidationChangedHandler extends EventHandler { 053 054 /** 055 * On validation changed. 056 * 057 * @param event the event 058 */ 059 public void onValidationChanged(ValidationChangedEvent event); 060 } 061 062 private static final Type<ValidationChangedHandler> TYPE = new Type<ValidationChangedHandler>(); 063 064 /** 065 * Fire the event. 066 * 067 * @param source the source 068 * @param valid the valid 069 */ 070 public static void fire(HasHandlers source, boolean valid) { 071 ValidationChangedEvent eventInstance = new ValidationChangedEvent(valid); 072 source.fireEvent(eventInstance); 073 } 074 075 /** 076 * Fire. 077 * 078 * @param source the source 079 * @param eventInstance the event instance 080 */ 081 public static void fire(HasHandlers source, ValidationChangedEvent eventInstance) { 082 source.fireEvent(eventInstance); 083 } 084 085 /** 086 * Gets the event type. 087 * 088 * @return the type 089 */ 090 public static Type<ValidationChangedHandler> getType() { 091 return TYPE; 092 } 093 094 private boolean valid; 095 096 /** 097 * Constructor. 098 */ 099 protected ValidationChangedEvent() { 100 } 101 102 /** 103 * Constructor. 104 * 105 * @param valid the validation state. 106 */ 107 public ValidationChangedEvent(boolean valid) { 108 this.valid = valid; 109 } 110 111 /** {@inheritDoc} */ 112 @Override 113 protected void dispatch(ValidationChangedHandler handler) { 114 handler.onValidationChanged(this); 115 } 116 117 /** {@inheritDoc} */ 118 @Override 119 public boolean equals(Object obj) { 120 if (this == obj) return true; 121 if (obj == null) return false; 122 if (getClass() != obj.getClass()) return false; 123 ValidationChangedEvent other = (ValidationChangedEvent) obj; 124 if (valid != other.valid) return false; 125 return true; 126 } 127 128 /** {@inheritDoc} */ 129 @Override 130 public Type<ValidationChangedHandler> getAssociatedType() { 131 return TYPE; 132 } 133 134 /** {@inheritDoc} */ 135 @Override 136 public int hashCode() { 137 int hashCode = 23; 138 hashCode = (hashCode * 37) + new Boolean(valid).hashCode(); 139 return hashCode; 140 } 141 142 /** 143 * Checks if is valid. 144 * 145 * @return true, if is valid 146 */ 147 public boolean isValid() { 148 return valid; 149 } 150 151 /** {@inheritDoc} */ 152 @Override 153 public String toString() { 154 return "ValidationChangedEvent[" + valid + "]"; 155 } 156 157}