--- a/openide.actions/src/org/openide/actions/SaveAction.java +++ a/openide.actions/src/org/openide/actions/SaveAction.java @@ -45,14 +45,13 @@ package org.openide.actions; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeListener; import java.io.IOException; +import java.util.Collection; +import java.util.LinkedList; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; import org.openide.awt.StatusDisplayer; import org.openide.cookies.SaveCookie; import org.openide.nodes.Node; @@ -61,14 +60,13 @@ import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.NbBundle; -import org.openide.util.UserQuestionException; import org.openide.util.actions.CookieAction; /** Save a single object. -* @see SaveCookie -* -* @author Jan Jancura, Petr Hamernik, Ian Formanek, Dafe Simonek -*/ + * @see SaveCookie + * + * @author Jan Jancura, Petr Hamernik, Ian Formanek, Dafe Simonek + */ public class SaveAction extends CookieAction { private static Class dataObject; private static java.lang.reflect.Method getNodeDelegate; @@ -87,56 +85,56 @@ } final void performAction(Lookup context) { - SaveCookie sc = context.lookup(SaveCookie.class); - if (sc == null) { - return; + Collection cookieList = context.lookupAll(SaveCookie.class); + Collection nodeList = new LinkedList(context.lookupAll(Node.class)); + + for (SaveCookie saveCookie : cookieList) { + boolean cookieFromNode = false; + + //Determine if the saveCookie belongs to a node in our context + for (Node node : nodeList) { + if (saveCookie.equals(node.getCookie(SaveCookie.class))) { + performAction(saveCookie, node); + nodeList.remove(node); + cookieFromNode = true; + break; + } + } + + //The saveCookie was not found in any node in our context - save it + //by itself. + if (!cookieFromNode) performAction(saveCookie, null); } - Node n = context.lookup(Node.class); - performAction(sc, n); } + protected void performAction(final Node[] activatedNodes) { + for (int i = 0; i < activatedNodes.length; i++) { + Node node = activatedNodes[i]; + SaveCookie sc = node.getCookie(SaveCookie.class); + assert sc != null : "SaveCookie must be present on " + node + ". " + + "See http://www.netbeans.org/issues/show_bug.cgi?id=68285 for details on overriding " + node.getClass().getName() + ".getCookie correctly."; - protected void performAction(final Node[] activatedNodes) { - SaveCookie sc = activatedNodes[0].getCookie(SaveCookie.class); - assert sc != null : "SaveCookie must be present on " + activatedNodes[0] + ". " + - "See http://www.netbeans.org/issues/show_bug.cgi?id=68285 for details on overriding " + activatedNodes[0].getClass().getName() + ".getCookie correctly."; - - // avoid NPE if disabled assertions - if (sc == null) return ; + // avoid NPE if disabled assertions + if (sc == null) return ; - performAction(sc, activatedNodes[0]); + performAction(sc, node); + } } private void performAction(SaveCookie sc, Node n) { - UserQuestionException userEx = null; - for (;;) { - try { - if (userEx == null) { - sc.save(); - } else { - userEx.confirmed(); - } - StatusDisplayer.getDefault().setStatusText( + try { + sc.save(); + StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(SaveAction.class, "MSG_saved", getSaveMessage(sc, n)) - ); - } catch (UserQuestionException ex) { - NotifyDescriptor nd = new NotifyDescriptor.Confirmation(ex.getLocalizedMessage(), - NotifyDescriptor.YES_NO_OPTION); - Object res = DialogDisplayer.getDefault().notify(nd); - - if (NotifyDescriptor.OK_OPTION.equals(res)) { - userEx = ex; - continue; - } - } catch (IOException e) { - Exceptions.attachLocalizedMessage(e, - NbBundle.getMessage(SaveAction.class, - "EXC_notsaved", - getSaveMessage(sc, n), - e.getLocalizedMessage ())); - Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, e); - } - break; + ); + } + catch (IOException e) { + Exceptions.attachLocalizedMessage(e, + NbBundle.getMessage(SaveAction.class, + "EXC_notsaved", + getSaveMessage(sc, n), + e.getLocalizedMessage ())); + Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, e); } } @@ -182,7 +180,7 @@ } protected int mode() { - return MODE_EXACTLY_ONE; + return MODE_ANY; } public String getName() { @@ -234,4 +232,4 @@ } -} +}