KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > ui > customizer > AppClientSourceRootsUi


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.j2ee.clientproject.ui.customizer;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.GridBagConstraints JavaDoc;
24 import java.awt.GridBagLayout JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.io.File JavaDoc;
29 import java.net.URI JavaDoc;
30 import java.net.URL JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.Vector JavaDoc;
35 import java.text.MessageFormat JavaDoc;
36 import javax.swing.DefaultCellEditor JavaDoc;
37 import javax.swing.DefaultListCellRenderer JavaDoc;
38 import javax.swing.JButton JavaDoc;
39 import javax.swing.JComponent JavaDoc;
40 import javax.swing.JFileChooser JavaDoc;
41 import javax.swing.JLabel JavaDoc;
42 import javax.swing.JList JavaDoc;
43 import javax.swing.JOptionPane JavaDoc;
44 import javax.swing.JPanel JavaDoc;
45 import javax.swing.JScrollPane JavaDoc;
46 import javax.swing.JTable JavaDoc;
47 import javax.swing.JTextField JavaDoc;
48 import javax.swing.ListSelectionModel JavaDoc;
49 import javax.swing.SwingUtilities JavaDoc;
50 import javax.swing.event.ListSelectionEvent JavaDoc;
51 import javax.swing.event.ListSelectionListener JavaDoc;
52 import javax.swing.event.CellEditorListener JavaDoc;
53 import javax.swing.event.ChangeEvent JavaDoc;
54 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
55 import javax.swing.table.DefaultTableModel JavaDoc;
56 import org.netbeans.api.java.project.JavaProjectConstants;
57 import org.netbeans.api.project.ProjectUtils;
58 import org.netbeans.api.project.SourceGroup;
59 import org.netbeans.api.project.Sources;
60 import org.netbeans.modules.j2ee.clientproject.AppClientProject;
61 import org.netbeans.api.project.FileOwnerQuery;
62 import org.netbeans.api.project.Project;
63 import org.netbeans.api.project.ProjectInformation;
64 import org.netbeans.modules.j2ee.clientproject.SourceRoots;
65 import org.openide.DialogDisplayer;
66 import org.openide.DialogDescriptor;
67 import org.openide.filesystems.FileObject;
68 import org.openide.filesystems.FileUtil;
69 import org.openide.util.NbBundle;
70
71 /** Handles adding, removing, reordering of source roots.
72  *
73  * @author Tomas Zezula
74  */

