1 19 20 21 package org.netbeans.core.windows.actions; 22 23 24 import org.openide.util.NbBundle; 25 import org.openide.util.WeakListeners; 26 import org.openide.util.Mutex; 27 import org.openide.windows.TopComponent; 28 import org.netbeans.core.windows.ModeImpl; 29 import org.netbeans.core.windows.WindowManagerImpl; 30 import org.netbeans.core.windows.Constants; 31 32 import javax.swing.*; 33 import java.beans.PropertyChangeEvent ; 34 import java.beans.PropertyChangeListener ; 35 import java.awt.event.KeyEvent ; 36 37 38 41 public class CloseAllButThisAction extends AbstractAction 42 implements PropertyChangeListener , Runnable { 43 44 public CloseAllButThisAction() { 45 putValue(NAME, NbBundle.getMessage(CloseAllButThisAction.class, 46 "CTL_CloseAllButThisAction")); 48 TopComponent.getRegistry().addPropertyChangeListener( 49 WeakListeners.propertyChange(this, TopComponent.getRegistry())); 50 updateEnabled(); 51 } 52 53 private TopComponent tc; 54 public CloseAllButThisAction(TopComponent topComp) { 55 tc = topComp; 56 putValue(Action.NAME, NbBundle.getMessage(ActionUtils.class, 59 "LBL_CloseAllButThisAction")); 61 } 62 63 64 public void actionPerformed(java.awt.event.ActionEvent ev) { 65 TopComponent topC = tc; 66 if (topC == null) { 67 topC = TopComponent.getRegistry().getActivated(); 69 } 70 if(topC != null) { 71 ActionUtils.closeAllExcept(topC); 72 } 73 } 74 75 public void propertyChange(PropertyChangeEvent evt) { 76 if(TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) { 77 updateEnabled(); 78 } 79 } 80 81 private void updateEnabled() { 82 Mutex.EVENT.readAccess(this); 83 } 84 85 88 public void putValue(String key, Object newValue) { 89 if (Action.ACCELERATOR_KEY.equals(key)) { 90 ActionUtils.putSharedAccelerator("CloseAllButThis", newValue); } else { 92 super.putValue(key, newValue); 93 } 94 } 95 96 99 public Object getValue(String key) { 100 if (Action.ACCELERATOR_KEY.equals(key)) { 101 return ActionUtils.getSharedAccelerator("CloseAllButThis"); } else { 103 return super.getValue(key); 104 } 105 } 106 107 public void run() { 108 TopComponent tc = TopComponent.getRegistry().getActivated(); 109 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc); 110 setEnabled(tc instanceof TopComponent.Cloneable 111 && mode != null && mode.getKind() == Constants.MODE_KIND_EDITOR); 112 } 113 114 } 115 116 | Popular Tags |