This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 192948
Collapse All | Expand All

(-)a/core.ui/src/org/netbeans/core/ui/resources/layer.xml (-4 / +4 lines)
Lines 172-178 Link Here
172
            <file name="org-openide-actions-SaveAction.instance">
172
            <file name="org-openide-actions-SaveAction.instance">
173
                <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.context'/>
173
                <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.context'/>
174
                <attr name='delegate' newvalue='org.openide.actions.SaveAction'/>
174
                <attr name='delegate' newvalue='org.openide.actions.SaveAction'/>
175
                <attr name="selectionType" stringvalue="EXACTLY_ONE"/>
175
                <attr name="selectionType" stringvalue="ANY"/>
176
                <attr name='surviveFocusChange' boolvalue="false"/>
176
                <attr name='surviveFocusChange' boolvalue="false"/>
177
                <attr name='displayName' bundlevalue='org/openide/actions/Bundle#Save'/>
177
                <attr name='displayName' bundlevalue='org/openide/actions/Bundle#Save'/>
178
                <attr name='noIconInMenu' boolvalue="true"/>
178
                <attr name='noIconInMenu' boolvalue="true"/>
Lines 212-219 Link Here
212
                <attr name="iconBase" stringvalue="org/netbeans/core/resources/log-file.gif"/>
212
                <attr name="iconBase" stringvalue="org/netbeans/core/resources/log-file.gif"/>
213
                <attr name="displayName" bundlevalue="org.netbeans.core.actions.Bundle#MSG_LogTab_name"/>
213
                <attr name="displayName" bundlevalue="org.netbeans.core.actions.Bundle#MSG_LogTab_name"/>
214
            </file>
214
            </file>
215
        </folder>        
215
        </folder>
216
        
216
217
        <folder name="Tools">
217
        <folder name="Tools">
218
            <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.core.ui.resources.Bundle"/>
218
            <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.core.ui.resources.Bundle"/>
219
        </folder>
219
        </folder>
Lines 333-339 Link Here
333
            <file name="org-netbeans-core-actions-LogAction.shadow">
333
            <file name="org-netbeans-core-actions-LogAction.shadow">
334
                <attr name="position" intvalue="500"/>
334
                <attr name="position" intvalue="500"/>
335
                <attr name="originalFile" stringvalue="Actions/View/org-netbeans-core-actions-LogAction.instance"/>
335
                <attr name="originalFile" stringvalue="Actions/View/org-netbeans-core-actions-LogAction.instance"/>
336
            </file>	 
336
            </file>
337
        </folder>
337
        </folder>
338
338
339
        <folder name="GoTo">
339
        <folder name="GoTo">
(-)a/openide.actions/apichanges.xml (-2 / +16 lines)
Lines 52-57 Link Here
52
<changes>
52
<changes>
53
<change>
53
<change>
54
      <api name="actions"/>
54
      <api name="actions"/>
55
      <summary><code>SelectionType ANY in SaveAction</code></summary>
56
      <version major="6" minor="20"/>
57
      <date day="14" month="12" year="2010"/>
58
      <author login="krissco"/>
59
      <compatibility binary="compatible" source="compatible" semantic="compatible" addition="no" deprecation="no" deletion="no" modification="yes"/>
60
      <description>
61
          <code>SaveAction</code> has been modified to allow one or more <code>SaveCookie</code>s
62
          into it's context. The previous behavior was to allow EXACTLY_ONE.
63
      </description>
64
      <class package="org.openide.actions" name="SaveAction"/>
65
      <issue number="192948"/>
66
</change>
67
<change>
68
      <api name="actions"/>
55
      <summary><code>ToolsAction via layers</code></summary>
69
      <summary><code>ToolsAction via layers</code></summary>
56
      <version major="6" minor="15"/>
70
      <version major="6" minor="15"/>
57
      <date day="26" month="2" year="2010"/>
71
      <date day="26" month="2" year="2010"/>
Lines 91-97 Link Here
91
 topComponent.getActionMap().put("jumpPrev", new YourPrevAction());
105
 topComponent.getActionMap().put("jumpPrev", new YourPrevAction());
92
 topComponent.getActionMap().put("jumpNext", new YourNextAction());
106
 topComponent.getActionMap().put("jumpNext", new YourNextAction());
93
          </pre>
107
          </pre>
94
          if your component provides items and you want the user to jump 
108
          if your component provides items and you want the user to jump
95
          among them using standard next/prev actions.
109
          among them using standard next/prev actions.
96
        </description>
110
        </description>
97
        <issue number="40185"/>
111
        <issue number="40185"/>
Lines 107-113 Link Here
107
        This action was used only as default action on templates. It instantiates the
121
        This action was used only as default action on templates. It instantiates the
108
        template when it was double clicked in the Options dialog. This behaviour
122
        template when it was double clicked in the Options dialog. This behaviour
109
        was changed and action is not useful anymore. It is deprecated and it usage
123
        was changed and action is not useful anymore. It is deprecated and it usage
110
        should be avoided. Part of the deprecatation was that 
124
        should be avoided. Part of the deprecatation was that
111
        org.openide.loadersDataNode.getDefaultAction() does not return this action
125
        org.openide.loadersDataNode.getDefaultAction() does not return this action
112
        on templates anymore.
126
        on templates anymore.
113
     </description>
127
     </description>
(-)a/openide.actions/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.actions
2
OpenIDE-Module: org.openide.actions
3
OpenIDE-Module-Localizing-Bundle: org/openide/actions/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/actions/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 6.19
5
OpenIDE-Module-Specification-Version: 6.20
6
6
(-)a/openide.actions/src/org/openide/actions/SaveAction.java (-18 / +34 lines)
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) {
(-)a/openide.actions/test/unit/src/org/openide/actions/SaveActionTest.java (+20 lines)
Lines 67-72 Link Here
67
    }
67
    }
68
68
69
    public void testActionWorksOnSaveCookieOnly() {
69
    public void testActionWorksOnSaveCookieOnly() {
70
        cnt = 0;
70
        Lookup lkp = Lookups.singleton(this);
71
        Lookup lkp = Lookups.singleton(this);
71
        SaveAction sa = SaveAction.get(SaveAction.class);
72
        SaveAction sa = SaveAction.get(SaveAction.class);
72
        Action clone = sa.createContextAwareInstance(lkp);
73
        Action clone = sa.createContextAwareInstance(lkp);
Lines 77-80 Link Here
77
    public void save() throws IOException {
78
    public void save() throws IOException {
78
        cnt++;
79
        cnt++;
79
    }
80
    }
81
    
82
    public void testActionWorksOnMultipleSaveCookies() {
83
        cnt = 0;
84
        SaveCookie cookie1 = new SaveCookieTestImpl();
85
        SaveCookie cookie2 = new SaveCookieTestImpl();
86
        Lookup lkp = Lookups.fixed(cookie1, cookie2);
87
        SaveAction sa = SaveAction.get(SaveAction.class);
88
        Action clone = sa.createContextAwareInstance(lkp);
89
        clone.actionPerformed(new ActionEvent(this, 0, ""));
90
        assertEquals("Save was called multiple times", 2, cnt);
91
    }
92
93
    private class SaveCookieTestImpl implements SaveCookie {
94
95
        @Override
96
        public void save() throws IOException {
97
            cnt++;
98
        }
99
    }
80
}
100
}

Return to bug 192948