KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ui > DocumentsDlg


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.core.windows.view.ui;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Image JavaDoc;
26 import java.awt.Window JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.beans.PropertyChangeEvent JavaDoc;
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.beans.PropertyVetoException JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.text.Collator JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Arrays JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39 import javax.swing.Action JavaDoc;
40 import javax.swing.JPanel JavaDoc;
41 import javax.swing.SwingUtilities JavaDoc;
42 import javax.swing.UIManager JavaDoc;
43 import javax.swing.border.Border JavaDoc;
44 import org.netbeans.core.windows.Constants;
45 import org.netbeans.core.windows.ModeImpl;
46 import org.netbeans.core.windows.WindowManagerImpl;
47 import org.openide.DialogDescriptor;
48 import org.openide.DialogDisplayer;
49 import org.openide.awt.Mnemonics;
50 import org.openide.cookies.SaveCookie;
51 import org.openide.explorer.ExplorerManager;
52 import org.openide.explorer.view.ListView;
53 import org.openide.nodes.AbstractNode;
54 import org.openide.nodes.Children;
55 import org.openide.nodes.Node;
56 import org.openide.util.HelpCtx;
57 import org.openide.util.Lookup;
58 import org.openide.util.NbBundle;
59 import org.openide.util.Utilities;
60 import org.openide.util.WeakListeners;
61 import org.openide.windows.TopComponent;
62
63 /**
64  * Panel to display list of TopComponents in editor area.
65  *
66  * @author Marek Slama
67  */

68 public class DocumentsDlg extends JPanel JavaDoc implements PropertyChangeListener JavaDoc, ExplorerManager.Provider {
69     
70     private static DocumentsDlg defaultInstance;
71     
72     private final ExplorerManager explorer = new ExplorerManager();
73     
74     /** Creates new form DocumentsDlg */
75     private DocumentsDlg () {
76         initComponents();
77         
78         // Internationalize.
79
Mnemonics.setLocalizedText(jButtonActivate, NbBundle.getMessage(DocumentsDlg.class, "LBL_Activate"));
80         Mnemonics.setLocalizedText(jButtonClose, NbBundle.getMessage(DocumentsDlg.class, "LBL_CloseDocuments"));
81         Mnemonics.setLocalizedText(jButtonSave, NbBundle.getMessage(DocumentsDlg.class, "LBL_SaveDocuments"));
82         Mnemonics.setLocalizedText(explorerLabel, NbBundle.getMessage(DocumentsDlg.class, "LBL_Documents"));
83         Mnemonics.setLocalizedText(descriptionLabel, NbBundle.getMessage(DocumentsDlg.class, "LBL_Description"));
84         
85         Mnemonics.setLocalizedText(closeButton, NbBundle.getMessage(DocumentsDlg.class, "LBL_Close"));
86             
87         // Set labels for.
88
explorerLabel.setLabelFor(listView);
89         descriptionLabel.setLabelFor(descriptionArea);
90         
91         // Accessible context.
92
jButtonActivate.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_Activate"));
93         jButtonClose.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_CloseDocuments"));
94         jButtonSave.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_SaveDocuments"));
95         closeButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_Close"));
96         descriptionArea.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_DescriptionArea"));
97     }
98     
99
100     private static DocumentsDlg getDefault() {
101         if(defaultInstance == null) {
102             defaultInstance = new DocumentsDlg();
103         }
104         return defaultInstance;
105     }
106     
107     /** Gets <code>HelpCtx</code>. Implements <code>HelpCtx.Provider</code>. */
108     public HelpCtx getHelpCtx() {
109         // PENDING replace by id string.
110
return new HelpCtx(DocumentsDlg.class);
111     }
112     
113     /** This method is called from within the constructor to
114      * initialize the form.
115      * WARNING: Do NOT modify this code. The content of this method is
116      * always regenerated by the Form Editor.
117      */

118     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
119
private void initComponents() {
120         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
121
122         explorerLabel = new javax.swing.JLabel JavaDoc();
123         descriptionLabel = new javax.swing.JLabel JavaDoc();
124         explorerPanel = createListView();
125         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
126         descriptionArea = new javax.swing.JTextArea JavaDoc();
127         jButtonActivate = new javax.swing.JButton JavaDoc();
128         jButtonClose = new javax.swing.JButton JavaDoc();
129         jButtonSave = new javax.swing.JButton JavaDoc();
130         closeButton = new javax.swing.JButton JavaDoc();
131
132         FormListener formListener = new FormListener();
133
134         setLayout(new java.awt.GridBagLayout JavaDoc());
135
136         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 0, 11));
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
139         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 0);
140         add(explorerLabel, gridBagConstraints);
141
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 0;
144         gridBagConstraints.gridy = 5;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 0);
147         add(descriptionLabel, gridBagConstraints);
148
149         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridx = 0;
151         gridBagConstraints.gridy = 1;
152         gridBagConstraints.gridheight = 4;
153         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
154         gridBagConstraints.weightx = 1.0;
155         gridBagConstraints.weighty = 1.0;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
157         add(explorerPanel, gridBagConstraints);
158
159         jScrollPane1.setPreferredSize(new java.awt.Dimension JavaDoc(3, 60));
160         descriptionArea.setEditable(false);
161         jScrollPane1.setViewportView(descriptionArea);
162
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridx = 0;
165         gridBagConstraints.gridy = 6;
166         gridBagConstraints.gridheight = 3;
167         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
168         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
170         add(jScrollPane1, gridBagConstraints);
171
172         jButtonActivate.addActionListener(formListener);
173
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 1;
176         gridBagConstraints.gridy = 1;
177         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
178         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
180         add(jButtonActivate, gridBagConstraints);
181
182         jButtonClose.addActionListener(formListener);
183
184         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridx = 1;
186         gridBagConstraints.gridy = 2;
187         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
188         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
190         add(jButtonClose, gridBagConstraints);
191
192         jButtonSave.addActionListener(formListener);
193
194         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
195         gridBagConstraints.gridx = 1;
196         gridBagConstraints.gridy = 3;
197         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
198         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
199         gridBagConstraints.weighty = 1.0;
200         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
201         add(jButtonSave, gridBagConstraints);
202
203         closeButton.addActionListener(formListener);
204
205         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
206         gridBagConstraints.gridx = 1;
207         gridBagConstraints.gridy = 7;
208         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
209         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
210         gridBagConstraints.weighty = 0.1;
211         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
212         add(closeButton, gridBagConstraints);
213
214     }
215
216     // Code for dispatching events from components to event handlers.
217

