Search in sources :

Example 1 with KnownException

use of org.omegat.core.KnownException in project omegat by omegat-org.

the class RealProject method createProject.

/**
 * Create new project.
 */
public void createProject() {
    Log.logInfoRB("LOG_DATAENGINE_CREATE_START");
    UIThreadsUtil.mustNotBeSwingThread();
    try {
        if (!lockProject()) {
            throw new KnownException("PROJECT_LOCKED");
        }
        createDirectory(config.getProjectRoot(), null);
        createDirectory(config.getProjectInternal(), OConsts.DEFAULT_INTERNAL);
        createDirectory(config.getSourceRoot(), OConsts.DEFAULT_SOURCE);
        createDirectory(config.getGlossaryRoot(), OConsts.DEFAULT_GLOSSARY);
        createDirectory(config.getTMRoot(), OConsts.DEFAULT_TM);
        createDirectory(config.getTMAutoRoot(), OConsts.AUTO_TM);
        createDirectory(config.getDictRoot(), OConsts.DEFAULT_DICT);
        createDirectory(config.getTargetRoot(), OConsts.DEFAULT_TARGET);
        // createDirectory(m_config.getTMOtherLangRoot(), OConsts.DEFAULT_OTHERLANG);
        saveProjectProperties();
        // Set project specific segmentation rules if they exist, or
        // defaults otherwise.
        SRX srx = config.getProjectSRX();
        Core.setSegmenter(new Segmenter(srx == null ? Preferences.getSRX() : srx));
        loadTranslations();
        setProjectModified(true);
        saveProject(false);
        loadSourceFiles();
        allProjectEntries = Collections.unmodifiableList(allProjectEntries);
        importHandler = new ImportFromAutoTMX(this, allProjectEntries);
        importTranslationsFromSources();
        loadTM();
        loadOtherLanguages();
        loaded = true;
        // clear status message
        Core.getMainWindow().showStatusMessageRB(null);
    } catch (Exception e) {
        // trouble in Tinseltown...
        Log.logErrorRB(e, "CT_ERROR_CREATING_PROJECT");
        Core.getMainWindow().displayErrorRB(e, "CT_ERROR_CREATING_PROJECT");
    }
    Log.logInfoRB("LOG_DATAENGINE_CREATE_END");
}
Also used : KnownException(org.omegat.core.KnownException) SRX(org.omegat.core.segmentation.SRX) Segmenter(org.omegat.core.segmentation.Segmenter) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Example 2 with KnownException

use of org.omegat.core.KnownException 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 3 with KnownException

use of org.omegat.core.KnownException in project omegat by omegat-org.

the class SaveThread method run.

@Override
public void run() {
    try {
        while (true) {
            synchronized (this) {
                // Set flag for saving. If somebody will reset time, he will
                // clear this flag also.
                needToSaveNow = true;
                // sleep
                wait(waitDuration);
            }
            if (needToSaveNow && enabled) {
                // Wait finished by time and autosaving enabled.
                IProject dataEngine = Core.getProject();
                LOGGER.fine("Start project save from SaveThread");
                try {
                    Core.executeExclusively(false, () -> {
                        dataEngine.saveProject(false);
                        dataEngine.teamSyncPrepare();
                    });
                    Core.getMainWindow().showStatusMessageRB("ST_PROJECT_AUTOSAVED", DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date()));
                } catch (TimeoutException ex) {
                    LOGGER.warning("Lock trying timeout during autosave");
                } catch (KnownException ex) {
                    Core.getMainWindow().showStatusMessageRB(ex.getMessage(), ex.getParams());
                } catch (Exception ex) {
                    LOGGER.log(Level.WARNING, "Error save", ex);
                }
                LOGGER.fine("Finish project save from SaveThread");
            }
        }
    } catch (InterruptedException ex) {
        LOGGER.log(Level.WARNING, "Save thread interrupted", ex);
        return;
    }
}
Also used : KnownException(org.omegat.core.KnownException) IProject(org.omegat.core.data.IProject) Date(java.util.Date) KnownException(org.omegat.core.KnownException) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with KnownException

use of org.omegat.core.KnownException in project omegat by omegat-org.

the class ProjectUICommands method processSwingWorkerException.

private static void processSwingWorkerException(Exception ex, String errorCode) {
    if (ex instanceof ExecutionException) {
        Log.logErrorRB(ex.getCause(), errorCode);
        if (ex.getCause() instanceof KnownException) {
            KnownException e = (KnownException) ex.getCause();
            Core.getMainWindow().displayErrorRB(e.getCause(), e.getMessage(), e.getParams());
        } else {
            Core.getMainWindow().displayErrorRB(ex.getCause(), errorCode);
        }
    } else {
        Log.logErrorRB(ex, errorCode);
        Core.getMainWindow().displayErrorRB(ex, errorCode);
    }
}
Also used : KnownException(org.omegat.core.KnownException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with KnownException

use of org.omegat.core.KnownException 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)5 IOException (java.io.IOException)2 StatsResult (org.omegat.core.statistics.StatsResult)2 IRemoteRepository2 (org.omegat.core.team2.IRemoteRepository2)2 SAXParseException (org.xml.sax.SAXParseException)2 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 IProject (org.omegat.core.data.IProject)1 SRX (org.omegat.core.segmentation.SRX)1 Segmenter (org.omegat.core.segmentation.Segmenter)1