1 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 ; 31 import java.beans.PropertyChangeListener ; 32 33 34 39 public class DocumentsAction extends AbstractAction implements Runnable { 40 41 private final PropertyChangeListener propListener; 42 43 public DocumentsAction() { 44 putValue(Action.NAME, NbBundle.getMessage(DocumentsAction.class, "CTL_DocumentsAction")); 45 46 propListener = new PropertyChangeListener () { 47 public void propertyChange(PropertyChangeEvent 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 if(SwingUtilities.isEventDispatchThread()) { 58 updateState(); 59 } else { 60 SwingUtilities.invokeLater(new Runnable () { 61 public void run() { 62 updateState(); 63 } 64 }); 65 } 66 } 67 68 71 public void actionPerformed(java.awt.event.ActionEvent ev) { 72 if (SwingUtilities.isEventDispatchThread()) { 73 run(); 74 } else { 75 SwingUtilities.invokeLater(this); 76 } 77 } 78 79 80 public void run () { 81 DocumentsDlg.showDocumentsDialog(); 82 } 83 84 private void updateState() { 85 setEnabled(!DocumentsDlg.isEmpty()); 87 } 88 89 } 90 91 | Popular Tags |