Author: tchemit Date: 2008-10-25 19:46:47 +0000 (Sat, 25 Oct 2008) New Revision: 995 Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ErrorListMouseListener.java Modified: lutinjaxx/trunk/jaxx-core/changelog lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx Log: add a errorList attribute for set a ErrorListMouseListener on the errorList Modified: lutinjaxx/trunk/jaxx-core/changelog =================================================================== --- lutinjaxx/trunk/jaxx-core/changelog 2008-10-25 17:03:27 UTC (rev 994) +++ lutinjaxx/trunk/jaxx-core/changelog 2008-10-25 19:46:47 UTC (rev 995) @@ -1,5 +1,6 @@ ver-0-6 chemit 200811?? * 20081025 [chemit] improve BeanValidator tag : + - add a errorList attribute for set a ErrorListMouseListener on the errorList - add a beanInitializer attribute for set the validator's bean at runtime - add a default errorListModel value 'errors' * 20081025 [chemit] introduce JAXXInitialContext to fill JAXXContext at runtime before $initialize() method Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ErrorListMouseListener.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ErrorListMouseListener.java (rev 0) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ErrorListMouseListener.java 2008-10-25 19:46:47 UTC (rev 995) @@ -0,0 +1,62 @@ +package jaxx.runtime.validator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JComponent; +import javax.swing.JList; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/** + * A mouse listener to put on a {@link JList} with a {@link BeanValidatorErrorListModel} as a model. + * <p/> + * When a double click occurs, find the selected error in model and then focus to the associated component of error. + * + * @author chemit + */ +public class ErrorListMouseListener extends MouseAdapter { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ErrorListMouseListener.class); + + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + if (e.getClickCount() == 2) { + + BeanValidatorError<?> entry = getSelectedError(e); + if (entry == null) { + // no entry found + return; + } + JComponent component = entry.getComponent(); + if (component == null) { + return; + } + component.requestFocus(); + } + } + + + protected BeanValidatorError<?> getSelectedError(MouseEvent e) { + JList list = (JList) e.getSource(); + if (!(list.getModel() instanceof BeanValidatorErrorListModel)) { + log.warn("model must ne a " + BeanValidatorErrorListModel.class + ", but was " + list.getModel()); + return null; + } + + BeanValidatorErrorListModel model = (BeanValidatorErrorListModel) list.getModel(); + int index = list.getSelectionModel().getMinSelectionIndex(); + if (index == -1) { + // nothing is selected + return null; + } + BeanValidatorError<?> entry = (BeanValidatorError) model.getElementAt(index); + if (log.isDebugEnabled()) { + log.debug("selected index: " + index + " : error: " + entry); + } + return entry; + } + +} Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-25 17:03:27 UTC (rev 994) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-25 19:46:47 UTC (rev 995) @@ -12,6 +12,7 @@ import jaxx.reflect.ClassDescriptor; import jaxx.reflect.ClassDescriptorLoader; import jaxx.runtime.validator.BeanValidator; +import jaxx.runtime.validator.ErrorListMouseListener; import jaxx.runtime.validator.ui.AbstractBeanValidatorUI; import jaxx.tags.DefaultObjectHandler; import jaxx.types.TypeManager; @@ -33,7 +34,9 @@ public static final String BEAN_INITIALIZER_ATTRIBUTE = "beanInitializer"; public static final String ERROR_LIST_MODEL_ATTRIBUTE = "errorListModel"; + public static final String ERROR_LIST_ATTRIBUTE = "errorList"; public static final String ERROR_LIST_MODEL_DEFAULT = "errors"; + public static final String ERROR_LIST_DEFAULT = "errorList"; public static final String AUTOFIELD_ATTRIBUTE = "autoField"; public static final String UI_CLASS_ATTRIBUTE = "uiClass"; @@ -74,6 +77,10 @@ boolean error = info.addErrorListModel(tag, this, compiler); if (!error) { + error = info.addErrorList(tag, compiler); + } + + if (!error) { error = info.addUiClass(this, compiler); } @@ -117,6 +124,7 @@ protected String beanInitializer; protected String uiClass; protected String errorListModel; + protected String errorList; protected Boolean autoField; protected Boolean strictMode; protected JAXXBeanInfo beanDescriptor; @@ -162,6 +170,12 @@ } return; } + if (ERROR_LIST_ATTRIBUTE.equals(property)) { + if (value != null && !value.trim().isEmpty()) { + errorList = value; + } + return; + } if (UI_CLASS_ATTRIBUTE.equals(property)) { if (value != null && !value.trim().isEmpty()) { uiClass = value; @@ -269,23 +283,42 @@ protected boolean addErrorListModel(Element tag, BeanValidatorHandler handler, JAXXCompiler compiler) { if (errorListModel == null) { // try with the default "errors" - - if (!compiler.checkReference(tag, ERROR_LIST_MODEL_DEFAULT, true, ERROR_LIST_MODEL_ATTRIBUTE)) { + if (!compiler.checkReference(tag, ERROR_LIST_MODEL_DEFAULT, false, ERROR_LIST_MODEL_ATTRIBUTE)) { + return false; + } + errorListModel = ERROR_LIST_MODEL_DEFAULT; + } else { + if (!compiler.checkReference(tag, errorListModel, true, ERROR_LIST_MODEL_ATTRIBUTE)) { return true; } - String code = handler.getSetPropertyCode(getJavaCode(), ERROR_LIST_MODEL_ATTRIBUTE, ERROR_LIST_MODEL_DEFAULT, compiler); - appendAdditionCode(code); - return false; } - if (!compiler.checkReference(tag, errorListModel, true, ERROR_LIST_MODEL_ATTRIBUTE)) { - return true; + String code = handler.getSetPropertyCode(getJavaCode(), ERROR_LIST_MODEL_ATTRIBUTE, errorListModel, compiler); + appendAdditionCode(code); + + return false; + + } + + protected boolean addErrorList(Element tag, JAXXCompiler compiler) { + + if (errorList == null) { + // try with the default "errorList" + if (!compiler.checkReference(tag, ERROR_LIST_DEFAULT, false, ERROR_LIST_ATTRIBUTE)) { + return false; + } + errorList = ERROR_LIST_DEFAULT; + } else { + if (!compiler.checkReference(tag, errorList, true, ERROR_LIST_ATTRIBUTE)) { + return true; + } } - String code = handler.getSetPropertyCode(getJavaCode(), ERROR_LIST_MODEL_ATTRIBUTE, errorListModel, compiler); + String code = errorList + ".addMouseListener(new " + ErrorListMouseListener.class.getName() + "());"; appendAdditionCode(code); return false; + } protected boolean addBean(Element tag, BeanValidatorHandler handler, JAXXCompiler compiler) { Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx =================================================================== --- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-25 17:03:27 UTC (rev 994) +++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-25 19:46:47 UTC (rev 995) @@ -10,17 +10,17 @@ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/> <!-- validators --> - <BeanValidator id='validator' bean='model' errorListModel='errors'> + <BeanValidator id='validator' bean='model'> <field name="text"/> <field name="text2"/> <field name="ratio"/> </BeanValidator> - <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI"> + <BeanValidator id='validator2' bean='model2' uiClass="jaxx.runtime.validator.ui.IconValidationUI"> <field name="text" component="_text"/> <field name="text2" component="_text2"/> <field name="ratio" component="_ratio"/> </BeanValidator> - <BeanValidator id='validator3' autoField='true' bean='identity' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.TranslucentValidationUI"> + <BeanValidator id='validator3' autoField='true' bean='identity' uiClass="jaxx.runtime.validator.ui.TranslucentValidationUI"> <field name="email" component="email2"/> </BeanValidator> @@ -286,7 +286,7 @@ <cell columns='2' fill="both"> <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'> <JScrollPane> - <JList model='{errors}'/> + <JList id='errorList' model='{errors}'/> </JScrollPane> </JPanel> </cell>