~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.java.freeform.ui;
 
43
 
 
44
import java.awt.event.ItemEvent;
 
45
import java.io.File;
 
46
import java.util.ArrayList;
 
47
import java.util.List;
 
48
import javax.swing.DefaultListModel;
 
49
import javax.swing.JFileChooser;
 
50
import javax.swing.ListSelectionModel;
 
51
import javax.swing.event.ChangeEvent;
 
52
import javax.swing.event.ChangeListener;
 
53
import javax.swing.event.DocumentEvent;
 
54
import org.netbeans.modules.ant.freeform.spi.support.Util;
 
55
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
 
56
import org.openide.filesystems.FileUtil;
 
57
import org.openide.util.HelpCtx;
 
58
import org.openide.util.NbBundle;
 
59
 
 
60
/**
 
61
 *
 
62
 * @author  David Konecny
 
63
 */
 
64
public class OutputPanel extends javax.swing.JPanel implements HelpCtx.Provider {
 
65
 
 
66
    private DefaultListModel listModel;
 
67
    private File lastChosenFile = null;
 
68
    private boolean isSeparateClasspath = true;
 
69
    private List<ProjectModel.CompilationUnitKey> compUnitsKeys;
 
70
    private boolean ignoreEvent;
 
71
    private ProjectModel model;
 
72
    
 
73
    public OutputPanel() {
 
74
        initComponents();
 
75
        jTextArea1.setBackground(getBackground());
 
76
        listModel = new DefaultListModel();
 
77
        output.setModel(listModel);
 
78
        // XXX: for now only single selection
 
79
        output.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
80
        javadoc.getDocument().addDocumentListener(new javax.swing.event.DocumentListener () {
 
81
            public void insertUpdate(DocumentEvent e) {
 
82
                update ();
 
83
            }
 
84
    
 
85
            public void removeUpdate(DocumentEvent e) {
 
86
                update ();
 
87
            }
 
88
    
 
89
            public void changedUpdate(DocumentEvent e) {
 
90
                update ();
 
91
            }
 
92
        });        
 
93
        jTextArea1.setDisabledTextColor(jLabel2.getForeground());
 
94
    }    
 
95
    
 
96
    private void update() {
 
97
        int index = sourceFolder.getSelectedIndex();
 
98
        assert index >= 0;
 
99
        ProjectModel.CompilationUnitKey key = compUnitsKeys.get(index);
 
100
        JavaProjectGenerator.JavaCompilationUnit cu = model.getCompilationUnit(key, model.isTestSourceFolder(index));
 
101
        updateCompilationUnitJavadoc(cu);
 
102
    }
 
103
 
 
104
 
 
105
    public HelpCtx getHelpCtx() {
 
106
        return new HelpCtx( OutputPanel.class );
 
107
    }
 
108
    
 
109
    private void updateControls() {
 
110
        sourceFolder.removeAllItems();
 
111
        compUnitsKeys = model.createCompilationUnitKeys();
 
112
        isSeparateClasspath = !ProjectModel.isSingleCompilationUnit(compUnitsKeys);
 
113
        List<String> names = ClasspathPanel.createComboContent(compUnitsKeys, model.getEvaluator(), model.getNBProjectFolder());
 
114
        for (String nm : names) {
 
115
            sourceFolder.addItem(nm);
 
116
        }
 
117
        if (names.size() > 0) {
 
118
            ignoreEvent = true;
 
119
            sourceFolder.setSelectedIndex(0);
 
120
            ignoreEvent = false;
 
121
        }
 
122
        
 
123
        loadOutput();        
 
124
        
 
125
        // enable/disable "Separate Classpath" checkbox
 
126
        boolean sepClasspath = model.canHaveSeparateClasspath();
 
127
        jLabel2.setEnabled(sepClasspath && isSeparateClasspath);
 
128
        sourceFolder.setEnabled(sepClasspath && isSeparateClasspath);
 
129
        
 
130
        // disable ouput panel and Add Output button if there is 
 
131
        // no compilation unit ot be configured
 
132
        addOutput.setEnabled(compUnitsKeys.size() > 0);        
 
133
        output.setEnabled(compUnitsKeys.size() > 0);
 
134
        javadoc.setEnabled(compUnitsKeys.size() > 0);
 
135
        javadocBrowse.setEnabled(compUnitsKeys.size() > 0);
 
136
        updateButtons();
 
137
    }
 
138
    
 
139
    /** This method is called from within the constructor to
 
140
     * initialize the form.
 
141
     * WARNING: Do NOT modify this code. The content of this method is
 
142
     * always regenerated by the Form Editor.
 
143
     */
 
144
    private void initComponents() {//GEN-BEGIN:initComponents
 
145
        java.awt.GridBagConstraints gridBagConstraints;
 
146
 
 
147
        jLabel2 = new javax.swing.JLabel();
 
148
        jLabel3 = new javax.swing.JLabel();
 
149
        addOutput = new javax.swing.JButton();
 
150
        removeOutput = new javax.swing.JButton();
 
151
        jScrollPane1 = new javax.swing.JScrollPane();
 
152
        output = new javax.swing.JList();
 
153
        jPanel1 = new javax.swing.JPanel();
 
154
        sourceFolder = new javax.swing.JComboBox();
 
155
        jTextArea1 = new javax.swing.JTextArea();
 
156
        jPanel2 = new javax.swing.JPanel();
 
157
        javadoc = new javax.swing.JTextField();
 
158
        javadocBrowse = new javax.swing.JButton();
 
159
        javadocLabel = new javax.swing.JLabel();
 
160
 
 
161
        setLayout(new java.awt.GridBagLayout());
 
162
 
 
163
        setPreferredSize(new java.awt.Dimension(275, 202));
 
164
        jLabel2.setLabelFor(sourceFolder);
 
165
        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(OutputPanel.class, "LBL_OutputPanel_jLabel1"));
 
166
        gridBagConstraints = new java.awt.GridBagConstraints();
 
167
        gridBagConstraints.gridx = 0;
 
168
        gridBagConstraints.gridy = 2;
 
169
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
170
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
 
171
        add(jLabel2, gridBagConstraints);
 
172
 
 
173
        jLabel3.setLabelFor(output);
 
174
        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(OutputPanel.class, "LBL_OutputPanel_jLabel3"));
 
