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