/**
   * look for all the required modules for a given bundle, and let the user decide to download it.
   * this method is blocked until the dialog box is closed.
   *
   * @param jarMissingEvent, must never be null
   */
  protected void showMissingModuleDialog(final JarMissingEvent jarMissingEvent) {
    if (allModulesNeededExtensionsForPlugin == null) {
      this.allModulesNeededExtensionsForPlugin =
          ModulesNeededProvider.getAllModulesNeededExtensionsForPlugin();
    }
    List<ModuleNeeded> requiredModulesForBundle =
        ModulesNeededProvider.filterRequiredModulesForBundle(
            jarMissingEvent.getBundleSymbolicName(), allModulesNeededExtensionsForPlugin);
    final List<String> requiredJars = new ArrayList<String>(requiredModulesForBundle.size());
    // filter the jar that are already installed
    for (ModuleNeeded module : requiredModulesForBundle) {
      String moduleName = module.getModuleName();
      // if jar does not exist at expected folder then check if it is registered in the Studio
      if (!new File(jarMissingEvent.getExpectedLibFolder(), moduleName).exists()) {
        // check that library is already available and registered but not deployed to lib/java.
        try {
          if (librariesService != null
              && (librariesService.getLibraryStatus(moduleName)
                  == ELibraryInstallStatus.INSTALLED)) {
            // lib exist so deploy it
            List<ModuleNeeded> allModuleNeeded =
                ModulesNeededProvider.getModulesNeededForName(moduleName);
            for (ModuleNeeded sameModule : allModuleNeeded) {
              String moduleLocation = sameModule.getModuleLocaion();
              if (sameModule.getStatus() == ELibraryInstallStatus.INSTALLED
                  && moduleLocation != null
                  && !moduleLocation.isEmpty()) {
                URI uri = new URI(moduleLocation);
                URL url = FileLocator.toFileURL(uri.toURL());
                if ("file".equals(url.getProtocol())) { // $NON-NLS-1$
                  libraryManagerService.deploy(url.toURI(), null);
                } // else not a file so keep going
                break;
              } // else not an installed module or no url so keep so keep looking
            }
          } // else no installed so keep going and ask the user
        } catch (BusinessException e) {
          log.warn("Could not get installade status for library:" + moduleName, e);
        } catch (URISyntaxException e) {
          log.warn("Could not get installade status for library:" + moduleName, e);
        } catch (IOException e) {
          log.warn("Could not get installade status for library:" + moduleName, e);
        }
      }
      if (!new File(jarMissingEvent.getExpectedLibFolder(), moduleName).exists()) {
        requiredJars.add(moduleName);
      } // else jar already installed to filter it by ignoring it.
    }
    if (!requiredJars.isEmpty()) {
      Display.getDefault()
          .syncExec(
              new Runnable() {

                @Override
                public void run() {
                  ExternalModulesInstallDialogWithProgress dialog =
                      new ExternalModulesInstallDialogWithProgress(
                          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                          Messages.getString(
                              "ExternalModulesInstallDialog_Title_Missing_jars_for_plugin"), //$NON-NLS-1$
                          Messages.getString(
                              "ExternalModulesInstallDialog_description_jars_to_be_installed_in"),
                          SWT.APPLICATION_MODAL); //$NON-NLS-1$
                  dialog.showDialog(true, requiredJars.toArray(new String[requiredJars.size()]));
                }
              });
    } // else there is not extension point defining the required bundles so do not ask the user
      // ignor.
  }
  // TODO the implementation of this method is horrible and creating too many widgets
  // table/column renderer/editor should be used instead should be used instead
  protected void addInstallButtons() {
    final AtomicInteger enabledButtonCount = new AtomicInteger(0);
    tableViewerCreator.getTableViewer().getControl().setRedraw(false);
    final Table table = tableViewerCreator.getTable();
    manualInstallButtonMap = new HashMap<ModuleToInstall, Button>();
    ILibrariesService librariesService = LibManagerUiPlugin.getDefault().getLibrariesService();

    disposePreviousEditors();
    for (final TableItem item : table.getItems()) {
      TableEditor editor = new TableEditor(table);
      installButtonsEditors.add(editor);
      Control control = null;
      Object obj = item.getData();
      if (obj instanceof ModuleToInstall) {
        final ModuleToInstall data = (ModuleToInstall) obj;
        boolean isInstalled = false;
        try {
          isInstalled =
              librariesService.getLibraryStatus(data.getName()) == ELibraryInstallStatus.INSTALLED;
        } catch (BusinessException e1) { // log the error and consider as unsinstalled
          log.error(e1);
        }
        boolean hasDownloadUrl = data.getUrl_description() != null;
        if (!MavenConstants.DOWNLOAD_MANUAL.equals(
            data.getDistribution())) { // add the button to download
          final Button button = new Button(table, SWT.FLAT);
          control = button;
          enabledButtonCount.incrementAndGet();
          button.setText(
              Messages.getString("ExternalModulesInstallDialog_Download")); // $NON-NLS-1$
          button.setData(item);
          button.addSelectionListener(
              new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                  table.select(table.indexOf(item));
                  launchIndividualDownload(enabledButtonCount, data, button);
                }
              });
          button.setEnabled(!isInstalled);
          button.setToolTipText(data.toString());
        } else { // add the link for manual download
          Composite composite = new Composite(table, SWT.NONE);
          composite.setBackground(color);
          control = composite;
          GridLayout layout = new GridLayout(hasDownloadUrl ? 2 : 1, false);
          layout.marginHeight = 0;
          layout.verticalSpacing = 1;
          composite.setLayout(layout);
          if (hasDownloadUrl) {
            Link openLink = new Link(composite, SWT.NONE);
            GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(openLink);
            openLink.setBackground(color);
            // openLink.setLayoutData(gData);
            openLink.setText(
                "<a href=\"\">"
                    + Messages.getString("ExternalModulesInstallDialog.openInBrowser")
                    + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            openLink.addSelectionListener(
                new SelectionAdapter() {

                  @Override
                  public void widgetSelected(final SelectionEvent e) {
                    // Program.launch(data.getUrl_description());
                    openURL(data.getUrl_description());
                  }
                });
          } // else no download URL so just add the install buttonb
          enabledButtonCount.incrementAndGet();
          Button importButton = new Button(composite, SWT.FLAT);
          importButton.setImage(ImageProvider.getImage(ECoreImage.IMPORT_JAR));
          importButton.setToolTipText(
              Messages.getString("ImportExternalJarAction.title")); // $NON-NLS-1$
          importButton.addSelectionListener(
              new ImportButtonSelectionListener(enabledButtonCount, item));
          manualInstallButtonMap.put(data, importButton);
          GridDataFactory.fillDefaults()
              .align(SWT.RIGHT, SWT.CENTER)
              .grab(true, false)
              .applyTo(importButton);
          importButton.setEnabled(!isInstalled);
          importButton.setToolTipText(data.toString());
        }
        editor.grabHorizontal = true;
        editor.setEditor(control, item, tableViewerCreator.getColumns().indexOf(installcolumn));
        editor.layout();
        // url
        editor = new TableEditor(table);
        installButtonsEditors.add(editor);
        Composite composite = new Composite(table, SWT.NONE);
        composite.setBackground(color);
        // GridLayout layout = new GridLayout();
        FormLayout layout = new FormLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        composite.setLayout(layout);
        FormData gData = new FormData();
        gData.left = new FormAttachment(0);
        gData.right = new FormAttachment(100);
        gData.top = new FormAttachment(composite, 0, SWT.CENTER);
        final Link openLink = new Link(composite, SWT.NONE);
        openLink.setLayoutData(gData);
        openLink.setBackground(color);
        gData.height = new GC(composite).stringExtent(" ").y; // $NON-NLS-1$
        openLink.setText(
            "<a href=\"\">"
                + (hasDownloadUrl ? data.getUrl_description() : "")
                + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$
        openLink.addSelectionListener(
            new SelectionAdapter() {

              @Override
              public void widgetSelected(final SelectionEvent e) {
                // Program.launch(data.getUrl_description());
                openURL(data.getUrl_description());
              }
            });
        editor.grabHorizontal = true;
        // editor.minimumHeight = 20;
        editor.setEditor(composite, item, tableViewerCreator.getColumns().indexOf(urlcolumn));
        editor.layout();
      }
    }
    tableViewerCreator.getTableViewer().getTable().layout();
    tableViewerCreator.getTableViewer().refresh(true);
    tableViewerCreator.getTableViewer().getControl().setRedraw(true);
  }