public void selectOutputFile() {
   FileDialog dlg = new FileDialog(getParentShell(), SWT.SAVE);
   ArrayList<String> extensionList = new ArrayList<String>();
   if (chosenOutputFormat != null && chosenOutputFormat.getFileSuffix() != null) {
     extensionList.add("*." + chosenOutputFormat.getFileSuffix()); // $NON-NLS-1$
   }
   extensionList.add("*.*"); // $NON-NLS-1$
   dlg.setFilterExtensions(extensionList.toArray(new String[extensionList.size()]));
   dlg.setFileName(getDefaultOutputFilename());
   dlg.setOverwrite(true);
   String path;
   if (isFilePath()) {
     path = getOldFolderPath();
   } else {
     path = defaultFolder;
   }
   if (LOG.isDebugEnabled()) {
     LOG.debug("File dialog path set to: " + path); // $NON-NLS-1$
   }
   dlg.setFilterPath(path);
   String fn = dlg.open();
   if (fn != null) {
     textFile.setText(fn);
     getButton(IDialogConstants.OK_ID).setEnabled(true);
   }
 }
  public OutputStream getOutputStream(Shell shell) {
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);

    String filterPath;
    String relativeFileName;

    int lastIndexOfFileSeparator = defaultFileName.lastIndexOf(File.separator);
    if (lastIndexOfFileSeparator >= 0) {
      filterPath = defaultFileName.substring(0, lastIndexOfFileSeparator);
      relativeFileName = defaultFileName.substring(lastIndexOfFileSeparator + 1);
    } else {
      filterPath = "/"; // $NON-NLS-1$
      relativeFileName = defaultFileName;
    }

    dialog.setFilterPath(filterPath);
    dialog.setOverwrite(true);

    dialog.setFileName(relativeFileName);
    dialog.setFilterNames(defaultFilterNames);
    dialog.setFilterExtensions(defaultFilterExtensions);
    String fileName = dialog.open();
    if (fileName == null) {
      return null;
    }

    try {
      return new PrintStream(fileName);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      return null;
    }
  }
Example #3
0
  public void saveRWorkspace() {
    String selected = null;

    Shell s = new Shell();
    FileDialog fd = new FileDialog(s, SWT.SAVE);

    fd.setText("Save");
    if (ApplicationWorkbenchWindowAdvisor.getOS().equals("Windows")) {
      prefs = Preferences.userNodeForPackage(this.getClass());
      String lastOutputDir = prefs.get("R_FILE_DIR", "");
      fd.setFilterPath(lastOutputDir);

      String[] filterExt = {"*.RData"};
      fd.setFilterExtensions(filterExt);
      fd.setOverwrite(true);
      selected = fd.open();
      prefs.put("R_FILE_DIR", fd.getFilterPath());
      if (selected != null) {
        selected = selected.replace("\\", "\\\\");
        selected = selected.replace("ä", "ae");
        selected = selected.replace("ü", "ue");
        selected = selected.replace("ö", "oe");

        saveRData(selected);
      }
    } else {
      prefs = Preferences.userNodeForPackage(this.getClass());
      String lastOutputDir = prefs.get("R_FILE_DIR", "");
      fd.setFilterPath(lastOutputDir);
      String[] filterExt = {"*.RData"};
      fd.setFilterExtensions(filterExt);
      fd.setOverwrite(true);
      selected = fd.open();
      prefs.put("R_FILE_DIR", fd.getFilterPath());

      if (selected != null) {
        saveRData(selected);
      }
    }
  }
  /** Override this to plugin custom OutputStream. */
  protected OutputStream getOutputStream(ExportToExcelCommand command) throws IOException {
    FileDialog dialog = new FileDialog(command.getShell(), SWT.SAVE);
    dialog.setFilterPath("/");
    dialog.setOverwrite(true);

    dialog.setFileName("table_export.xls");
    dialog.setFilterExtensions(new String[] {"Microsoft Office Excel Workbook(.xls)"});
    String fileName = dialog.open();
    if (fileName == null) {
      return null;
    }
    return new PrintStream(fileName);
  }
  /** Exports the view to an image file. The user is prompted for the image location. */
  public void exportImage() {
    if (embeddedView != null) {
      // Make the array of strings needed to pass to the file dialog.
      String[] extensionStrings = new String[] {".png"};

      // Create the file save dialog.
      FileDialog fileDialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
      fileDialog.setFilterExtensions(extensionStrings);
      fileDialog.setOverwrite(true);

      // Get the path of the new/overwritten image file.
      String path = fileDialog.open();
      if (path != null) {
        embeddedView.exportImage(new File(path));
      }
    }
    return;
  }
  private String getFilePathByFileDialog(String modelElementName) {
    FileDialog dialog =
        new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
    dialog.setFilterNames(FILTER_NAMES);
    dialog.setFilterExtensions(FILTER_EXTS);
    String initialPath =
        PreferenceHelper.getPreference(EXPORT_MODEL_PATH, System.getProperty("user.home"));
    dialog.setFilterPath(initialPath);
    dialog.setOverwrite(true);

    try {
      // String initialFileName = projectSpace.getProjectName() + "@"
      // + projectSpace.getBaseVersion().getIdentifier() + ".ucp";
      String initialFileName = "ModelElement_" + modelElementName + "." + FILE_EXTENSION;
      dialog.setFileName(initialFileName);

    } catch (NullPointerException e) {
      // do nothing
    }

    String filePath = dialog.open();

    return filePath;
  }
        @Override
        public void widgetSelected(SelectionEvent e) {
          BarcodeViewGuiData guiData = null;

          try {
            guiData = new BarcodeViewGuiData();

            // save dialog for pdf file.
            FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
            fileDialog.setFilterPath(
                perferenceStore.getString(PreferenceConstants.PDF_DIRECTORY_PATH));
            fileDialog.setOverwrite(true);
            fileDialog.setFileName("default.pdf"); // $NON-NLS-1$
            String pdfFilePath = fileDialog.open();

            if (pdfFilePath == null) return;

            List<String> patientNumbers =
                SessionManager.getAppService().executeGetSourceSpecimenUniqueInventoryIds(32);

            SaveOperation saveOperation = new SaveOperation(guiData, patientNumbers, pdfFilePath);

            try {
              new ProgressMonitorDialog(shell).run(true, true, saveOperation);

            } catch (InvocationTargetException e1) {
              saveOperation.saveFailed();
              saveOperation.setError(
                  Messages.PatientLabelEntryForm_saveop_error_title,
                  "InvocationTargetException: " //$NON-NLS-1$
                      + e1.getCause().getMessage());

            } catch (InterruptedException e2) {
              BgcPlugin.openAsyncError(Messages.PatientLabelEntryForm_save_error_title, e2);
            }

            if (saveOperation.isSuccessful()) {
              String parentDir = new File(pdfFilePath).getParentFile().getPath();
              if (parentDir != null)
                perferenceStore.setValue(PreferenceConstants.PDF_DIRECTORY_PATH, parentDir);

              updateSavePreferences();
              clearFieldsConfirm();
              return;
            }

            if (saveOperation.errorExists()) {
              BgcPlugin.openAsyncError(saveOperation.getError()[0], saveOperation.getError()[1]);
            }

          } catch (CBSRGuiVerificationException e1) {
            BgcPlugin.openAsyncError(e1.title, e1.messsage);
            return;
          } catch (BiobankServerException e2) {
            BgcPlugin.openAsyncError(
                Messages.PatientLabelEntryForm_specId_error_title, e2.getMessage());
          } catch (ApplicationException e3) {
            BgcPlugin.openAsyncError(
                Messages.PatientLabelEntryForm_server_error_title, e3.getMessage());
          }
        }
