KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > railsprojects > ui > customizer > CustomizerRun


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ruby.railsprojects.ui.customizer;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.awt.event.MouseEvent JavaDoc;
28 import java.io.File JavaDoc;
29 import java.text.Collator JavaDoc;
30 import java.util.Comparator JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.SortedSet JavaDoc;
35 import java.util.TreeSet JavaDoc;
36 import javax.swing.DefaultComboBoxModel JavaDoc;
37 import javax.swing.DefaultListCellRenderer JavaDoc;
38 import javax.swing.JButton JavaDoc;
39 import javax.swing.JFileChooser JavaDoc;
40 import javax.swing.JLabel JavaDoc;
41 import javax.swing.JList JavaDoc;
42 import javax.swing.JPanel JavaDoc;
43 import javax.swing.JTextField JavaDoc;
44 import javax.swing.event.ChangeEvent JavaDoc;
45 import javax.swing.event.ChangeListener JavaDoc;
46 import javax.swing.event.DocumentEvent JavaDoc;
47 import javax.swing.event.DocumentListener JavaDoc;
48 import org.netbeans.modules.ruby.railsprojects.RailsProject;
49 import org.netbeans.modules.ruby.railsprojects.SourceRoots;
50 import org.openide.DialogDescriptor;
51 import org.openide.DialogDisplayer;
52 import org.openide.NotifyDescriptor;
53 import org.openide.awt.MouseUtils;
54 import org.openide.filesystems.FileUtil;
55 import org.openide.util.HelpCtx;
56 import org.openide.util.NbBundle;
57 import org.openide.util.Utilities;
58
59 public class CustomizerRun extends JPanel JavaDoc implements HelpCtx.Provider {
60     
61     private RailsProject project;
62     
63     private JTextField JavaDoc[] data;
64     private JLabel JavaDoc[] dataLabels;
65     private String JavaDoc[] keys;
66     private Map JavaDoc<String JavaDoc/*|null*/,Map JavaDoc<String JavaDoc,String JavaDoc/*|null*/>/*|null*/> configs;
67     RailsProjectProperties uiProperties;
68     
69     public CustomizerRun( RailsProjectProperties uiProperties ) {
70         this.uiProperties = uiProperties;
71         initComponents();
72
73         this.project = uiProperties.getProject();
74         
75         configs = uiProperties.RUN_CONFIGS;
76         
77         data = new JTextField JavaDoc[] {
78             jTextFieldMainClass,
79             jTextFieldArgs,
80             jTextVMOptions,
81             jTextWorkingDirectory,
82         };
83         dataLabels = new JLabel JavaDoc[] {
84             jLabelMainClass,
85             jLabelArgs,
86             jLabelVMOptions,
87             jLabelWorkingDirectory,
88         };
89         keys = new String JavaDoc[] {
90             RailsProjectProperties.MAIN_CLASS,
91             RailsProjectProperties.APPLICATION_ARGS,
92             RailsProjectProperties.RUN_JVM_ARGS,
93             RailsProjectProperties.RUN_WORK_DIR,
94         };
95         assert data.length == keys.length;
96         
97         configChanged(uiProperties.activeConfig);
98         
99         configCombo.setRenderer(new DefaultListCellRenderer JavaDoc() {
100             public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
101                 String JavaDoc config = (String JavaDoc) value;
102                 String JavaDoc label;
103                 if (config == null) {
104                     // uninitialized?
105
label = null;
106                 } else if (config.length() > 0) {
107                     Map JavaDoc<String JavaDoc,String JavaDoc> m = configs.get(config);
108                     label = m != null ? m.get("$label") : /* temporary? */ null;
109                     if (label == null) {
110                         label = config;
111                     }
112                 } else {
113                     label = NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.default");
114                 }
115                 return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
116             }
117         });
118         
119         for (int i = 0; i < data.length; i++) {
120             final JTextField JavaDoc field = data[i];
121             final String JavaDoc prop = keys[i];
122             final JLabel JavaDoc label = dataLabels[i];
123             field.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
124                 Font JavaDoc basefont = label.getFont();
125                 Font JavaDoc boldfont = basefont.deriveFont(Font.BOLD);
126                 {
127                     updateFont();
128                 }
129                 public void insertUpdate(DocumentEvent JavaDoc e) {
130                     changed();
131                 }
132                 public void removeUpdate(DocumentEvent JavaDoc e) {
133                     changed();
134                 }
135                 public void changedUpdate(DocumentEvent JavaDoc e) {}
136                 void changed() {
137                     String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
138                     if (config.length() == 0) {
139                         config = null;
140                     }
141                     String JavaDoc v = field.getText();
142                     if (v != null && config != null && v.equals(configs.get(null).get(prop))) {
143                         // default value, do not store as such
144
v = null;
145                     }
146                     configs.get(config).put(prop, v);
147                     updateFont();
148                 }
149                 void updateFont() {
150                     String JavaDoc v = field.getText();
151                     String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
152                     if (config.length() == 0) {
153                         config = null;
154                     }
155                     String JavaDoc def = configs.get(null).get(prop);
156                     label.setFont(config != null && !Utilities.compareObjects(v != null ? v : "", def != null ? def : "") ? boldfont : basefont);
157                 }
158             });
159         }
160     }
161         
162     public HelpCtx getHelpCtx() {
163         return new HelpCtx( CustomizerRun.class );
164     }
165     
166     /** This method is called from within the constructor to
167      * initialize the form.
168      * WARNING: Do NOT modify this code. The content of this method is
169      * always regenerated by the Form Editor.
170      */

