}
@Override
public boolean performDrop(final Object data) {
final String jobName = "Deploying application"; //$NON-NLS-1$
UIJob job = new UIJob(jobName) {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (data instanceof IStructuredSelection) {
Object modObj = ((IStructuredSelection) data).getFirstElement();
IProject prj = null;
if (modObj instanceof IProject) {
prj = (IProject) modObj;
}
else if (modObj instanceof IJavaProject) {
prj = ((IJavaProject) modObj).getProject();
}
if (prj != null) {
final CloudFoundryServer cloudServer = (CloudFoundryServer) editorPage.getServer()
.getOriginal().loadAdapter(CloudFoundryServer.class, monitor);
if (cloudServer != null) {
final String moduleName = prj.getName();
// First of all, should make sure there is no
// CloundApplicationModule
// with the same name of the selected project,
// otherwise it will cause
// the CloundApplicationModule with the same
// name and its related remote
// application in CF to be deleted.
if (cloudServer.getBehaviour().existCloudApplicationModule(moduleName)) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(
editorPage.getSite().getShell(),
Messages.ApplicationMasterPart_ERROR_DEPLOY_FAIL_TITLE,
NLS.bind(
Messages.ApplicationMasterPart_ERROR_DEPLOY_FAIL_BODY,
moduleName));
}
});
return Status.CANCEL_STATUS;
}
// Make sure parent performs the drop first to
// create the IModule. Unsupported modules will
// not proceed result in IModule creation
// therefore checks on the IProject are not
// necessary
ApplicationViewersDropAdapter.super.performDrop(data);
// Now do a publish AFTER the IModule is
// created. If no IModule is created (either
// user cancels or project
// is not supported), the publish operation will
// do nothing.
Job job = new Job(jobName) {
@Override
protected IStatus run(IProgressMonitor monitor) {
cloudServer.getBehaviour().publishAdd(moduleName, monitor);
return Status.OK_STATUS;
}
};
job.setPriority(Job.INTERACTIVE);
job.schedule();
return Status.OK_STATUS;
}
}
}
return Status.CANCEL_STATUS;
}
};
job.schedule();
return true;
}