Changeset 1884

Show
Ignore:
Timestamp:
05/14/09 16:05:13 (3 years ago)
Author:
eitan
Message:

ds-wizard: adding support for step-specific validation, to veto going to next step (requested on mailing list)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • jmatter-complet/trunk/demo-apps/ContactMgr

    • Property svn:ignore changed from
      db
      build
      dist
      jws-dist
      run.sh
      jetty
      tempKeystore
      appbundle
      to
      db
      build
      dist
      jws-dist
      run.sh
      jetty
      tempKeystore
      appbundle
      *.log
  • jmatter-complet/trunk/demo-apps/ContactMgr/src/com/u2d/contactmgr/NewPersonWizard.java

    r1883 r1884  
    44import com.u2d.view.swing.FormView; 
    55import com.u2d.model.ComplexType; 
     6import com.u2d.validation.ValidationNotifier; 
    67 
    78import javax.swing.*; 
     
    3233   // ==================================================================== 
    3334 
     35   private int attempts = 0; 
     36 
    3437   class NameStep extends BasicStep 
    3538   { 
     
    3942      { 
    4043         return new FormView(pc.getName()); 
     44      } 
     45 
     46      /* 
     47        testing new validation hook added to wizard implementation 
     48       */ 
     49      @Override 
     50      public int validate(ValidationNotifier notifier) 
     51      { 
     52         attempts++; 
     53         switch (attempts) 
     54         { 
     55            case 1: 
     56            { 
     57               notifier.fireValidationException("Try again."); 
     58               return 1; 
     59            } 
     60            case 2: 
     61            { 
     62               notifier.fireValidationException("Not yet.  One more time please."); 
     63               return 1; 
     64            } 
     65            default: 
     66            { 
     67               return 0; 
     68            } 
     69         } 
    4170      } 
    4271   } 
  • jmatter-complet/trunk/modules/ds-wizard/src/com/u2d/validation/ValidationEvent.java

    • Property svn:mergeinfo set
  • jmatter-complet/trunk/modules/ds-wizard/src/com/u2d/validation/ValidationListener.java

    • Property svn:mergeinfo set
  • jmatter-complet/trunk/modules/ds-wizard/src/com/u2d/validation/ValidationNotifier.java

    • Property svn:mergeinfo set
  • jmatter-complet/trunk/modules/ds-wizard/src/com/u2d/wizard/details/BasicStep.java

    r1 r1884  
    22 
    33import com.u2d.wizard.abstractions.Step; 
     4import com.u2d.validation.ValidationNotifier; 
     5 
    46import javax.swing.*; 
    57 
     
    2628   public boolean viewDirty() { return false; } 
    2729 
     30   /** 
     31    * @param notifier use this object to send validation messages to the ui 
     32    * @return number of validation errors (should return 0 if validation passed) 
     33    */ 
     34   public int validate(ValidationNotifier notifier) 
     35   { 
     36      return 0; // default implementation.  overriding optional. 
     37   } 
     38 
    2839   public String toString() { return title(); } 
    2940} 
  • jmatter-complet/trunk/modules/swingvm/src/com/u2d/view/swing/ValidationNoticePanel.java

    r1647 r1884  
    2222   private ValidationNotifier _target; 
    2323   private boolean _listening = false; 
    24     
     24 
     25   public ValidationNoticePanel() 
     26   { 
     27      setText(""); 
     28      ComponentStyle.addClass(this, "validation-msg"); 
     29   } 
    2530   public ValidationNoticePanel(ValidationNotifier target, boolean startListening) 
    2631   { 
     32      this(); 
    2733      _target = target; 
    28        
    29       setText(""); 
    30       ComponentStyle.addClass(this, "validation-msg"); 
    31        
    32       if (startListening) 
    33          startListening(); 
     34      if (startListening) startListening(); 
    3435   } 
    3536   public ValidationNoticePanel(ValidationNotifier target, ComplexEObject ceo) 
    3637   { 
    3738      this(target, ceo.isEditableState()); 
     39   } 
     40 
     41   public void setTarget(ValidationNotifier notifier) 
     42   { 
     43      stopListening(); 
     44      _target = notifier; 
     45      startListening(); 
    3846   } 
    3947    
     
    4755   public synchronized void stopListening() 
    4856   { 
    49       _target.removeValidationListener(this); 
     57      if (_target != null) 
     58      { 
     59         _target.removeValidationListener(this); 
     60      } 
    5061      _listening = false; 
    5162   } 
  • jmatter-complet/trunk/modules/swingvm/src/com/u2d/wizard/ui/CenterPane.java

    r1660 r1884  
    33import com.u2d.wizard.abstractions.Step; 
    44import com.u2d.view.EView; 
     5import com.u2d.view.swing.ValidationNoticePanel; 
    56import com.u2d.ui.UIUtils; 
     7import com.u2d.model.EObject; 
    68 
    79import javax.swing.*; 
     
    911import java.util.Map; 
    1012import java.util.HashMap; 
    11 import java.util.Iterator; 
    1213 
    1314/** 
     
    2223   private Map<String,JComponent> _stepViewMap = new HashMap<String,JComponent>(); 
    2324   private JComponent _currentView; 
     25   private ValidationNoticePanel _validationPnl; 
     26   private JPanel _stepsPnl; 
    2427 
    2528   public CenterPane(Dimension preferredSize) 
    2629   { 
     30      setLayout(new BorderLayout()); 
     31 
     32      _stepsPnl = new JPanel(); 
    2733      _cardLayout = new CardLayout(); 
    28       setLayout(_cardLayout); 
    29       setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); 
    30       setPreferredSize(preferredSize); 
     34      _stepsPnl.setLayout(_cardLayout); 
     35      _stepsPnl.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); 
     36      _stepsPnl.setPreferredSize(preferredSize); 
     37 
     38      _validationPnl = new ValidationNoticePanel(); 
     39      add(_validationPnl, BorderLayout.NORTH); 
     40      add(_stepsPnl, BorderLayout.CENTER); 
    3141   } 
    3242 
    3343   public void updateStep(Step step) 
    3444   { 
    35       _cardLayout.show(this, viewName(step)); 
     45      _cardLayout.show(_stepsPnl, viewName(step)); 
     46 
     47      if (_currentView instanceof EView) 
     48      { 
     49         EObject eo = ((EView) _currentView).getEObject(); 
     50         _validationPnl.setTarget(eo); 
     51      } 
     52 
    3653      // must delay this otherwise may not have any effect.. 
    3754      SwingUtilities.invokeLater(new Runnable() 
     
    4663   private String viewName(Step step) 
    4764   { 
    48       JComponent view = (JComponent) _stepViewMap.get(step.title()); 
     65      JComponent view = _stepViewMap.get(step.title()); 
    4966      if ( (view!=null) && (step.viewDirty()) ) 
    5067      { 
    51          remove(view); 
     68         _stepsPnl.remove(view); 
    5269         _stepViewMap.remove(step.title()); 
    5370         if (view instanceof EView) 
     
    6178         view = step.getView(); 
    6279         _stepViewMap.put(step.title(), view); 
    63          add(view, step.title()); 
     80         _stepsPnl.add(view, step.title()); 
    6481      } 
    6582      _currentView = view; 
     
    7188   public void detach() 
    7289   { 
    73       for (Iterator views = _stepViewMap.values().iterator(); views.hasNext();
     90      for (Object next : _stepViewMap.values()
    7491      { 
    75          Object next = views.next(); 
    7692         if (next instanceof EView) 
    7793         { 
     
    7995         } 
    8096      } 
     97      _validationPnl.stopListening(); 
    8198   } 
    8299 
  • jmatter-complet/trunk/modules/swingvm/src/com/u2d/wizard/ui/WizardPane.java

    r1660 r1884  
    33import com.u2d.wizard.abstractions.Step; 
    44import com.u2d.wizard.details.Wizard; 
     5import com.u2d.wizard.details.BasicStep; 
    56import com.u2d.model.Editor; 
    67import com.u2d.model.EObject; 
     
    130131            errorCount = eo.field().validate(eo.parentObject()); 
    131132         } 
    132           
     133 
    133134         if (errorCount > 0) 
    134135         { 
     
    136137            eo.fireValidationException("["+errorCount+" validation error"+plural+".]", true); 
    137138            return false; 
     139         } 
     140 
     141         if (_wizard.currentStep() instanceof BasicStep) 
     142         { 
     143            BasicStep bstep = (BasicStep) _wizard.currentStep(); 
     144            errorCount = bstep.validate(eo); 
     145            if (errorCount > 0) 
     146            { 
     147               return false; 
     148            } 
    138149         } 
    139150 
     
    159170 
    160171         StepLabel label = null; 
    161          Step step = null
     172         Step step
    162173         for (int i=0; i<flattenedSteps.size(); i++) 
    163174         {