OSDN Git Service

[#34243] Change the error message more detail when initializing Connector ( only...
authorargius <argius.net@gmail.com>
Fri, 3 Oct 2014 10:50:36 +0000 (19:50 +0900)
committerargius <argius.net@gmail.com>
Fri, 14 Nov 2014 13:31:33 +0000 (22:31 +0900)
src/net/argius/stew/Connector.java
src/net/argius/stew/messages.u8p
src/net/argius/stew/messages_ja.u8p
src/net/argius/stew/ui/window/ConnectorMapEditDialog.java

index eeb7c87..e7473d9 100644 (file)
@@ -23,8 +23,8 @@ public final class Connector {
      */
     public Connector(String id, Properties props) {
         assert id != null;
-        if (!id.matches("[A-Za-z0-9]+")) {
-            throw new IllegalArgumentException("illegal id : " + id);
+        if (!id.matches("[A-Za-z0-9]+")) { // XXX move to new public method isValid
+            throw new IllegalArgumentException(ResourceManager.Default.get("e.id-can-only-contain-alphanum", id));
         }
         Properties p = new Properties();
         p.putAll(props);
index 8ea8824..e4ae485 100644 (file)
@@ -29,6 +29,7 @@ e.database=Database Error: {0}
 e.dir-not-exists=Directory[{0}] does not exist.
 e.fatal=Fatal Error: {0}
 e.file-not-exists=File[{0}] does not exist.
+e.id-can-only-contain-alphanum=ID can only contain alphanumeric characters: ID=[{0}]
 e.no-connector=Connector [{0}] does not exist.
 e.not-connect=Not connected.
 e.not-found=Error: Command [{0}] was not found.
index 8561eb8..78ad1c8 100644 (file)
@@ -28,6 +28,7 @@ e.database=データベースエラー: {0}
 e.dir-not-exists=ディレクトリ[{0}]は存在しません。
 e.fatal=致命的なエラー: {0}
 e.file-not-exists=ファイル[{0}]は存在しません。
+e.id-can-only-contain-alphanum=IDには英数字のみ使用できます: ID=[{0}]
 e.no-connector=コネクタ [{0}] はありません。
 e.not-connect=接続されていません。
 e.not-found=エラー: コマンド [{0}] は見つかりませんでした。
index 285cf80..518aa76 100644 (file)
@@ -108,7 +108,14 @@ final class ConnectorMapEditDialog extends JDialog implements ChangeListener, An
                 final String message = res.get("e.id-already-exists", id);
                 showMessageDialog(this, message, null, ERROR_MESSAGE);
             } else {
-                openConnectorEditDialog(new Connector(id, new Properties()));
+                Connector connector;
+                try {
+                    connector = new Connector(id, new Properties());
+                } catch (IllegalArgumentException ex) {
+                    showMessageDialog(this, ex.getMessage(), null, ERROR_MESSAGE);
+                    return;
+                }
+                openConnectorEditDialog(connector);
             }
         } else if (ev.isAnyOf(modify)) {
             ConnectorEntry entry = (ConnectorEntry)idList.getSelectedValue();
@@ -130,7 +137,13 @@ final class ConnectorMapEditDialog extends JDialog implements ChangeListener, An
             connectorMap.remove(entry);
             connectorMap.put(newId, entry.getConnector());
             DefaultListModel m = (DefaultListModel)idList.getModel();
-            Connector newConnector = new Connector(newId, entry.getConnector());
+            Connector newConnector;
+            try {
+                newConnector = new Connector(newId, entry.getConnector());
+            } catch (IllegalArgumentException ex) {
+                showMessageDialog(this, ex.getMessage(), null, ERROR_MESSAGE);
+                return;
+            }
             m.set(m.indexOf(entry), new ConnectorEntry(newId, newConnector));
             idList.repaint();
         } else if (ev.isAnyOf(remove)) {