KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-components/org/opencms/util/ant/CmsAntTaskSelectionTreePrompt.java,v $
3  * Date : $Date: 2006/03/27 14:53:01 $
4  * Version: $Revision: 1.3 $
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.
38  * <p>
39  *
40  * Task that prompts user for selection to allow interactive builds.
41  * <p>
42  *
43  * @author Michael Moossen (original)
44  *
45  * @author Achim Westermann (modification)
46  *
47  * @version $Revision: 1.3 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsAntTaskSelectionTreePrompt extends org.apache.tools.ant.Task {
52
53     /** Options list separator constant. */
54     public static final String JavaDoc LIST_SEPARATOR = ",";
55
56     /** List of all options. */
57     private String JavaDoc m_allValues; // required
58

59     /** List of by default selected options. */
60     private String JavaDoc m_defaultValue = "";
61
62     /** Property to force initial tree expansion for the given amount of levels. */
63     private int m_expansionLevels = 0;
64
65     /** Prompt message. */
66     private String JavaDoc m_prompt = "Please make your choice:";
67
68     /** Destination property. */
69     private String JavaDoc m_property; // required
70

71     /** Mode flag. */
72     private boolean m_singleSelection = false;
73
74     /** Title message. */
75     private String JavaDoc m_title = "Selection Dialog";
76
77     /**
78      * Default constructor.
79      * <p>
80      */

81     public CmsAntTaskSelectionTreePrompt() {
82
83         super();
84     }
85
86     /**
87      * For debuggin only.
88      *
89      * @param args cmdline args.
90      */

91     public static void main(String JavaDoc[] args) {
92
93         CmsAntTaskSelectionTreePrompt prompt = new CmsAntTaskSelectionTreePrompt();
94         prompt.setAllValues("org.opencms.test,org.opencms.test.subtest,org.opencms.code,org.opencms.blabla,com.lgt.module,com.lgt.code,com.lgt.dummy");
95         prompt.setTitle("title");
96
97         prompt.execute();
98
99     }
100
101     /**
102      * Run the task.
103      * <p>
104      *
105      * Sets the given property to <code>__ABORT__</code> if canceled, or to a list of selected
106      * modules if not.
107      * <p>
108      *
109      * @throws org.apache.tools.ant.BuildException
110      *
111      * @see org.apache.tools.ant.Task#execute()
112      */

113     public void execute() throws org.apache.tools.ant.BuildException {
114
115         log("Prompting user for " + m_property);
116
117         String JavaDoc value = new CmsAntTaskSelectionTreeDialog(this).getSelection();
118
119         if (value == null) {
120             value = "__ABORT__";
121         } else {
122             log("user selection: " + value);
123         }
124         getProject().setProperty(m_property, value);
125     }
126
127     /**
128      * Returns the <code>{@link #LIST_SEPARATOR}</code> separated list of all available modules.
129      * <p>
130      *
131      * @return Returns the all-modules list
132      */

133     public String JavaDoc getAllValues() {
134
135         return m_allValues;
136     }
137
138     /**
139      * Returns the <code>{@link #LIST_SEPARATOR}</code> separated list of pre-selected modules.
140      * <p>
141      *
142      * @return Returns the pre-selected module list
143      */

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

155     public int getExpansionLevels() {
156
157         // the mandatory "root" node is needed but invisible
158
return m_expansionLevels - 1;
159     }
160
161     /**
162      * Returns the prompt.
163      * <p>
164      *
165      * @return the prompt
166      */

167     public String JavaDoc getPrompt() {
168
169         return m_prompt;
170     }
171
172     /**
173      * Returns the property to store the user selection.
174      * <p>
175      *
176      * @return Returns the m_propertyName.
177      */

178     public String JavaDoc getProperty() {
179
180         return m_property;
181     }
182
183     /**
184      * Returns the title.
185      * <p>
186      *
187      * @return the title
188      */

189     public String JavaDoc getTitle() {
190
191         return m_title;
192     }
193
194     /**
195      * Initializes this task.
196      * <p>
197      */

198     public void init() {
199
200         super.init();
201         try {
202             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
203         } catch (Exception JavaDoc e) {
204             // noop
205
}
206     }
207
208     /**
209      * Returns the Single Selection flag.
210      * <p>
211      *
212      * @return the single Selection flag
213      */

214     public boolean isSingleSelection() {
215
216         return m_singleSelection;
217     }
218
219     /**
220      * Overridden to allow debugging.
221      * <p>
222      *
223      * @see org.apache.tools.ant.Task#log(java.lang.String)
224      */

225     public void log(String JavaDoc arg0) {
226
227         try {
228             super.log(arg0);
229         } catch (Exception JavaDoc ex) {
230             System.err.println(arg0);
231         }
232
233     }
234
235     /**
236      * Overridden to allow debugging.
237      * <p>
238      *
239      * @see org.apache.tools.ant.Task#log(java.lang.String, int)
240      */

241     public void log(String JavaDoc arg0, int arg1) {
242
243         try {
244             super.log(arg0, arg1);
245         } catch (Exception JavaDoc ex) {
246             System.err.println(arg0);
247         }
248     }
249
250     /**
251      * Sets the <code>{@link #LIST_SEPARATOR}</code> separated list of all available modules.
252      * <p>
253      *
254      * @param allValues all-modules list to set
255      */

256     public void setAllValues(String JavaDoc allValues) {
257
258         this.m_allValues = allValues;
259     }
260
261     /**
262      * Sets the <code>{@link #LIST_SEPARATOR}</code> separated list of pre-selected modules.
263      * <p>
264      *
265      * @param defaultValue the pre-selected module list to set
266      */

267     public void setDefaultValue(String JavaDoc defaultValue) {
268
269         this.m_defaultValue = defaultValue;
270     }
271
272     /**
273      * Sets the expansionLevels.
274      * <p>
275      *
276      * @param expansionLevels the expansionLevels to set
277      */

278     public void setExpansionLevels(int expansionLevels) {
279
280         // the mandatory "root" node is needed but invisible
281
m_expansionLevels = expansionLevels + 1;
282     }
283
284     /**
285      * Sets the prompt.
286      * <p>
287      *
288      * @param prompt the prompt to set
289      */

290     public void setPrompt(String JavaDoc prompt) {
291
292         m_prompt = prompt;
293     }
294
295     /**
296      * Sets the property for storing the selected value.
297      *
298      * @param property The property to set.
299      */

300     public void setProperty(String JavaDoc property) {
301
302         this.m_property = property;
303     }
304
305     /**
306      * Sets the single Selection flag.
307      * <p>
308      *
309      * @param singleSelection the single Selection flag to set
310      */

311     public void setSingleSelection(boolean singleSelection) {
312
313         m_singleSelection = singleSelection;
314     }
315
316     /**
317      * Sets the title.
318      * <p>
319      *
320      * @param title the title to set
321      */

322     public void setTitle(String JavaDoc title) {
323
324         m_title = title;
325     }
326
327 }
Popular Tags