Search in sources :

Example 26 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectUICommands method projectTeamCreate.

public static void projectTeamCreate() {
    UIThreadsUtil.mustBeSwingThread();
    if (Core.getProject().isProjectLoaded()) {
        return;
    }
    new SwingWorker<Void, Void>() {

        File projectRoot;

        protected Void doInBackground() throws Exception {
            Core.getMainWindow().showStatusMessageRB(null);
            final NewTeamProject dialog = new NewTeamProject(Core.getMainWindow().getApplicationFrame());
            dialog.setVisible(true);
            if (!dialog.ok) {
                Core.getMainWindow().showStatusMessageRB("TEAM_CANCELLED");
                return null;
            }
            IMainWindow mainWindow = Core.getMainWindow();
            Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
            Cursor oldCursor = mainWindow.getCursor();
            mainWindow.setCursor(hourglassCursor);
            Core.getMainWindow().showStatusMessageRB("CT_DOWNLOADING_PROJECT");
            // retrieve omegat.project
            projectRoot = new File(dialog.getSaveLocation());
            List<RepositoryDefinition> repos = new ArrayList<RepositoryDefinition>();
            RepositoryDefinition repo = new RepositoryDefinition();
            repos.add(repo);
            repo.setType(dialog.getRepoType());
            repo.setUrl(dialog.getRepoUrl());
            RepositoryMapping mapping = new RepositoryMapping();
            mapping.setLocal("");
            mapping.setRepository("");
            repo.getMapping().add(mapping);
            RemoteRepositoryProvider remoteRepositoryProvider = new RemoteRepositoryProvider(projectRoot, repos);
            remoteRepositoryProvider.switchAllToLatest();
            for (String file : new String[] { OConsts.FILE_PROJECT, OConsts.DEFAULT_INTERNAL + '/' + FilterMaster.FILE_FILTERS, OConsts.DEFAULT_INTERNAL + '/' + SRX.CONF_SENTSEG }) {
                remoteRepositoryProvider.copyFilesFromRepoToProject(file);
            }
            ProjectProperties props = ProjectFileStorage.loadProjectProperties(projectRoot);
            if (props.getRepositories() == null) {
                // We assume it's a 3.6 style project with no repository mapping,
                // so we add root repository mapping
                props.setRepositories(repos);
            }
            // We write in all cases, because we might have added default excludes, for instance
            ProjectFileStorage.writeProjectFile(props);
            // String projectFileURL = dialog.txtRepositoryOrProjectFileURL.getText();
            // File localDirectory = new File(dialog.txtDirectory.getText());
            // try {
            // localDirectory.mkdirs();
            // byte[] projectFile = WikiGet.getURLasByteArray(projectFileURL);
            // FileUtils.writeByteArrayToFile(new File(localDirectory, OConsts.FILE_PROJECT), projectFile);
            // } catch (Exception ex) {
            // ex.printStackTrace();
            // Core.getMainWindow().displayErrorRB(ex, "TEAM_CHECKOUT_ERROR");
            // mainWindow.setCursor(oldCursor);
            // return null;
            // }
            // projectOpen(localDirectory);
            mainWindow.setCursor(oldCursor);
            return null;
        }

        @Override
        protected void done() {
            Core.getMainWindow().showProgressMessage(" ");
            try {
                get();
                if (projectRoot != null) {
                    // don't ask open if user cancelled previous dialog
                    SwingUtilities.invokeLater(() -> {
                        Core.getEditor().requestFocus();
                        projectOpen(projectRoot);
                    });
                }
            } catch (Exception ex) {
                Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_DOWNLOAD_TEAM_PROJECT");
                Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_DOWNLOAD_TEAM_PROJECT");
            }
        }
    }.execute();
}
Also used : RemoteRepositoryProvider(org.omegat.core.team2.RemoteRepositoryProvider) NewTeamProject(org.omegat.gui.dialogs.NewTeamProject) ProjectProperties(org.omegat.core.data.ProjectProperties) Cursor(java.awt.Cursor) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RepositoryDefinition(gen.core.project.RepositoryDefinition) RepositoryMapping(gen.core.project.RepositoryMapping) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 27 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectUICommands method projectReload.

public static void projectReload() {
    UIThreadsUtil.mustBeSwingThread();
    if (!Core.getProject().isProjectLoaded()) {
        return;
    }
    // commit the current entry first
    Core.getEditor().commitAndLeave();
    final ProjectProperties props = Core.getProject().getProjectProperties();
    new SwingWorker<Void, Void>() {

        int previousCurEntryNum = Core.getEditor().getCurrentEntryNumber();

        protected Void doInBackground() throws Exception {
            IMainWindow mainWindow = Core.getMainWindow();
            Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
            Cursor oldCursor = mainWindow.getCursor();
            mainWindow.setCursor(hourglassCursor);
            Core.executeExclusively(true, () -> {
                Core.getProject().saveProject(true);
                ProjectFactory.closeProject();
                ProjectFactory.loadProject(props, true);
            });
            mainWindow.setCursor(oldCursor);
            return null;
        }

        protected void done() {
            try {
                get();
                SwingUtilities.invokeLater(() -> {
                    // activate entry later - after project will be loaded
                    Core.getEditor().gotoEntry(previousCurEntryNum);
                    Core.getEditor().requestFocus();
                });
            } catch (Exception ex) {
                processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
            }
        }
    }.execute();
}
Also used : ProjectProperties(org.omegat.core.data.ProjectProperties) Cursor(java.awt.Cursor) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 28 with ProjectProperties

use of org.omegat.core.data.ProjectProperties 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 29 with ProjectProperties

use of org.omegat.core.data.ProjectProperties 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

ProjectProperties (org.omegat.core.data.ProjectProperties)29 File (java.io.File)20 Test (org.junit.Test)11 IOException (java.io.IOException)10 ExecutionException (java.util.concurrent.ExecutionException)6 KnownException (org.omegat.core.KnownException)6 Omegat (gen.core.project.Omegat)4 Cursor (java.awt.Cursor)4 List (java.util.List)4 Language (org.omegat.util.Language)4 ArrayList (java.util.ArrayList)3 NotLoadedProject (org.omegat.core.data.NotLoadedProject)3 ProjectPropertiesDialog (org.omegat.gui.dialogs.ProjectPropertiesDialog)3 RepositoryDefinition (gen.core.project.RepositoryDefinition)2 RepositoryMapping (gen.core.project.RepositoryMapping)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 Before (org.junit.Before)2