/*
  * Check that the default teiid instance is connected.  Show dialog if it is not.
  * @return 'true' if default teiid instance is connected, 'false' if not.
  */
 private boolean checkForConnectedServer() {
   ITeiidServer teiidServer = getServerManager().getDefaultServer();
   if (teiidServer == null || !teiidServer.isConnected()) {
     Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
     String title = UTIL.getString("ActionRequiresServer.title"); // $NON-NLS-1$
     String msg = UTIL.getString("ActionRequiresServer.msg"); // $NON-NLS-1$
     MessageDialog.openInformation(shell, title, msg);
     return false;
   }
   return true;
 }
  /**
   * Deploy the given vdb to the given Teiid Instance
   *
   * @param teiidServer the Teiid Instance
   * @param vdbOrVdbFile the VDB
   * @param doCreateDataSource 'true' to create corresponding datasource, 'false' if not.
   */
  public static boolean deployVdb(
      ITeiidServer teiidServer, final Object vdbOrVdbFile, final boolean doCreateDataSource) {
    Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();

    try {
      if (!(vdbOrVdbFile instanceof IFile) && !(vdbOrVdbFile instanceof Vdb)) {
        throw new IllegalArgumentException(
            UTIL.getString(I18N_PREFIX + "selectionIsNotAVdb")); // $NON-NLS-1$
      }

      // make sure there is a Teiid connection
      if (!teiidServer.isConnected()) {
        return false;
      }

      Vdb vdb =
          ((vdbOrVdbFile instanceof IFile)
              ? new Vdb((IFile) vdbOrVdbFile, null)
              : (Vdb) vdbOrVdbFile);

      if (!vdb.isSynchronized()) {
        String title = UTIL.getString("VdbNotSyncdDialog.title"); // $NON-NLS-1$
        String msg = UTIL.getString("VdbNotSyncdDialog.msg"); // $NON-NLS-1$
        if (!MessageDialog.openQuestion(shell, title, msg)) return false;
      }

      final VdbDeployer deployer = new VdbDeployer(shell, vdb, teiidServer, doCreateDataSource);
      ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);

      failedModelName = null;

      IRunnableWithProgress runnable =
          new IRunnableWithProgress() {
            /**
             * {@inheritDoc}
             *
             * @see
             *     org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
             */
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
              try {
                failedModelName = deployer.deploy(monitor);
              } catch (Exception e) {
                throw new InvocationTargetException(e);
              }
            }
          };

      // deploy using progress monitor (UI is blocked)
      dialog.run(true, false, runnable);

      // process results
      VdbDeployer.DeployStatus status = deployer.getStatus();

      if (status.isError()) {
        String message = null;

        if (VdbDeployer.DeployStatus.CREATE_DATA_SOURCE_FAILED == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "createDataSourceFailed",
                  deployer.getVdbName(),
                  failedModelName); //$NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.DEPLOY_VDB_FAILED == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "vdbFailedToDeploy", deployer.getVdbName()); // $NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.TRANSLATOR_PROBLEM == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "translatorDoesNotExistOnServer",
                  deployer.getVdbName()); // $NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.SOURCE_CONNECTION_INFO_PROBLEM == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "sourceMissingConnectionInfo",
                  deployer.getVdbName()); // $NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.EXCEPTION == status) {
          throw deployer.getException(); // let catch block below
          // handle
        } else {
          // unexpected
          message =
              UTIL.getString(
                  I18N_PREFIX + "unknownDeployError", deployer.getVdbName(), status); // $NON-NLS-1$
        }

        // show user the error
        MessageDialog.openError(
            shell, UTIL.getString(I18N_PREFIX + "vdbNotDeployedTitle"), message); // $NON-NLS-1$
        return false;
      } else if (status.isDeployed()) {
        if (teiidServer.wasVdbRemoved(deployer.getVdbName())) {
          StringBuilder message =
              new StringBuilder(
                  UTIL.getString(
                      I18N_PREFIX + "vdbNotActiveMessage", // $NON-NLS-1$
                      vdb.getName()));

          for (String error : teiidServer.retrieveVdbValidityErrors(deployer.getVdbName())) {
            message.append(
                UTIL.getString(I18N_PREFIX + "notActiveErrorMessage", error)); // $NON-NLS-1$
          }

          MessageDialog.openWarning(
              shell,
              UTIL.getString(I18N_PREFIX + "vdbNotActiveTitle"),
              message.toString()); // $NON-NLS-1$
          return true;
        }
      } else {
        return false;
      }
    } catch (Throwable e) {
      if (e instanceof InvocationTargetException) {
        e = ((InvocationTargetException) e).getCause();
      }

      String vdbName = null;

      if (vdbOrVdbFile instanceof IFile) {
        vdbName = ((IFile) vdbOrVdbFile).getName();
      } else if (vdbOrVdbFile instanceof Vdb) {
        vdbName = ((Vdb) vdbOrVdbFile).getFile().getName();
      } else {
        vdbName = UTIL.getString(I18N_PREFIX + "selectionIsNotAVdb"); // $NON-NLS-1$
      }

      String message =
          UTIL.getString(
              I18N_PREFIX + "problemDeployingVdbToServer", vdbName, teiidServer); // $NON-NLS-1$
      UTIL.log(e);
      ErrorDialog.openError(shell, message, null, new Status(IStatus.ERROR, PLUGIN_ID, message, e));

      return false;
    }

    return true;
  }