171     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
172
private void initComponents() {
173         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
174
175         configSep = new javax.swing.JSeparator JavaDoc();
176         configPanel = new javax.swing.JPanel JavaDoc();
177         configLabel = new javax.swing.JLabel JavaDoc();
178         configCombo = new javax.swing.JComboBox JavaDoc();
179         configNew = new javax.swing.JButton JavaDoc();
180         configDel = new javax.swing.JButton JavaDoc();
181         mainPanel = new javax.swing.JPanel JavaDoc();
182         jLabelMainClass = new javax.swing.JLabel JavaDoc();
183         jTextFieldMainClass = new javax.swing.JTextField JavaDoc();
184         jButtonMainClass = new javax.swing.JButton JavaDoc();
185         jLabelArgs = new javax.swing.JLabel JavaDoc();
186         jTextFieldArgs = new javax.swing.JTextField JavaDoc();
187         jLabelWorkingDirectory = new javax.swing.JLabel JavaDoc();
188         jTextWorkingDirectory = new javax.swing.JTextField JavaDoc();
189         jButtonWorkingDirectoryBrowse = new javax.swing.JButton JavaDoc();
190         jLabelVMOptions = new javax.swing.JLabel JavaDoc();
191         jTextVMOptions = new javax.swing.JTextField JavaDoc();
192         jLabelVMOptionsExample = new javax.swing.JLabel JavaDoc();
193
194         setLayout(new java.awt.GridBagLayout JavaDoc());
195         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
196         gridBagConstraints.gridx = 0;
197         gridBagConstraints.gridy = 1;
198         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
199         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
200         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
201         add(configSep, gridBagConstraints);
202
203         configPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
204
205         configLabel.setLabelFor(configCombo);
206         org.openide.awt.Mnemonics.setLocalizedText(configLabel, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.configLabel")); // NOI18N
207
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
208         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
209         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 2, 0);
210         configPanel.add(configLabel, gridBagConstraints);
211
212         configCombo.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "<default>" }));
213         configCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
214             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
215                 configComboActionPerformed(evt);
216             }
217         });
218         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
219         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
220         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
221         gridBagConstraints.weightx = 1.0;
222         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 6, 2, 0);
223         configPanel.add(configCombo, gridBagConstraints);
224
225         org.openide.awt.Mnemonics.setLocalizedText(configNew, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.configNew")); // NOI18N
226
configNew.addActionListener(new java.awt.event.ActionListener JavaDoc() {
227             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
228                 configNewActionPerformed(evt);
229             }
230         });
231         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
232         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
233         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 6, 2, 0);
234         configPanel.add(configNew, gridBagConstraints);
235
236         org.openide.awt.Mnemonics.setLocalizedText(configDel, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.configDelete")); // NOI18N
237
configDel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
238             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
239                 configDelActionPerformed(evt);
240             }
241         });
242         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
243         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
244         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 6, 2, 0);
245         configPanel.add(configDel, gridBagConstraints);
246
247         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
248         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
249         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
250         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
251         add(configPanel, gridBagConstraints);
252
253         mainPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
254
255         jLabelMainClass.setLabelFor(jTextFieldMainClass);
256         org.openide.awt.Mnemonics.setLocalizedText(jLabelMainClass, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_MainClass_JLabel")); // NOI18N
257
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
258         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
259         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
260         mainPanel.add(jLabelMainClass, gridBagConstraints);
261         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
262         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
263         gridBagConstraints.weightx = 1.0;
264         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
265         mainPanel.add(jTextFieldMainClass, gridBagConstraints);
266         jTextFieldMainClass.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jTextFieldMainClass")); // NOI18N
267

268         org.openide.awt.Mnemonics.setLocalizedText(jButtonMainClass, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_MainClass_JButton")); // NOI18N
269
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
270         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
271         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
272         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
273         mainPanel.add(jButtonMainClass, gridBagConstraints);
274         jButtonMainClass.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jButtonMainClass")); // NOI18N
275

276         jLabelArgs.setLabelFor(jTextFieldArgs);
277         org.openide.awt.Mnemonics.setLocalizedText(jLabelArgs, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Args_JLabel")); // NOI18N
278
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
279         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
280         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
281         mainPanel.add(jLabelArgs, gridBagConstraints);
282         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
283         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
284         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
285         gridBagConstraints.weightx = 1.0;
286         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 0);
287         mainPanel.add(jTextFieldArgs, gridBagConstraints);
288         jTextFieldArgs.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jTextFieldArgs")); // NOI18N
289

290         jLabelWorkingDirectory.setLabelFor(jTextWorkingDirectory);
291         org.openide.awt.Mnemonics.setLocalizedText(jLabelWorkingDirectory, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory")); // NOI18N
292
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
293         gridBagConstraints.gridy = 2;
294         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
295         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
296         mainPanel.add(jLabelWorkingDirectory, gridBagConstraints);
297         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
298         gridBagConstraints.gridy = 2;
299         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
300         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
301         gridBagConstraints.weightx = 1.0;
302         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
303         mainPanel.add(jTextWorkingDirectory, gridBagConstraints);
304         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/ruby/railsprojects/ui/customizer/Bundle"); // NOI18N
305
jTextWorkingDirectory.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_Working_Directory")); // NOI18N
306

307         org.openide.awt.Mnemonics.setLocalizedText(jButtonWorkingDirectoryBrowse, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse")); // NOI18N
308
jButtonWorkingDirectoryBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
309             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
310                 jButtonWorkingDirectoryBrowseActionPerformed(evt);
311             }
312         });
313         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
314         gridBagConstraints.gridy = 2;
315         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
316         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
317         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
318         mainPanel.add(jButtonWorkingDirectoryBrowse, gridBagConstraints);
319         jButtonWorkingDirectoryBrowse.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_Working_Directory_Browse")); // NOI18N
320

321         jLabelVMOptions.setLabelFor(jTextVMOptions);
322         org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptions, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options")); // NOI18N
323
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
324         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
325         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
326         mainPanel.add(jLabelVMOptions, gridBagConstraints);
327         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
328         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
329         gridBagConstraints.weightx = 1.0;
330         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
331         mainPanel.add(jTextVMOptions, gridBagConstraints);
332         jTextVMOptions.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_VM_Options")); // NOI18N
333

334         jLabelVMOptionsExample.setLabelFor(jTextFieldMainClass);
335         org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptionsExample, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options_Example")); // NOI18N
336
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
337         gridBagConstraints.gridx = 1;
338         gridBagConstraints.gridy = 4;
339         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
340         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
341         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
342         gridBagConstraints.weighty = 1.0;
343         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 0);
344         mainPanel.add(jLabelVMOptionsExample, gridBagConstraints);
345         jLabelVMOptionsExample.getAccessibleContext().setAccessibleDescription(bundle.getString("LBL_CustomizeRun_Run_VM_Options_Example")); // NOI18N
346

