Exemplo n.º 1
0
 @Override
 public boolean canFinish() {
   return exportPage.isPageComplete();
 }
Exemplo n.º 2
0
  /**
   * Called when the user clicks finish. Saves the connection data. Waits until all overwrite
   * decisions have been made before starting to save files. If any overwrite is canceled, no files
   * are saved and the user must adjust the dialog.
   */
  @Override
  public boolean performFinish() {

    // Get file paths to check for existence
    final String destDir = exportPage.getDestinationDirectory();
    final File destDirFile = new File(destDir);
    assert !destDirFile.exists() || !destDirFile.isDirectory() : "Output Detractory should exists";
    String outputFile = ExportWizardPage.getOutputFile();
    final File destZipFile = new File(destDir, outputFile);

    if (destZipFile.exists()) {

      if (!MessageDialog.open(
          MessageDialog.CONFIRM,
          getShell(),
          "Override",
          String.format("The file '%s' already exist. Do you want to override it?", outputFile),
          SWT.SHEET)) {
        return false;
      }
    }

    try {
      final IRunnableWithProgress job =
          new IRunnableWithProgress() {

            SnippetSelectionItem[] items = exportPage.getItems();

            public void run(IProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              try {
                File temDir = File.createTempFile("apdt-snippet", "dir");
                temDir.delete();
                temDir.mkdir();

                LocalSnippetProvider exportProvider =
                    new LocalSnippetProvider(temDir.getAbsolutePath());

                SnippetProvider snippetProvider = exportPage.getSnippetProvider();

                for (SnippetSelectionItem item : items) {
                  if (!item.isSelected()) {
                    continue;
                  }
                  EObject snippetData = snippetProvider.getSnippetData(item.getHandle());
                  if (snippetData != null) {

                    exportProvider.addSnippet(item.getHandle().getName(), snippetData);
                  }
                }

                ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destZipFile));

                File[] list = temDir.listFiles();
                // Compress the files
                byte[] buf = new byte[1024];
                for (int i = 0; i < list.length; i++) {
                  FileInputStream in = new FileInputStream(list[i]);

                  // Add ZIP entry to output stream.
                  out.putNextEntry(new ZipEntry(list[i].getName()));

                  // Transfer bytes from the file to the ZIP file
                  int len;
                  while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                  }

                  // Complete the entry
                  out.closeEntry();
                  in.close();
                }
                out.close();
              } catch (IOException e) {
                APDTLog.log(e);
              }
            }
          };
      getContainer().run(true, true, job);
    } catch (final InvocationTargetException e) {
      APDTLog.log(e);
    } catch (final InterruptedException e) {
      APDTLog.log(e);
    }

    exportPage.saveSettings();
    return true;
  }
Exemplo n.º 3
0
 @Override
 public void addPages() {
   exportPage = new ExportWizardPage();
   exportPage.setWizard(this);
   addPage(exportPage);
 }