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;
}
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;
}
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;
}
Aggregations