1 11 package org.eclipse.ant.internal.ui.antsupport.inputhandler; 12 13 14 import org.apache.tools.ant.BuildException; 15 import org.apache.tools.ant.input.DefaultInputHandler; 16 import org.apache.tools.ant.input.InputRequest; 17 import org.eclipse.ant.internal.ui.antsupport.AntSupportMessages; 18 import org.eclipse.jface.dialogs.IInputValidator; 19 import org.eclipse.jface.dialogs.InputDialog; 20 import org.eclipse.jface.window.Window; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.widgets.Display; 23 24 31 public class AntInputHandler extends DefaultInputHandler { 32 33 36 public void handleInput(InputRequest request) throws BuildException { 37 if (System.getProperty("eclipse.ant.noInput") != null) { throw new BuildException(AntSupportMessages.AntInputHandler_5); 39 } 40 BuildException[] problem= new BuildException[1]; 41 Runnable runnable= getHandleInputRunnable(request, problem); 42 Display.getDefault().syncExec(runnable); 43 if (problem[0] != null) { 44 throw problem[0]; 45 } 46 } 47 48 protected Runnable getHandleInputRunnable(final InputRequest request, final BuildException[] problem) { 49 return new Runnable () { 50 public void run() { 51 String prompt = getPrompt(request); 52 String title= AntSupportMessages.AntInputHandler_Ant_Input_Request_1; 53 IInputValidator validator= new IInputValidator() { 54 private boolean fFirstValidation =true; 55 public String isValid(String value) { 56 request.setInput(value); 57 if (request.isInputValid()) { 58 return null; 59 } 60 if (fFirstValidation) { 61 fFirstValidation= false; 62 return ""; } 64 return AntSupportMessages.AntInputHandler_Invalid_input_2; 65 } 66 }; 67 68 String initialValue = null; 69 try { 70 request.getClass().getMethod("getDefaultValue", new Class [0]); initialValue = request.getDefaultValue(); 72 } catch (SecurityException e) { 73 } catch (NoSuchMethodException e) { 74 } 76 InputDialog dialog= new InputDialog(null, title, prompt, initialValue, validator) { 77 protected int getShellStyle() { 78 return super.getShellStyle() | SWT.RESIZE; 79 } 80 }; 81 if (dialog.open() != Window.OK) { 82 problem[0]= new BuildException(AntSupportMessages.AntInputHandler_Unable_to_respond_to__input__request_4); 83 } 84 } 85 }; 86 } 87 } 88 | Popular Tags |