75 public final class AppClientSourceRootsUi {
76     
77     public static DefaultTableModel JavaDoc createModel( SourceRoots roots ) {
78         
79         String JavaDoc[] rootLabels = roots.getRootNames();
80         String JavaDoc[] rootProps = roots.getRootProperties();
81         URL JavaDoc[] rootURLs = roots.getRootURLs();
82         Object JavaDoc[][] data = new Object JavaDoc[rootURLs.length] [2];
83         for (int i=0; i< rootURLs.length; i++) {
84             data[i][0] = new File JavaDoc(URI.create(rootURLs[i].toExternalForm()));
85             data[i][1] = roots.getRootDisplayName(rootLabels[i], rootProps[i]);
86         }
87         return new SourceRootsModel(data);
88         
89     }
90     
91     public static EditMediator registerEditMediator( AppClientProject master,
92             SourceRoots sourceRoots,
93             JTable JavaDoc rootsList,
94             JButton JavaDoc addFolderButton,
95             JButton JavaDoc removeButton,
96             JButton JavaDoc upButton,
97             JButton JavaDoc downButton) {
98         
99         EditMediator em = new EditMediator( master,
100                 sourceRoots,
101                 rootsList,
102                 addFolderButton,
103                 removeButton,
104                 upButton,
105                 downButton);
106         
107         // Register the listeners
108
// On all buttons
109
addFolderButton.addActionListener( em );
110         removeButton.addActionListener( em );
111         upButton.addActionListener( em );
112         downButton.addActionListener( em );
113         // On list selection
114
rootsList.getSelectionModel().addListSelectionListener( em );
115         DefaultCellEditor JavaDoc editor = new DefaultCellEditor JavaDoc(new JTextField JavaDoc());
116         editor.addCellEditorListener(em);
117         rootsList.setDefaultRenderer( File JavaDoc.class, new FileRenderer(FileUtil.toFile(master.getProjectDirectory())));
118         rootsList.setDefaultEditor(String JavaDoc.class, editor);
119         // Set the initial state of the buttons
120
em.valueChanged( null );
121         
122         DefaultTableModel JavaDoc model = (DefaultTableModel JavaDoc)rootsList.getModel();
123         String JavaDoc[] columnNames = new String JavaDoc[2];
124         columnNames[0] = NbBundle.getMessage( AppClientSourceRootsUi.class,"CTL_PackageFolders");
125         columnNames[1] = NbBundle.getMessage( AppClientSourceRootsUi.class,"CTL_PackageLabels");
126         model.setColumnIdentifiers(columnNames);
127         rootsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
128         
129         return em;
130     }
131     
132     /**
133      * Opens the standard dialog for warning an user about illegal source roots.
134      * @param roots the set of illegal source/test roots
135      */

136     public static void showIllegalRootsDialog(Set JavaDoc<File JavaDoc> roots) {
137         JButton JavaDoc closeOption = new JButton JavaDoc(NbBundle.getMessage(AppClientSourceRootsUi.class,"CTL_J2SESourceRootsUi_Close"));
138         closeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AppClientSourceRootsUi.class,"AD_J2SESourceRootsUi_Close"));
139         JPanel JavaDoc warning = new WarningDlg(roots);
140         String JavaDoc message = NbBundle.getMessage(AppClientSourceRootsUi.class,"MSG_InvalidRoot");
141         JOptionPane JavaDoc optionPane = new JOptionPane JavaDoc(new Object JavaDoc[] {message, warning},
142                 JOptionPane.WARNING_MESSAGE,
143                 0,
144                 null,
145                 new Object JavaDoc[0],
146                 null);
147         optionPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AppClientSourceRootsUi.class,"AD_InvalidRootDlg"));
148         DialogDescriptor dd = new DialogDescriptor(optionPane,
149                 NbBundle.getMessage(AppClientSourceRootsUi.class,"TITLE_InvalidRoot"),
150                 true,
151                 new Object JavaDoc[] {
152             closeOption,
153         },
154                 closeOption,
155                 DialogDescriptor.DEFAULT_ALIGN,
156                 null,
157                 null);
158         DialogDisplayer.getDefault().notify(dd);
159     }
160     
161     // Private innerclasses ----------------------------------------------------
162

