sysmodelmgr/com.symbian.smt.gui/src/com/symbian/smt/gui/smtwidgets/ValidModelEvent.java
changeset 0 522a326673b6
equal deleted inserted replaced
-1:000000000000 0:522a326673b6
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 package com.symbian.smt.gui.smtwidgets;
       
    19 
       
    20 /**
       
    21  * This class encapsulates the outcome of the validation of a field which the
       
    22  * user has touched.
       
    23  * <p>
       
    24  * It contains information on the event result (whether validation was
       
    25  * successful or failed) and the message associated with the event.
       
    26  * </p>
       
    27  * <p>
       
    28  * It is created by objects of type ValidModelObservable when validation of a
       
    29  * field occurs and it is propagated to registered ValidModelDefinedListener
       
    30  * objects in order to allow them to set their state accordingly.
       
    31  * </p>
       
    32  * <p>
       
    33  * An example of usage of this class is provided by Properties pages which
       
    34  * require to disable their "Ok" and "Apply" buttons and to show a relevant
       
    35  * error message when validation of a specific field fails.
       
    36  * </p>
       
    37  * 
       
    38  * @author barbararosi-schwartz
       
    39  * 
       
    40  */
       
    41 public class ValidModelEvent {
       
    42 	public enum Type {
       
    43 		ERROR, SUCCESS, WARNING;
       
    44 	}
       
    45 
       
    46 	private Boolean isValid;
       
    47 	private String message;
       
    48 	private Type type;
       
    49 
       
    50 	/**
       
    51 	 * The constructor.
       
    52 	 * 
       
    53 	 * @param result
       
    54 	 *            a Boolean representing whether validation was successful or
       
    55 	 *            not
       
    56 	 * @param message
       
    57 	 *            the message associated with the validation. If validation
       
    58 	 *            succeeded, the message may be empty. If validation failed, the
       
    59 	 *            message cannot be empty. If it is, a default error message is
       
    60 	 *            enforced.
       
    61 	 */
       
    62 	public ValidModelEvent(Boolean isValid, String message, Type type) {
       
    63 		if (isValid == null) {
       
    64 			throw new IllegalArgumentException("Arg result cannot be null.");
       
    65 		}
       
    66 
       
    67 		if (message == null) {
       
    68 			throw new IllegalArgumentException("Arg message cannot be null.");
       
    69 		}
       
    70 
       
    71 		// Enforcing the message not to be non empty
       
    72 		if ((!isValid) && (message.length() == 0)) {
       
    73 			message = "Error message unavailable.";
       
    74 		}
       
    75 
       
    76 		this.isValid = isValid;
       
    77 		this.message = message;
       
    78 		this.type = type;
       
    79 	}
       
    80 
       
    81 	public String getMessage() {
       
    82 		return message;
       
    83 	}
       
    84 
       
    85 	public Type getType() {
       
    86 		return type;
       
    87 	}
       
    88 
       
    89 	public Boolean isValid() {
       
    90 		return isValid;
       
    91 	}
       
    92 
       
    93 }