private Properties getModelConnectionProperties(ModelResource mr) {

    try {
      if (ModelIdentifier.isRelationalSourceModel(mr)) {
        IConnectionInfoProvider provider = null;

        try {
          provider = getProvider(mr);
        } catch (Exception e) {
          // If provider throws exception its OK because some models may not have connection info.
        }

        if (provider != null) {
          Properties properties = provider.getProfileProperties(mr); // ConnectionProperties(mr);
          Properties p2 = provider.getConnectionProperties(mr);
          String translatorName = provider.getTranslatorName(mr);
          for (Object key : p2.keySet()) {
            properties.put(key, p2.get(key));
          }
          if (translatorName != null) {
            properties.put(getString("translatorKey"), translatorName); // $NON-NLS-1$
          }
          if (properties != null && !properties.isEmpty()) {
            return properties;
          }
        }
      }
    } catch (CoreException e) {
      DatatoolsUiConstants.UTIL.log(e);
    }

    return null;
  }
  private Collection<ModelResource> getRelationalModelsWithConnections() {
    Collection<ModelResource> result = new ArrayList<ModelResource>();

    try {
      ModelResource[] mrs =
          ModelWorkspaceManager.getModelWorkspaceManager().getModelWorkspace().getModelResources();
      for (ModelResource mr : mrs) {
        if (ModelIdentifier.isRelationalSourceModel(mr)) {
          IConnectionInfoProvider provider = null;

          try {
            provider = getProvider(mr);
          } catch (Exception e) {
            // If provider throws exception its OK because some models may not have connection info.
          }

          if (provider != null) {
            Properties properties = provider.getConnectionProperties(mr);
            if (properties != null && !properties.isEmpty()) {
              result.add(mr);
            }
          }
        }
      }

    } catch (CoreException e) {
      DqpUiConstants.UTIL.log(e);
    }

    return result;
  }
  /**
   * @param selection the selection
   * @return if selection is applicable for this action
   */
  public boolean isApplicable(ISelection selection) {
    boolean result = false;
    if (!SelectionUtilities.isMultiSelection(selection)) {
      Object obj = SelectionUtilities.getSelectedObject(selection);
      if (obj instanceof IResource) {
        IResource iRes = (IResource) obj;
        if (ModelIdentifier.isRelationalViewModel(iRes)) {
          this.selectedModel = (IFile) obj;
          result = true;
        }
      }
    }

    return result;
  }
  private boolean sourceModelSelected(ISelection theSelection) {
    boolean result = false;
    List<?> allObjs = SelectionUtilities.getSelectedObjects(theSelection);
    if (!allObjs.isEmpty() && allObjs.size() == 1) {
      Iterator<?> iter = allObjs.iterator();
      result = true;
      Object nextObj = null;
      while (iter.hasNext() && result) {
        nextObj = iter.next();

        if (nextObj instanceof IFile) {
          result = ModelIdentifier.isRelationalSourceModel((IFile) nextObj);
        } else {
          result = false;
        }
      }
    }

    return result;
  }
  /** @see IDialogPage#createControl(Composite) */
  @Override
  public void createControl(Composite parent) {

    ModelResource selectedResource = null;
    if (selection != null && SelectionUtilities.isSingleSelection(selection)) {
      Object obj = SelectionUtilities.getSelectedObject(selection);
      if (obj instanceof IFile) {
        if (ModelUtilities.isModelFile((IFile) obj)) {
          try {
            selectedResource = ModelUtil.getModelResource((IFile) obj, false);
            if (!selectedResource
                .getPrimaryMetamodelDescriptor()
                .equals(this.metamodelDescriptor)) {
              selectedResource = null;
            } else {
              setPageComplete(true);
            }
          } catch (ModelWorkspaceException e) {
            // no need to log, just launch the dialog empty
          }
        }
      }
    }

    if (selectedResource != null) {
      sourceIsPhysical = ModelIdentifier.isPhysicalModelType(selectedResource);
    }
    panel =
        new TreeViewerWizardPanel(
            parent,
            this,
            metamodelDescriptor,
            selectedResource,
            sourceIsPhysical,
            targetIsVirtual,
            false);
    setControl(panel);
  }
  /**
   * @param selection
   * @return
   */
  public boolean setSelection(ISelection selection) {
    if (SelectionUtilities.isMultiSelection(selection)) return false;

    Object obj = SelectionUtilities.getSelectedObject(selection);
    // If a VDB is selected and it contains a web service model then
    // enable
    if (!(obj instanceof IFile)) return false;

    if (!isVdb(obj)) return false;

    this.selectedVDB = (IFile) obj;

    boolean result = false;
    try {
      Vdb vdb = new Vdb(this.selectedVDB, new NullProgressMonitor());
      Set<VdbModelEntry> modelEntrySet = vdb.getModelEntries();
      for (VdbModelEntry vdbModelEntry : modelEntrySet) {
        final ModelResource modelResource =
            ModelerCore.getModelWorkspace().findModelResource(vdbModelEntry.getName());
        if (!ModelIdentifier.isVirtualModelType(modelResource)) continue;

        List<RestProcedure> restfulProcedureArray = findRestProcedures(modelResource);
        if (restfulProcedureArray.size() > 0) {
          String modelName =
              FileUtils.getFilenameWithoutExtension(vdbModelEntry.getName().lastSegment());
          restfulProcedureMap.put(modelName, restfulProcedureArray);
          result = true;
        }
      }
    } catch (Exception ex) {
      DqpPlugin.Util.log(ex);
      return false;
    }

    return result;
  }