Search in sources :

Example 1 with WarnUserException

use of com.mucommander.viewer.WarnUserException in project mucommander by mucommander.

the class EditorRegistrar method registerFileEditors.

/**
 * Registers all available editor services for the given file type.
 *
 * @param file the file that will be displayed by the returned FileEditor
 * @param presenter file editor presenter to register to
 * @param frame the frame in which the FileEditor is shown
 * @return number of editor services registered
 * @throws UserCancelledException if the user has been asked to confirm the
 * operation and canceled
 */
public static int registerFileEditors(AbstractFile file, FileEditorPresenter presenter, EditorFrame frame) throws UserCancelledException {
    int counter = 0;
    boolean editorCanceled = false;
    List<FileEditorService> editorServices = FileEditorServiceTracker.getEditorServices();
    for (FileEditorService service : editorServices) {
        try {
            if (service.canEditFile(file)) {
                presenter.addEditorService(service);
                counter++;
            }
        } catch (WarnUserException e) {
            QuestionDialog dialog = new QuestionDialog((Frame) null, Translator.get("warning"), Translator.get(e.getMessage()), frame.getMainFrame(), Arrays.asList(EditorRegistrarAction.OPEN_ANYWAY, EditorRegistrarAction.CANCEL), 0);
            DialogAction ret = dialog.getActionValue();
            if (ret == EditorRegistrarAction.CANCEL || ret == DIALOG_DISPOSED_ACTION) {
                // User canceled the operation
                editorCanceled = true;
            } else {
                // User confirmed the operation
                presenter.addEditorService(service);
                counter++;
            }
        }
    }
    if (counter == 0 && editorCanceled) {
        throw new UserCancelledException();
    }
    return counter;
}
Also used : Frame(java.awt.Frame) MainFrame(com.mucommander.ui.main.MainFrame) QuestionDialog(com.mucommander.ui.dialog.QuestionDialog) DialogAction(com.mucommander.ui.dialog.DialogAction) FileEditorService(com.mucommander.viewer.FileEditorService) WarnUserException(com.mucommander.viewer.WarnUserException)

Example 2 with WarnUserException

use of com.mucommander.viewer.WarnUserException in project mucommander by mucommander.

the class ViewerRegistrar method registerFileViewers.

/**
 * Registers all available viewer services for the given file type.
 *
 * @param file the file that will be displayed by the returned FileViewer
 * @param presenter file viewer presenter to register to
 * @return number of viewer services registered
 * @throws UserCancelledException if the user has been asked to confirm the
 * operation and canceled
 */
public static int registerFileViewers(AbstractFile file, FileViewerPresenter presenter, ViewerFrame viewerFrame) throws UserCancelledException {
    int counter = 0;
    boolean viewerCanceled = false;
    List<FileViewerService> viewerServices = FileViewerServiceTracker.getViewerServices();
    for (FileViewerService service : viewerServices) {
        try {
            if (service.canViewFile(file)) {
                presenter.addViewerService(service);
                counter++;
            }
        } catch (WarnUserException e) {
            // TODO: question the user how does he want to open the file (as image, text..)
            // Todo: display a proper warning dialog with the appropriate icon
            QuestionDialog dialog = new QuestionDialog((Frame) null, Translator.get("warning"), Translator.get(e.getMessage()), viewerFrame.getMainFrame(), Arrays.asList(ViewerRegistrarAction.OPEN_ANYWAY, ViewerRegistrarAction.CANCEL), 0);
            DialogAction ret = dialog.getActionValue();
            if (ret == ViewerRegistrarAction.CANCEL || ret == DIALOG_DISPOSED_ACTION) {
                // User canceled the operation
                viewerCanceled = true;
            } else {
                // User confirmed the operation
                presenter.addViewerService(service);
                counter++;
            }
        }
    }
    if (counter == 0 && viewerCanceled) {
        throw new UserCancelledException();
    }
    return counter;
}
Also used : Frame(java.awt.Frame) MainFrame(com.mucommander.ui.main.MainFrame) QuestionDialog(com.mucommander.ui.dialog.QuestionDialog) DialogAction(com.mucommander.ui.dialog.DialogAction) FileViewerService(com.mucommander.viewer.FileViewerService) WarnUserException(com.mucommander.viewer.WarnUserException)

Example 3 with WarnUserException

use of com.mucommander.viewer.WarnUserException in project mucommander by mucommander.

the class FileViewerPresenter method goToFile.

@Override
public void goToFile(Function<Integer, Integer> advance, FileViewerService viewerService) throws IOException {
    FileTable fileTable = getFrame().getMainFrame().getActiveTable();
    AbstractFile newFile;
    int originalRow = fileTable.getSelectedRow();
    boolean canView;
    do {
        int currentRow = fileTable.getSelectedRow();
        int newRow = advance.apply(currentRow);
        if (newRow < 0 || newRow >= fileTable.getRowCount()) {
            fileTable.selectRow(originalRow);
            return;
        }
        fileTable.selectRow(newRow);
        newFile = fileTable.getSelectedFile();
        try {
            canView = viewerService.canViewFile(newFile);
        } catch (WarnUserException ex) {
            canView = false;
        }
    } while (newFile == null || !canView);
    setCurrentFile(newFile);
    fileViewer.open(newFile);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileTable(com.mucommander.ui.main.table.FileTable) WarnUserException(com.mucommander.viewer.WarnUserException)

Aggregations

WarnUserException (com.mucommander.viewer.WarnUserException)3 DialogAction (com.mucommander.ui.dialog.DialogAction)2 QuestionDialog (com.mucommander.ui.dialog.QuestionDialog)2 MainFrame (com.mucommander.ui.main.MainFrame)2 Frame (java.awt.Frame)2 AbstractFile (com.mucommander.commons.file.AbstractFile)1 FileTable (com.mucommander.ui.main.table.FileTable)1 FileEditorService (com.mucommander.viewer.FileEditorService)1 FileViewerService (com.mucommander.viewer.FileViewerService)1