at.spardat.xma.mdl.ValidationErrorClient Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
// @(#) $Id: ValidationErrorClient.java 3080 2009-01-28 12:59:14Z gub $
package at.spardat.xma.mdl;
import java.util.Locale;
import at.spardat.enterprise.fmt.*;
/**
* An object of this class indicates that the value provided by the user
* in a particular SimpleWM is not an accepted input.
*/
public class ValidationErrorClient {
/**
* Constructor.
*
* @param wModel the WModel whose UI is in error
* @param control the UI control, e.g., a SWT control
* @param label text describing the label of a control; may be null;
* @param ex an exception indicating the reason of the error
*/
public ValidationErrorClient (WModel wModel, Object control, String label, AParseException ex) {
wModel_ = wModel;
control_ = control;
label_ = label;
ex_ = ex;
}
/**
* Returns the control which is in error.
*
* @return the UI control
*/
public Object getControl() {
return control_;
}
/**
* Returns the widget model whose UI is in error.
*
* @return widget model
*/
public WModel getWModel() {
return wModel_;
}
/**
* Returns an internationalized error message of the defect.
*
* @return error message
*/
public String getErrorText (Locale l) {
String message = ex_.getUIMessage(l);
if (label_ != null && label_.trim().length() > 0) {
// prepend label, if any
StringBuffer b = new StringBuffer ();
String label = label_.trim();
label = stripAmp(label);
if (label.length() > 20) {
b.append(label.substring(0, 16)).append("...:");
} else {
b.append(label);
if (label.length()>0&&label.charAt(label.length()-1) != ':') b.append(':');
}
b.append(' ').append(message);
message = b.toString();
}
return message;
}
/**
* Strips ampersands from the given label string.
* '&' signs are used to mark access keys. They are not shown in the label, instead
* the next character is underlined. Double ampersands are shown as one ampersand.
* This method resembles this behavior of windows/SWT except of the underlining.
*/
private String stripAmp(String label) {
StringBuffer result = new StringBuffer(label.length());
boolean esc = false;
for(int i=0;i