Fix Class cast Exception (see #9960) (rebased onto develop)



This is the same as gh-882 but rebased onto develop.

----

Fix exception when object selected was not a dataset.
see https://trac.openmicroscopy.org.uk/ome/ticket/9960