001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: // <RAVE> Copy from projects/projectui/src/org/netbeans/modules/project/ui
043: package org.netbeans.modules.visualweb.project.jsf.ui;
044:
045: import java.awt.Component;
046: import java.awt.event.ActionListener;
047: import java.io.File;
048: import java.text.MessageFormat;
049: import java.util.ArrayList;
050: import java.util.Iterator;
051: import java.util.List;
052: import javax.swing.DefaultComboBoxModel;
053: import javax.swing.JLabel;
054: import javax.swing.JList;
055: import javax.swing.ListCellRenderer;
056: import javax.swing.event.ChangeEvent;
057: import javax.swing.event.ChangeListener;
058: import javax.swing.event.DocumentListener;
059: import org.netbeans.api.project.Project;
060: import org.netbeans.api.project.ProjectUtils;
061: import org.netbeans.api.project.SourceGroup;
062: import org.netbeans.api.project.Sources;
063: import org.netbeans.spi.project.support.GenericSources;
064: import org.openide.filesystems.FileObject;
065: import org.openide.filesystems.FileUtil;
066: import org.openide.loaders.DataObject;
067: import org.openide.loaders.DataObjectNotFoundException;
068: import org.openide.util.NbBundle;
069:
070: /**
071: *
072: * @author phrebejk
073: */
074: public class SimpleTargetChooserPanelGUI extends javax.swing.JPanel
075: implements ActionListener, DocumentListener {
076:
077: /** prefered dimmension of the panels */
078: private static final java.awt.Dimension PREF_DIM = new java.awt.Dimension(
079: 500, 340);
080:
081: private static final String NEW_FILE_PREFIX = NbBundle.getMessage(
082: SimpleTargetChooserPanelGUI.class,
083: "LBL_SimpleTargetChooserPanelGUI_NewFilePrefix"); // NOI18N
084:
085: private final ListCellRenderer CELL_RENDERER = new GroupCellRenderer();
086:
087: private Project project;
088: private String expectedExtension;
089: private final List/*<ChangeListener>*/listeners = new ArrayList();
090: private SourceGroup[] folders;
091: private boolean isFolder;
092:
093: /** Creates new form SimpleTargetChooserGUI */
094: public SimpleTargetChooserPanelGUI(Project project,
095: SourceGroup[] folders, Component bottomPanel,
096: boolean isFolder) {
097: this .project = project;
098: this .folders = folders;
099: this .isFolder = isFolder;
100: initComponents();
101:
102: locationComboBox.setRenderer(CELL_RENDERER);
103:
104: if (bottomPanel != null) {
105: bottomPanelContainer.add(bottomPanel,
106: java.awt.BorderLayout.CENTER);
107: }
108: initValues(null, null);
109:
110: browseButton.addActionListener(this );
111: locationComboBox.addActionListener(this );
112: documentNameTextField.getDocument().addDocumentListener(this );
113: folderTextField.getDocument().addDocumentListener(this );
114:
115: setName(NbBundle.getMessage(SimpleTargetChooserPanelGUI.class,
116: "LBL_SimpleTargetChooserPanel_Name")); // NOI18N
117: }
118:
119: public void initValues(FileObject template,
120: FileObject preselectedFolder) {
121: initValues(template, preselectedFolder, null);
122: }
123:
124: public void initValues(FileObject template,
125: FileObject preselectedFolder, String documentName) {
126: assert project != null;
127:
128: projectTextField.setText(ProjectUtils.getInformation(project)
129: .getDisplayName());
130:
131: Sources sources = ProjectUtils.getSources(project);
132:
133: folders = sources.getSourceGroups(Sources.TYPE_GENERIC);
134:
135: if (folders.length < 2) {
136: // one source group i.e. hide Location
137: locationLabel.setVisible(false);
138: locationComboBox.setVisible(false);
139: } else {
140: // more source groups user needs to select location
141: locationLabel.setVisible(true);
142: locationComboBox.setVisible(true);
143:
144: }
145:
146: locationComboBox.setModel(new DefaultComboBoxModel(folders));
147: // Guess the group we want to create the file in
148: SourceGroup preselectedGroup = getPreselectedGroup(folders,
149: preselectedFolder);
150: locationComboBox.setSelectedItem(preselectedGroup);
151: // Create OS dependent relative name
152: folderTextField.setText(getRelativeNativeName(preselectedGroup
153: .getRootFolder(), preselectedFolder));
154:
155: String ext = template == null ? "" : template.getExt(); // NOI18N
156: expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N
157:
158: String displayName = null;
159: try {
160: if (template != null) {
161: DataObject templateDo = DataObject.find(template);
162: displayName = templateDo.getNodeDelegate()
163: .getDisplayName();
164: }
165: } catch (DataObjectNotFoundException ex) {
166: displayName = template.getName();
167: }
168: putClientProperty("NewFileWizard_Title", displayName);// NOI18N
169:
170: if (template != null) {
171: if (documentName == null) {
172: documentName = NEW_FILE_PREFIX + template.getName();
173: }
174: documentNameTextField.setText(documentName);
175: documentNameTextField.selectAll();
176: }
177:
178: if (isFolder) {
179: jLabel3.setText(NbBundle.getMessage(
180: SimpleTargetChooserPanelGUI.class,
181: "LBL_TargetChooser_FolderName_Label")); // NOI18N
182: jLabel3.setDisplayedMnemonic(NbBundle.getMessage(
183: SimpleTargetChooserPanelGUI.class,
184: "MNE_TargetChooser_FolderName_Label").charAt(0)); // NOI18N
185: jLabel2.setText(NbBundle.getMessage(
186: SimpleTargetChooserPanelGUI.class,
187: "LBL_TargetChooser_ParentFolder_Label")); // NOI18N
188: jLabel2.setDisplayedMnemonic(NbBundle.getMessage(
189: SimpleTargetChooserPanelGUI.class,
190: "MNE_TargetChooser_ParentFolder_Label").charAt(0)); // NOI18N
191: jLabel4.setText(NbBundle.getMessage(
192: SimpleTargetChooserPanelGUI.class,
193: "LBL_TargetChooser_CreatedFolder_Label")); // NOI18N
194: jLabel4.setDisplayedMnemonic(NbBundle.getMessage(
195: SimpleTargetChooserPanelGUI.class,
196: "MNE_TargetChooser_CreatedFolder_Label").charAt(0)); // NOI18N
197: } else {
198: jLabel3.setText(NbBundle.getMessage(
199: SimpleTargetChooserPanelGUI.class,
200: "LBL_TargetChooser_FileName_Label")); // NOI18N
201: jLabel2.setText(NbBundle.getMessage(
202: SimpleTargetChooserPanelGUI.class,
203: "LBL_TargetChooser_Folder_Label")); // NOI18N
204: jLabel4.setText(NbBundle.getMessage(
205: SimpleTargetChooserPanelGUI.class,
206: "LBL_TargetChooser_CreatedFile_Label")); // NOI18N
207: jLabel3.setDisplayedMnemonic(NbBundle.getMessage(
208: SimpleTargetChooserPanelGUI.class,
209: "MNE_TargetChooser_FileName_Label").charAt(0)); // NOI18N
210: jLabel2.setDisplayedMnemonic(NbBundle.getMessage(
211: SimpleTargetChooserPanelGUI.class,
212: "MNE_TargetChooser_Folder_Label").charAt(0)); // NOI18N
213: jLabel4.setDisplayedMnemonic(NbBundle.getMessage(
214: SimpleTargetChooserPanelGUI.class,
215: "MNE_TargetChooser_CreatedFile_Label").charAt(0)); // NOI18N
216: }
217: }
218:
219: public SourceGroup getTargetGroup() {
220: return (SourceGroup) locationComboBox.getSelectedItem();
221: }
222:
223: public void setTargetFolder(String folder) {
224: folderTextField
225: .setText(folder.replace('/', File.separatorChar));
226: }
227:
228: public String getTargetFolder() {
229:
230: String folderName = folderTextField.getText().trim();
231:
232: if (folderName.length() == 0) {
233: return null;
234: } else {
235: return folderName.replace(File.separatorChar, '/'); // NOI18N
236: }
237: }
238:
239: public String getTargetName() {
240:
241: String text = documentNameTextField.getText().trim();
242:
243: if (text.length() == 0) {
244: return null;
245: } else {
246: return text;
247: }
248: }
249:
250: public java.awt.Dimension getPreferredSize() {
251: return PREF_DIM;
252: }
253:
254: public synchronized void addChangeListener(ChangeListener l) {
255: listeners.add(l);
256: }
257:
258: public synchronized void removeChangeListener(ChangeListener l) {
259: listeners.remove(l);
260: }
261:
262: private void fireChange() {
263: ChangeEvent e = new ChangeEvent(this );
264: List templist;
265: synchronized (this ) {
266: templist = new ArrayList(listeners);
267: }
268: Iterator it = templist.iterator();
269: while (it.hasNext()) {
270: ((ChangeListener) it.next()).stateChanged(e);
271: }
272: }
273:
274: /** This method is called from within the constructor to
275: * initialize the form.
276: * WARNING: Do NOT modify this code. The content of this method is
277: * always regenerated by the Form Editor.
278: */
279: private void initComponents() {//GEN-BEGIN:initComponents
280: java.awt.GridBagConstraints gridBagConstraints;
281:
282: jPanel1 = new javax.swing.JPanel();
283: jLabel3 = new javax.swing.JLabel();
284: documentNameTextField = new javax.swing.JTextField();
285: jLabel1 = new javax.swing.JLabel();
286: projectTextField = new javax.swing.JTextField();
287: locationLabel = new javax.swing.JLabel();
288: locationComboBox = new javax.swing.JComboBox();
289: jLabel2 = new javax.swing.JLabel();
290: folderTextField = new javax.swing.JTextField();
291: browseButton = new javax.swing.JButton();
292: jLabel4 = new javax.swing.JLabel();
293: fileTextField = new javax.swing.JTextField();
294: targetSeparator = new javax.swing.JSeparator();
295: bottomPanelContainer = new javax.swing.JPanel();
296:
297: setLayout(new java.awt.GridBagLayout());
298:
299: getAccessibleContext().setAccessibleDescription(
300: org.openide.util.NbBundle.getBundle(
301: SimpleTargetChooserPanelGUI.class).getString(
302: "AD_SimpleTargetChooserPanelGUI"));
303: jPanel1.setLayout(new java.awt.GridBagLayout());
304:
305: jLabel3.setDisplayedMnemonic(org.openide.util.NbBundle
306: .getMessage(SimpleTargetChooserPanelGUI.class,
307: "MNE_TargetChooser_FileName_Label").charAt(0));
308: jLabel3.setLabelFor(documentNameTextField);
309: jLabel3.setText(org.openide.util.NbBundle.getMessage(
310: SimpleTargetChooserPanelGUI.class,
311: "LBL_TargetChooser_FileName_Label"));
312: gridBagConstraints = new java.awt.GridBagConstraints();
313: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
314: jPanel1.add(jLabel3, gridBagConstraints);
315:
316: gridBagConstraints = new java.awt.GridBagConstraints();
317: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
318: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
319: gridBagConstraints.weightx = 1.0;
320: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
321: jPanel1.add(documentNameTextField, gridBagConstraints);
322: documentNameTextField.getAccessibleContext()
323: .setAccessibleDescription(
324: org.openide.util.NbBundle.getBundle(
325: SimpleTargetChooserPanelGUI.class)
326: .getString("AD_documentNameTextField"));
327:
328: gridBagConstraints = new java.awt.GridBagConstraints();
329: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
330: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
331: gridBagConstraints.insets = new java.awt.Insets(0, 0, 24, 0);
332: add(jPanel1, gridBagConstraints);
333:
334: jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle
335: .getMessage(SimpleTargetChooserPanelGUI.class,
336: "MNE_TargetChooser_Project_Label").charAt(0));
337: jLabel1.setText(org.openide.util.NbBundle.getMessage(
338: SimpleTargetChooserPanelGUI.class,
339: "LBL_TargetChooser_Project_Label"));
340: jLabel1.setLabelFor(projectTextField);
341: gridBagConstraints = new java.awt.GridBagConstraints();
342: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
343: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
344: add(jLabel1, gridBagConstraints);
345:
346: projectTextField.setEditable(false);
347: gridBagConstraints = new java.awt.GridBagConstraints();
348: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
349: gridBagConstraints.weightx = 1.0;
350: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
351: add(projectTextField, gridBagConstraints);
352: projectTextField.getAccessibleContext()
353: .setAccessibleDescription(
354: org.openide.util.NbBundle.getBundle(
355: SimpleTargetChooserPanelGUI.class)
356: .getString("AD_projectTextField"));
357:
358: locationLabel.setDisplayedMnemonic(org.openide.util.NbBundle
359: .getMessage(SimpleTargetChooserPanelGUI.class,
360: "MNE_TargetChooser_Location_Label").charAt(0));
361: locationLabel.setLabelFor(locationComboBox);
362: locationLabel.setText(org.openide.util.NbBundle.getMessage(
363: SimpleTargetChooserPanelGUI.class,
364: "LBL_TargetChooser_Location_Label"));
365: gridBagConstraints = new java.awt.GridBagConstraints();
366: gridBagConstraints.gridy = 2;
367: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
368: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
369: add(locationLabel, gridBagConstraints);
370:
371: gridBagConstraints = new java.awt.GridBagConstraints();
372: gridBagConstraints.gridy = 2;
373: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
374: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
375: gridBagConstraints.insets = new java.awt.Insets(0, 6, 5, 0);
376: add(locationComboBox, gridBagConstraints);
377: locationComboBox.getAccessibleContext()
378: .setAccessibleDescription(
379: org.openide.util.NbBundle.getBundle(
380: SimpleTargetChooserPanelGUI.class)
381: .getString("AD_locationComboBox"));
382:
383: jLabel2.setDisplayedMnemonic(org.openide.util.NbBundle
384: .getMessage(SimpleTargetChooserPanelGUI.class,
385: "MNE_TargetChooser_ParentFolder_Label").charAt(
386: 0));
387: jLabel2.setLabelFor(folderTextField);
388: jLabel2.setText(org.openide.util.NbBundle.getMessage(
389: SimpleTargetChooserPanelGUI.class,
390: "LBL_TargetChooser_Folder_Label"));
391: gridBagConstraints = new java.awt.GridBagConstraints();
392: gridBagConstraints.gridx = 0;
393: gridBagConstraints.gridy = 3;
394: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
395: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
396: add(jLabel2, gridBagConstraints);
397:
398: gridBagConstraints = new java.awt.GridBagConstraints();
399: gridBagConstraints.gridy = 3;
400: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
401: gridBagConstraints.weightx = 1.0;
402: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
403: add(folderTextField, gridBagConstraints);
404: folderTextField.getAccessibleContext()
405: .setAccessibleDescription(
406: org.openide.util.NbBundle.getBundle(
407: SimpleTargetChooserPanelGUI.class)
408: .getString("AD_folderTextField"));
409:
410: browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(
411: SimpleTargetChooserPanelGUI.class,
412: "MNE_TargetChooser_Browse_Button").charAt(0));
413: browseButton.setText(org.openide.util.NbBundle.getMessage(
414: SimpleTargetChooserPanelGUI.class,
415: "LBL_TargetChooser_Browse_Button"));
416: gridBagConstraints = new java.awt.GridBagConstraints();
417: gridBagConstraints.gridy = 3;
418: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
419: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
420: add(browseButton, gridBagConstraints);
421: browseButton.getAccessibleContext().setAccessibleDescription(
422: org.openide.util.NbBundle.getBundle(
423: SimpleTargetChooserPanelGUI.class).getString(
424: "AD_browseButton"));
425:
426: jLabel4.setDisplayedMnemonic(org.openide.util.NbBundle
427: .getMessage(SimpleTargetChooserPanelGUI.class,
428: "MNE_TargetChooser_CreatedFile_Label")
429: .charAt(0));
430: jLabel4.setText(org.openide.util.NbBundle.getMessage(
431: SimpleTargetChooserPanelGUI.class,
432: "LBL_TargetChooser_CreatedFile_Label"));
433: jLabel4.setLabelFor(fileTextField);
434: gridBagConstraints = new java.awt.GridBagConstraints();
435: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
436: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
437: add(jLabel4, gridBagConstraints);
438:
439: fileTextField.setEditable(false);
440: gridBagConstraints = new java.awt.GridBagConstraints();
441: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
442: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
443: gridBagConstraints.weightx = 1.0;
444: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
445: add(fileTextField, gridBagConstraints);
446: fileTextField.getAccessibleContext().setAccessibleDescription(
447: org.openide.util.NbBundle.getBundle(
448: SimpleTargetChooserPanelGUI.class).getString(
449: "AD_fileTextField"));
450:
451: gridBagConstraints = new java.awt.GridBagConstraints();
452: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
453: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
454: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
455: add(targetSeparator, gridBagConstraints);
456:
457: bottomPanelContainer.setLayout(new java.awt.BorderLayout());
458:
459: gridBagConstraints = new java.awt.GridBagConstraints();
460: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
461: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
462: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
463: gridBagConstraints.weighty = 1.0;
464: add(bottomPanelContainer, gridBagConstraints);
465:
466: }//GEN-END:initComponents
467:
468: // Variables declaration - do not modify//GEN-BEGIN:variables
469: private javax.swing.JPanel bottomPanelContainer;
470: private javax.swing.JButton browseButton;
471: private javax.swing.JTextField documentNameTextField;
472: private javax.swing.JTextField fileTextField;
473: private javax.swing.JTextField folderTextField;
474: private javax.swing.JLabel jLabel1;
475: private javax.swing.JLabel jLabel2;
476: private javax.swing.JLabel jLabel3;
477: private javax.swing.JLabel jLabel4;
478: private javax.swing.JPanel jPanel1;
479: private javax.swing.JComboBox locationComboBox;
480: private javax.swing.JLabel locationLabel;
481: private javax.swing.JTextField projectTextField;
482: private javax.swing.JSeparator targetSeparator;
483:
484: // End of variables declaration//GEN-END:variables
485:
486: private SourceGroup getPreselectedGroup(SourceGroup[] groups,
487: FileObject folder) {
488: for (int i = 0; folder != null && i < groups.length; i++) {
489: if (FileUtil.isParentOf(groups[i].getRootFolder(), folder)
490: || groups[i].getRootFolder().equals(folder)) {
491: return groups[i];
492: }
493: }
494: return groups[0];
495: }
496:
497: private String getRelativeNativeName(FileObject root,
498: FileObject folder) {
499: if (root == null) {
500: throw new NullPointerException(
501: "null root passed to getRelativeNativeName"); // NOI18N
502: }
503:
504: String path;
505:
506: if (folder == null) {
507: path = ""; // NOI18N
508: } else {
509: path = FileUtil.getRelativePath(root, folder);
510: }
511:
512: return path == null ? "" : path
513: .replace('/', File.separatorChar); // NOI18N
514: }
515:
516: private void updateCreatedFolder() {
517:
518: FileObject root = ((SourceGroup) locationComboBox
519: .getSelectedItem()).getRootFolder();
520:
521: String folderName = folderTextField.getText().trim();
522: String documentName = documentNameTextField.getText().trim();
523:
524: String createdFileName = FileUtil.getFileDisplayName(root)
525: + (folderName.startsWith("/")
526: || folderName.startsWith(File.separator) ? ""
527: : "/")
528: + // NOI18N
529: folderName
530: + (folderName.endsWith("/")
531: || folderName.endsWith(File.separator)
532: || folderName.length() == 0 ? "" : "/") + // NOI18N
533: documentName + expectedExtension;
534:
535: fileTextField.setText(createdFileName.replace('/',
536: File.separatorChar)); // NOI18N
537:
538: fireChange();
539: }
540:
541: // ActionListener implementation -------------------------------------------
542:
543: public void actionPerformed(java.awt.event.ActionEvent e) {
544: if (browseButton == e.getSource()) {
545: FileObject fo = null;
546: // Show the browse dialog
547:
548: SourceGroup group = (SourceGroup) locationComboBox
549: .getSelectedItem();
550:
551: fo = BrowseFolders.showDialog(new SourceGroup[] { group },
552: project, folderTextField.getText().replace(
553: File.separatorChar, '/')); // NOI18N
554:
555: if (fo != null && fo.isFolder()) {
556: String relPath = FileUtil.getRelativePath(group
557: .getRootFolder(), fo);
558: folderTextField.setText(relPath.replace('/',
559: File.separatorChar)); // NOI18N
560: }
561: } else if (locationComboBox == e.getSource()) {
562: updateCreatedFolder();
563: }
564: }
565:
566: // DocumentListener implementation -----------------------------------------
567:
568: public void changedUpdate(javax.swing.event.DocumentEvent e) {
569: updateCreatedFolder();
570: }
571:
572: public void insertUpdate(javax.swing.event.DocumentEvent e) {
573: updateCreatedFolder();
574: }
575:
576: public void removeUpdate(javax.swing.event.DocumentEvent e) {
577: updateCreatedFolder();
578: }
579:
580: // Rendering of the location combo box -------------------------------------
581:
582: private class GroupCellRenderer extends JLabel implements
583: ListCellRenderer {
584:
585: public GroupCellRenderer() {
586: setOpaque(true);
587: }
588:
589: public Component getListCellRendererComponent(JList list,
590: Object value, int index, boolean isSelected,
591: boolean cellHasFocus) {
592: if (value instanceof SourceGroup) {
593: SourceGroup group = (SourceGroup) value;
594: String projectDisplayName = ProjectUtils
595: .getInformation(project).getDisplayName();
596: String groupDisplayName = group.getDisplayName();
597: if (projectDisplayName.equals(groupDisplayName)) {
598: setText(groupDisplayName);
599: } else {
600: setText(MessageFormat.format(
601: PhysicalView.GroupNode.GROUP_NAME_PATTERN,
602: new Object[] { groupDisplayName,
603: projectDisplayName,
604: group.getRootFolder().getName() }));
605: /*
606: setText( MessageFormat.format(
607: NbBundle.getMessage( SimpleTargetChooserPanelGUI.class, "FMT_TargetChooser_GroupProjectNameBadge" ), // NOI18N
608: new Object[] { groupDisplayName, projectDisplayName } ) );
609: */
610: }
611:
612: setIcon(group.getIcon(false));
613: } else {
614: setText(value.toString());
615: setIcon(null);
616: }
617: if (isSelected) {
618: setBackground(list.getSelectionBackground());
619: setForeground(list.getSelectionForeground());
620: } else {
621: setBackground(list.getBackground());
622: setForeground(list.getForeground());
623:
624: }
625: return this;
626: }
627:
628: }
629: }
|