KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > actions > UTSaveAction


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.modules.tasklist.usertasks.actions;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.InputEvent JavaDoc;
24 import java.awt.event.KeyEvent JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.io.IOException JavaDoc;
28 import javax.swing.AbstractAction JavaDoc;
29 import javax.swing.Action JavaDoc;
30 import javax.swing.KeyStroke JavaDoc;
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 /**
44  * Save.
45  *
46  * @author tl
47  */

48 public class UTSaveAction extends AbstractAction JavaDoc
49         implements PropertyChangeListener JavaDoc {
50     private DataObject n;
51     
52     /**
53      * Creates a new instance of UTSaveAction.
54      *
55      * @param do_ looking here for SaveCookie
56      */

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 JavaDoc e) {
70         try {
71             SaveCookie c = n.getCookie(SaveCookie.class);
72             c.save();
73         } catch (IOException JavaDoc ex) {
74             NotifyDescriptor nd = new NotifyDescriptor.Message(
75                     NbBundle.getMessage(UTSaveAction.class,
76                     "ErrorSaving", // NOI18N
77
ex.getMessage()),
78                     NotifyDescriptor.ERROR_MESSAGE);
79         }
80     }
81
82     public void propertyChange(PropertyChangeEvent JavaDoc e) {
83         setEnabled(n.getCookie(SaveCookie.class) != null);
84     }
85 }
86
Popular Tags