218     private class FormListener implements java.awt.event.ActionListener JavaDoc {
219         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
220             if (evt.getSource() == jButtonActivate) {
221                 DocumentsDlg.this.activate(evt);
222             }
223             else if (evt.getSource() == jButtonClose) {
224                 DocumentsDlg.this.closeDocuments(evt);
225             }
226             else if (evt.getSource() == jButtonSave) {
227                 DocumentsDlg.this.saveDocuments(evt);
228             }
229             else if (evt.getSource() == closeButton) {
230                 DocumentsDlg.this.closeButtonActionPerformed(evt);
231             }
232         }
233     }// </editor-fold>//GEN-END:initComponents
234

235     private void closeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_closeButtonActionPerformed
236
closeDialog();
237     }//GEN-LAST:event_closeButtonActionPerformed
238

239     private void saveDocuments(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_saveDocuments
240
// Add your handling code here:
241
Node[] selNodes = explorer.getSelectedNodes();
242         if (selNodes.length == 0) {
243             return;
244         }
245         for (int i = 0; i < selNodes.length; i++) {
246             TopComponent tc = ((TopComponentNode) selNodes[i]).getTopComponent();
247             Lookup l = tc.getLookup();
248             SaveCookie sc = (SaveCookie) l.lookup(SaveCookie.class);
249             if (sc != null) {
250                 try {
251                     sc.save();
252                 } catch (IOException JavaDoc exc) {
253                     Logger.getAnonymousLogger().log(Level.WARNING,
254                     "[WinSys.DocumentsDlg.saveDocuments]" // NOI18N
255
+ " Warning: Cannot save content of TopComponent: [" // NOI18N
256
+ WindowManagerImpl.getInstance().getTopComponentDisplayName(tc) + "]" // NOI18N
257
+ " [" + tc.getClass().getName() + "]", exc); // NOI18N
258
}
259                 //Refresh name of node because TopComponent name is probably changed too
260
//('*' is removed)
261
((TopComponentNode) selNodes[i]).refresh();
262             }
263         }
264         jButtonSave.setEnabled(false);
265     }//GEN-LAST:event_saveDocuments
266

