Search in sources :

Example 1 with VocabHunterException

use of io.github.vocabhunter.analysis.core.VocabHunterException in project VocabHunter by VocabHunter.

the class SelectionExportTool method exportSelection.

public static void exportSelection(final SessionState state, final Path file) {
    try {
        List<String> words = state.getOrderedUses().stream().filter(sessionWord -> sessionWord.getState().equals(WordState.UNKNOWN)).map(SessionWord::getWordIdentifier).collect(Collectors.toList());
        Files.write(file, words);
    } catch (final IOException e) {
        throw new VocabHunterException(String.format("Unable to export to file '%s", file), e);
    }
}
Also used : VocabHunterException(io.github.vocabhunter.analysis.core.VocabHunterException) IOException(java.io.IOException)

Example 2 with VocabHunterException

use of io.github.vocabhunter.analysis.core.VocabHunterException in project VocabHunter by VocabHunter.

the class SessionController method updateWordList.

private void updateWordList() {
    boolean isEditable = sessionModel.isEditable();
    FilterSettings filterSettings = sessionModel.getFilterSettings();
    boolean isFilterEnabled = sessionModel.isEnableFilters();
    VocabHunterException exception;
    boolean isFilterSuccess;
    try {
        WordFilter filter = filterSettingsTool.filter(filterSettings, isFilterEnabled);
        MarkTool<WordModel> markTool = new MarkTool<>(filter, sessionModel.getAllWords());
        isFilterSuccess = markTool.isValidFilter();
        if (isFilterSuccess) {
            sessionModel.updateWordList(isEditable, markTool);
            wordListHandler.selectClosestWord(isEditable, filter);
        }
        exception = null;
    } catch (final VocabHunterException e) {
        LOG.error("Failed to activate filter", e);
        exception = e;
        isFilterSuccess = false;
    }
    if (!isFilterSuccess) {
        processFilterFailure(exception);
    }
}
Also used : WordFilter(io.github.vocabhunter.analysis.filter.WordFilter) VocabHunterException(io.github.vocabhunter.analysis.core.VocabHunterException) MarkTool(io.github.vocabhunter.analysis.marked.MarkTool)

Example 3 with VocabHunterException

use of io.github.vocabhunter.analysis.core.VocabHunterException in project VocabHunter by VocabHunter.

the class FilterFileModelTranslatorImpl method fromModel.

@Override
public BaseListedFile fromModel(final FilterFileModel model) {
    FilterFileMode mode = model.getMode();
    Path file = model.getFile();
    switch(mode) {
        case SESSION_KNOWN:
            return new SessionListedFile(file, false);
        case SESSION_SEEN:
            return new SessionListedFile(file, true);
        case EXCEL:
            return new ExcelListedFile(file, model.getColumns());
        case DOCUMENT:
            return new DocumentListedFile(file);
        default:
            throw new VocabHunterException("Unsupported mode " + mode);
    }
}
Also used : Path(java.nio.file.Path) DocumentListedFile(io.github.vocabhunter.analysis.settings.DocumentListedFile) VocabHunterException(io.github.vocabhunter.analysis.core.VocabHunterException) ExcelListedFile(io.github.vocabhunter.analysis.settings.ExcelListedFile) FilterFileMode(io.github.vocabhunter.gui.model.FilterFileMode) SessionListedFile(io.github.vocabhunter.analysis.settings.SessionListedFile)

Aggregations

VocabHunterException (io.github.vocabhunter.analysis.core.VocabHunterException)3 WordFilter (io.github.vocabhunter.analysis.filter.WordFilter)1 MarkTool (io.github.vocabhunter.analysis.marked.MarkTool)1 DocumentListedFile (io.github.vocabhunter.analysis.settings.DocumentListedFile)1 ExcelListedFile (io.github.vocabhunter.analysis.settings.ExcelListedFile)1 SessionListedFile (io.github.vocabhunter.analysis.settings.SessionListedFile)1 FilterFileMode (io.github.vocabhunter.gui.model.FilterFileMode)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1