Modified viewFile to accept a given file filter - this allows context

menus to change to a non-default file view. (For example, show a
binary file as text.) Additionally added a couple of show___Dialog
methods. Will need to incorporate these further for code cleanup.
This commit is contained in:
Robert Greene 2004-06-06 02:12:39 +00:00
parent 60647d3f09
commit a31c317740

View File

@ -362,7 +362,7 @@ public class DiskExplorerTab {
item.setImage(imageManager.get(ImageManager.ICON_VIEW_FILE)); item.setImage(imageManager.get(ImageManager.ICON_VIEW_FILE));
item.addSelectionListener(new SelectionAdapter() { item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
viewFile(); viewFile(null);
} }
}); });
@ -417,7 +417,7 @@ public class DiskExplorerTab {
item.setText("Text"); item.setText("Text");
item.addSelectionListener(new SelectionAdapter() { item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
viewFile(); // FIXME viewFile(TextFileFilter.class);
} }
}); });
@ -425,7 +425,7 @@ public class DiskExplorerTab {
item.setText("Graphics"); item.setText("Graphics");
item.addSelectionListener(new SelectionAdapter() { item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
viewFile(); // FIXME viewFile(GraphicsFileFilter.class);
} }
}); });
@ -781,7 +781,7 @@ public class DiskExplorerTab {
* Double-click handler. * Double-click handler.
*/ */
public void widgetDefaultSelected(SelectionEvent event) { public void widgetDefaultSelected(SelectionEvent event) {
viewFile(); viewFile(null);
} }
}); });
TableColumn column = null; TableColumn column = null;
@ -1247,7 +1247,7 @@ public class DiskExplorerTab {
viewFileItem.addSelectionListener(new SelectionAdapter () { viewFileItem.addSelectionListener(new SelectionAdapter () {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
if (event.detail != SWT.ARROW) { if (event.detail != SWT.ARROW) {
viewFile(); viewFile(null);
} }
} }
}); });
@ -1458,13 +1458,11 @@ public class DiskExplorerTab {
/** /**
* Open up the view file window for the currently selected file. * Open up the view file window for the currently selected file.
*/ */
protected void viewFile() { protected void viewFile(Class fileFilterClass) {
FileEntry fileEntry = getSelectedFileEntry(); FileEntry fileEntry = getSelectedFileEntry();
if (fileEntry.isDeleted()) { if (fileEntry.isDeleted()) {
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); showErrorDialogBox("Unable to view a deleted file!",
box.setText("Unable to view a deleted file!"); "Sorry, you cannot view a deleted file.", null);
box.setMessage("Sorry, you cannot view a deleted file.");
box.open();
} else if (fileEntry.isDirectory()) { } else if (fileEntry.isDirectory()) {
TreeItem item = findDirectoryItem(directoryTree.getSelection()[0].getItems(), fileEntry.getFilename(), 1, 0); TreeItem item = findDirectoryItem(directoryTree.getSelection()[0].getItems(), fileEntry.getFilename(), 1, 0);
if (item != null) { if (item != null) {
@ -1473,10 +1471,47 @@ public class DiskExplorerTab {
changeCurrentFormat(currentFormat); // minor hack changeCurrentFormat(currentFormat); // minor hack
} }
} else { // Assuming a normal file! } else { // Assuming a normal file!
FileViewerWindow window = new FileViewerWindow(shell, fileEntry, imageManager); FileViewerWindow window = null;
FileFilter fileFilter = null;
try {
fileFilter = (FileFilter) fileFilterClass.newInstance();
} catch (NullPointerException ex) {
// This is expected
} catch (InstantiationException e) {
showSystemErrorDialogBox(e);
} catch (IllegalAccessException e) {
showSystemErrorDialogBox(e);
}
if (fileFilter != null) {
window = new FileViewerWindow(shell, fileEntry, imageManager, fileFilter);
} else {
window = new FileViewerWindow(shell, fileEntry, imageManager);
}
window.open(); window.open();
} }
} }
/**
* Display an error dialog box with the OK button.
* Note that the Throwable message may be embedded in the displayed message.
* TODO: Should this be a shared method somewhere?
*/
protected void showErrorDialogBox(String title, String message, Throwable throwable) {
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
box.setText(title);
if (throwable != null) {
message.replaceAll("%MESSAGE%", throwable.getMessage());
}
box.setMessage(message);
box.open();
}
/**
* Display a system-level error dialog box.
*/
protected void showSystemErrorDialogBox(Throwable throwable) {
showErrorDialogBox("A system error occurred!",
"A system error occurred. The message given was '%MESSAGE%'.",
throwable);
}
/** /**
* Locate a named item in the directory tree. * Locate a named item in the directory tree.
*/ */
@ -1521,7 +1556,7 @@ public class DiskExplorerTab {
exportFileWizard(); exportFileWizard();
break; break;
case CTRL_V: // View file case CTRL_V: // View file
viewFile(); viewFile(null);
break; break;
} }
} }