267     private void closeDocuments(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_closeDocuments
268
// Add your handling code here:
269
Node[] selNodes = explorer.getSelectedNodes();
270         if (selNodes.length == 0) {
271             return;
272         }
273         for (int i = 0; i < selNodes.length; i++) {
274             TopComponent tc = ((TopComponentNode) selNodes[i]).getTopComponent();
275             tc.close();
276         }
277         
278         List JavaDoc<TopComponent> tcList = getOpenedDocuments();
279         List JavaDoc<TopComponentNode> tcNodes = new ArrayList JavaDoc<TopComponentNode> (tcList.size());
280         for (TopComponent tc : tcList) {
281             tcNodes.add(new TopComponentNode(tc));
282         }
283         
284         if(tcList.isEmpty()) {
285             // No opened documents left, close the dialog.
286
closeDialog();
287         } else {
288             // Update list view.
289
java.util.Collections.sort(tcNodes);
290             Children.Array nodeArray = new Children.Array();
291             nodeArray.add((TopComponentNode[])tcNodes.toArray(new TopComponentNode[0]));
292             Node root = new AbstractNode(nodeArray);
293             explorer.setRootContext(root);
294             //#54656 begin
295
try {
296                 explorer.setSelectedNodes(new Node[] {root.getChildren().getNodes()[0]});
297             } catch (PropertyVetoException JavaDoc exc) {
298                 //mkleint - well, what can we do, I've never seen the selection being vetoed anyway.
299
}
300             listView.requestFocusInWindow();
301             //#54656 end
302
}
303     }//GEN-LAST:event_closeDocuments
304

305     private void activate(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_activate
306
// Add your handling code here:
307
Node[] selNodes = explorer.getSelectedNodes();
308         if (selNodes.length == 0) {
309             return;
310         }
311         
312         closeDialog();
313         
314         final TopComponent tc = ((TopComponentNode) selNodes[0]).getTopComponent();
315         //Call using invokeLater to make sure it is performed after dialog
316
//is closed.
317
SwingUtilities.invokeLater(new Runnable JavaDoc () {
318             public void run() {
319                 // #37226-41075 Unmaximized the other mode if needed.
320
WindowManagerImpl wm = WindowManagerImpl.getInstance();
321                 ModeImpl mode = (ModeImpl)wm.findMode(tc);
322                 if(mode != null && mode != wm.getCurrentMaximizedMode()) {
323                     wm.switchMaximizedMode(null);
324                 }
325                 tc.requestActive();
326             }
327         });
328     }//GEN-LAST:event_activate
329

330     private void closeDialog() {
331         Window JavaDoc w = SwingUtilities.getWindowAncestor(this);
332         w.setVisible(false);
333         w.dispose();
334     }
335     
336     public void addNotify () {
337         explorer.addPropertyChangeListener(this);
338         jButtonActivate.setEnabled(false);
339         jButtonClose.setEnabled(false);
340         jButtonSave.setEnabled(false);
341         super.addNotify();
342     }
343     
344     public void removeNotify () {
345         super.removeNotify();
346         explorer.removePropertyChangeListener(this);
347     }
348
349
350     public static void showDocumentsDialog() {
351         DocumentsDlg documentsPanel = getDefault();
352         DialogDescriptor dlgDesc = new DialogDescriptor(
353             documentsPanel,
354             NbBundle.getMessage(DocumentsDlg.class, "CTL_DocumentsTitle"),
355             true, // is modal!!
356
new Object JavaDoc[0],
357             // make "switcch to document" button default
358
getDefault().jButtonActivate,
359             DialogDescriptor.DEFAULT_ALIGN,
360             null,
361             null
362         );
363         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);
364         dlg.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_DocumentsDialog"));
365         getDefault().updateNodes();
366         dlg.setVisible(true);
367         getDefault().clearNodes();
368     }
369     
370     /**
371      * Tells whether documents list is empty or not.
372      *
373      * @return true when document list contains no documents, false otherwise.
374      */

