OSDN Git Service

fixed bug #31273 (DatabaseInfoTree#generateInsertStatement) t31273
authorargius <argius.net@gmail.com>
Fri, 3 May 2013 01:57:46 +0000 (10:57 +0900)
committerargius <argius.net@gmail.com>
Fri, 3 May 2013 01:57:46 +0000 (10:57 +0900)
src/net/argius/stew/ui/window/DatabaseInfoTree.java
src/net/argius/stew/ui/window/messages.u8p
src/net/argius/stew/ui/window/messages_ja.u8p

index 5d2c3ad..3eeb3c3 100644 (file)
@@ -207,9 +207,21 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
                 InfoNode node = (InfoNode)path.getLastPathComponent();
                 if (node instanceof ColumnNode) {
                     ColumnNode columnNode = (ColumnNode)node;
-                    if (columnNode.getTableNode().isKindOfTable()) {
-                        a.add(columnNode);
-                    }
+                    a.add(columnNode);
+                }
+            }
+        }
+        return a;
+    }
+
+    private static List<TableNode> collectTableNode(TreePath[] paths) {
+        List<TableNode> a = new ArrayList<TableNode>();
+        if (paths != null) {
+            for (TreePath path : paths) {
+                InfoNode node = (InfoNode)path.getLastPathComponent();
+                if (node instanceof TableNode) {
+                    TableNode columnNode = (TableNode)node;
+                    a.add(columnNode);
                 }
             }
         }
@@ -227,36 +239,47 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
     private void generateInsertStatement() {
         TreePath[] paths = getSelectionPaths();
         List<ColumnNode> columns = collectColumnNode(paths);
-        String[] tableNames = collectTableName(columns);
-        if (tableNames.length == 0) {
-            return;
-        }
-        if (tableNames.length != 1) {
-            showInformationMessageDialog(this, res.get("e.enables-select-just-1-table"), "");
-            return;
-        }
-        final String tableName = tableNames[0];
-        List<String> columnNames = new ArrayList<String>();
-        final Iterable<ColumnNode> columnNodes;
+        final String tableName;
+        final int tableCount;
         if (columns.isEmpty()) {
-            final TreePath path = paths[0];
-            TableNode tableNode = (TableNode)path.getLastPathComponent();
+            List<TableNode> tables = collectTableNode(paths);
+            if (tables.isEmpty()) {
+                return;
+            }
+            TableNode tableNode = tables.get(0);
             if (tableNode.getChildCount() == 0) {
-                expandPath(path);
+                showInformationMessageDialog(this,
+                                             res.get("i.can-only-use-after-tablenode-expanded"),
+                                             "");
+                return;
             }
             @SuppressWarnings("unchecked")
-            Iterable<ColumnNode> it = Collections.list(tableNode.children());
-            columnNodes = it;
+            List<ColumnNode> list = Collections.list(tableNode.children());
+            columns.addAll(list);
+            tableName = tableNode.getNodeFullName();
+            tableCount = tables.size();
         } else {
-            columnNodes = columns;
+            String[] tableNames = collectTableName(columns);
+            tableCount = tableNames.length;
+            if (tableCount == 0) {
+                return;
+            }
+            tableName = tableNames[0];
+        }
+        if (tableCount != 1) {
+            showInformationMessageDialog(this, res.get("e.enables-select-just-1-table"), "");
+            return;
         }
-        for (ColumnNode node : columnNodes) {
+        List<String> columnNames = new ArrayList<String>();
+        for (ColumnNode node : columns) {
             columnNames.add(node.getName());
         }
-        insertTextToTextArea(String.format("INSERT INTO %s (%s) VALUES (%s);",
+        final int columnCount = columnNames.size();
+        insertTextToTextArea(String.format("INSERT INTO %s (%s) VALUES (%s);%s",
                                            tableName,
                                            joinByComma(columnNames),
-                                           joinByComma(nCopies(columnNames.size(), "?"))));
+                                           joinByComma(nCopies(columnCount, "?")),
+                                           TextUtilities.join(",", nCopies(columnCount, ""))));
     }
 
     private void jumpToColumnByName() {
index a96566f..a7bfeea 100644 (file)
@@ -14,6 +14,7 @@ i.help-see-release-package=\
 ヘルプ機能は実装されていません。\n\n\
 簡易ヘルプについては、インストールパッケージ内の\n\
 Manual_ja.htmlを参照してください。
+i.can-only-use-after-tablenode-expanded=It can only use after the table node is expanded.
 i.input-encryption-key=暗号鍵を入力
 i.input-new-connector-id=新しいコネクタのIDを入力
 i.paren-in-processing=(処理中)
index eb94bf4..57060c2 100644 (file)
@@ -14,6 +14,7 @@ i.help-see-release-package=\
 ヘルプ機能は実装されていません。\n\n\
 簡易ヘルプについては、インストールパッケージ内の\n\
 Manual_ja.htmlを参照してください。
+i.can-only-use-after-tablenode-expanded=テーブルノードを展開した後でのみ実行できます。
 i.input-encryption-key=暗号鍵を入力
 i.input-new-connector-id=新しいコネクタのIDを入力
 i.paren-in-processing=(処理中)