Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 192948 | Differences between
and this patch

Collapse All | Expand All

(-)a/openide.actions/src/org/openide/actions/SaveAction.java (-51 / +49 lines)
 Lines 45-58    Link Here 
45
package org.openide.actions;
45
package org.openide.actions;
46
46
47
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionEvent;
48
import java.beans.PropertyChangeListener;
49
import java.io.IOException;
48
import java.io.IOException;
49
import java.util.Collection;
50
import java.util.LinkedList;
50
import java.util.logging.Level;
51
import java.util.logging.Level;
51
import java.util.logging.Logger;
52
import java.util.logging.Logger;
52
import javax.swing.AbstractAction;
53
import javax.swing.AbstractAction;
53
import javax.swing.Action;
54
import javax.swing.Action;
54
import org.openide.DialogDisplayer;
55
import org.openide.NotifyDescriptor;
56
import org.openide.awt.StatusDisplayer;
55
import org.openide.awt.StatusDisplayer;
57
import org.openide.cookies.SaveCookie;
56
import org.openide.cookies.SaveCookie;
58
import org.openide.nodes.Node;
57
import org.openide.nodes.Node;
 Lines 61-74    Link Here 
61
import org.openide.util.HelpCtx;
60
import org.openide.util.HelpCtx;
62
import org.openide.util.Lookup;
61
import org.openide.util.Lookup;
63
import org.openide.util.NbBundle;
62
import org.openide.util.NbBundle;
64
import org.openide.util.UserQuestionException;
65
import org.openide.util.actions.CookieAction;
63
import org.openide.util.actions.CookieAction;
66
64
67
/** Save a single object.
65
/** Save a single object.
68
* @see SaveCookie
66
 * @see SaveCookie
69
*
67
 *
70
* @author   Jan Jancura, Petr Hamernik, Ian Formanek, Dafe Simonek
68
 * @author   Jan Jancura, Petr Hamernik, Ian Formanek, Dafe Simonek
71
*/
69
 */
72
public class SaveAction extends CookieAction {
70
public class SaveAction extends CookieAction {
73
    private static Class<? extends Node.Cookie> dataObject;
71
    private static Class<? extends Node.Cookie> dataObject;
74
    private static java.lang.reflect.Method getNodeDelegate;
72
    private static java.lang.reflect.Method getNodeDelegate;
 Lines 87-142    Link Here 
87
    }
85
    }
88
86
89
    final void performAction(Lookup context) {
87
    final void performAction(Lookup context) {
90
        SaveCookie sc = context.lookup(SaveCookie.class);
88
        Collection<? extends SaveCookie> cookieList = context.lookupAll(SaveCookie.class);
91
        if (sc == null) {
89
        Collection<? extends Node> nodeList = new LinkedList<Node>(context.lookupAll(Node.class));
92
            return;
90
91
        for (SaveCookie saveCookie : cookieList) {
92
            boolean cookieFromNode = false;
93
94
            //Determine if the saveCookie belongs to a node in our context
95
            for (Node node : nodeList) {
96
                if (saveCookie.equals(node.getCookie(SaveCookie.class))) {
97
                    performAction(saveCookie, node);
98
                    nodeList.remove(node);
99
                    cookieFromNode = true;
100
                    break;
101
                }
102
            }
103
104
            //The saveCookie was not found in any node in our context - save it
105
            //by itself.
106
            if (!cookieFromNode) performAction(saveCookie, null);
93
        }
107
        }
94
        Node n = context.lookup(Node.class);
95
        performAction(sc, n);
96
    }
108
    }
97
109
110
    protected void performAction(final Node[] activatedNodes) {
111
        for (int i = 0; i < activatedNodes.length; i++) {
112
            Node node = activatedNodes[i];
113
            SaveCookie sc = node.getCookie(SaveCookie.class);
114
            assert sc != null : "SaveCookie must be present on " + node + ". "
115
                    + "See http://www.netbeans.org/issues/show_bug.cgi?id=68285 for details on overriding " + node.getClass().getName() + ".getCookie correctly.";
98
116
99
    protected void performAction(final Node[] activatedNodes) {
117
            // avoid NPE if disabled assertions
100
        SaveCookie sc = activatedNodes[0].getCookie(SaveCookie.class);
118
            if (sc == null) return ;
101
        assert sc != null : "SaveCookie must be present on " + activatedNodes[0] + ". " +
102
                "See http://www.netbeans.org/issues/show_bug.cgi?id=68285 for details on overriding " + activatedNodes[0].getClass().getName() + ".getCookie correctly.";
103
        
104
        // avoid NPE if disabled assertions
105
        if (sc == null) return ;
106
119
107
        performAction(sc, activatedNodes[0]);
120
            performAction(sc, node);
121
        }
108
    }
122
    }
109
123
110
    private void performAction(SaveCookie sc, Node n) {
124
    private void performAction(SaveCookie sc, Node n) {
111
        UserQuestionException userEx = null;
125
        try {
112
        for (;;) {
126
            sc.save();
113
            try {
127
            StatusDisplayer.getDefault().setStatusText(
114
                if (userEx == null) {
115
                    sc.save();
116
                } else {
117
                    userEx.confirmed();
118
                }
119
                StatusDisplayer.getDefault().setStatusText(
120
                    NbBundle.getMessage(SaveAction.class, "MSG_saved", getSaveMessage(sc, n))
128
                    NbBundle.getMessage(SaveAction.class, "MSG_saved", getSaveMessage(sc, n))
121
                );
129
            );
122
            } catch (UserQuestionException ex) {
130
        }
123
                NotifyDescriptor nd = new NotifyDescriptor.Confirmation(ex.getLocalizedMessage(),
131
        catch (IOException e) {
124
                        NotifyDescriptor.YES_NO_OPTION);
132
            Exceptions.attachLocalizedMessage(e,
125
                Object res = DialogDisplayer.getDefault().notify(nd);
133
                                              NbBundle.getMessage(SaveAction.class,
126
134
                                                                  "EXC_notsaved",
127
                if (NotifyDescriptor.OK_OPTION.equals(res)) {
135
                                                                  getSaveMessage(sc, n),
128
                    userEx = ex;
136
                                                                  e.getLocalizedMessage ()));
129
                    continue;
137
            Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, e);
130
                }
131
            } catch (IOException e) {
132
                Exceptions.attachLocalizedMessage(e,
133
                                                  NbBundle.getMessage(SaveAction.class,
134
                                                                      "EXC_notsaved",
135
                                                                      getSaveMessage(sc, n),
136
                                                                      e.getLocalizedMessage ()));
137
                Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, e);
138
            }
139
            break;
140
        }
138
        }
141
    }
139
    }
142
140
 Lines 182-188    Link Here 
182
    }
180
    }
183
181
184
    protected int mode() {
182
    protected int mode() {
185
        return MODE_EXACTLY_ONE;
183
        return MODE_ANY;
186
    }
184
    }
187
185
188
    public String getName() {
186
    public String getName() {
 Lines 234-237    Link Here 
234
232
235
233
236
    }
234
    }
237
}
235
}

Return to bug 192948
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo