Lines 47-52
Link Here
|
47 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionEvent; |
48 |
import java.beans.PropertyChangeListener; |
48 |
import java.beans.PropertyChangeListener; |
49 |
import java.io.IOException; |
49 |
import java.io.IOException; |
|
|
50 |
import java.util.Collection; |
51 |
import java.util.LinkedList; |
50 |
import java.util.logging.Level; |
52 |
import java.util.logging.Level; |
51 |
import java.util.logging.Logger; |
53 |
import java.util.logging.Logger; |
52 |
import javax.swing.AbstractAction; |
54 |
import javax.swing.AbstractAction; |
Lines 64-74
Link Here
|
64 |
import org.openide.util.UserQuestionException; |
66 |
import org.openide.util.UserQuestionException; |
65 |
import org.openide.util.actions.CookieAction; |
67 |
import org.openide.util.actions.CookieAction; |
66 |
|
68 |
|
67 |
/** Save a single object. |
69 |
/** Save a one or more objects. Since version 6.20 this handles ANY selection |
68 |
* @see SaveCookie |
70 |
* instead of EXACTLY_ONE selection. |
69 |
* |
71 |
* @see SaveCookie |
70 |
* @author Jan Jancura, Petr Hamernik, Ian Formanek, Dafe Simonek |
72 |
* |
71 |
*/ |
73 |
* @author Jan Jancura, Petr Hamernik, Ian Formanek, Dafe Simonek |
|
|
74 |
*/ |
72 |
public class SaveAction extends CookieAction { |
75 |
public class SaveAction extends CookieAction { |
73 |
private static Class<? extends Node.Cookie> dataObject; |
76 |
private static Class<? extends Node.Cookie> dataObject; |
74 |
private static java.lang.reflect.Method getNodeDelegate; |
77 |
private static java.lang.reflect.Method getNodeDelegate; |
Lines 87-110
Link Here
|
87 |
} |
90 |
} |
88 |
|
91 |
|
89 |
final void performAction(Lookup context) { |
92 |
final void performAction(Lookup context) { |
90 |
SaveCookie sc = context.lookup(SaveCookie.class); |
93 |
Collection<? extends SaveCookie> cookieList = context.lookupAll(SaveCookie.class); |
91 |
if (sc == null) { |
94 |
Collection<? extends Node> nodeList = new LinkedList<Node>(context.lookupAll(Node.class)); |
92 |
return; |
95 |
|
|
|
96 |
COOKIE: for (SaveCookie saveCookie : cookieList) { |
97 |
|
98 |
//Determine if the saveCookie belongs to a node in our context |
99 |
for (Node node : nodeList) { |
100 |
if (saveCookie.equals(node.getCookie(SaveCookie.class))) { |
101 |
performAction(saveCookie, node); |
102 |
nodeList.remove(node); |
103 |
continue COOKIE; |
104 |
} |
105 |
} |
106 |
|
107 |
//The saveCookie was not found in any node in our context - save it by itself. |
108 |
performAction(saveCookie, null); |
93 |
} |
109 |
} |
94 |
Node n = context.lookup(Node.class); |
|
|
95 |
performAction(sc, n); |
96 |
} |
110 |
} |
97 |
|
111 |
|
|
|
112 |
protected void performAction(final Node[] activatedNodes) { |
113 |
for (int i = 0; i < activatedNodes.length; i++) { |
114 |
Node node = activatedNodes[i]; |
115 |
SaveCookie sc = node.getCookie(SaveCookie.class); |
116 |
assert sc != null : "SaveCookie must be present on " + node + ". " |
117 |
+ "See http://www.netbeans.org/issues/show_bug.cgi?id=68285 for details on overriding " + node.getClass().getName() + ".getCookie correctly."; |
98 |
|
118 |
|
99 |
protected void performAction(final Node[] activatedNodes) { |
119 |
// avoid NPE if disabled assertions |
100 |
SaveCookie sc = activatedNodes[0].getCookie(SaveCookie.class); |
120 |
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 |
|
121 |
|
107 |
performAction(sc, activatedNodes[0]); |
122 |
performAction(sc, node); |
|
|
123 |
} |
108 |
} |
124 |
} |
109 |
|
125 |
|
110 |
private void performAction(SaveCookie sc, Node n) { |
126 |
private void performAction(SaveCookie sc, Node n) { |
Lines 182-188
Link Here
|
182 |
} |
198 |
} |
183 |
|
199 |
|
184 |
protected int mode() { |
200 |
protected int mode() { |
185 |
return MODE_EXACTLY_ONE; |
201 |
return MODE_ANY; |
186 |
} |
202 |
} |
187 |
|
203 |
|
188 |
public String getName() { |
204 |
public String getName() { |