more meaningful error messages

This commit is contained in:
hneemann 2017-04-05 14:49:13 +02:00
parent 9b4a9eedef
commit 65f14ca0db
7 changed files with 20 additions and 10 deletions

View File

@ -263,7 +263,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
if (node != null) if (node != null)
return node.getDescription(); return node.getDescription();
} catch (IOException e) { } catch (IOException e) {
throw new ElementNotFoundException(Lang.get("msg_errorImportingModel"), e); throw new ElementNotFoundException(Lang.get("msg_errorImportingModel_N0", elementName), e);
} }
throw new ElementNotFoundException(Lang.get("err_element_N_notFound", elementName)); throw new ElementNotFoundException(Lang.get("err_element_N_notFound", elementName));
@ -436,7 +436,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
} }
return description; return description;
} catch (PinException e) { } catch (PinException e) {
throw new IOException(Lang.get("msg_errorImportingModel"), e); throw new IOException(Lang.get("msg_errorImportingModel_N0", file), e);
} }
} }

View File

@ -30,6 +30,7 @@ public class LibraryNode implements Iterable<LibraryNode> {
private ElementLibrary library; private ElementLibrary library;
private LibraryNode parent; private LibraryNode parent;
private boolean unique; private boolean unique;
private boolean descriptionImportError = false;
/** /**
* Creates a new node with the given name. * Creates a new node with the given name.
@ -126,8 +127,12 @@ public class LibraryNode implements Iterable<LibraryNode> {
if (description == null) { if (description == null) {
if (!unique) if (!unique)
throw new IOException(Lang.get("err_file_N0_ExistsTwiceBelow_N1", file, library.getRootFilePath())); throw new IOException(Lang.get("err_file_N0_ExistsTwiceBelow_N1", file, library.getRootFilePath()));
try {
description = library.importElement(file); description = library.importElement(file);
} catch (IOException e) {
descriptionImportError = true;
throw e;
}
library.fireLibraryChanged(this); library.fireLibraryChanged(this);
} }
return description; return description;
@ -217,6 +222,9 @@ public class LibraryNode implements Iterable<LibraryNode> {
* @throws IOException IOException * @throws IOException IOException
*/ */
public Icon getIcon(ShapeFactory shapeFactory) throws IOException { public Icon getIcon(ShapeFactory shapeFactory) throws IOException {
if (descriptionImportError)
return ICON_NOT_UNIQUE;
getDescription(); getDescription();
return getIconOrNull(shapeFactory); return getIconOrNull(shapeFactory);
} }

View File

@ -49,7 +49,7 @@ public final class InsertAction extends ToolTipAction {
node.getDescription(); node.getDescription();
setIcon(node.getIcon(shapeFactory)); setIcon(node.getIcon(shapeFactory));
} catch (IOException ex) { } catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel")).addCause(ex)); SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel_N0", node.getName())).addCause(ex));
} }
} }
insertHistory.add(this); insertHistory.add(this);
@ -80,7 +80,7 @@ public final class InsertAction extends ToolTipAction {
final Icon icon = node.getIcon(shapeFactory); final Icon icon = node.getIcon(shapeFactory);
setIcon(icon); setIcon(icon);
} catch (IOException ex) { } catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel")).addCause(ex)); SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel_N0", node.getName())).addCause(ex));
} }
} }

View File

@ -73,7 +73,7 @@ public class LibrarySelector implements LibraryListener {
try { try {
library.updateEntries(); library.updateEntries();
} catch (IOException ex) { } catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel")).addCause(ex)); SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorUpdatingLibrary")).addCause(ex));
} }
} }
}.setToolTip(Lang.get("menu_update_tt")).createJMenuItem()); }.setToolTip(Lang.get("menu_update_tt")).createJMenuItem());

View File

@ -50,7 +50,7 @@ public class SelectTree extends JTree {
component.setPartToInsert(new VisualElement(d.getName()).setShapeFactory(shapeFactory)); component.setPartToInsert(new VisualElement(d.getName()).setShapeFactory(shapeFactory));
insertHistory.add(new InsertAction(node, insertHistory, component, shapeFactory)); insertHistory.add(new InsertAction(node, insertHistory, component, shapeFactory));
} catch (IOException e) { } catch (IOException e) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel")).addCause(e)); SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel_N0", node.getName())).addCause(e));
} }
} }
} }

View File

@ -711,7 +711,8 @@ Die Icons stammen aus dem Tango Desktop Project.</string>
<string name="msg_errorCreatingModel">Fehler beim Erzeugen der Schaltung</string> <string name="msg_errorCreatingModel">Fehler beim Erzeugen der Schaltung</string>
<string name="msg_errorDuringCalculation">Fehler während der Vereinfachung.</string> <string name="msg_errorDuringCalculation">Fehler während der Vereinfachung.</string>
<string name="msg_errorEditingValue">Fehler bei der Eingabe eines Wertes</string> <string name="msg_errorEditingValue">Fehler bei der Eingabe eines Wertes</string>
<string name="msg_errorImportingModel">Fehler beim Import einer Schaltung</string> <string name="msg_errorImportingModel_N0">Fehler beim Import der Schaltung {0}.</string>
<string name="msg_errorUpdatingLibrary">Fehler beim Aktualisieren der Bauteile-Bibliothek!</string>
<string name="msg_errorReadingFile">Fehler beim Lesen einer Datei</string> <string name="msg_errorReadingFile">Fehler beim Lesen einer Datei</string>
<string name="msg_remoteUnknownCommand">Das Kommando {0} ist unbekannt!</string> <string name="msg_remoteUnknownCommand">Das Kommando {0} ist unbekannt!</string>
<string name="msg_errorWritingFile">Fehler beim Schreiben einer Datei</string> <string name="msg_errorWritingFile">Fehler beim Schreiben einer Datei</string>

View File

@ -698,7 +698,8 @@ The icons are taken from the Tango Desktop Project.</string>
<string name="msg_errorCreatingModel">Error creating the circuit</string> <string name="msg_errorCreatingModel">Error creating the circuit</string>
<string name="msg_errorDuringCalculation">Error during simplification</string> <string name="msg_errorDuringCalculation">Error during simplification</string>
<string name="msg_errorEditingValue">Error editing a atribute value</string> <string name="msg_errorEditingValue">Error editing a atribute value</string>
<string name="msg_errorImportingModel">Error importing a circuit</string> <string name="msg_errorImportingModel_N0">Error importing the circuit {0}!</string>
<string name="msg_errorUpdatingLibrary">Error updating the component library!!</string>
<string name="msg_errorReadingFile">Error reading a file</string> <string name="msg_errorReadingFile">Error reading a file</string>
<string name="msg_errorWritingFile">Error writing a file</string> <string name="msg_errorWritingFile">Error writing a file</string>
<string name="msg_fastRunError">Error at fast run</string> <string name="msg_fastRunError">Error at fast run</string>