KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > 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.rubyproject.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.rubyproject.RubyProject;
49 import org.netbeans.modules.ruby.rubyproject.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 RubyProject 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     RubyProjectProperties uiProperties;
68     
69     public CustomizerRun( RubyProjectProperties 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             RubyProjectProperties.MAIN_CLASS,
91             RubyProjectProperties.APPLICATION_ARGS,
92             RubyProjectProperties.RUN_JVM_ARGS,
93             RubyProjectProperties.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         jButtonMainClass.addActionListener( new MainClassListener( project.getSourceRoots(), jTextFieldMainClass ) );
162     }
163         
164     public HelpCtx getHelpCtx() {
165         return new HelpCtx( CustomizerRun.class );
166     }
167     
168     /** This method is called from within the constructor to
169      * initialize the form.
170      * WARNING: Do NOT modify this code. The content of this method is
171      * always regenerated by the Form Editor.
172      */

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

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

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

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

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

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

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

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

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

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

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

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

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

481     
482     // Innercasses -------------------------------------------------------------------------
483

484     private class MainClassListener implements ActionListener JavaDoc /*, DocumentListener */ {
485         
486         private final JButton JavaDoc okButton;
487         private SourceRoots sourceRoots;
488         private JTextField JavaDoc mainClassTextField;
489         
490         MainClassListener( SourceRoots sourceRoots, JTextField JavaDoc mainClassTextField ) {
491             this.sourceRoots = sourceRoots;
492             this.mainClassTextField = mainClassTextField;
493             this.okButton = new JButton JavaDoc (NbBundle.getMessage (CustomizerRun.class, "LBL_ChooseMainClass_OK"));
494             this.okButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage (CustomizerRun.class, "AD_ChooseMainClass_OK"));
495         }
496         
497         // Implementation of ActionListener ------------------------------------
498

499         /** Handles button events
500          */

501         public void actionPerformed( ActionEvent JavaDoc e ) {
502             
503             // only chooseMainClassButton can be performed
504

505             final MainClassChooser panel = new MainClassChooser (sourceRoots.getRoots());
506             Object JavaDoc[] options = new Object JavaDoc[] {
507                 okButton,
508                 DialogDescriptor.CANCEL_OPTION
509             };
510             panel.addChangeListener (new ChangeListener JavaDoc () {
511                public void stateChanged(ChangeEvent JavaDoc e) {
512                    if (e.getSource () instanceof MouseEvent JavaDoc && MouseUtils.isDoubleClick (((MouseEvent JavaDoc)e.getSource ()))) {
513                        // click button and finish the dialog with selected class
514
okButton.doClick ();
515                    } else {
516                        okButton.setEnabled (panel.getSelectedMainClass () != null);
517                    }
518                }
519             });
520             okButton.setEnabled (false);
521             DialogDescriptor desc = new DialogDescriptor (
522                 panel,
523                 NbBundle.getMessage (CustomizerRun.class, "LBL_ChooseMainClass_Title" ),
524                 true,
525                 options,
526                 options[0],
527                 DialogDescriptor.BOTTOM_ALIGN,
528                 null,
529                 null);
530             //desc.setMessageType (DialogDescriptor.INFORMATION_MESSAGE);
531
Dialog JavaDoc dlg = DialogDisplayer.getDefault ().createDialog (desc);
532             dlg.setVisible (true);
533             if (desc.getValue() == options[0]) {
534                mainClassTextField.setText (panel.getSelectedMainClass ());
535             }
536             dlg.dispose();
537         }
538         
539     }
540     
541 }
542
Popular Tags