KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > actions > DocumentsAction


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.actions;
21
22 import org.netbeans.core.windows.ModeImpl;
23 import org.netbeans.core.windows.WindowManagerImpl;
24 import org.netbeans.core.windows.view.ui.DocumentsDlg;
25 import org.openide.util.NbBundle;
26 import org.openide.util.WeakListeners;
27 import org.openide.windows.TopComponent;
28
29 import javax.swing.*;
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32
33
34 /**
35  * Shows list of opened documents in dialog.
36  *
37  * @author Peter Zavadsky
38  */

39 public class DocumentsAction extends AbstractAction implements Runnable JavaDoc {
40
41     private final PropertyChangeListener JavaDoc propListener;
42     
43     public DocumentsAction() {
44         putValue(Action.NAME, NbBundle.getMessage(DocumentsAction.class, "CTL_DocumentsAction"));
45
46         propListener = new PropertyChangeListener JavaDoc() {
47             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
48                 if(TopComponent.Registry.PROP_OPENED.equals(evt.getPropertyName())) {
49                     updateState();
50                 }
51            }
52         };
53         TopComponent.Registry registry = TopComponent.getRegistry();
54         registry.addPropertyChangeListener(WeakListeners.propertyChange(propListener, registry));
55
56         // #37529 WindowsAPI to be called from AWT thread only.
57
if(SwingUtilities.isEventDispatchThread()) {
58             updateState();
59         } else {
60             SwingUtilities.invokeLater(new Runnable JavaDoc() {
61                 public void run() {
62                     updateState();
63                 }
64             });
65         }
66     }
67     
68     /** Perform the action. Tries the performer and then scans the ActionMap
69      * of selected topcomponent.
70      */

71     public void actionPerformed(java.awt.event.ActionEvent JavaDoc ev) {
72         if (SwingUtilities.isEventDispatchThread()) {
73             run();
74         } else {
75             SwingUtilities.invokeLater(this);
76         }
77     }
78     
79     /** Display Documents dialog in AWT thread. */
80     public void run () {
81         DocumentsDlg.showDocumentsDialog();
82     }
83     
84     private void updateState() {
85         // #81939: enable action if documents list isn't empty
86
setEnabled(!DocumentsDlg.isEmpty());
87     }
88     
89 }
90
91
Popular Tags