175
        gridBagConstraints = new java.awt.GridBagConstraints();
 
176
        gridBagConstraints.gridx = 0;
 
177
        gridBagConstraints.gridy = 3;
 
178
        gridBagConstraints.gridwidth = 2;
 
179
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
180
        gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
 
181
        add(jLabel3, gridBagConstraints);
 
182
        jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(OutputPanel.class, "ACSD_OutputPanel_jLabel3"));
 
183
 
 
184
        org.openide.awt.Mnemonics.setLocalizedText(addOutput, org.openide.util.NbBundle.getMessage(OutputPanel.class, "BTN_OutputPanel_addOutput"));
 
185
        addOutput.addActionListener(new java.awt.event.ActionListener() {
 
186
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
187
                addOutputActionPerformed(evt);
 
188
            }
 
189
        });
 
190
 
 
191
        gridBagConstraints = new java.awt.GridBagConstraints();
 
192
        gridBagConstraints.gridx = 2;
 
193
        gridBagConstraints.gridy = 4;
 
194
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
 
195
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
 
196
        add(addOutput, gridBagConstraints);
 
197
        addOutput.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(OutputPanel.class, "ACSD_OutputPanel_addOutput"));
 
198
 
 
199
        org.openide.awt.Mnemonics.setLocalizedText(removeOutput, org.openide.util.NbBundle.getMessage(OutputPanel.class, "BTN_OutputPanel_removeOutput"));
 
200
        removeOutput.addActionListener(new java.awt.event.ActionListener() {
 
201
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
202
                removeOutputActionPerformed(evt);
 
203
            }
 
204
        });
 
205
 
 
206
        gridBagConstraints = new java.awt.GridBagConstraints();
 
