109
|
|
private void onOpen(String fileId) {
|
110
|
|
if (model.isFileModified(fileId)) {
|
111
|
|
int result = view.showConfirmationDialog(
|
112
|
|
"The file has modifications. Save before proceeding?",
|
113
|
|
fileId);
|
114
|
|
|
115
|
|
switch (result) {
|
116
|
|
case JOptionPane.YES_OPTION:
|
117
|
|
if (!onSave(fileId)) {
|
118
|
|
/* Saving was aborted or failed, so we don't proceed */
|
119
|
|
return;
|
120
|
|
}
|
121
|
|
break;
|
122
|
|
case JOptionPane.NO_OPTION:
|
123
|
|
break;
|
124
|
|
case JOptionPane.CANCEL_OPTION:
|
125
|
|
/* Saving was aborted or failed, so we don't proceed */
|
126
|
|
return;
|
127
|
|
}
|
128
|
|
}
|
129
|
|
|
130
|
|
String path = view.showOpenDialog(fileId);
|
131
|
|
|
132
|
|
if (path == null) {
|
133
|
|
return;
|
134
|
|
}
|
135
|
|
|
136
|
|
try {
|
137
|
|
String newFileId = model.loadFile(new File(path));
|
138
|
|
|
139
|
|
view.openFileInWindow(fileId, newFileId);
|
140
|
|
model.closeFile(fileId, true);
|
141
|
|
} catch (ParserConfigurationException e) {
|
142
|
|
view.showErrorDialog("Error loading file", fileId);
|
143
|
|
} catch (SAXException e) {
|
144
|
|
view.showErrorDialog("Error loading file", fileId);
|
145
|
|
} catch (IOException e) {
|
146
|
|
view.showErrorDialog("Error loading file", fileId);
|
147
|
|
}
|
148
|
|
}
|