}
Object selection = firstSelectedElement();
if (contents != null) {
MapEditorPart activeEditor = ApplicationGISInternal.getActiveEditor();
final Map finalMap;
final UDIGDropHandler finalDropHandler;
if( selection instanceof Map){
finalMap = (Map)selection;
finalDropHandler = new UDIGDropHandler();
activeEditor=null;
} else if( activeEditor==null ){
CreateMapCommand command = new CreateMapCommand(null,Collections.<IGeoResource>emptyList(), null);
try {
command.run(new NullProgressMonitor());
} catch (Exception e) {
throw (RuntimeException) new RuntimeException( ).initCause( e );
}
finalMap = (Map) command.getCreatedMap();
finalDropHandler = new UDIGDropHandler();
} else {
finalDropHandler = activeEditor.getDropHandler();
finalMap = activeEditor.getMap();
}
final MapEditorPart finalActiveEditor = activeEditor;
ILayer selectedLayer = finalMap.getEditManager().getSelectedLayer();
if( selectedLayer==null ){
finalDropHandler.setTarget(finalMap);
}else{
finalDropHandler.setTarget(selectedLayer);