163     public static class EditMediator implements ActionListener JavaDoc, ListSelectionListener JavaDoc, CellEditorListener JavaDoc {
164         
165         
166         final JTable JavaDoc rootsList;
167         final JButton JavaDoc addFolderButton;
168         final JButton JavaDoc removeButton;
169         final JButton JavaDoc upButton;
170         final JButton JavaDoc downButton;
171         private final Project project;
172         private final SourceRoots sourceRoots;
173         private final Set JavaDoc<File JavaDoc> ownedFolders;
174         private DefaultTableModel JavaDoc rootsModel;
175         private EditMediator relatedEditMediator;
176         private File JavaDoc lastUsedDir; //Last used current folder in JFileChooser
177

178         
179         public EditMediator( AppClientProject master,
180                 SourceRoots sourceRoots,
181                 JTable JavaDoc rootsList,
182                 JButton JavaDoc addFolderButton,
183                 JButton JavaDoc removeButton,
184                 JButton JavaDoc upButton,
185                 JButton JavaDoc downButton) {
186             
187             if ( !( rootsList.getModel() instanceof DefaultTableModel JavaDoc ) ) {
188                 throw new IllegalArgumentException JavaDoc( "Jtable's model has to be of class DefaultTableModel" ); // NOI18N
189
}
190             
191             this.rootsList = rootsList;
192             this.addFolderButton = addFolderButton;
193             this.removeButton = removeButton;
194             this.upButton = upButton;
195             this.downButton = downButton;
196             this.ownedFolders = new HashSet JavaDoc<File JavaDoc>();
197             
198             this.project = master;
199             this.sourceRoots = sourceRoots;
200             
201             this.ownedFolders.clear();
202             this.rootsModel = (DefaultTableModel JavaDoc)rootsList.getModel();
203             Vector JavaDoc data = rootsModel.getDataVector();
204             for (Iterator JavaDoc it = data.iterator(); it.hasNext();) {
205                 Vector JavaDoc row = (Vector JavaDoc) it.next();
206                 File JavaDoc f = (File JavaDoc) row.elementAt(0);
207                 this.ownedFolders.add(f);
208             }
209         }
210         
211         public void setRelatedEditMediator(EditMediator rem) {
212             this.relatedEditMediator = rem;
213         }
214         
215         // Implementation of ActionListener ------------------------------------
216

217         /** Handles button events
218          */

219         public void actionPerformed( ActionEvent JavaDoc e ) {
220             
221             Object JavaDoc source = e.getSource();
222             
223             if ( source == addFolderButton ) {
224                 
225                 // Let user search for the Jar file
226
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
227                 FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
228                 chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
229                 chooser.setMultiSelectionEnabled( true );
230                 if (this.sourceRoots.isTest()) {
231                     chooser.setDialogTitle( NbBundle.getMessage( AppClientSourceRootsUi.class, "LBL_TestFolder_DialogTitle" )); // NOI18N
232
} else {
233                     chooser.setDialogTitle( NbBundle.getMessage( AppClientSourceRootsUi.class, "LBL_SourceFolder_DialogTitle" )); // NOI18N
234
}
235                 File JavaDoc curDir = this.lastUsedDir;
236                 if (curDir == null) {
237                     curDir = FileUtil.toFile(this.project.getProjectDirectory());
238                 }
239                 if (curDir != null) {
240                     chooser.setCurrentDirectory(curDir);
241                 }
242                 int option = chooser.showOpenDialog( SwingUtilities.getWindowAncestor( addFolderButton ) ); // Sow the chooser
243

244                 if ( option == JFileChooser.APPROVE_OPTION ) {
245                     curDir = chooser.getCurrentDirectory();
246                     if (curDir != null) {
247                         this.lastUsedDir = curDir;
248                         if (this.relatedEditMediator != null) {
249                             this.relatedEditMediator.lastUsedDir = curDir;
250                         }
251                     }
252                     File JavaDoc files[] = chooser.getSelectedFiles();
253                     addFolders( files );
254                 }
255                 
256             } else if ( source == removeButton ) {
257                 removeElements();
258             } else if ( source == upButton ) {
259                 moveUp();
260             } else if ( source == downButton ) {
261                 moveDown();
262             }
263         }
264         
265         // Selection listener implementation ----------------------------------
266

267         /** Handles changes in the selection
268          */

269         public void valueChanged( ListSelectionEvent JavaDoc e ) {
270             
271             int[] si = rootsList.getSelectedRows();
272             
273             // addJar allways enabled
274

275             // addLibrary allways enabled
276

277             // addArtifact allways enabled
278

279             // edit enabled only if selection is not empty
280
boolean edit = si != null && si.length > 0;
281             
282             // remove enabled only if selection is not empty
283
boolean remove = si != null && si.length > 0;
284             // and when the selection does not contain unremovable item
285

286             // up button enabled if selection is not empty
287
// and the first selected index is not the first row
288
boolean up = si != null && si.length > 0 && si[0] != 0;
289             
290             // up button enabled if selection is not empty
291
// and the laset selected index is not the last row
292
boolean down = si != null && si.length > 0 && si[si.length-1] !=rootsList.getRowCount() - 1;
293             
294             removeButton.setEnabled( remove );
295             upButton.setEnabled( up );
296             downButton.setEnabled( down );
297             
298             //System.out.println("Selection changed " + edit + ", " + remove + ", " + + ", " + + ", ");
299

300         }
301         
302         public void editingCanceled(ChangeEvent JavaDoc e) {
303             
304         }
305         
306         public void editingStopped(ChangeEvent JavaDoc e) {
307             // fireActionPerformed();
308
}
309         
310         private void addFolders( File JavaDoc files[] ) {
311             int[] si = rootsList.getSelectedRows();
312             int lastIndex = si == null || si.length == 0 ? -1 : si[si.length - 1];
313             ListSelectionModel JavaDoc selectionModel = this.rootsList.getSelectionModel();
314             selectionModel.clearSelection();
315             Set JavaDoc<File JavaDoc> rootsFromOtherProjects = new HashSet JavaDoc<File JavaDoc>();
316             Set JavaDoc<File JavaDoc> rootsFromRelatedSourceRoots = new HashSet JavaDoc<File JavaDoc>();
317             out: for( int i = 0; i < files.length; i++ ) {
318                 File JavaDoc normalizedFile = FileUtil.normalizeFile(files[i]);
319                 Project p;
320                 if (ownedFolders.contains(normalizedFile)) {
321                     Vector JavaDoc dataVector = rootsModel.getDataVector();
322                     for (int j=0; j<dataVector.size();j++) {
323                         //Sequential search in this minor case is faster than update of positions during each modification
324
File JavaDoc f = (File JavaDoc )((Vector JavaDoc)dataVector.elementAt(j)).elementAt(0);
325                         if (f.equals(normalizedFile)) {
326                             selectionModel.addSelectionInterval(j,j);
327                         }
328                     }
329                 } else if (this.relatedEditMediator != null && this.relatedEditMediator.ownedFolders.contains(normalizedFile)) {
330                     rootsFromRelatedSourceRoots.add(normalizedFile);
331                     continue;
332                 }
333                 if ((p=FileOwnerQuery.getOwner(normalizedFile.toURI()))!=null && !p.getProjectDirectory().equals(project.getProjectDirectory())) {
334                     final Sources sources = (Sources) p.getLookup().lookup(Sources.class);
335                     if (sources == null) {
336                         rootsFromOtherProjects.add(normalizedFile);
337                         continue;
338                     }
339                     final SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
340                     final SourceGroup[] javaGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
341                     final SourceGroup[] groups = new SourceGroup [sourceGroups.length + javaGroups.length];
342                     System.arraycopy(sourceGroups,0,groups,0,sourceGroups.length);
343                     System.arraycopy(javaGroups,0,groups,sourceGroups.length,javaGroups.length);
344                     final FileObject projectDirectory = p.getProjectDirectory();
345                     final FileObject fileObject = FileUtil.toFileObject(normalizedFile);
346                     if (projectDirectory == null || fileObject == null) {
347                         rootsFromOtherProjects.add(normalizedFile);
348                         continue;
349                     }
350                     for (int j=0; j<groups.length; j++) {
351                         final FileObject sgRoot = groups[j].getRootFolder();
352                         if (fileObject.equals(sgRoot)) {
353                             rootsFromOtherProjects.add(normalizedFile);
354                             continue out;
355                         }
356                         if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) {
357                             rootsFromOtherProjects.add(normalizedFile);
358                             continue out;
359                         }
360                     }
361                 }
362                 int current = lastIndex + 1 + i;
363                 rootsModel.insertRow( current, new Object JavaDoc[] {normalizedFile, sourceRoots.createInitialDisplayName(normalizedFile)}); //NOI18N
364
selectionModel.addSelectionInterval(current,current);
365                 this.ownedFolders.add(normalizedFile);
366             }
367             if (rootsFromOtherProjects.size() > 0 || rootsFromRelatedSourceRoots.size() > 0) {
368                 rootsFromOtherProjects.addAll(rootsFromRelatedSourceRoots);
369                 showIllegalRootsDialog(rootsFromOtherProjects);
370             }
371             // fireActionPerformed();
372
}
373         
374         private void removeElements() {
375             
376             int[] si = rootsList.getSelectedRows();
377             
378             if( si == null || si.length == 0 ) {
379                 assert false : "Remove button should be disabled"; // NOI18N
380
}
381             
382             // Remove the items
383
for( int i = si.length - 1 ; i >= 0 ; i-- ) {
384                 this.ownedFolders.remove(((Vector JavaDoc)rootsModel.getDataVector().elementAt(si[i])).elementAt(0));
385                 rootsModel.removeRow( si[i] );
386             }
387             
388             
389             if ( rootsModel.getRowCount() != 0) {
390                 // Select reasonable item
391
int selectedIndex = si[si.length - 1] - si.length + 1;
392                 if ( selectedIndex > rootsModel.getRowCount() - 1) {
393                     selectedIndex = rootsModel.getRowCount() - 1;
394                 }
395                 rootsList.setRowSelectionInterval( selectedIndex, selectedIndex );
396             }
397             
398             // fireActionPerformed();
399

400         }
401         
402         private void moveUp() {
403             
404             int[] si = rootsList.getSelectedRows();
405             
406             if( si == null || si.length == 0 ) {
407                 assert false : "MoveUp button should be disabled"; // NOI18N
408
}
409             
410             // Move the items up
411
ListSelectionModel JavaDoc selectionModel = this.rootsList.getSelectionModel();
412             selectionModel.clearSelection();
413             for( int i = 0; i < si.length; i++ ) {
414                 Vector JavaDoc item = (Vector JavaDoc) rootsModel.getDataVector().elementAt(si[i]);
415                 int newIndex = si[i]-1;
416                 rootsModel.removeRow( si[i] );
417                 rootsModel.insertRow( newIndex, item );
418                 selectionModel.addSelectionInterval(newIndex,newIndex);
419             }
420             // fireActionPerformed();
421
}
422         
423         private void moveDown() {
424             
425             int[] si = rootsList.getSelectedRows();
426             
427             if( si == null || si.length == 0 ) {
428                 assert false : "MoveDown button should be disabled"; // NOI18N
429
}
430             
431             // Move the items up
432
ListSelectionModel JavaDoc selectionModel = this.rootsList.getSelectionModel();
433             selectionModel.clearSelection();
434             for( int i = si.length -1 ; i >= 0 ; i-- ) {
435                 Vector JavaDoc item = (Vector JavaDoc) rootsModel.getDataVector().elementAt(si[i]);
436                 int newIndex = si[i] + 1;
437                 rootsModel.removeRow( si[i] );
438                 rootsModel.insertRow( newIndex, item );
439                 selectionModel.addSelectionInterval(newIndex,newIndex);
440             }
441             // fireActionPerformed();
442
}
443         
444         
445     }
446     
447     private static class SourceRootsModel extends DefaultTableModel JavaDoc {
448         
449         public SourceRootsModel(Object JavaDoc[][] data) {
450             super(data,new Object JavaDoc[]{"location","label"});//NOI18N
451
}
452         
453         public boolean isCellEditable(int row, int column) {
454             return column == 1;
455         }
456         
457         public Class JavaDoc getColumnClass(int columnIndex) {
458             switch (columnIndex) {
459                 case 0:
460                     return File JavaDoc.class;
461                 case 1:
462                     return String JavaDoc.class;
463                 default:
464                     return super.getColumnClass(columnIndex);
465             }
466         }
467     }
468     
469     private static class FileRenderer extends DefaultTableCellRenderer JavaDoc {
470         
471         private File JavaDoc projectFolder;
472         
473         public FileRenderer(File JavaDoc projectFolder) {
474             this.projectFolder = projectFolder;
475         }
476         
477         public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value, boolean isSelected, boolean hasFocus,int row, int column) {
478             String JavaDoc displayName;
479             if (value instanceof File JavaDoc) {
480                 File JavaDoc root = (File JavaDoc) value;
481                 String JavaDoc pfPath = projectFolder.getAbsolutePath() + File.separatorChar;
482                 String JavaDoc srPath = root.getAbsolutePath();
483                 if (srPath.startsWith(pfPath)) {
484                     displayName = srPath.substring(pfPath.length());
485                 } else {
486                     displayName = srPath;
487                 }
488             } else {
489                 displayName = null;
490             }
491             Component JavaDoc c = super.getTableCellRendererComponent(table, displayName, isSelected, hasFocus, row, column);
492             if (c instanceof JComponent JavaDoc) {
493                 ((JComponent JavaDoc) c).setToolTipText(displayName);
494             }
495             return c;
496         }
497         
498     }
499     
500     private static class WarningDlg extends JPanel JavaDoc {
501         
502         public WarningDlg(Set JavaDoc<File JavaDoc> invalidRoots) {
503             this.initGui(invalidRoots);
504         }
505         
506         private void initGui(Set JavaDoc<File JavaDoc> invalidRoots) {
507             setLayout( new GridBagLayout JavaDoc());
508             JLabel JavaDoc label = new JLabel JavaDoc();
509             label.setText(NbBundle.getMessage(AppClientSourceRootsUi.class,"LBL_InvalidRoot"));
510             label.setDisplayedMnemonic(NbBundle.getMessage(AppClientSourceRootsUi.class,"MNE_InvalidRoot").charAt(0));
511             GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
512             c.gridx = GridBagConstraints.RELATIVE;
513             c.gridy = GridBagConstraints.RELATIVE;
514             c.gridwidth = GridBagConstraints.REMAINDER;
515             c.fill = GridBagConstraints.HORIZONTAL;
516             c.anchor = GridBagConstraints.NORTHWEST;
517             c.weightx = 1.0;
518             c.insets = new Insets JavaDoc(12,0,6,0);
519             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(label,c);
520             this.add(label);
521             JList JavaDoc roots = new JList JavaDoc(invalidRoots.toArray());
522             roots.setCellRenderer(new InvalidRootRenderer(true));
523             JScrollPane JavaDoc p = new JScrollPane JavaDoc(roots);
524             c = new GridBagConstraints JavaDoc();
525             c.gridx = GridBagConstraints.RELATIVE;
526             c.gridy = GridBagConstraints.RELATIVE;
527             c.gridwidth = GridBagConstraints.REMAINDER;
528             c.fill = GridBagConstraints.BOTH;
529             c.anchor = GridBagConstraints.NORTHWEST;
530             c.weightx = c.weighty = 1.0;
531             c.insets = new Insets JavaDoc(0,0,12,0);
532             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(p,c);
533             this.add(p);
534             label.setLabelFor(roots);
535             roots.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AppClientSourceRootsUi.class,"AD_InvalidRoot"));
536             JLabel JavaDoc label2 = new JLabel JavaDoc();
537             label2.setText(NbBundle.getMessage(AppClientSourceRootsUi.class,"MSG_InvalidRoot2"));
538             c = new GridBagConstraints JavaDoc();
539             c.gridx = GridBagConstraints.RELATIVE;
540             c.gridy = GridBagConstraints.RELATIVE;
541             c.gridwidth = GridBagConstraints.REMAINDER;
542             c.fill = GridBagConstraints.HORIZONTAL;
543             c.anchor = GridBagConstraints.NORTHWEST;
544             c.weightx = 1.0;
545             c.insets = new Insets JavaDoc(0,0,0,0);
546             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(label2,c);
547             this.add(label2);
548         }
549         
550         private static class InvalidRootRenderer extends DefaultListCellRenderer JavaDoc {
551             
552             private boolean projectConflict;
553             
554             public InvalidRootRenderer(boolean projectConflict) {
555                 this.projectConflict = projectConflict;
556             }
557             
558             public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
559                 File JavaDoc f = (File JavaDoc) value;
560                 String JavaDoc message = f.getAbsolutePath();
561                 if (projectConflict) {
562                     Project p = FileOwnerQuery.getOwner(f.toURI());
563                     if (p!=null) {
564                         ProjectInformation pi = ProjectUtils.getInformation(p);
565                         String JavaDoc projectName = pi.getDisplayName();
566                         message = MessageFormat.format(NbBundle.getMessage(AppClientSourceRootsUi.class,"TXT_RootOwnedByProject"), new Object JavaDoc[] {
567                             message,
568                             projectName});
569                     }
570                 }
571                 return super.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus);
572             }
573         }
574     }
575     
576 }
577
Popular Tags