375     public static boolean isEmpty () {
376         for(Object JavaDoc elem : WindowManagerImpl.getInstance().getModes()) {
377             ModeImpl mode = (ModeImpl)elem;
378             if(mode.getKind() == Constants.MODE_KIND_EDITOR &&
379                !mode.getOpenedTopComponents().isEmpty()) {
380                 return false;
381             }
382         }
383         return true;
384     }
385     
386     private JPanel JavaDoc createListView () {
387         JPanel JavaDoc panel = new JPanel JavaDoc();
388         // Defined size in #36907 - surrounding controls will add to this size
389
// and result is desired 540x400. Note that we can't hardcode size of
390
// whole dialog to work correctly with different font size
391
panel.setPreferredSize(new Dimension JavaDoc(375, 232));
392         panel.setLayout(new BorderLayout JavaDoc());
393         listView = new ListView();
394         // proper border for the view
395
listView.setBorder((Border JavaDoc)UIManager.get("Nb.ScrollPane.border")); // NOI18N
396
listView.setPopupAllowed(false);
397         listView.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_ListView"));
398         //view.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
399
panel.add(listView, BorderLayout.CENTER);
400         return panel;
401     }
402     
403     private void updateNodes() {
404         //Create nodes for TopComponents, sort them using their own comparator
405
List JavaDoc<TopComponent> tcList = getOpenedDocuments();
406         TopComponent activeTC = TopComponent.getRegistry().getActivated();
407         TopComponentNode[] tcNodes = new TopComponentNode[tcList.size()];
408         TopComponentNode toSelect = null;
409         for (int i = 0; i < tcNodes.length; i++) {
410             TopComponent tc = tcList.get(i);
411             tcNodes[i] = new TopComponentNode(tc);
412             if( tc == activeTC ) {
413                 toSelect = tcNodes[i];
414             }
415         }
416         Arrays.sort(tcNodes);
417         
418         Children.Array nodeArray = new Children.Array();
419         nodeArray.add(tcNodes);
420         Node root = new AbstractNode(nodeArray);
421         explorer.setRootContext(root);
422         // set focus to documents list
423
listView.requestFocus();
424         // select the active editor tab or the first item if possible
425
if (tcNodes.length > 0) {
426             try {
427                 if( null == toSelect )
428                     toSelect = tcNodes[0];
429                 explorer.setSelectedNodes(new Node[] {toSelect} );
430             } catch (PropertyVetoException JavaDoc exc) {
431                 // do nothing, what should I do?
432
}
433         }
434     }
435     
436     private void clearNodes() {
437         explorer.setRootContext(Node.EMPTY);
438     }
439     
440     private static List JavaDoc<TopComponent> getOpenedDocuments() {
441         List JavaDoc<TopComponent> documents = new ArrayList JavaDoc<TopComponent> ();
442         for(Object JavaDoc elem : WindowManagerImpl.getInstance().getModes()) {
443             ModeImpl mode = (ModeImpl)elem;
444             if(mode.getKind() == Constants.MODE_KIND_EDITOR) {
445                 documents.addAll(mode.getOpenedTopComponents());
446             }
447         }
448         
449         return documents;
450     }
451     
452     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
453         if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
454             Node [] selNodes = (Node []) evt.getNewValue();
455             //Enable button Activate only if one node is selected
456
if (selNodes.length == 1) {
457                 jButtonActivate.setEnabled(true);
458             } else {
459                 jButtonActivate.setEnabled(false);
460             }
461             //Enable button Close only if at least one node is selected
462
if (selNodes.length > 0) {
463                 jButtonClose.setEnabled(true);
464             } else {
465                 jButtonClose.setEnabled(false);
466             }
467             //Check if any TopComponent in selection is modified.
468
//If TopComponent lookup returns SaveCookie
469
boolean enableSave = false;
470             for (int i = 0; i < selNodes.length; i++) {
471                 TopComponent tc = ((TopComponentNode) selNodes[i]).getTopComponent();
472                 Lookup l = tc.getLookup();
473                 SaveCookie sc = (SaveCookie) l.lookup(SaveCookie.class);
474                 if (sc != null) {
475                     enableSave = true;
476                     break;
477                 }
478             }
479             jButtonSave.setEnabled(enableSave);
480             
481             // Set description.
482
if(selNodes != null && selNodes.length == 1) {
483                 descriptionArea.setText(((TopComponentNode)selNodes[0]).getDescription());
484             } else {
485                 descriptionArea.setText(null);
486             }
487         }
488     }
489     
490     // Variables declaration - do not modify//GEN-BEGIN:variables
491
private javax.swing.JButton JavaDoc closeButton;
492     private javax.swing.JTextArea JavaDoc descriptionArea;
493     private javax.swing.JLabel JavaDoc descriptionLabel;
494     private javax.swing.JLabel JavaDoc explorerLabel;
495     private javax.swing.JPanel JavaDoc explorerPanel;
496     private javax.swing.JButton JavaDoc jButtonActivate;
497     private javax.swing.JButton JavaDoc jButtonClose;
498     private javax.swing.JButton JavaDoc jButtonSave;
499     private javax.swing.JScrollPane JavaDoc jScrollPane1;
500     // End of variables declaration//GEN-END:variables
501
private ListView listView;
502     
503     public ExplorerManager getExplorerManager() {
504         return explorer;
505     }
506     
507     private static final Collator JavaDoc COLLATOR = Collator.getInstance();
508
509     /** Used to display list of TopComponent in ListView. */
510     private class TopComponentNode extends AbstractNode
511                                    implements Comparable JavaDoc<TopComponentNode>, Action JavaDoc, PropertyChangeListener JavaDoc {
512         
513         private TopComponent tc;
514         
515         public TopComponentNode (TopComponent tc) {
516             super(Children.LEAF);
517             this.tc = tc;
518             tc.addPropertyChangeListener(WeakListeners.propertyChange(this, tc));
519         }
520         
521         public String JavaDoc getName() {
522             // #60263: apparently used by functional tests.
523
return tc.getName();
524         }
525         public String JavaDoc getDisplayName() {
526             // Also #60263. Forms do not have a tc.name??
527
String JavaDoc result = tc.getDisplayName();
528             return result != null ? result : tc.getName();
529         }
530
531         public String JavaDoc getHtmlDisplayName() {
532             return tc.getHtmlDisplayName();
533         }
534         
535         public Image JavaDoc getIcon (int type) {
536             Image JavaDoc image = tc.getIcon();
537             return image == null ? Utilities.loadImage("org/openide/resources/actions/empty.gif") : image; // NOI18N
538
}
539         
540         public String JavaDoc getDescription() {
541             return tc.getToolTipText();
542         }
543         
544         public TopComponent getTopComponent () {
545             return tc;
546         }
547         
548         /** Force refresh of node name in ListView. */
549         void refresh () {
550             fireNameChange(null, null);
551         }
552         
553         public int compareTo(TopComponentNode tcn) {
554             String JavaDoc displayName1 = getDisplayName();
555             String JavaDoc displayName2 = tcn.getDisplayName();
556             
557             if(displayName1 == null) {
558                 return displayName2 == null ? 0 : -1;
559             } else {
560                 return displayName2 == null ? 1 : COLLATOR.compare(displayName1, displayName2);
561             }
562         }
563         
564         /** Invokes itself ac action when double click or Enter pressed on node
565          */

566         public Action JavaDoc getPreferredAction() {
567             return this;
568         }
569
570         /** Implementation of Action interface, activates TopComponent
571          * currently selected in the list view (should be the same component
572          * that is asociated with this Node)
573          */

574         public void actionPerformed(ActionEvent JavaDoc evt) {
575             activate(evt);
576         }
577         
578         public boolean isEnabled() {
579             return true;
580         }
581         
582         public void putValue(String JavaDoc key, Object JavaDoc value) {
583             // no operation
584
}
585         
586         public void setEnabled(boolean b) {
587             // no operation
588
}
589
590         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
591             fireDisplayNameChange(null, null);
592         }
593         
594     }
595 }
596
Popular Tags