347         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
348         gridBagConstraints.gridx = 0;
349         gridBagConstraints.gridy = 2;
350         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
351         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
352         gridBagConstraints.weightx = 1.0;
353         gridBagConstraints.weighty = 1.0;
354         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
355         add(mainPanel, gridBagConstraints);
356     }// </editor-fold>//GEN-END:initComponents
357

358     private void configDelActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_configDelActionPerformed
359
String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
360         assert config != null;
361         configs.put(config, null);
362         configChanged(null);
363         uiProperties.activeConfig = null;
364     }//GEN-LAST:event_configDelActionPerformed
365

366     private void configNewActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_configNewActionPerformed
367
NotifyDescriptor.InputLine d = new NotifyDescriptor.InputLine(
368                 NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.input.prompt"),
369                 NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.input.title"));
370         if (DialogDisplayer.getDefault().notify(d) != NotifyDescriptor.OK_OPTION) {
371             return;
372         }
373         String JavaDoc name = d.getInputText();
374         String JavaDoc config = name.replaceAll("[^a-zA-Z0-9_.-]", "_"); // NOI18N
375
if (configs.get(config) != null) {
376             DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
377                     NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.input.duplicate", config),
378                     NotifyDescriptor.WARNING_MESSAGE));
379             return;
380         }
381         Map JavaDoc<String JavaDoc,String JavaDoc> m = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
382         if (!name.equals(config)) {
383             m.put("$label", name); // NOI18N
384
}
385         configs.put(config, m);
386         configChanged(config);
387         uiProperties.activeConfig = config;
388     }//GEN-LAST:event_configNewActionPerformed
389

