1 19 20 21 package org.netbeans.core.windows.actions; 22 23 24 import org.netbeans.core.windows.Constants; 25 import org.netbeans.core.windows.ModeImpl; 26 import org.netbeans.core.windows.WindowManagerImpl; 27 import org.openide.util.NbBundle; 28 import org.openide.util.WeakListeners; 29 import org.openide.windows.TopComponent; 30 31 import javax.swing.*; 32 import java.beans.PropertyChangeEvent ; 33 import java.beans.PropertyChangeListener ; 34 35 36 39 public class CloneDocumentAction extends AbstractAction 40 implements PropertyChangeListener { 41 42 public CloneDocumentAction() { 43 putValue(NAME, NbBundle.getMessage(CloneDocumentAction.class, "CTL_CloneDocumentAction")); 44 TopComponent.getRegistry().addPropertyChangeListener( 45 WeakListeners.propertyChange(this, TopComponent.getRegistry())); 46 updateEnabled(); 47 } 48 49 50 public void actionPerformed(java.awt.event.ActionEvent ev) { 51 TopComponent tc = TopComponent.getRegistry().getActivated(); 52 if(tc == null || !(tc instanceof TopComponent.Cloneable)) { 53 return; 54 } 55 56 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc); 57 if(mode == null) { 58 return; 59 } 60 61 if(mode.getKind() == Constants.MODE_KIND_EDITOR) { 62 ActionUtils.cloneWindow(tc); 63 } 64 } 65 66 public void propertyChange(PropertyChangeEvent evt) { 67 if(TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) { 68 updateEnabled(); 69 } 70 } 71 72 private void updateEnabled() { 73 TopComponent tc = TopComponent.getRegistry().getActivated(); 74 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc); 75 setEnabled(tc instanceof TopComponent.Cloneable 76 && mode != null && mode.getKind() == Constants.MODE_KIND_EDITOR); 77 } 78 79 } 80 81 | Popular Tags |