protected void addConnectorDefinition(
      ConnectorImplementation impl, List<IResource> resourcesToExport)
      throws FileNotFoundException, CoreException {
    final IRepositoryStore store = getDefinitionStore();
    ConnectorDefinition def =
        ((IDefinitionRepositoryStore) store)
            .getDefinition(impl.getDefinitionId(), impl.getDefinitionVersion());
    EMFFileStore file =
        (EMFFileStore) store.getChild(URI.decode(def.eResource().getURI().lastSegment()));

    if (file != null && !file.canBeShared()) {
      File f = new File(file.getEMFResource().getURI().toFileString());
      if (f.exists()) {
        IFile defFile = store.getResource().getFile(f.getName());
        defFile.create(new FileInputStream(f), true, Repository.NULL_PROGRESS_MONITOR);
        resourcesToExport.add(defFile);
        cleanAfterExport.add(defFile);
      }
    } else if (file != null) {
      resourcesToExport.add(file.getResource());
    }

    addDefinitionIcons(resourcesToExport, store, def);
    addDefinitionPropertiesFile(resourcesToExport, store, def);
  }
 public String getDefinitionText(DefinitionMapping association) {
   ConnectorDefinition definition =
       defStore.getDefinition(association.getDefinitionId(), association.getDefinitionVersion());
   if (definition != null) {
     String connectorDefinitionLabel = resourceProvider.getConnectorDefinitionLabel(definition);
     if (connectorDefinitionLabel == null) {
       connectorDefinitionLabel = definition.getId();
     }
     return connectorDefinitionLabel + " (" + definition.getVersion() + ")";
   } else {
     return "defintion not found for "
         + association.getDefinitionId()
         + " with version"
         + association.getDefinitionVersion();
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.EditingSupport#getCellEditor(java.lang.Object)
  */
 @Override
 protected CellEditor getCellEditor(final Object element) {
   List<String> inputs = new ArrayList<String>();
   for (Input input : definition.getInput()) {
     inputs.add(input.getName());
   }
   ComboBoxCellEditor editor =
       new ComboBoxCellEditor(
           (Composite) getViewer().getControl(), inputs.toArray(new String[0]), SWT.READ_ONLY);
   return editor;
 }
  @Test
  public void testAddCategory() throws Exception {
    final String id = "testEdit4";
    final String version = "1.0.0";

    SWTBotConnectorTestUtil.activateConnectorDefinitionShell(bot);
    SWTBotConnectorTestUtil.createConnectorDefinition(bot, id, version);
    bot.button(IDialogConstants.FINISH_LABEL).click();
    SWTBotConnectorTestUtil.activateConnectorDefEditionShell(bot);
    bot.tree().setFocus();
    bot.waitUntil(
        Conditions.widgetIsEnabled(
            bot.tree().expandNode("Uncategorized").select(id + " (" + version + ")")),
        10000);
    bot.tree()
        .select("Uncategorized")
        .expandNode("Uncategorized")
        .select(id + " (" + version + ")");
    bot.button(Messages.Edit).click();
    bot.treeWithLabel(Messages.categoryLabel).select(0);
    bot.button(IDialogConstants.FINISH_LABEL).click();
    ConnectorDefRepositoryStore store =
        (ConnectorDefRepositoryStore)
            RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class);
    ConnectorDefinition connectorDef = store.getDefinition(id, version);
    assertEquals("category size should be equal to 1", 1, connectorDef.getCategory().size());
    DefinitionResourceProvider messageProvider =
        DefinitionResourceProvider.getInstance(store, ConnectorPlugin.getDefault().getBundle());
    SWTBotConnectorTestUtil.activateConnectorDefEditionShell(bot);
    final Category category = connectorDef.getCategory().get(0);
    String categoryLabel = messageProvider.getCategoryLabel(category);
    if (categoryLabel == null) {
      categoryLabel = category.getId();
    }
    final String connectorLabel =
        new ConnectorDefinitionTreeLabelProvider(messageProvider).getText(connectorDef);
    assertNotNull(
        "could not find " + connectorLabel,
        bot.tree().getTreeItem(categoryLabel).expand().getNode(connectorLabel));
    bot.button(IDialogConstants.CANCEL_LABEL).click();
  }
  protected IStatus addDependencies(ConnectorImplementation impl, IFolder classpathFolder)
      throws CoreException {
    final IDefinitionRepositoryStore store = (IDefinitionRepositoryStore) getDefinitionStore();
    final DependencyRepositoryStore depStore =
        (DependencyRepositoryStore)
            RepositoryManager.getInstance().getRepositoryStore(DependencyRepositoryStore.class);
    final DefinitionResourceProvider resourceProvider =
        DefinitionResourceProvider.getInstance(getDefinitionStore(), getBundle());

    ConnectorDefinition def =
        store.getDefinition(impl.getDefinitionId(), impl.getDefinitionVersion());
    for (String jarName : def.getJarDependency()) {
      if (ignoredLibs.contains(jarName)) {
        continue;
      }
      IRepositoryFileStore file = depStore.getChild(jarName);
      if (file != null) {
        if (file.getResource().exists()) {
          if (!classpathFolder.getFile(file.getName()).exists()) {
            try {
              file.getResource()
                  .copy(
                      classpathFolder.getFullPath().append(file.getName()),
                      true,
                      Repository.NULL_PROGRESS_MONITOR);
            } catch (CoreException e) {
              BonitaStudioLog.error(e);
            }
          }
        }
      } else { // Search in provided jars
        InputStream is = resourceProvider.getDependencyInputStream(jarName);
        if (is != null) {
          IFile jarFile = classpathFolder.getFile(jarName);
          if (!jarFile.exists()) {
            jarFile.create(is, true, Repository.NULL_PROGRESS_MONITOR);
          }
        } else {
          return ValidationStatus.error(Messages.bind(Messages.implementationDepNotFound, jarName));
        }
      }
    }
    for (String jarName : impl.getJarDependencies().getJarDependency()) {
      if (ignoredLibs.contains(jarName)) {
        continue;
      }
      IRepositoryFileStore file = depStore.getChild(jarName);
      if (file != null) {
        if (file.getResource().exists()) {
          if (!classpathFolder.getFile(file.getName()).exists()) {
            try {
              file.getResource()
                  .copy(
                      classpathFolder.getFullPath().append(file.getName()),
                      true,
                      Repository.NULL_PROGRESS_MONITOR);
            } catch (CoreException e) {
              BonitaStudioLog.error(e);
            }
          }
        }
      } else { // Search in provided jars
        InputStream is = resourceProvider.getDependencyInputStream(jarName);
        if (is != null) {
          IFile jarFile = classpathFolder.getFile(jarName);
          if (!jarFile.exists()) {
            jarFile.create(is, true, Repository.NULL_PROGRESS_MONITOR);
          }
        } else {
          return ValidationStatus.error(Messages.bind(Messages.implementationDepNotFound, jarName));
        }
      }
    }
    return Status.OK_STATUS;
  }
  protected void addDefinitionIcons(
      List<IResource> resourcesToExport, final IRepositoryStore store, ConnectorDefinition def) {
    if (def.getIcon() != null) {
      IFile iconFile = store.getResource().getFile(Path.fromOSString(def.getIcon()));
      if (iconFile != null && iconFile.exists()) {
        resourcesToExport.add(iconFile);
      } else {
        URL url =
            ConnectorPlugin.getDefault()
                .getBundle()
                .getResource(ConnectorDefRepositoryStore.STORE_NAME + "/" + def.getIcon());
        if (url != null) {
          try {
            IFile f = store.getResource().getFile(def.getIcon());
            if (!f.exists()) {
              InputStream is = url.openStream();
              f.create(is, true, Repository.NULL_PROGRESS_MONITOR);
              if (!resourcesToExport.contains(f)) {
                resourcesToExport.add(f);
              }
              cleanAfterExport.add(f);
              is.close();
            }

          } catch (Exception e) {
            BonitaStudioLog.error(e);
          }
        }
      }
    }

    for (Category c : def.getCategory()) {
      if (c.getIcon() != null) {
        IFile iconFile = store.getResource().getFile(Path.fromOSString(c.getIcon()));
        if (iconFile != null && iconFile.exists()) {
          if (!resourcesToExport.contains(iconFile)) {
            resourcesToExport.add(iconFile);
          }
        } else {
          URL url =
              ConnectorPlugin.getDefault()
                  .getBundle()
                  .getResource(ConnectorDefRepositoryStore.STORE_NAME + "/" + c.getIcon());
          if (url != null) {
            try {
              IFile f = store.getResource().getFile(c.getIcon());
              if (!f.exists()) {
                InputStream is = url.openStream();
                f.create(is, true, Repository.NULL_PROGRESS_MONITOR);
                if (!resourcesToExport.contains(f)) {
                  resourcesToExport.add(f);
                }
                cleanAfterExport.add(f);
                is.close();
              }
            } catch (Exception e) {
              BonitaStudioLog.error(e);
            }
          }
        }
      }
    }
  }