1 package org.objectstyle.cayenne.modeler.dialog; 2 3 import java.awt.Component ; 4 import java.util.Iterator ; 5 6 import javax.swing.JDialog ; 7 8 import org.objectstyle.cayenne.modeler.util.CayenneController; 9 import org.objectstyle.cayenne.swing.BindingBuilder; 10 import org.objectstyle.cayenne.validation.ValidationFailure; 11 import org.objectstyle.cayenne.validation.ValidationResult; 12 13 16 public class ValidationResultBrowser extends CayenneController { 17 18 protected ValidationResultBrowserView view; 19 20 public ValidationResultBrowser(CayenneController parent) { 21 super(parent); 22 23 this.view = new ValidationResultBrowserView(); 24 25 initController(); 26 } 27 28 protected void initController() { 29 BindingBuilder builder = new BindingBuilder( 30 getApplication().getBindingFactory(), 31 this); 32 builder.bindToAction(view.getCloseButton(), "closeDialogAction()"); 33 } 34 35 public Component getView() { 36 return view; 37 } 38 39 public void closeDialogAction() { 40 view.dispose(); 41 } 42 43 public void startupAction( 44 String title, 45 String message, 46 ValidationResult validationResult) { 47 48 this.view.setTitle(title); 49 this.view.getMessageLabel().setText(message); 50 this.view.getErrorsDisplay().setText(buildValidationText(validationResult)); 51 52 view.pack(); 53 view.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 54 view.setModal(true); 55 makeCloseableOnEscape(); 56 centerView(); 57 view.setVisible(true); 58 } 59 60 63 protected String buildValidationText(ValidationResult validationResult) { 64 StringBuffer buffer = new StringBuffer (); 65 String separator = System.getProperty("line.separator"); 66 67 Iterator it = validationResult.getFailures().iterator(); 68 while (it.hasNext()) { 69 70 if (buffer.length() > 0) { 71 buffer.append(separator); 72 } 73 74 ValidationFailure failure = (ValidationFailure) it.next(); 75 if (failure.getSource() != null) { 76 buffer.append("[SQL: ").append(failure.getSource()).append("] - "); 77 } 78 79 if (failure.getDescription() != null) { 80 buffer.append(failure.getDescription()); 81 } 82 } 83 84 return buffer.toString(); 85 } 86 } | Popular Tags |