001package gwt.material.design.client.base.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 protected 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 @Override 112 protected void dispatch(ValidationChangedHandler handler) { 113 handler.onValidationChanged(this); 114 } 115 116 @Override 117 public boolean equals(Object obj) { 118 if (this == obj) return true; 119 if (obj == null) return false; 120 if (getClass() != obj.getClass()) return false; 121 ValidationChangedEvent other = (ValidationChangedEvent) obj; 122 return valid == other.valid; 123 } 124 125 @Override 126 public Type<ValidationChangedHandler> getAssociatedType() { 127 return TYPE; 128 } 129 130 @Override 131 public int hashCode() { 132 int hashCode = 23; 133 hashCode = (hashCode * 37) + Boolean.valueOf(valid).hashCode(); 134 return hashCode; 135 } 136 137 /** 138 * Checks if is valid. 139 * 140 * @return true, if is valid 141 */ 142 public boolean isValid() { 143 return valid; 144 } 145 146 @Override 147 public String toString() { 148 return "ValidationChangedEvent[" + valid + "]"; 149 } 150 151}