Search in sources :

Example 1 with NewTeamProject

use of org.omegat.gui.dialogs.NewTeamProject 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)

Aggregations

RepositoryDefinition (gen.core.project.RepositoryDefinition)1 RepositoryMapping (gen.core.project.RepositoryMapping)1 Cursor (java.awt.Cursor)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 KnownException (org.omegat.core.KnownException)1 ProjectProperties (org.omegat.core.data.ProjectProperties)1 RemoteRepositoryProvider (org.omegat.core.team2.RemoteRepositoryProvider)1 NewTeamProject (org.omegat.gui.dialogs.NewTeamProject)1