Search in sources :

Example 6 with IProject

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

the class EditorController method removeFilter.

/**
 * {@inheritDoc} Document is reloaded if appropriate to immediately remove
 * the filter;
 */
public void removeFilter() {
    UIThreadsUtil.mustBeSwingThread();
    if (entriesFilter == null && entriesFilterControlComponent == null) {
        return;
    }
    entriesFilter = null;
    if (entriesFilterControlComponent != null) {
        pane.remove(entriesFilterControlComponent);
        pane.revalidate();
        entriesFilterControlComponent = null;
    }
    int curEntryNum = getCurrentEntryNumber();
    Document3 doc = editor.getOmDocument();
    IProject project = Core.getProject();
    // Only load if there is a document and the project is loaded.
    if (doc != null && project != null && project.isProjectLoaded()) {
        List<FileInfo> files = project.getProjectFiles();
        if (files != null && !files.isEmpty()) {
            loadDocument();
            gotoEntry(curEntryNum);
        }
    }
}
Also used : FileInfo(org.omegat.core.data.IProject.FileInfo) Point(java.awt.Point) IProject(org.omegat.core.data.IProject)

Example 7 with IProject

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

the class HistoryPredictor method train.

synchronized void train() {
    IProject project = Core.getProject();
    if (!project.isProjectLoaded()) {
        return;
    }
    long start = System.currentTimeMillis();
    predictor.reset();
    project.iterateByDefaultTranslations((source, trans) -> trainString(trans.translation));
    project.iterateByMultipleTranslations((source, trans) -> trainString(trans.translation));
    long time = System.currentTimeMillis() - start;
    LOGGER.finer(() -> String.format("Time to train History Predictor: %d ms", time));
}
Also used : IProject(org.omegat.core.data.IProject)

Example 8 with IProject

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

the class GlossarySearcher method getCjkMatchingTokens.

private static List<Token[]> getCjkMatchingTokens(String fullText, String term) {
    // This is a CJK word and our source language is not space-delimited, so include if
    // word appears anywhere in source string.
    IProject project = Core.getProject();
    if (!project.isProjectLoaded() || project.getProjectProperties().getSourceLanguage().isSpaceDelimited()) {
        return Collections.emptyList();
    }
    if (!StringUtil.isCJK(term)) {
        return Collections.emptyList();
    }
    int i = fullText.indexOf(term);
    if (i == -1) {
        return Collections.emptyList();
    }
    List<Token[]> result = new ArrayList<>();
    result.add(new Token[] { new Token(term, i) });
    while ((i = fullText.indexOf(term, i + 1)) != -1) {
        result.add(new Token[] { new Token(term, i) });
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Token(org.omegat.util.Token) IProject(org.omegat.core.data.IProject)

Example 9 with IProject

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

the class FalseFriendsTest method setUp.

@Before
public final void setUp() {
    final ProjectProperties props = new ProjectProperties() {

        public Language getSourceLanguage() {
            return new Language("en");
        }

        public Language getTargetLanguage() {
            return new Language("pl");
        }
    };
    Core.setProject(new IProject() {

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, TMXEntry.ExternalLinked externalLinked) {
        }

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, ExternalLinked externalLinked, AllTranslations previousTranslations) throws OptimisticLockingFail {
        }

        public void setNote(SourceTextEntry entry, TMXEntry oldTrans, String note) {
        }

        public void saveProjectProperties() throws Exception {
        }

        public void saveProject(boolean doTeamSync) {
        }

        public void iterateByMultipleTranslations(MultipleTranslationsIterator it) {
        }

        public void iterateByDefaultTranslations(DefaultTranslationsIterator it) {
        }

        public boolean isProjectModified() {
            return false;
        }

        public boolean isProjectLoaded() {
            return true;
        }

        public boolean isOrphaned(EntryKey entry) {
            return false;
        }

        public boolean isOrphaned(String source) {
            return false;
        }

        public TMXEntry getTranslationInfo(SourceTextEntry ste) {
            return null;
        }

        public AllTranslations getAllTranslations(SourceTextEntry ste) {
            return null;
        }

        public Map<String, ExternalTMX> getTransMemories() {
            return null;
        }

        public ITokenizer getTargetTokenizer() {
            return null;
        }

        public StatisticsInfo getStatistics() {
            return null;
        }

        public ITokenizer getSourceTokenizer() {
            return null;
        }

        public ProjectProperties getProjectProperties() {
            return props;
        }

        public List<FileInfo> getProjectFiles() {
            return null;
        }

        public Map<Language, ProjectTMX> getOtherTargetLanguageTMs() {
            return null;
        }

        public List<SourceTextEntry> getAllEntries() {
            return null;
        }

        public void compileProject(String sourcePattern) throws Exception {
        }

        public void closeProject() {
        }

        public List<String> getSourceFilesOrder() {
            return null;
        }

        public void setSourceFilesOrder(List<String> filesList) {
        }

        @Override
        public String getTargetPathForSourceFile(String sourceFile) {
            return null;
        }

        @Override
        public boolean isTeamSyncPrepared() {
            return false;
        }

        @Override
        public void teamSync() {
        }

        @Override
        public void teamSyncPrepare() throws Exception {
        }

        @Override
        public boolean isRemoteProject() {
            return false;
        }

        @Override
        public void commitSourceFiles() throws Exception {
        }

        @Override
        public void compileProjectAndCommit(String sourcePattern, boolean doPostProcessing, boolean commitTargetFiles) throws Exception {
        }
    });
    LanguageToolWrapper.setBridgeFromCurrentProject();
}
Also used : ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) EntryKey(org.omegat.core.data.EntryKey) StatisticsInfo(org.omegat.core.statistics.StatisticsInfo) ProjectProperties(org.omegat.core.data.ProjectProperties) IProject(org.omegat.core.data.IProject) ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) ITokenizer(org.omegat.tokenizer.ITokenizer) Language(org.omegat.util.Language) SourceTextEntry(org.omegat.core.data.SourceTextEntry) List(java.util.List) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) Map(java.util.Map) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry) Before(org.junit.Before)

Example 10 with IProject

use of org.omegat.core.data.IProject 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);
                        try {
                            dataEngine.teamSyncPrepare();
                        } catch (Exception ex) {
                            LOGGER.log(Level.WARNING, "Error save", ex);
                        }
                    });
                    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());
                }
                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) KnownException(org.omegat.core.KnownException) TimeoutException(java.util.concurrent.TimeoutException) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

IProject (org.omegat.core.data.IProject)15 SourceTextEntry (org.omegat.core.data.SourceTextEntry)5 Point (java.awt.Point)4 File (java.io.File)4 FileInfo (org.omegat.core.data.IProject.FileInfo)3 TMXEntry (org.omegat.core.data.TMXEntry)3 Map (java.util.Map)2 EntryKey (org.omegat.core.data.EntryKey)2 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)2 StatisticsInfo (org.omegat.core.statistics.StatisticsInfo)2 Language (org.omegat.util.Language)2 Cursor (java.awt.Cursor)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 Before (org.junit.Before)1 KnownException (org.omegat.core.KnownException)1