Search in sources :

Example 1 with FileEditorService

use of com.mucommander.viewer.FileEditorService 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 FileEditorService

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

the class FileEditorServiceTracker method addingService.

@Override
public FileEditorService addingService(ServiceReference<FileEditorService> reference) {
    FileEditorService service = super.addingService(reference);
    FileEditorServiceTracker.addEditorService(service);
    LOGGER.info("FileEditorService is registered: " + service);
    return service;
}
Also used : FileEditorService(com.mucommander.viewer.FileEditorService)

Example 3 with FileEditorService

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

the class FileEditorPresenter method switchFileEditor.

private void switchFileEditor(int index) throws IOException, CloseCancelledException {
    if (fileEditor != null) {
        fileEditor.close();
        clearComponentToPresent();
        resetTitle();
    }
    menuBar.removeAll();
    menuBar.add(editorMenu);
    FileEditorService service = services.get(index);
    fileEditor = service.createFileEditor();
    fileEditor.setPresenter(this);
    JComponent editorComponent = fileEditor.getUI();
    fileEditor.open(getCurrentFile());
    fileEditor.extendMenu(menuBar);
    menuBar.revalidate();
    setComponentToPresent(editorComponent);
    activeEditor = index;
}
Also used : JComponent(javax.swing.JComponent) FileEditorService(com.mucommander.viewer.FileEditorService)

Aggregations

FileEditorService (com.mucommander.viewer.FileEditorService)3 DialogAction (com.mucommander.ui.dialog.DialogAction)1 QuestionDialog (com.mucommander.ui.dialog.QuestionDialog)1 MainFrame (com.mucommander.ui.main.MainFrame)1 WarnUserException (com.mucommander.viewer.WarnUserException)1 Frame (java.awt.Frame)1 JComponent (javax.swing.JComponent)1