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);
}
finalDropHandler.addListener(new IDropHandlerListener(){
public void done( IDropAction action, Throwable error ) {
if( finalActiveEditor==null && finalMap.getMapLayers().size()==0 ){
finalMap.getProjectInternal().getElementsInternal().remove(finalMap);
}
finalDropHandler.removeListener(this);
}
public void noAction( Object data ) {
if( finalActiveEditor==null && finalMap.getMapLayers().size()==0 ){
finalMap.getProjectInternal().getElementsInternal().remove(finalMap);
}
finalDropHandler.removeListener(this);
}
public void starting( IDropAction action ) {
}
});
finalDropHandler.setViewerLocation(ViewerDropLocation.ON);
finalDropHandler.performDrop(contents, null);
}
}