ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Anson <dan...@germane-software.com>
Subject Re: Conditional Statement
Date Thu, 31 Jul 2003 22:38:01 GMT
Antelope (the application) also pops up a dialog for input. The source 
for the input dialog is fairly short and self-contained, so I've 
included it below. I left out the license, it's standard ASF, same as 
Ant. To use it, compile it (you might want to change the package name), 
then use the -inputhandler <classname> parameter when starting Ant. Then 
your <input> statements in Ant will pop up a dialog.

Maybe this helps?

Dale


package ise.antelope.common;

import java.awt.Component;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
import javax.swing.Icon;
import javax.swing.JOptionPane;

import org.apache.tools.ant.input.InputHandler;
import org.apache.tools.ant.input.InputRequest;
import org.apache.tools.ant.input.MultipleChoiceInputRequest;
import org.apache.tools.ant.BuildException;

/**
 * Prompts for user input using a JOptionPane. Developed for use with
 * Antelope.
 *
 * @author <a href="mailto:danson@germane-software.com">Dale Anson</a>
 * @version $Revision: 1.3 $
 * @since Ant 1.5
 */
public class AntInputHandler implements InputHandler {

    private Component parent = null;

    public AntInputHandler() {}

    /**
     * @param parent the parent component to display the input dialog.
     */
    public AntInputHandler( Component parent ) {
        this.parent = parent;
    }

    /**
     * Prompts and requests input.  May loop until a valid input has
     * been entered.
     */
    public void handleInput( InputRequest request ) throws BuildException {

        if ( request instanceof MultipleChoiceInputRequest ) {
            String prompt = request.getPrompt();
            String title = "Select Input";
            int optionType = JOptionPane.YES_NO_OPTION;
            int messageType = JOptionPane.QUESTION_MESSAGE;
            Icon icon = null;
            Object[] choices = ( ( MultipleChoiceInputRequest ) request 
).getChoices().toArray();
            Object initialChoice = null;
            do {
                Object input = JOptionPane.showInputDialog(parent, prompt,
                    title, optionType, icon, choices, initialChoice);
                if (input == null)
                   throw new BuildException("User cancelled.");
                request.setInput(input.toString());
            } while (!request.isInputValid());
           
        }
        else {
            do {
                String input = JOptionPane.showInputDialog( parent, 
request.getPrompt() );
                request.setInput( input );
            } while ( !request.isInputValid() );
        }
    }

}

Harkness, David wrote:

>First, <input> is what you need. For example,
>
>  <input message="Enter a commit message:" addproperty="p4.commit.msg"/>
>
>IIRC, you said you're using Eclispe. If so, someone else on this list
>said that when running Ant in Eclipse, it pops up a dialog box rather
>than entering text in a shell. Either way, you can also create your own
>InputHandler (sp?) to create a dialog box if you want to.
>
>Next, you can write that to a file I believe using <echo>, but I haven't
>tried this. Someone else was talking about doing this a couple days ago.
>
>Finally, the <if> task from ant-contrib or Antelope would allow you to
>start by reading the property file (or use <available> to test if the
>file exists) and testing for the presence of the property.
>
>Of course, you don't need the <if> tasks -- you can use <target ...
>if="" ...> instead. I, however, don't like creating so many targets for
>such a simple if test. YMMV.
>
>David Harkness
>Sony Pictures Digital Networks
>(310) 482-4756
>
>
>-----Original Message-----
>From: Matt [mailto:mathews_julien@hotmail.com] 
>Sent: Wednesday, July 30, 2003 3:54 PM
>To: 'Ant Users List'
>Subject: RE: Conditional Statement
>
>
>Ok Guys, Please tell me another thing
>
>I want to make a small gui program that would come up/run when an Ant
>script is executed and would prompt the user to enter the information
>for CVS repository.The entered values would be used to set properties in
>that ant script for use in later targets and also would be entered in a
>property file so that next time when the script is run the GUI has its
>fields populated for user to make sure.
>
>Now if anyone has attempted something like that, I want to know if using
>anything else (like antelope etc) along with basic Ant 1.5.3 would make
>the job easier.
>
>Thanks in advance
>
>Matt.
>
>
>-----Original Message-----
>From: Dominique Devienne [mailto:DDevienne@lgc.com] 
>Sent: Wednesday, July 30, 2003 3:39 PM
>To: 'Ant Users List'
>Subject: RE: Conditional Statement
>
>Then you don't use JDK 1.4.x I guess... Also, you should prefer Xerces
>to Crimson. --DD
>
>  
>
>>-----Original Message-----
>>From: Harkness, David [mailto:DHarkness@sonypictures.com]
>>Sent: Wednesday, July 30, 2003 5:37 PM
>>To: Ant Users List
>>Subject: RE: Conditional Statement
>>
>>I have to have crimson, jakarta-oro, and xalan in there.
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message