1 19 20 package org.objectweb.jac.aspects.gui; 21 22 import org.objectweb.jac.core.Display; 23 import org.objectweb.jac.core.rtti.AbstractMethodItem; 24 import org.objectweb.jac.core.rtti.ClassRepository; 25 import org.objectweb.jac.util.Stack; 26 27 88 89 public abstract class InputSequence { 90 91 AbstractMethodItem method; 92 Object [] parameters; 93 Display display; 94 95 Stack stepParameters = new Stack(); 96 int currentStep = 0; 97 98 106 107 public InputSequence( Display display, AbstractMethodItem method, 108 Object [] parameters ) { 109 this.display = display; 110 this.method = method; 111 this.parameters = parameters; 112 } 113 114 120 121 public abstract void init(); 122 123 134 135 public abstract boolean validate(); 136 137 142 143 public abstract int getNbSteps(); 144 145 149 150 public final int getCurrentStep() { 151 return currentStep; 152 } 153 154 159 160 public final boolean hasNextStep() { 161 return currentStep < getNbSteps(); 162 } 163 164 180 181 public abstract AbstractMethodItem getStepMethod( int step ); 182 183 188 189 public final boolean proceedInputs() { 190 init(); 191 while( hasNextStep() ) { 192 if ( ! nextStep() ) return false; 193 } 194 return validate(); 195 } 196 197 200 201 public final boolean nextStep() { 202 currentStep++; 203 AbstractMethodItem stepMethod = getStepMethod( currentStep ); 204 Object [] params = null; 205 stepParameters.push( params = new Object [stepMethod.getParameterTypes().length] ); 206 return display.showInput( null, stepMethod, params ); 207 } 208 209 212 213 public boolean previousStep() { 214 stepParameters.pop(); 215 currentStep--; 216 AbstractMethodItem stepMethod = getStepMethod( currentStep ); 217 return display.showInput( null, stepMethod, (Object [])stepParameters.peek() ); 218 } 219 220 226 227 protected AbstractMethodItem getLocalInputMethod( String name ) { 228 return ClassRepository.get().getClass( this.getClass() ).getMethod( name ); 229 } 230 231 237 238 protected Object [] getStepValues( int step ) { 239 if( currentStep < step ) { 240 throw new RuntimeException ("Step "+step+" result is not available yet"); 241 } 242 return (Object [])stepParameters.get(step-1); 243 } 244 245 251 252 protected void setParameterValue( int i, Object value ) { 253 parameters[i] = value; 254 } 255 } 256 257 258 | Popular Tags |