2 * $Id: SomeItemInputDialog.java,v 1.1 2004-10-05 20:51:57 jsurfer Exp $
3 * Copyright Narushima Hironori. All rights reserved.
5 package net.sourceforge.phpeclipse.wizards.html;
7 import org.eclipse.jface.dialogs.*;
8 import org.eclipse.jface.dialogs.Dialog;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.*;
11 import org.eclipse.swt.graphics.Point;
12 import org.eclipse.swt.layout.*;
13 import org.eclipse.swt.widgets.*;
18 public class SomeItemInputDialog extends Dialog {
21 String[] inputMessages;
23 IInputValidator[] validators;
28 String[] resultValues;
30 public SomeItemInputDialog(Shell parentShell, String dialogTitle, String[] inputMessages, IInputValidator[] validators) {
32 if(inputMessages.length != validators.length){
33 throw new IllegalArgumentException("Specify validator counts and input message count is not same.");
36 this.dialogTitle = dialogTitle;
37 this.inputMessages = (String[])inputMessages.clone();
38 this.validators = (IInputValidator[])validators.clone();
39 this.errorMsgs = new String[validators.length];
41 setShellStyle(SWT.RESIZE | getShellStyle());
44 protected void configureShell(Shell newShell) {
45 super.configureShell(newShell);
46 newShell.setText(dialogTitle);
49 protected Control createDialogArea(Composite parent) {
50 Composite base = (Composite)super.createDialogArea(parent);
51 GridLayout gl = new GridLayout(2, false);
56 texts = new Text[inputMessages.length];
57 for(int i=0; i<inputMessages.length; i++){
58 new Label(base, SWT.NONE).setText(inputMessages[i] + ":");
61 Text t = new Text(base, SWT.BORDER);
62 t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
63 t.addModifyListener(new ModifyListener() {
64 public void modifyText(ModifyEvent e) {
65 refreshValidator(index);
71 error = new Text(base, SWT.READ_ONLY);
72 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
73 gd.horizontalSpan = 2;
74 error.setLayoutData(gd);
79 void refreshValidator(int index){
80 String data = texts[index].getText();
81 IInputValidator validator = validators[index];
82 if( validator != null){
83 errorMsgs[index] = validator.isValid(data);
86 Button okButton = getButton(IDialogConstants.OK_ID);
87 for(int i=0; i<errorMsgs.length; i++){
88 String msg = errorMsgs[i];
91 okButton.setEnabled(false);
96 okButton.setEnabled(true);
99 public String[] getValues(){
100 return (String[]) resultValues.clone();
103 protected Point getInitialSize() {
104 Point p = super.getInitialSize();
105 return new Point( p.x * 2, (int)(p.y * 1.25) );
108 protected void okPressed() {
109 resultValues = new String[texts.length];
110 for (int i = 0; i < texts.length; i++) {
111 resultValues[i] = texts[i].getText();