207
        gridBagConstraints.gridx = 2;
 
208
        gridBagConstraints.gridy = 5;
 
209
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
210
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
 
211
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
 
212
        add(removeOutput, gridBagConstraints);
 
213
        removeOutput.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(OutputPanel.class, "ACSD_OutputPanel_removeOutput"));
 
214
 
 
215
        output.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
 
216
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
 
217
                outputValueChanged(evt);
 
218
            }
 
219
        });
 
220
 
 
221
        jScrollPane1.setViewportView(output);
 
222
        output.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(OutputPanel.class, "ACSD_OutputPanel_output"));
 
223
 
 
224
        gridBagConstraints = new java.awt.GridBagConstraints();
 
225
        gridBagConstraints.gridx = 0;
 
226
        gridBagConstraints.gridy = 4;
 
227
        gridBagConstraints.gridwidth = 2;
 
228
        gridBagConstraints.gridheight = 4;
 
229
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
 
230
        gridBagConstraints.weightx = 1.0;
 
231
        gridBagConstraints.weighty = 1.0;
 
232
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
 
233
        add(jScrollPane1, gridBagConstraints);
 
234
        jScrollPane1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(OutputPanel.class, "ACSD_OutputPanel_jScrollPanel1"));
 
235
 
 
236
        jPanel1.setLayout(new java.awt.GridBagLayout());
 
237
 
 
238
        sourceFolder.addItemListener(new java.awt.event.ItemListener() {
 
239
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
 
240
                sourceFolderItemStateChanged(evt);
 
241
            }
 
242
        });
 
243
 
 
244
        gridBagConstraints = new java.awt.GridBagConstraints();
 
245
        gridBagConstraints.gridx = 0;
 
246
        gridBagConstraints.gridy = 0;
 
247
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
 
248
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
249
        gridBagConstraints.weightx = 1.0;
 
250
        jPanel1.add(sourceFolder, gridBagConstraints);
 
251
        sourceFolder.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("AD_OutputPanel_sourceFolder"));
 
252
 
 
253
        gridBagConstraints = new java.awt.GridBagConstraints();
 
254
        gridBagConstraints.gridx = 1;
 
255
        gridBagConstraints.gridy = 2;
 
256
        gridBagConstraints.gridwidth = 2;
 
257
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
 
258
        add(jPanel1, gridBagConstraints);
 
259
 
 
260
        jTextArea1.setEditable(false);
 
261
        jTextArea1.setLineWrap(true);
 
262
        jTextArea1.setText(org.openide.util.NbBundle.getMessage(OutputPanel.class, "MSG_OutputPanel_jTextArea1"));
 
263
        jTextArea1.setWrapStyleWord(true);
 
264
        jTextArea1.setEnabled(false);
 
265
        gridBagConstraints = new java.awt.GridBagConstraints();
 
266
        gridBagConstraints.gridwidth = 3;
 
267
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
268
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0);
 
269
        add(jTextArea1, gridBagConstraints);
 
270
        jTextArea1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(OutputPanel.class, "ACSN_OutputPanel_jTextArea1"));
 
271
        jTextArea1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(OutputPanel.class, "ACSD_OutputPanel_jTextArea1"));
 
272
 
 
273
        jPanel2.setLayout(new java.awt.GridBagLayout());
 
274
 
 
275
        gridBagConstraints = new java.awt.GridBagConstraints();
 
276
        gridBagConstraints.gridx = 1;
 
277
        gridBagConstraints.gridy = 0;
 
278
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
279
        gridBagConstraints.weightx = 1.0;
 
280
        gridBagConstraints.weighty = 1.0;
 
281
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
 
282
        jPanel2.add(javadoc, gridBagConstraints);
 
283
        javadoc.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("AD_OutputPanel_javadoc"));
 
284
 
 
285
        org.openide.awt.Mnemonics.setLocalizedText(javadocBrowse, org.openide.util.NbBundle.getMessage(OutputPanel.class, "BTN_OutputPanel_browseJavadoc"));
 