390     private void configComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_configComboActionPerformed
391
String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
392         if (config.length() == 0) {
393             config = null;
394         }
395         configChanged(config);
396         uiProperties.activeConfig = config;
397     }//GEN-LAST:event_configComboActionPerformed
398

399     private void jButtonWorkingDirectoryBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed
400
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
401         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
402         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
403         chooser.setMultiSelectionEnabled(false);
404         
405         String JavaDoc workDir = jTextWorkingDirectory.getText();
406         if (workDir.equals("")) {
407             workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
408         }
409         chooser.setSelectedFile(new File JavaDoc(workDir));
410         chooser.setDialogTitle(NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title"));
411         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
412
File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
413             jTextWorkingDirectory.setText(file.getAbsolutePath());
414         }
415     }//GEN-LAST:event_jButtonWorkingDirectoryBrowseActionPerformed
416

417     private void configChanged(String JavaDoc activeConfig) {
418         DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc();
419         model.addElement("");
420         SortedSet JavaDoc<String JavaDoc> alphaConfigs = new TreeSet JavaDoc<String JavaDoc>(new Comparator JavaDoc<String JavaDoc>() {
421             Collator JavaDoc coll = Collator.getInstance();
422             public int compare(String JavaDoc s1, String JavaDoc s2) {
423                 return coll.compare(label(s1), label(s2));
424             }
425             private String JavaDoc label(String JavaDoc c) {
426                 Map JavaDoc<String JavaDoc,String JavaDoc> m = configs.get(c);
427                 String JavaDoc label = m.get("$label"); // NOI18N
428
return label != null ? label : c;
429             }
430         });
431         for (Map.Entry JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>> entry : configs.entrySet()) {
432             String JavaDoc config = entry.getKey();
433             if (config != null && entry.getValue() != null) {
434                 alphaConfigs.add(config);
435             }
436         }
437         for (String JavaDoc c : alphaConfigs) {
438             model.addElement(c);
439         }
440         configCombo.setModel(model);
441         configCombo.setSelectedItem(activeConfig != null ? activeConfig : "");
442         Map JavaDoc<String JavaDoc,String JavaDoc> m = configs.get(activeConfig);
443         Map JavaDoc<String JavaDoc,String JavaDoc> def = configs.get(null);
444         if (m != null) {
445             for (int i = 0; i < data.length; i++) {
446                 String JavaDoc v = m.get(keys[i]);
447                 if (v == null) {
448                     // display default value
449
v = def.get(keys[i]);
450                 }
451                 data[i].setText(v);
452             }
453         } // else ??
454
configDel.setEnabled(activeConfig != null);
455     }
456     
457     
458     // Variables declaration - do not modify//GEN-BEGIN:variables
459
private javax.swing.JComboBox JavaDoc configCombo;
460     private javax.swing.JButton JavaDoc configDel;
461     private javax.swing.JLabel JavaDoc configLabel;
462     private javax.swing.JButton JavaDoc configNew;
463     private javax.swing.JPanel JavaDoc configPanel;
464     private javax.swing.JSeparator JavaDoc configSep;
465     private javax.swing.JButton JavaDoc jButtonMainClass;
466     private javax.swing.JButton JavaDoc jButtonWorkingDirectoryBrowse;
467     private javax.swing.JLabel JavaDoc jLabelArgs;
468     private javax.swing.JLabel JavaDoc jLabelMainClass;
469     private javax.swing.JLabel JavaDoc jLabelVMOptions;
470     private javax.swing.JLabel JavaDoc jLabelVMOptionsExample;
471     private javax.swing.JLabel JavaDoc jLabelWorkingDirectory;
472     private javax.swing.JTextField JavaDoc jTextFieldArgs;
473     private javax.swing.JTextField JavaDoc jTextFieldMainClass;
474     private javax.swing.JTextField JavaDoc jTextVMOptions;
475     private javax.swing.JTextField JavaDoc jTextWorkingDirectory;
476     private javax.swing.JPanel JavaDoc mainPanel;
477     // End of variables declaration//GEN-END:variables
478

479     
480 }
481
Popular Tags