public static void saveResource() {
   if (isModified()) {
     String installLocation =
         new Path(Platform.getConfigurationLocation().getURL().getPath())
             .toFile()
             .getAbsolutePath();
     try {
       Resource resource = createComponentCacheResource(installLocation);
       resource.getContents().add(cache);
       EmfHelper.saveResource(cache.eResource());
     } catch (PersistenceException e1) {
       ExceptionHandler.process(e1);
     }
     ILibraryManagerService repositoryBundleService =
         (ILibraryManagerService)
             GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
     repositoryBundleService.clearCache();
     if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
       ILibrariesService libService =
           (ILibrariesService)
               GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
       if (libService != null) {
         libService.syncLibraries();
       }
     }
     setModified(false);
   }
 }
  /**
   * 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);
  }
示例#4
0
  protected void createSystemSQLPatterns() throws PersistenceException {
    ERepositoryObjectType sqlpatternsType = ERepositoryObjectType.SQLPATTERNS;
    if (sqlpatternsType == null) {
      return; // don't load, nothing to do
    }
    ILibrariesService service = null;
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
      return;
    }
    service =
        (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
    Project project = getRepositoryContext().getProject();
    FolderHelper folderHelper = getFolderHelper(project.getEmfProject());
    // will automatically set the children folders
    // FolderItem folderItem = folderHelper.getFolder("sqlPatterns/system");
    // if (folderItem == null) {
    //            folderItem = folderHelper.createFolder("sqlPatterns/system"); //$NON-NLS-1$
    // }

    List<URL> routines = service.getSystemSQLPatterns();

    List<IRepositoryViewObject> repositoryObjects = getAll(project, sqlpatternsType, false, false);

    for (URL url : routines) {
      String[] fragments = url.toString().split("/"); // $NON-NLS-1$
      String label = fragments[fragments.length - 1];
      String[] tmp = label.split("\\."); // $NON-NLS-1$

      Path relativePath = new Path(url.getFile());

      // for instance: categoryName is Teradata; fileName is
      // Loadfile.sqlpattern
      String fileName = relativePath.segment(relativePath.segmentCount() - 1);
      String categoryName = relativePath.segment(relativePath.segmentCount() - 2);

      tmp = fileName.split("\\."); // $NON-NLS-1$

      String sqlPatternLabel = tmp[0];

      SQLPatternItem existingItem = null;
      for (IRepositoryViewObject object : repositoryObjects) {
        if (object.getLabel().equals(sqlPatternLabel)
            && object.getProperty().getItem() instanceof SQLPatternItem
            && ((SQLPatternItem) object.getProperty().getItem())
                .getEltName()
                .equals(categoryName)) {
          existingItem = (SQLPatternItem) object.getProperty().getItem();
          break;
        }
      }
      // check the folder for categoryName,system,UserDefined
      // set the item's relative path in the repository view
      IPath categoryPath = new Path(categoryName);
      IPath systemPath = categoryPath.append(RepositoryConstants.SYSTEM_DIRECTORY);
      IPath userPath = categoryPath.append(RepositoryConstants.USER_DEFINED);

      IPath parentPath = new Path(ERepositoryObjectType.getFolderName(sqlpatternsType));
      if (folderHelper.getFolder(parentPath.append(categoryPath)) == null) {
        createFolder(
            getRepositoryContext().getProject(),
            sqlpatternsType,
            new Path(""),
            categoryPath //$NON-NLS-1$
                .lastSegment());
      }
      FolderItem systemFolder = folderHelper.getFolder(parentPath.append(systemPath));
      if (systemFolder == null) {
        Folder folder =
            createFolder(
                getRepositoryContext().getProject(),
                sqlpatternsType,
                categoryPath,
                systemPath.lastSegment());
        ((FolderItem) folder.getProperty().getItem()).setType(FolderType.FOLDER_LITERAL);
      }
      if (folderHelper.getFolder(parentPath.append(userPath)) == null) {
        Folder folder =
            createFolder(
                getRepositoryContext().getProject(),
                sqlpatternsType,
                categoryPath,
                userPath.lastSegment());
        ((FolderItem) folder.getProperty().getItem()).setType(FolderType.FOLDER_LITERAL);
      }
      //
      if (existingItem == null) {
        createSQLPattern(url, sqlPatternLabel, categoryName);
      } else {
        updateSQLPattern(url, existingItem);
        existingItem.setParent(systemFolder);
      }
    }
  }
示例#5
0
  protected void createSystemRoutines() throws PersistenceException {
    ERepositoryObjectType routinesType = ERepositoryObjectType.ROUTINES;
    if (routinesType == null) {
      return; // don't load, nothing to do
    }
    ILibrariesService service = null;
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
      return;
    }

    service =
        (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);

    Project project = getRepositoryContext().getProject();
    FolderHelper folderHelper = getFolderHelper(project.getEmfProject());

    List<URL> routines = service.getSystemRoutines();
    Path path = new Path(RepositoryConstants.SYSTEM_DIRECTORY);
    // will automatically set the children folders
    IPath systemRoutinePath = new Path(ERepositoryObjectType.getFolderName(routinesType));
    systemRoutinePath = systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY);
    FolderItem folderItem = folderHelper.getFolder(systemRoutinePath);
    if (folderItem == null) {
      folderItem = folderHelper.createFolder(systemRoutinePath.toString());
    }
    IPath systemRoutineApiPath = new Path(ERepositoryObjectType.getFolderName(routinesType));
    systemRoutineApiPath =
        systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY).append("api");
    FolderItem folderItemApi = folderHelper.getFolder(systemRoutineApiPath);
    if (folderItemApi == null) {
      folderItemApi = folderHelper.createFolder(systemRoutineApiPath.toString());
    }

    List<IRepositoryViewObject> repositoryObjects = getAll(project, routinesType, false, false);
    Map<String, List<LibraryInfo>> routineAndJars = coreSerivce.getRoutineAndJars();
    for (URL url : routines) {
      String[] fragments = url.toString().split("/"); // $NON-NLS-1$
      String label = fragments[fragments.length - 1];
      String[] tmp = label.split("\\."); // $NON-NLS-1$
      String routineLabel = tmp[0];

      if (routineLabel.equals(coreSerivce.getTemplateString())) {
        continue;
      }

      RoutineItem existingItem = null;
      for (IRepositoryViewObject object : repositoryObjects) {
        if (object.getLabel().equals(routineLabel)
            && object.getProperty().getItem() instanceof RoutineItem) {
          existingItem = (RoutineItem) object.getProperty().getItem();
          break;
        }
      }
      if (existingItem == null) {
        createRoutine(
            url,
            path,
            routineLabel,
            routineAndJars != null ? routineAndJars.get(routineLabel) : null);
      } else {
        updateRoutine(url, existingItem);
        existingItem.setParent(folderItem);
      }
    }
  }