286
        javadocBrowse.addActionListener(new java.awt.event.ActionListener() {
 
287
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
288
                javadocBrowseActionPerformed(evt);
 
289
            }
 
290
        });
 
291
 
 
292
        gridBagConstraints = new java.awt.GridBagConstraints();
 
293
        gridBagConstraints.gridx = 2;
 
294
        gridBagConstraints.gridy = 0;
 
295
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
296
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
 
297
        jPanel2.add(javadocBrowse, gridBagConstraints);
 
298
        javadocBrowse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("AD_OutputPanel_javadocBrowse"));
 
299
 
 
300
        javadocLabel.setLabelFor(javadoc);
 
301
        org.openide.awt.Mnemonics.setLocalizedText(javadocLabel, org.openide.util.NbBundle.getMessage(OutputPanel.class, "LBL_OutputPanel_JavadocLabel"));
 
302
        gridBagConstraints = new java.awt.GridBagConstraints();
 
303
        gridBagConstraints.gridx = 0;
 
304
        gridBagConstraints.gridy = 0;
 
305
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
306
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
 
307
        jPanel2.add(javadocLabel, gridBagConstraints);
 
308
 
 
309
        gridBagConstraints = new java.awt.GridBagConstraints();
 
310
        gridBagConstraints.gridx = 0;
 
311
        gridBagConstraints.gridy = 8;
 
312
        gridBagConstraints.gridwidth = 3;
 
313
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
314
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
 
315
        gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
 
316
        add(jPanel2, gridBagConstraints);
 
317
 
 
318
    }//GEN-END:initComponents
 
319
 
 
320
    private void javadocBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javadocBrowseActionPerformed
 
321
        JFileChooser chooser = new JFileChooser();
 
322
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
 
323
        chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
 
324
        chooser.setMultiSelectionEnabled(false);
 
325
        if (lastChosenFile != null) {
 
326
            chooser.setSelectedFile(lastChosenFile);
 
327
        } else if (javadoc.getText().length() > 0) {
 
328
            chooser.setSelectedFile(new File(javadoc.getText()));
 
329
        } else {
 
330
            File files[] = model.getBaseFolder().listFiles();
 
331
            if (files != null && files.length > 0) {
 
332
                chooser.setSelectedFile(files[0]);
 
333
            } else {
 
334
                chooser.setSelectedFile(model.getBaseFolder());
 
335
            }
 
336
        }
 
337
        chooser.setDialogTitle(NbBundle.getMessage(OutputPanel.class, "LBL_Browse_Javadoc")); // NOI18N
 
338
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
 
339
            File file = chooser.getSelectedFile();
 
340
            file = FileUtil.normalizeFile(file);
 
341
            javadoc.setText(file.getAbsolutePath());
 
342
            lastChosenFile = file;
 
343
        }
 
344
    }//GEN-LAST:event_javadocBrowseActionPerformed
 
345
 
 
346
    private void outputValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_outputValueChanged
 
347
        updateButtons();
 
348
    }//GEN-LAST:event_outputValueChanged
 
349
 
 
350
    private void sourceFolderItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sourceFolderItemStateChanged
 
351
        if (ignoreEvent) {
 
352
            return;
 
353
        }
 
354
        if (evt.getStateChange() == ItemEvent.DESELECTED) {
 
355
            int index = findIndex(evt.getItem());
 
356
            // if index == -1 then item was removed and will not be saved
 
357
            if (index != -1) {
 
358
                saveOutput(index);
 
359
            }
 
360
        } else {
 
361
            loadOutput();
 
362
        }
 
363
    }//GEN-LAST:event_sourceFolderItemStateChanged
 
364
 
 
365
    private int findIndex(Object o) {
 
366
        for (int i=0; i<sourceFolder.getModel().getSize(); i++) {
 
367
            if (sourceFolder.getModel().getElementAt(i).equals(o)) {
 
368
                return i;
 
369
            }
 
370
        }
 
371
        return -1;
 
372
    }
 
