KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > util > ant > CmsAntTaskSelectionPrompt


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-components/org/opencms/util/ant/CmsAntTaskSelectionPrompt.java,v $
3  * Date : $Date: 2006/03/27 14:53:01 $
4  * Version: $Revision: 1.7 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.util.ant;
33
34 import javax.swing.UIManager JavaDoc;
35
36 /**
37  * Ant task for a highly configurable Swing GUI based selection dialog.<p>
38  *
39  * Task that prompts user for selection to allow interactive builds.<p>
40  *
41  * @author Michael Moossen
42  *
43  * @version $Revision: 1.7 $
44  *
45  * @since 6.0.0
46  */

47 public class CmsAntTaskSelectionPrompt extends org.apache.tools.ant.Task {
48
49     /** Options list separator constant. */
50     public static final String JavaDoc LIST_SEPARATOR = ",";
51
52     /** List of all options. */
53     private String JavaDoc m_allValues; // required
54
/** The amount of columns to use for display of selection elements. */
55     private int m_columns = 2;
56     /** List of by default selected options. */
57     private String JavaDoc m_defaultValue = "";
58     /** Prompt message. */
59     private String JavaDoc m_prompt = "Please make your choice:";
60     /** Destination property. */
61     private String JavaDoc m_property; // required
62
/** Mode flag. */
63     private boolean m_singleSelection = false;
64
65     /** Title message. */
66     private String JavaDoc m_title = "Selection Dialog";
67
68     /**
69      * Default constructor.<p>
70      */

71     public CmsAntTaskSelectionPrompt() {
72
73         super();
74     }
75
76     /**
77      * Run the task.<p>
78      *
79      * Sets the given property to <code>__ABORT__</code> if canceled, or to a list of selected
80      * modules if not.<p>
81      *
82      * @throws org.apache.tools.ant.BuildException
83      *
84      * @see org.apache.tools.ant.Task#execute()
85      */

86     public void execute() throws org.apache.tools.ant.BuildException {
87
88         log("Prompting user for " + m_property);
89
90         String JavaDoc value = new CmsAntTaskSelectionDialog(this).getSelection();
91
92         if (value == null) {
93             value = "__ABORT__";
94         } else {
95             log("user selection: " + value);
96         }
97         getProject().setProperty(m_property, value);
98     }
99
100     /**
101      * Returns the <code>{@link #LIST_SEPARATOR}</code> separated list of all available modules.<p>
102      *
103      * @return Returns the all-modules list
104      */

105     public String JavaDoc getAllValues() {
106
107         return m_allValues;
108     }
109
110     /**
111      * Returns the columns.<p>
112      *
113      * @return the columns.
114      */

115     public int getColumns() {
116
117         return m_columns;
118     }
119
120     /**
121      * Returns the <code>{@link #LIST_SEPARATOR}</code> separated list of pre-selected modules.<p>
122      *
123      * @return Returns the pre-selected module list
124      */

125     public String JavaDoc getDefaultValue() {
126
127         return m_defaultValue;
128     }
129
130     /**
131      * Returns the prompt.<p>
132      *
133      * @return the prompt
134      */

135     public String JavaDoc getPrompt() {
136
137         return m_prompt;
138     }
139
140     /**
141      * Returns the property to store the user selection.<p>
142      *
143      * @return Returns the m_propertyName.
144      */

145     public String JavaDoc getProperty() {
146
147         return m_property;
148     }
149
150     /**
151      * Returns the title.<p>
152      *
153      * @return the title
154      */

155     public String JavaDoc getTitle() {
156
157         return m_title;
158     }
159
160     /**
161      * Initializes this task.<p>
162      */

163     public void init() {
164
165         super.init();
166         try {
167             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
168         } catch (Exception JavaDoc e) {
169             // noop
170
}
171     }
172
173     /**
174      * Returns the Single Selection flag.<p>
175      *
176      * @return the single Selection flag
177      */

178     public boolean isSingleSelection() {
179
180         return m_singleSelection;
181     }
182
183     /**
184      * Sets the <code>{@link #LIST_SEPARATOR}</code> separated list of all available modules.<p>
185      *
186      * @param allValues all-modules list to set
187      */

188     public void setAllValues(String JavaDoc allValues) {
189
190         this.m_allValues = allValues;
191     }
192
193     /**
194      * Sets the columns.<p>
195      *
196      * @param cols the columns to set
197      */

198     public void setColumns(String JavaDoc cols) {
199
200         m_columns = Integer.parseInt(cols);
201     }
202
203     /**
204      * Sets the <code>{@link #LIST_SEPARATOR}</code> separated list of pre-selected modules.<p>
205      *
206      * @param defaultValue the pre-selected module list to set
207      */

208     public void setDefaultValue(String JavaDoc defaultValue) {
209
210         this.m_defaultValue = defaultValue;
211     }
212
213     /**
214      * Sets the prompt.<p>
215      *
216      * @param prompt the prompt to set
217      */

218     public void setPrompt(String JavaDoc prompt) {
219
220         m_prompt = prompt;
221     }
222
223     /**
224      * Sets the property for storing the selected value.
225      *
226      * @param property The property to set.
227      */

228     public void setProperty(String JavaDoc property) {
229
230         this.m_property = property;
231     }
232
233     /**
234      * Sets the single Selection flag.<p>
235      *
236      * @param singleSelection the single Selection flag to set
237      */

238     public void setSingleSelection(boolean singleSelection) {
239
240         m_singleSelection = singleSelection;
241     }
242
243     /**
244      * Sets the title.<p>
245      *
246      * @param title the title to set
247      */

248     public void setTitle(String JavaDoc title) {
249
250         m_title = title;
251     }
252
253 }
Popular Tags