Example #8
0
  public void run() {

    IPreferenceStore store = Bio7Plugin.getDefault().getPreferenceStore();
    RConnection con = RServe.getConnection();
    // boolean rPipe = store.getBoolean("r_pipe");
    if (con == null) {

      String selectionConsole = ConsolePageParticipant.getInterpreterSelection();
      if (selectionConsole.equals("R")) {
        String selected = null;

        Shell s = new Shell();
        FileDialog fd = new FileDialog(s, SWT.SAVE);

        if (ApplicationWorkbenchWindowAdvisor.getOS().equals("Windows")) {
          prefs = Preferences.userNodeForPackage(this.getClass());
          String lastOutputDir = prefs.get("R_FILE_DIR", "");
          fd.setFilterPath(lastOutputDir);

          String[] filterExt = {"*.RData"};
          fd.setFilterExtensions(filterExt);
          fd.setOverwrite(true);
          selected = fd.open();
          prefs.put("R_FILE_DIR", fd.getFilterPath());
          if (selected != null) {
            selected = selected.replace("\\", "\\\\");
            // selected = selected.replace("ä", "ae");
            // selected = selected.replace("ü", "ue");
            // selected = selected.replace("ö", "oe");

            ConsolePageParticipant.pipeInputToConsole(
                "save.image(file =\"" + selected + "\", version = NULL, ascii = FALSE)",
                true,
                true);
            System.out.print(
                "save.image(file =\"" + selected + "\", version = NULL, ascii = FALSE)");
            System.out.println();
          }
        } else {
          prefs = Preferences.userNodeForPackage(this.getClass());
          String lastOutputDir = prefs.get("R_FILE_DIR", "");
          fd.setFilterPath(lastOutputDir);
          String[] filterExt = {"*.RData"};
          fd.setFilterExtensions(filterExt);
          fd.setOverwrite(true);
          selected = fd.open();
          prefs.put("R_FILE_DIR", fd.getFilterPath());

          if (selected != null) {
            ConsolePageParticipant.pipeInputToConsole(
                "save.image(file =\"" + selected + "\", version = NULL, ascii = FALSE)",
                true,
                true);
            System.out.print(
                "save.image(file =\"" + selected + "\", version = NULL, ascii = FALSE)");
            System.out.println();
          }
        }

        ConsolePageParticipant.pipeInputToConsole("load(file = \"" + selected + "\")", true, true);

      } else {
        Bio7Dialog.message(
            "Please start the \"Native R\" shell in the Bio7 console or the Rserve connection!");
      }

    } else {

      saveRWorkspace();
    }
  }