1 19 20 package org.netbeans.modules.tasklist.usertasks.actions; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.InputEvent ; 24 import java.awt.event.KeyEvent ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.io.IOException ; 28 import javax.swing.AbstractAction ; 29 import javax.swing.Action ; 30 import javax.swing.KeyStroke ; 31 import org.openide.NotifyDescriptor; 32 import org.openide.NotifyDescriptor; 33 import org.openide.actions.SaveAction; 34 import org.openide.cookies.SaveCookie; 35 import org.openide.loaders.DataObject; 36 import org.openide.nodes.Node; 37 import org.openide.util.Lookup; 38 import org.openide.util.LookupEvent; 39 import org.openide.util.LookupListener; 40 import org.openide.util.NbBundle; 41 import org.openide.util.actions.SystemAction; 42 43 48 public class UTSaveAction extends AbstractAction 49 implements PropertyChangeListener { 50 private DataObject n; 51 52 57 public UTSaveAction(DataObject do_) { 58 this.n = do_; 59 putValue(Action.NAME, SystemAction.get(SaveAction.class). 60 getValue(NAME)); 61 putValue(SMALL_ICON, SystemAction.get(SaveAction.class). 62 getValue(SMALL_ICON)); 63 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, 64 InputEvent.CTRL_MASK)); 65 n.addPropertyChangeListener(this); 66 propertyChange(null); 67 } 68 69 public void actionPerformed(ActionEvent e) { 70 try { 71 SaveCookie c = n.getCookie(SaveCookie.class); 72 c.save(); 73 } catch (IOException ex) { 74 NotifyDescriptor nd = new NotifyDescriptor.Message( 75 NbBundle.getMessage(UTSaveAction.class, 76 "ErrorSaving", ex.getMessage()), 78 NotifyDescriptor.ERROR_MESSAGE); 79 } 80 } 81 82 public void propertyChange(PropertyChangeEvent e) { 83 setEnabled(n.getCookie(SaveCookie.class) != null); 84 } 85 } 86 | Popular Tags |