001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
004: */
005:
006: package org.netbeans.modules.etl.ui.view.wizards;
007:
008: import org.netbeans.api.project.Project;
009: import org.netbeans.api.project.ProjectUtils;
010: import org.netbeans.api.project.SourceGroup;
011: import org.netbeans.api.project.Sources;
012:
013: import org.openide.filesystems.FileObject;
014: import org.openide.filesystems.FileUtil;
015:
016: import org.openide.loaders.DataObject;
017: import org.openide.loaders.DataObjectNotFoundException;
018: import java.awt.Component;
019: import java.awt.event.ActionListener;
020:
021: import java.io.File;
022:
023: import java.text.MessageFormat;
024:
025: import java.util.ArrayList;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: import javax.swing.DefaultComboBoxModel;
030: import javax.swing.JLabel;
031: import javax.swing.JList;
032: import javax.swing.ListCellRenderer;
033: import javax.swing.event.ChangeEvent;
034: import javax.swing.event.ChangeListener;
035: import javax.swing.event.DocumentListener;
036: import net.java.hulp.i18n.Logger;
037: import org.netbeans.modules.etl.logger.Localizer;
038: import org.netbeans.modules.etl.logger.LogUtil;
039:
040: /**
041: * DOCUMENT ME!
042: *
043: * @author phrebejk
044: */
045: public class SimpleTargetChooserPanelGUI extends javax.swing.JPanel
046: implements ActionListener, DocumentListener {
047: /** prefered dimmension of the panels */
048: private static final java.awt.Dimension PREF_DIM = new java.awt.Dimension(
049: 500, 340);
050: String nbBundle20 = mLoc.t("PRSR001: new");
051: String nbBundle28 = mLoc.t("PRSR001: Browse...");
052: private final String NEW_FILE_PREFIX = Localizer.parse(nbBundle20); // NOI18N
053: private final ListCellRenderer CELL_RENDERER = new GroupCellRenderer();
054: private Project project;
055: private String expectedExtension;
056: private final List /*<ChangeListener>*/listeners = new ArrayList();
057: private SourceGroup[] folders;
058: private boolean isFolder;
059:
060: // Variables declaration - do not modify
061: private javax.swing.JPanel bottomPanelContainer;
062: private javax.swing.JButton browseButton;
063: private javax.swing.JTextField documentNameTextField;
064: private javax.swing.JTextField fileTextField;
065: private javax.swing.JTextField folderTextField;
066: private javax.swing.JLabel jLabel1;
067: private javax.swing.JLabel jLabel2;
068: private javax.swing.JLabel jLabel3;
069: private javax.swing.JLabel jLabel4;
070: private javax.swing.JPanel jPanel1;
071: private javax.swing.JComboBox locationComboBox;
072: private javax.swing.JLabel locationLabel;
073: private javax.swing.JTextField projectTextField;
074: private javax.swing.JSeparator targetSeparator;
075:
076: private static transient final Logger mLogger = LogUtil
077: .getLogger(SimpleTargetChooserPanelGUI.class.getName());
078: private static transient final Localizer mLoc = Localizer.get();
079:
080: /**
081: * Creates new form SimpleTargetChooserGUI
082: *
083: * @param project DOCUMENT ME!
084: * @param folders DOCUMENT ME!
085: * @param bottomPanel DOCUMENT ME!
086: * @param isFolder DOCUMENT ME!
087: */
088: public SimpleTargetChooserPanelGUI(Project project,
089: SourceGroup[] folders, Component bottomPanel,
090: boolean isFolder) {
091: this .project = project;
092: this .folders = folders;
093: this .isFolder = isFolder;
094: initComponents();
095:
096: locationComboBox.setRenderer(CELL_RENDERER);
097:
098: if (bottomPanel != null) {
099: bottomPanelContainer.add(bottomPanel,
100: java.awt.BorderLayout.CENTER);
101: }
102:
103: initValues(null, null);
104:
105: browseButton.addActionListener(this );
106: locationComboBox.addActionListener(this );
107: documentNameTextField.getDocument().addDocumentListener(this );
108: folderTextField.getDocument().addDocumentListener(this );
109: String nbBundle1 = mLoc.t("PRSR001: Name and Location");
110: setName(Localizer.parse(nbBundle1)); // NOI18N
111: }
112:
113: /**
114: * DOCUMENT ME!
115: *
116: * @param template DOCUMENT ME!
117: * @param preselectedFolder DOCUMENT ME!
118: */
119: public void initValues(FileObject template,
120: FileObject preselectedFolder) {
121: assert project != null;
122:
123: projectTextField.setText(ProjectUtils.getInformation(project)
124: .getDisplayName());
125:
126: Sources sources = ProjectUtils.getSources(project);
127:
128: folders = sources.getSourceGroups(Sources.TYPE_GENERIC);
129:
130: if ((folders == null) || (folders.length < 1)) {
131: folders = sources.getSourceGroups(Sources.TYPE_GENERIC);
132: }
133:
134: if (folders.length < 2) {
135: // one source group i.e. hide Location
136: locationLabel.setVisible(false);
137: locationComboBox.setVisible(false);
138: } else {
139: // more source groups user needs to select location
140: locationLabel.setVisible(true);
141: locationComboBox.setVisible(true);
142: }
143:
144: locationComboBox.setModel(new DefaultComboBoxModel(folders));
145:
146: // Guess the group we want to create the file in
147: SourceGroup preselectedGroup = getPreselectedGroup(folders,
148: preselectedFolder);
149: locationComboBox.setSelectedItem(preselectedGroup);
150:
151: // Create OS dependent relative name
152: /*folderTextField.setText(
153: getRelativeNativeName(preselectedGroup.getRootFolder(), preselectedFolder)
154: );*/
155: folderTextField.setText("collaborations");
156:
157: String ext = (template == null) ? "" : template.getExt(); // NOI18N
158: expectedExtension = (ext.length() == 0) ? "" : ("." + ext); // NOI18N
159:
160: String displayName = null;
161:
162: try {
163: if (template != null) {
164: DataObject templateDo = DataObject.find(template);
165: displayName = templateDo.getNodeDelegate()
166: .getDisplayName();
167: }
168: } catch (DataObjectNotFoundException ex) {
169: displayName = template.getName();
170: }
171:
172: putClientProperty("NewEtlWizard_Title", displayName); // NOI18N
173:
174: if (template != null) {
175: documentNameTextField.setText(NEW_FILE_PREFIX
176: + template.getName());
177: documentNameTextField.selectAll();
178: }
179: String nbBundle2 = mLoc.t("PRSR001: Folder Name:");
180: if (isFolder) {
181: jLabel3.setText(Localizer.parse(nbBundle2)); // NOI18N
182: String nbBundle3 = mLoc.t("PRSR001: N");
183: jLabel3.setDisplayedMnemonic(Localizer.parse(nbBundle3)
184: .charAt(0)); // NOI18N
185: String nbBundle4 = mLoc.t("PRSR001: Parent Folder:");
186: jLabel2.setText(Localizer.parse(nbBundle4)); // NOI18N
187: String nbBundle5 = mLoc.t("PRSR001: r");
188: jLabel2.setDisplayedMnemonic(Localizer.parse(nbBundle5)
189: .charAt(0)); // NOI18N
190: String nbBundle6 = mLoc.t("PRSR001: Created Folder:");
191: jLabel4.setText(Localizer.parse(nbBundle6)); // NOI18N
192: String nbBundle7 = mLoc.t("PRSR001: C");
193: jLabel4.setDisplayedMnemonic(Localizer.parse(nbBundle7)
194: .charAt(0)); // NOI18N
195: } else {
196: String nbBundle8 = mLoc.t("PRSR001: File Name:");
197: jLabel3.setText(Localizer.parse(nbBundle8)); // NOI18N
198: String nbBundle9 = mLoc.t("PRSR001: Folder:");
199: jLabel2.setText(Localizer.parse(nbBundle9)); // NOI18N
200: String nbBundle10 = mLoc.t("PRSR001: Created File:");
201: jLabel4.setText(Localizer.parse(nbBundle10)); // NOI18N
202: String nbBundle11 = mLoc.t("PRSR001: N");
203: jLabel3.setDisplayedMnemonic(Localizer.parse(nbBundle11)
204: .charAt(0)); // NOI18N
205: String nbBundle12 = mLoc.t("PRSR001: l");
206: jLabel2.setDisplayedMnemonic(Localizer.parse(nbBundle12)
207: .charAt(0)); // NOI18N
208: String nbBundle13 = mLoc.t("PRSR001: C");
209: jLabel4.setDisplayedMnemonic(Localizer.parse(nbBundle13)
210: .charAt(0)); // NOI18N
211: }
212: }
213:
214: /**
215: * DOCUMENT ME!
216: *
217: * @return DOCUMENT ME!
218: */
219: public SourceGroup getTargetGroup() {
220: return (SourceGroup) locationComboBox.getSelectedItem();
221: }
222:
223: /**
224: * DOCUMENT ME!
225: *
226: * @return DOCUMENT ME!
227: */
228: public String getTargetFolder() {
229: String folderName = folderTextField.getText().trim();
230:
231: if (folderName.length() == 0) {
232: return null;
233: } else {
234: return folderName.replace(File.separatorChar, '/'); // NOI18N
235: }
236: }
237:
238: /**
239: * DOCUMENT ME!
240: *
241: * @return DOCUMENT ME!
242: */
243: public String getTargetName() {
244: String text = documentNameTextField.getText().trim();
245:
246: if (text.length() == 0) {
247: return null;
248: } else {
249: return text;
250: }
251: }
252:
253: /**
254: * DOCUMENT ME!
255: *
256: * @return DOCUMENT ME!
257: */
258: public java.awt.Dimension getPreferredSize() {
259: return PREF_DIM;
260: }
261:
262: /**
263: * DOCUMENT ME!
264: *
265: * @param l DOCUMENT ME!
266: */
267: public synchronized void addChangeListener(ChangeListener l) {
268: listeners.add(l);
269: }
270:
271: /**
272: * DOCUMENT ME!
273: *
274: * @param l DOCUMENT ME!
275: */
276: public synchronized void removeChangeListener(ChangeListener l) {
277: listeners.remove(l);
278: }
279:
280: private void fireChange() {
281: ChangeEvent e = new ChangeEvent(this );
282: List templist;
283:
284: synchronized (this ) {
285: templist = new ArrayList(listeners);
286: }
287:
288: Iterator it = templist.iterator();
289:
290: while (it.hasNext()) {
291: ((ChangeListener) it.next()).stateChanged(e);
292: }
293: }
294:
295: /**
296: * This method is called from within the constructor to initialize the form. WARNING: Do NOT
297: * modify this code. The content of this method is always regenerated by the Form Editor.
298: */
299: private void initComponents() {//GEN-BEGIN:initComponents
300:
301: java.awt.GridBagConstraints gridBagConstraints;
302:
303: jPanel1 = new javax.swing.JPanel();
304: jLabel3 = new javax.swing.JLabel();
305: documentNameTextField = new javax.swing.JTextField();
306: jLabel1 = new javax.swing.JLabel();
307: projectTextField = new javax.swing.JTextField();
308: locationLabel = new javax.swing.JLabel();
309: locationComboBox = new javax.swing.JComboBox();
310: jLabel2 = new javax.swing.JLabel();
311: folderTextField = new javax.swing.JTextField();
312: browseButton = new javax.swing.JButton();
313: browseButton.setMnemonic(Localizer.parse(nbBundle28).charAt(0));
314: browseButton.getAccessibleContext().setAccessibleName(
315: Localizer.parse(nbBundle28));
316: jLabel4 = new javax.swing.JLabel();
317: fileTextField = new javax.swing.JTextField();
318: targetSeparator = new javax.swing.JSeparator();
319: bottomPanelContainer = new javax.swing.JPanel();
320:
321: setLayout(new java.awt.GridBagLayout());
322:
323: String nbBundle14 = mLoc.t("PRSR001: N/A");
324: getAccessibleContext().setAccessibleDescription(
325: Localizer.parse(nbBundle14));
326: jPanel1.setLayout(new java.awt.GridBagLayout());
327:
328: String nbBundle15 = mLoc.t("PRSR001: N");
329: jLabel3.setDisplayedMnemonic(Localizer.parse(nbBundle15)
330: .charAt(0));
331: jLabel3.setLabelFor(documentNameTextField);
332: String nbBundle16 = mLoc.t("PRSR001: File Name:");
333: jLabel3.setText(Localizer.parse(nbBundle16));
334: gridBagConstraints = new java.awt.GridBagConstraints();
335: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
336: jPanel1.add(jLabel3, gridBagConstraints);
337:
338: gridBagConstraints = new java.awt.GridBagConstraints();
339: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
340: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
341: gridBagConstraints.weightx = 1.0;
342: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
343: jPanel1.add(documentNameTextField, gridBagConstraints);
344: String nbBundle17 = mLoc.t("PRSR001: N/A");
345: documentNameTextField.getAccessibleContext()
346: .setAccessibleDescription(Localizer.parse(nbBundle17));
347:
348: gridBagConstraints = new java.awt.GridBagConstraints();
349: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
350: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
351: gridBagConstraints.insets = new java.awt.Insets(0, 0, 24, 0);
352: add(jPanel1, gridBagConstraints);
353:
354: String nbBundle18 = mLoc.t("PRSR001: P");
355: jLabel1.setDisplayedMnemonic(Localizer.parse(nbBundle18)
356: .charAt(0));
357: String nbBundle19 = mLoc.t("PRSR001: Project:");
358: jLabel1.setText(Localizer.parse(nbBundle19));
359: jLabel1.setLabelFor(projectTextField);
360: gridBagConstraints = new java.awt.GridBagConstraints();
361: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
362: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
363: add(jLabel1, gridBagConstraints);
364:
365: projectTextField.setEditable(false);
366: gridBagConstraints = new java.awt.GridBagConstraints();
367: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
368: gridBagConstraints.weightx = 1.0;
369: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
370: add(projectTextField, gridBagConstraints);
371: String nbBundle20 = mLoc.t("PRSR001: N/A");
372: projectTextField.getAccessibleContext()
373: .setAccessibleDescription(Localizer.parse(nbBundle20));
374:
375: String nbBundle21 = mLoc.t("PRSR001: t");
376: locationLabel.setDisplayedMnemonic(Localizer.parse(nbBundle21)
377: .charAt(0));
378: locationLabel.setLabelFor(locationComboBox);
379: String nbBundle22 = mLoc.t("PRSR001: Location:");
380: locationLabel.setText(Localizer.parse(nbBundle22));
381: gridBagConstraints = new java.awt.GridBagConstraints();
382: gridBagConstraints.gridy = 2;
383: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
384: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
385: add(locationLabel, gridBagConstraints);
386:
387: gridBagConstraints = new java.awt.GridBagConstraints();
388: gridBagConstraints.gridy = 2;
389: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
390: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
391: gridBagConstraints.insets = new java.awt.Insets(0, 6, 5, 0);
392: add(locationComboBox, gridBagConstraints);
393: String nbBundle23 = mLoc.t("PRSR001: N/A");
394: locationComboBox.getAccessibleContext()
395: .setAccessibleDescription(Localizer.parse(nbBundle23));
396:
397: String nbBundle24 = mLoc.t("PRSR001: r");
398: jLabel2.setDisplayedMnemonic(Localizer.parse(nbBundle24)
399: .charAt(0));
400: jLabel2.setLabelFor(folderTextField);
401: String nbBundle25 = mLoc.t("PRSR001: Folder:");
402: jLabel2.setText(Localizer.parse(nbBundle25));
403: gridBagConstraints = new java.awt.GridBagConstraints();
404: gridBagConstraints.gridx = 0;
405: gridBagConstraints.gridy = 3;
406: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
407: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
408: add(jLabel2, gridBagConstraints);
409:
410: gridBagConstraints = new java.awt.GridBagConstraints();
411: gridBagConstraints.gridy = 3;
412: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
413: gridBagConstraints.weightx = 1.0;
414: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
415: add(folderTextField, gridBagConstraints);
416: String nbBundle26 = mLoc.t("PRSR001: N/A");
417: folderTextField.getAccessibleContext()
418: .setAccessibleDescription(Localizer.parse(nbBundle26));
419:
420: String nbBundle27 = mLoc.t("PRSR001: w");
421: browseButton.setMnemonic(Localizer.parse(nbBundle27).charAt(0));
422:
423: browseButton.setText(Localizer.parse(nbBundle28));
424: gridBagConstraints = new java.awt.GridBagConstraints();
425: gridBagConstraints.gridy = 3;
426: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
427: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
428: add(browseButton, gridBagConstraints);
429: String nbBundle29 = mLoc.t("PRSR001: N/A");
430: browseButton.getAccessibleContext().setAccessibleDescription(
431: Localizer.parse(nbBundle29));
432:
433: String nbBundle30 = mLoc.t("PRSR001: C");
434: jLabel4.setDisplayedMnemonic(Localizer.parse(nbBundle30)
435: .charAt(0));
436: String nbBundle31 = mLoc.t("PRSR001: Created File:");
437: jLabel4.setText(Localizer.parse(nbBundle31));
438: jLabel4.setLabelFor(fileTextField);
439: gridBagConstraints = new java.awt.GridBagConstraints();
440: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
441: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
442: add(jLabel4, gridBagConstraints);
443:
444: fileTextField.setEditable(false);
445: gridBagConstraints = new java.awt.GridBagConstraints();
446: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
447: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
448: gridBagConstraints.weightx = 1.0;
449: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
450: add(fileTextField, gridBagConstraints);
451: String nbBundle32 = mLoc.t("PRSR001: N/A");
452: fileTextField.getAccessibleContext().setAccessibleDescription(
453: Localizer.parse(nbBundle32));
454:
455: gridBagConstraints = new java.awt.GridBagConstraints();
456: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
457: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
458: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
459: add(targetSeparator, gridBagConstraints);
460:
461: bottomPanelContainer.setLayout(new java.awt.BorderLayout());
462:
463: gridBagConstraints = new java.awt.GridBagConstraints();
464: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
465: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
466: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
467: gridBagConstraints.weighty = 1.0;
468: add(bottomPanelContainer, gridBagConstraints);
469: }//GEN-END:initComponents
470:
471: // End of variables declaration
472: private SourceGroup getPreselectedGroup(SourceGroup[] groups,
473: FileObject folder) {
474: for (int i = 0; (folder != null) && (i < groups.length); i++) {
475: if (FileUtil.isParentOf(groups[i].getRootFolder(), folder)) {
476: return groups[i];
477: }
478: }
479:
480: return groups[0];
481: }
482:
483: public void setDocumentName(String documentName) {
484: documentNameTextField.setText(documentName);
485: }
486:
487: private String getRelativeNativeName(FileObject root,
488: FileObject folder) {
489: if (root == null) {
490: throw new NullPointerException(
491: "null root passed to getRelativeNativeName"); // NOI18N
492: }
493:
494: String path;
495:
496: if (folder == null) {
497: path = ""; // NOI18N
498: } else {
499: path = FileUtil.getRelativePath(root, folder);
500: }
501:
502: return (path == null) ? "" : path.replace('/',
503: File.separatorChar); // NOI18N
504: }
505:
506: private void updateCreatedFolder() {
507: FileObject root = ((SourceGroup) locationComboBox
508: .getSelectedItem()).getRootFolder();
509:
510: String folderName = folderTextField.getText().trim();
511: String documentName = documentNameTextField.getText().trim();
512:
513: String createdFileName = FileUtil.getFileDisplayName(root)
514: +
515: /*
516: ( mFolderText.startsWith("/") || mFolderText.startsWith( File.separator ) ? "" : "/" ) + // NOI18N
517: mFolderText +
518: */
519: ((folderName.startsWith("/") || folderName
520: .startsWith(File.separator)) ? "" : "/")
521: + // NOI18N
522: folderName
523: + ((folderName.endsWith("/")
524: || folderName.endsWith(File.separator) || (folderName
525: .length() == 0)) ? "" : "/") + // NOI18N
526: documentName + expectedExtension;
527:
528: fileTextField.setText(createdFileName.replace('/',
529: File.separatorChar)); // NOI18N
530:
531: fireChange();
532: }
533:
534: // ActionListener implementation -------------------------------------------
535: public void actionPerformed(java.awt.event.ActionEvent e) {
536: if (browseButton == e.getSource()) {
537: FileObject fo = null;
538:
539: // Show the browse dialog
540: SourceGroup group = (SourceGroup) locationComboBox
541: .getSelectedItem();
542:
543: fo = BrowseFolders.showDialog(new SourceGroup[] { group },
544: project, folderTextField.getText().replace(
545: File.separatorChar, '/')); // NOI18N
546:
547: if ((fo != null) && fo.isFolder()) {
548: String relPath = FileUtil.getRelativePath(group
549: .getRootFolder(), fo);
550: folderTextField.setText(relPath.replace('/',
551: File.separatorChar)); // NOI18N
552: }
553: } else if (locationComboBox == e.getSource()) {
554: updateCreatedFolder();
555: }
556: }
557:
558: // DocumentListener implementation -----------------------------------------
559: public void changedUpdate(javax.swing.event.DocumentEvent e) {
560: updateCreatedFolder();
561: }
562:
563: /**
564: * DOCUMENT ME!
565: *
566: * @param e DOCUMENT ME!
567: */
568: public void insertUpdate(javax.swing.event.DocumentEvent e) {
569: updateCreatedFolder();
570: }
571:
572: /**
573: * DOCUMENT ME!
574: *
575: * @param e DOCUMENT ME!
576: */
577: public void removeUpdate(javax.swing.event.DocumentEvent e) {
578: updateCreatedFolder();
579: }
580:
581: // Rendering of the location combo box -------------------------------------
582: private class GroupCellRenderer extends JLabel implements
583: ListCellRenderer {
584: /**
585: * Creates a new GroupCellRenderer object.
586: */
587: public GroupCellRenderer() {
588: setOpaque(true);
589: }
590:
591: /**
592: * DOCUMENT ME!
593: *
594: * @param list DOCUMENT ME!
595: * @param value DOCUMENT ME!
596: * @param index DOCUMENT ME!
597: * @param isSelected DOCUMENT ME!
598: * @param cellHasFocus DOCUMENT ME!
599: *
600: * @return DOCUMENT ME!
601: */
602: public Component getListCellRendererComponent(JList list,
603: Object value, int index, boolean isSelected,
604: boolean cellHasFocus) {
605: if (value instanceof SourceGroup) {
606: SourceGroup group = (SourceGroup) value;
607: String projectDisplayName = ProjectUtils
608: .getInformation(project).getDisplayName();
609: String groupDisplayName = group.getDisplayName();
610:
611: if (projectDisplayName.equals(groupDisplayName)) {
612: setText(groupDisplayName);
613: } else {
614: String nbBundle33 = mLoc.t("PRSR001: {0} [{1}]",
615: groupDisplayName, projectDisplayName);
616: setText(MessageFormat.format(Localizer
617: .parse(nbBundle33), // NOI18N
618: new Object[] { groupDisplayName,
619: projectDisplayName }));
620: }
621:
622: setIcon(group.getIcon(false));
623: } else {
624: setText(value.toString());
625: setIcon(null);
626: }
627:
628: if (isSelected) {
629: setBackground(list.getSelectionBackground());
630: setForeground(list.getSelectionForeground());
631: } else {
632: setBackground(list.getBackground());
633: setForeground(list.getForeground());
634: }
635:
636: return this;
637: }
638: }
639: }
|