373
    
 
374
    /** Source package combo is changing - take output from the listbox and
 
375
     * store it in compilaiton unit identified by the index.*/
 
376
    private void saveOutput(int index) {
 
377
        ProjectModel.CompilationUnitKey key = compUnitsKeys.get(index);
 
378
        JavaProjectGenerator.JavaCompilationUnit cu = model.getCompilationUnit(key, model.isTestSourceFolder(index));
 
379
        updateCompilationUnitOutput(cu);
 
380
        updateCompilationUnitJavadoc(cu);
 
381
    }
 
382
 
 
383
    /** Source package has changes - find current source package and read its compilation unit and
 
384
     * update classpath listbox with it.*/
 
385
    private void loadOutput() {
 
386
        int index;
 
387
        if (isSeparateClasspath) {
 
388
            index = sourceFolder.getSelectedIndex();
 
389
            if (index == -1) {
 
390
                return;
 
391
            }
 
392
        } else {
 
393
            index = 0;
 
394
        }
 
395
        ProjectModel.CompilationUnitKey key = compUnitsKeys.get(index);
 
396
        JavaProjectGenerator.JavaCompilationUnit cu = model.getCompilationUnit(key, model.isTestSourceFolder(index));
 
397
        updateJListOutput(cu.output);
 
398
        updateJavadocField(cu.javadoc);
 
399
    }
 
400
    
 
401
    private void updateJavadocField(List<String> jd) {
 
402
        String value = "";
 
403
        boolean enabled = true;
 
404
        if (jd != null) {
 
405
            if (jd.size() > 1) {
 
406
                value = getListAsString(jd);
 
407
                enabled = false;
 
408
            } else if (jd.size() == 1) {
 
409
                File f = Util.resolveFile(model.getEvaluator(), model.getNBProjectFolder(), jd.get(0));
 
410
                if (f != null) {
 
411
                    value = f.getAbsolutePath();
 
412
                }
 
413
            }
 
414
        }
 
415
        javadoc.setEnabled(enabled);
 
416
        javadocBrowse.setEnabled(enabled);
 
417
        javadoc.setText(value);
 
418
    }
 
419
    
 
420
    private String getListAsString(List<String> list) {
 
421
        assert list != null;
 
422
        StringBuffer sb = new StringBuffer();
 
423
        for (String s : list) {
 
424
            File f = Util.resolveFile(model.getEvaluator(), model.getNBProjectFolder(), s);
 
425
            if (f != null) {
 
426
                if (sb.length()>0) {
 
427
                    sb.append(", "); // NOI18N
 
428
                }
 
429
                sb.append(f.getAbsolutePath());
 
430
            }            
 
431
        }
 
432
        return sb.toString();
 
433
    }
 
434
    
 
435
    private void updateCompilationUnitJavadoc(JavaProjectGenerator.JavaCompilationUnit cu) {
 
436
        if (javadoc.isEnabled()) {
 
437
            if (javadoc.getText().length() > 0) {
 
438
                cu.javadoc = new ArrayList<String>();
 
439
                for (String part : javadoc.getText().split(",")) {
 
440
                    File f = FileUtil.normalizeFile(new File(part.trim()));
 
441
                    String path = Util.relativizeLocation(model.getBaseFolder(), model.getNBProjectFolder(), f);
 
442
                    cu.javadoc.add (path);
 
443
                }                
 
444
            } else {
 
445
                cu.javadoc = null;
 
446
            }
 
447
        }
 
448
    }
 
449
 
 
450
    /** Read content of list box and update compilation unit's output.*/
 
451
    private void updateCompilationUnitOutput(JavaProjectGenerator.JavaCompilationUnit cu) {
 
452
        if (output.getModel().getSize() == 0) {
 
453
            cu.output = null;
 
454
            return;
 
455
        }
 
456
        List<String> l = new ArrayList<String>();
 
457
        for (int i=0; i<output.getModel().getSize(); i++) {
 
458
            File f = new File((String)output.getModel().getElementAt(i));
 
459
            String path = Util.relativizeLocation(model.getBaseFolder(), model.getNBProjectFolder(), f);
 
460
            l.add(path);
 
461
        }
 
462
        cu.output = l;
 
463
    }
 
