Example #1
0
  public static void projectOpenMED() {
    UIThreadsUtil.mustBeSwingThread();

    if (Core.getProject().isProjectLoaded()) {
      return;
    }

    // ask for MED file
    ChooseMedProject ndm = new ChooseMedProject();
    int ndmResult = ndm.showOpenDialog(Core.getMainWindow().getApplicationFrame());
    if (ndmResult != OmegaTFileChooser.APPROVE_OPTION) {
      // user press 'Cancel' in project creation dialog
      return;
    }
    final File med = ndm.getSelectedFile();

    // ask for new project dir
    NewProjectFileChooser ndc = new NewProjectFileChooser();
    int ndcResult = ndc.showSaveDialog(Core.getMainWindow().getApplicationFrame());
    if (ndcResult != OmegaTFileChooser.APPROVE_OPTION) {
      // user press 'Cancel' in project creation dialog
      return;
    }
    final File dir = ndc.getSelectedFile();

    new SwingWorker<Object, Void>() {
      protected Object doInBackground() throws Exception {
        dir.mkdirs();

        final ProjectProperties newProps = new ProjectProperties(dir);
        ProjectMedProcessing.extractFromMed(med, newProps);
        // create project
        try {
          ProjectFactory.createProject(newProps);
        } catch (Exception ex) {
          Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
          Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }

        RecentProjects.add(dir.getAbsolutePath());

        return null;
      }

      protected void done() {
        try {
          get();
          SwingUtilities.invokeLater(Core.getEditor()::requestFocus);
        } catch (Exception ex) {
          Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
          Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }
      }
    }.execute();
  }
Example #2
0
  public static void projectCreateMED() {
    UIThreadsUtil.mustBeSwingThread();

    if (!Core.getProject().isProjectLoaded()) {
      return;
    }

    // commit the current entry first
    Core.getEditor().commitAndLeave();

    // ask for new MED file
    ChooseMedProject ndm = new ChooseMedProject();
    // default name
    String zipName = null;
    try {
      File origin = ProjectMedProcessing.getOriginMedFile(Core.getProject().getProjectProperties());
      if (origin != null) {
        zipName = origin.getName();
      }
    } catch (Exception ex) {
    }
    if (zipName == null) {
      zipName = Core.getProject().getProjectProperties().getProjectName() + "-MED.zip";
    }
    ndm.setSelectedFile(
        new File(
            Core.getProject().getProjectProperties().getProjectRootDir().getParentFile(), zipName));
    int ndmResult = ndm.showSaveDialog(Core.getMainWindow().getApplicationFrame());
    if (ndmResult != OmegaTFileChooser.APPROVE_OPTION) {
      // user press 'Cancel' in project creation dialog
      return;
    }
    // add .zip extension if there is no
    final File med =
        ndm.getSelectedFile().getName().toLowerCase().endsWith(".zip")
            ? ndm.getSelectedFile()
            : new File(ndm.getSelectedFile().getAbsolutePath() + ".zip");

    new SwingWorker<Object, Void>() {
      protected Object doInBackground() throws Exception {
        IMainWindow mainWindow = Core.getMainWindow();
        Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        Cursor oldCursor = mainWindow.getCursor();
        mainWindow.setCursor(hourglassCursor);

        mainWindow.showStatusMessageRB("MW_STATUS_SAVING");

        Core.executeExclusively(
            true,
            () -> {
              Core.getProject().saveProject(true);
              try {
                Core.getProject().compileProject(".*");
              } catch (Exception ex) {
                throw new RuntimeException(ex);
              }
            });

        ProjectMedProcessing.createMed(med, Core.getProject().getProjectProperties());

        mainWindow.showStatusMessageRB("MW_STATUS_SAVED");
        mainWindow.setCursor(oldCursor);
        return null;
      }

      protected void done() {
        try {
          get();
          SwingUtilities.invokeLater(Core.getEditor()::requestFocus);
        } catch (Exception ex) {
          Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
          Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }
      }
    }.execute();
  }