Search in sources :

Example 1 with NewProjectFileChooser

use of org.omegat.gui.dialogs.NewProjectFileChooser in project omegat by omegat-org.

the class ProjectUICommands method projectCreate.

public static void projectCreate() {
    UIThreadsUtil.mustBeSwingThread();
    if (Core.getProject().isProjectLoaded()) {
        return;
    }
    // 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<Void, Void>() {

        protected Void doInBackground() throws Exception {
            dir.mkdirs();
            // ask about new project properties
            ProjectProperties props = new ProjectProperties(dir);
            props.setSourceLanguage(Preferences.getPreferenceDefault(Preferences.SOURCE_LOCALE, "EN-US"));
            props.setTargetLanguage(Preferences.getPreferenceDefault(Preferences.TARGET_LOCALE, "EN-GB"));
            ProjectPropertiesDialog newProjDialog = new ProjectPropertiesDialog(Core.getMainWindow().getApplicationFrame(), props, dir.getAbsolutePath(), ProjectPropertiesDialog.Mode.NEW_PROJECT);
            newProjDialog.setVisible(true);
            newProjDialog.dispose();
            IMainWindow mainWindow = Core.getMainWindow();
            Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
            Cursor oldCursor = mainWindow.getCursor();
            mainWindow.setCursor(hourglassCursor);
            final ProjectProperties newProps = newProjDialog.getResult();
            if (newProps == null) {
                // user clicks on 'Cancel'
                dir.delete();
                mainWindow.setCursor(oldCursor);
                return null;
            }
            final String projectRoot = newProps.getProjectRoot();
            if (!StringUtil.isEmpty(projectRoot)) {
                // 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());
            mainWindow.setCursor(oldCursor);
            return null;
        }
    }.execute();
}
Also used : NewProjectFileChooser(org.omegat.gui.dialogs.NewProjectFileChooser) ProjectPropertiesDialog(org.omegat.gui.dialogs.ProjectPropertiesDialog) ProjectProperties(org.omegat.core.data.ProjectProperties) Cursor(java.awt.Cursor) File(java.io.File) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with NewProjectFileChooser

use of org.omegat.gui.dialogs.NewProjectFileChooser in project omegat by omegat-org.

the class ProjectUICommands method projectOpenMED.

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<Void, Void>() {

        protected Void 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();
}
Also used : ChooseMedProject(org.omegat.gui.dialogs.ChooseMedProject) NewProjectFileChooser(org.omegat.gui.dialogs.NewProjectFileChooser) ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 KnownException (org.omegat.core.KnownException)2 ProjectProperties (org.omegat.core.data.ProjectProperties)2 NewProjectFileChooser (org.omegat.gui.dialogs.NewProjectFileChooser)2 Cursor (java.awt.Cursor)1 ChooseMedProject (org.omegat.gui.dialogs.ChooseMedProject)1 ProjectPropertiesDialog (org.omegat.gui.dialogs.ProjectPropertiesDialog)1