Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 392110

Summary: forceSingleItem doesn't work for extension commands with a run() method
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: ClientAssignee: Mark Macdonald <mamacdon>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse, ken_walker, susan
Version: 1.0Flags: susan: review+
ken_walker: review+
Target Milestone: 1.0 RC3   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2012-10-16 15:24:42 EDT
1. Install the plugin: http://orionhub.org/plugins/sampleCommandsPlugin.html
2. Go to Navigator. Select a single item
3. Actions > Run Code on Single Item

The command prints 'undefined'. This is because it expects to receive a single element as its parameter, but it's getting an array instead.
Comment 2 Susan McCourt CLA 2012-10-16 16:04:48 EDT
+1 for the fix, good catch.
Clearly the intention was to do this and it was sloppily coded.

Adding Ken for approval for RC3.

RAFAEL - This change will break your existing implementation of the Cloudfier "Deploy" command which was coding around this bug.  You will need to change

    var deploy = function(selection) {
        return dojo.xhrPost({
             postData: '',
             handleAs: 'json',
             url: "../mdd/deployer/?path=" + selection[0].Location
        });
    };

to

    var deploy = function(selection) {
        return dojo.xhrPost({
             postData: '',
             handleAs: 'json',
             url: "../mdd/deployer/?path=" + selection.Location
        });
    };
Comment 3 Ken Walker CLA 2012-10-16 16:31:25 EDT
Tested and verified
Comment 5 Rafael Chaves CLA 2012-10-17 00:27:24 EDT
Thanks for the heads-up! Honestly, the original behavior didn't strike me as a surprising behavior - I wouldn't expect the type of an argument to change depending on the the size of the selection. I assume this (parameter type varying) is consistent with other Orion API? For a Java-head like me, the new behavior is surprising, but we are not in Java-land anyways.
Comment 6 Susan McCourt CLA 2012-10-17 11:14:05 EDT
(In reply to comment #5)
> Thanks for the heads-up! Honestly, the original behavior didn't strike me as
> a surprising behavior - I wouldn't expect the type of an argument to change
> depending on the the size of the selection. I assume this (parameter type
> varying) is consistent with other Orion API? For a Java-head like me, the
> new behavior is surprising, but we are not in Java-land anyways.

It's not so much that it changes depending on size of the selection, but that you were using "forceSingleItem" in your definition, which means your command is only ever enabled for a single item.  That is what affects the selection parameter.  If you weren't using that property, then your command would be enabled for multiple selection and you would get the array.
Comment 7 Rafael Chaves CLA 2012-10-17 11:32:48 EDT
Thanks, Susan, I understand that, I meant the size of the *intended* selection (single, multiple). But no biggie, just a data point.