1 18 19 package sync4j.framework.engine.dm; 20 21 import sync4j.framework.core.AlertCode; 22 23 32 public class UserAlertManagementOperation extends TreeManagementOperation { 33 35 protected final String INPUT_TYPES = "ANDTPI"; 36 protected final String ECHO_TYPES = "TP" ; 37 38 private static final String DESCRIPTION = "Alert"; 40 41 public String getDescription() { 43 return DESCRIPTION; 44 } 45 46 47 50 protected String [] alerts; 51 52 55 protected int minDisplayTime; 56 57 60 protected int maxDisplayTime; 61 62 65 protected String defaultResponse; 66 67 70 protected int maxLength; 71 72 84 protected char inputType; 85 86 93 protected char echoType; 94 95 98 protected int alertCode; 99 100 public UserAlertManagementOperation() { 102 } 103 104 117 public UserAlertManagementOperation(final int alertCode, final String [] alerts) 118 throws IllegalArgumentException { 119 this(alertCode, alerts, -1, -1, null, -1, ' ', ' '); 120 } 121 122 138 public UserAlertManagementOperation( 139 int alertCode, 140 String [] alerts , 141 int mindt , 142 int maxdt , 143 String dr , 144 int maxlen , 145 char it , 146 char et 147 ) { 148 if (!AlertCode.isUserAlertCode(alertCode)) { 149 throw new IllegalArgumentException (alertCode + " is not a user alert code"); 150 } 151 152 if ((it != ' ') && (INPUT_TYPES.indexOf(it) < 0)) { 153 throw new IllegalArgumentException ( "Input type '" 154 + it 155 + "' is not one of " 156 + INPUT_TYPES 157 ); 158 } 159 160 if ((et != ' ') && (ECHO_TYPES.indexOf(et) < 0)) { 161 throw new IllegalArgumentException ( "Echo type '" 162 + et 163 + "' is not one of " 164 + ECHO_TYPES 165 ); 166 } 167 168 this.alertCode = alertCode; 169 170 if (alerts == null) { 171 this.alerts = new String [0]; 172 } else { 173 this.alerts = alerts; 174 } 175 176 minDisplayTime = mindt ; 177 maxDisplayTime = maxdt ; 178 defaultResponse = dr ; 179 maxLength = maxlen; 180 inputType = it ; 181 echoType = et ; 182 } 183 184 185 187 191 public int getMinDisplayTime() { 192 return minDisplayTime; 193 } 194 195 199 public void setMinDisplayTime(int minDisplayTime) { 200 this.minDisplayTime = minDisplayTime; 201 } 202 203 207 public String [] getAlerts() { 208 return this.alerts; 209 } 210 211 215 public void setAlerts(String [] alerts) { 216 this.alerts = alerts; 217 } 218 219 223 public int getMaxDisplayTime() { 224 return maxDisplayTime; 225 } 226 227 231 public void setMaxDisplayTime(int maxDisplayTime) { 232 this.maxDisplayTime = maxDisplayTime; 233 } 234 235 239 public String getDefaultResponse() { 240 return defaultResponse; 241 } 242 243 247 public void setDefaultResponse(String defaultResponse) { 248 this.defaultResponse = defaultResponse; 249 } 250 251 255 public int getMaxLength() { 256 return maxLength; 257 } 258 259 263 public void setMaxLength(int maxLength) { 264 this.maxLength = maxLength; 265 } 266 267 271 public char getInputType() { 272 return inputType; 273 } 274 275 279 public void setInputType(char inputType) { 280 this.inputType = inputType; 281 } 282 283 287 public char getEchoType() { 288 return echoType; 289 } 290 291 295 public void setEchoType(char echoType) { 296 this.echoType = echoType; 297 } 298 299 303 public int getAlertCode() { 304 return alertCode; 305 } 306 307 311 public void setAlertCode(int alertCode) { 312 this.alertCode = alertCode; 313 } 314 315 317 326 public static UserAlertManagementOperation getDisplay(final String text) { 327 return getDisplay(text, -1, -1); 328 } 329 330 340 public static UserAlertManagementOperation getDisplay( 341 final String text , 342 final int mindt, 343 final int maxdt) { 344 345 return getUserAlert( 346 AlertCode.DISPLAY , 347 new String [] { text }, 348 mindt , 349 maxdt , 350 null , 351 -1 , 352 ' ' , 353 ' ' 354 ); 355 } 356 357 366 public static UserAlertManagementOperation getConfirm(final String text) { 367 return getConfirm(text, -1, -1, null); 368 } 369 370 380 public static UserAlertManagementOperation getConfirm( 381 final String text , 382 final int mindt, 383 final int maxdt, 384 final String dr ) { 385 386 return getUserAlert( 387 AlertCode.CONFIRM_OR_REJECT, 388 new String [] { text } , 389 mindt , 390 maxdt , 391 dr , 392 -1 , 393 ' ' , 394 ' ' 395 ); 396 } 397 398 399 408 public static UserAlertManagementOperation getInput(final String text) { 409 return getInput(text, -1, -1, null, -1, ' ', ' '); 410 } 411 412 426 public static UserAlertManagementOperation getInput( 427 final String text , 428 final int mindt , 429 final int maxdt , 430 final String dr , 431 final int maxlen, 432 final char it , 433 final char et ) { 434 435 return getUserAlert( 436 AlertCode.INPUT , 437 new String [] { text }, 438 mindt , 439 maxdt , 440 dr , 441 maxlen , 442 it , 443 et 444 ); 445 } 446 447 457 public static UserAlertManagementOperation getChoice( 458 final String text , 459 final String [] options 460 ) { 461 return getChoice(text, options, -1, -1, null); 462 } 463 464 475 public static UserAlertManagementOperation getChoice( 476 final String text , 477 final String [] options, 478 final int mindt , 479 final int maxdt , 480 final String dr ) { 481 482 if ((options == null) || (options.length == 0)) { 483 throw new IllegalArgumentException ("options cannot be null or zero length"); 484 } 485 486 String [] alerts = new String [options.length+1]; 487 488 alerts[0] = text; 489 System.arraycopy(options, 0, alerts, 1, options.length); 490 491 return getUserAlert( 492 AlertCode.SINGLE_CHOICE, 493 alerts , 494 mindt , 495 maxdt , 496 dr , 497 -1 , 498 ' ' , 499 ' ' 500 ); 501 } 502 503 514 public static UserAlertManagementOperation getMultiChoice( 515 final String text , 516 final String [] options, 517 final int mindt , 518 final int maxdt , 519 final String dr ) { 520 521 if ((options == null) || (options.length == 0)) { 522 throw new IllegalArgumentException ("options cannot be null or zero length"); 523 } 524 525 String [] alerts = new String [options.length+1]; 526 527 alerts[0] = text; 528 System.arraycopy(options, 0, alerts, 1, options.length); 529 530 return getUserAlert( 531 AlertCode.MULTIPLE_CHOICE, 532 alerts , 533 mindt , 534 maxdt , 535 dr , 536 -1 , 537 ' ' , 538 ' ' 539 ); 540 } 541 542 544 558 protected static UserAlertManagementOperation getUserAlert( 559 final int alertCode, 560 final String [] alerts , 561 final int mindt , 562 final int maxdt , 563 final String dr , 564 final int maxlen , 565 final char it , 566 final char et 567 ) { 568 return new UserAlertManagementOperation( 569 alertCode, 570 alerts , 571 mindt , 572 maxdt , 573 dr , 574 maxlen , 575 it , 576 et 577 ); 578 } 579 580 } | Popular Tags |