Search in sources :

Example 1 with StatsResult

use of org.omegat.core.statistics.StatsResult in project omegat by omegat-org.

the class RealProject method saveProject.

/**
 * Saves the translation memory and preferences.
 *
 * This method must be executed in the Core.executeExclusively.
 */
public synchronized void saveProject(boolean doTeamSync) {
    if (isSaving) {
        return;
    }
    isSaving = true;
    Log.logInfoRB("LOG_DATAENGINE_SAVE_START");
    UIThreadsUtil.mustNotBeSwingThread();
    Core.getAutoSave().disable();
    try {
        Core.getMainWindow().getMainMenu().getProjectMenu().setEnabled(false);
        try {
            Preferences.save();
            try {
                saveProjectProperties();
                projectTMX.save(config, config.getProjectInternal() + OConsts.STATUS_EXTENSION, isProjectModified());
                if (remoteRepositoryProvider != null && doTeamSync) {
                    tmxPrepared = null;
                    glossaryPrepared = null;
                    remoteRepositoryProvider.cleanPrepared();
                    Core.getMainWindow().showStatusMessageRB("TEAM_SYNCHRONIZE");
                    rebaseAndCommitProject(true);
                    setOnlineMode();
                }
                setProjectModified(false);
            } catch (KnownException ex) {
                throw ex;
            } catch (IRemoteRepository2.NetworkException e) {
                if (isOnlineMode) {
                    Log.logErrorRB("TEAM_NETWORK_ERROR", e.getCause());
                    setOfflineMode();
                }
            } catch (Exception e) {
                Log.logErrorRB(e, "CT_ERROR_SAVING_PROJ");
                Core.getMainWindow().displayErrorRB(e, "CT_ERROR_SAVING_PROJ");
            }
            LastSegmentManager.saveLastSegment();
            // update statistics
            StatsResult stat = CalcStandardStatistics.buildProjectStats(this);
            stat.updateStatisticsInfo(hotStat);
            String fn = config.getProjectInternal() + OConsts.STATS_FILENAME;
            Statistics.writeStat(fn, stat.getTextData(config));
        } finally {
            Core.getMainWindow().getMainMenu().getProjectMenu().setEnabled(true);
        }
        CoreEvents.fireProjectChange(IProjectEventListener.PROJECT_CHANGE_TYPE.SAVE);
    } finally {
        Core.getAutoSave().enable();
    }
    Log.logInfoRB("LOG_DATAENGINE_SAVE_END");
    isSaving = false;
}
Also used : IRemoteRepository2(org.omegat.core.team2.IRemoteRepository2) KnownException(org.omegat.core.KnownException) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) StatsResult(org.omegat.core.statistics.StatsResult)

Example 2 with StatsResult

use of org.omegat.core.statistics.StatsResult in project omegat by omegat-org.

the class RealProject method loadProject.

/**
 * Load exist project in a "big" sense -- loads project's properties, glossaries, tms, source files etc.
 */
public synchronized void loadProject(boolean onlineMode) {
    Log.logInfoRB("LOG_DATAENGINE_LOAD_START");
    UIThreadsUtil.mustNotBeSwingThread();
    // load new project
    try {
        if (!lockProject()) {
            throw new KnownException("PROJECT_LOCKED");
        }
        isOnlineMode = onlineMode;
        if (RuntimePreferences.isLocationSaveEnabled()) {
            Preferences.setPreference(Preferences.CURRENT_FOLDER, new File(config.getProjectRoot()).getAbsoluteFile().getParent());
            Preferences.save();
        }
        Core.getMainWindow().showStatusMessageRB("CT_LOADING_PROJECT");
        if (remoteRepositoryProvider != null) {
            try {
                tmxPrepared = null;
                glossaryPrepared = null;
                remoteRepositoryProvider.switchAllToLatest();
            } catch (IRemoteRepository2.NetworkException e) {
                Log.logErrorRB("TEAM_NETWORK_ERROR", e.getCause());
                setOfflineMode();
            }
            remoteRepositoryProvider.copyFilesFromReposToProject("");
            // After adding filters.xml and segmentation.conf, we must reload them again
            config.loadProjectFilters();
            config.loadProjectSRX();
        }
        loadFilterSettings();
        loadSegmentationSettings();
        // load projectsave.tmx
        loadTranslations();
        loadSourceFiles();
        // This MUST happen after calling loadTranslations()
        if (remoteRepositoryProvider != null && isOnlineMode) {
            Core.getMainWindow().showStatusMessageRB("TEAM_REBASE_AND_COMMIT");
            rebaseAndCommitProject(true);
        }
        // after loadSourcefiles, the entries are filled. The list can now (and only now) be readonly.
        allProjectEntries = Collections.unmodifiableList(allProjectEntries);
        // and now we can set the importHandler, used by loadTM
        importHandler = new ImportFromAutoTMX(this, allProjectEntries);
        // imports translation from source files into ProjectTMX
        importTranslationsFromSources();
        // loads external tmx, and auto/enfoce tmx'es (appending to projectTMX)
        loadTM();
        loadOtherLanguages();
        // build word count
        StatsResult stat = CalcStandardStatistics.buildProjectStats(this);
        stat.updateStatisticsInfo(hotStat);
        String fn = config.getProjectInternal() + OConsts.STATS_FILENAME;
        Statistics.writeStat(fn, stat.getTextData(config));
        loaded = true;
        // Project Loaded...
        Core.getMainWindow().showStatusMessageRB(null);
        setProjectModified(false);
    } catch (OutOfMemoryError oome) {
        // Fix for bug 1571944 @author Henry Pijffers
        // (henry.pijffers@saxnot.com)
        // Oh shit, we're all out of storage space!
        // Of course we should've cleaned up after ourselves earlier,
        // but since we didn't, do a bit of cleaning up now, otherwise
        // we can't even inform the user about our slacking off.
        allProjectEntries.clear();
        projectFilesList.clear();
        transMemories.clear();
        projectTMX = null;
        // There, that should do it, now inform the user
        long memory = Runtime.getRuntime().maxMemory() / 1024 / 1024;
        Log.logErrorRB("OUT_OF_MEMORY", memory);
        Log.log(oome);
        Core.getMainWindow().showErrorDialogRB("TF_ERROR", "OUT_OF_MEMORY", memory);
        // Just quit, we can't help it anyway
        System.exit(0);
    } catch (Throwable e) {
        Log.logErrorRB(e, "TF_LOAD_ERROR");
        Core.getMainWindow().displayErrorRB(e, "TF_LOAD_ERROR");
        if (!loaded) {
            unlockProject();
        }
    }
    Log.logInfoRB("LOG_DATAENGINE_LOAD_END");
}
Also used : IRemoteRepository2(org.omegat.core.team2.IRemoteRepository2) KnownException(org.omegat.core.KnownException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) StatsResult(org.omegat.core.statistics.StatsResult)

Aggregations

KnownException (org.omegat.core.KnownException)2 StatsResult (org.omegat.core.statistics.StatsResult)2 IRemoteRepository2 (org.omegat.core.team2.IRemoteRepository2)2 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 SAXParseException (org.xml.sax.SAXParseException)1