464
 
 
465
    /** Update panel's listbox with given output list. */
 
466
    private void updateJListOutput(List<String> l) {
 
467
        listModel.removeAllElements();
 
468
        if (l != null) {
 
469
            for (String out : l) {
 
470
                File f = Util.resolveFile(model.getEvaluator(), model.getNBProjectFolder(), out);
 
471
                if (f != null) {
 
472
                    listModel.addElement(f.getAbsolutePath());
 
473
                }
 
474
            }
 
475
        }
 
476
        updateButtons();
 
477
    }
 
478
    
 
479
    private void updateButtons() {
 
480
        removeOutput.setEnabled(output.isEnabled() && listModel.getSize() > 0 && output.getSelectedIndex() != -1);
 
481
    }
 
482
    
 
483
    private void removeOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeOutputActionPerformed
 
484
        int i = output.getSelectedIndex();
 
485
        if (i != -1) {
 
486
            listModel.remove(i);
 
487
        }
 
488
        applyChanges();
 
489
        updateButtons();        
 
490
    }//GEN-LAST:event_removeOutputActionPerformed
 
491
 
 
492
    private void addOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOutputActionPerformed
 
493
        JFileChooser chooser = new JFileChooser();
 
494
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
 
495
        chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
 
496
        chooser.setMultiSelectionEnabled(true);
 
497
        if (lastChosenFile != null) {
 
498
            chooser.setSelectedFile(lastChosenFile);
 
499
        } else {
 
500
            File files[] = model.getBaseFolder().listFiles();
 
501
            if (files != null && files.length > 0) {
 
502
                chooser.setSelectedFile(files[0]);
 
503
            } else {
 
504
                chooser.setSelectedFile(model.getBaseFolder());
 
505
            }
 
506
        }
 
507
        chooser.setDialogTitle(NbBundle.getMessage(OutputPanel.class, "LBL_Browse_Output")); // NOI18N
 
508
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
 
509
            for (File file : chooser.getSelectedFiles()) {
 
510
                file = FileUtil.normalizeFile(file);
 
511
                listModel.addElement(file.getAbsolutePath());
 
512
                lastChosenFile = file;
 
513
            }
 
514
            applyChanges();
 
515
            updateButtons();
 
516
        }
 
517
    }//GEN-LAST:event_addOutputActionPerformed
 
518
 
 
519
    private void applyChanges() {
 
520
        if (isSeparateClasspath) {
 
521
            if (sourceFolder.getSelectedIndex() != -1) {
 
522
                saveOutput(sourceFolder.getSelectedIndex());
 
523
            }
 
524
        } else {
 
525
            saveOutput(0);
 
526
        }
 
527
    }
 
528
    
 
529
    void setModel(ProjectModel model) {
 
530
        this.model = model;
 
531
        updateControls();
 
532
        model.addChangeListener(new ChangeListener() {
 
533
            public void stateChanged(ChangeEvent arg0) {
 
534
                updateControls();
 
535
            }
 
536
        });
 
537
    }
 
538
 
 
539
    
 
540
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
541
    private javax.swing.JButton addOutput;
 
542
    private javax.swing.JLabel jLabel2;
 
543
    private javax.swing.JLabel jLabel3;
 
544
    private javax.swing.JPanel jPanel1;
 
545
    private javax.swing.JPanel jPanel2;
 
546
    private javax.swing.JScrollPane jScrollPane1;
 
547
    private javax.swing.JTextArea jTextArea1;
 
548
    private javax.swing.JTextField javadoc;
 
549
    private javax.swing.JButton javadocBrowse;
 
550
    private javax.swing.JLabel javadocLabel;
 
551
    private javax.swing.JList output;
 
552
    private javax.swing.JButton removeOutput;
 
553
    private javax.swing.JComboBox sourceFolder;
 
554
    // End of variables declaration//GEN-END:variables
 
555
    
 
556
}