minor changes
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 11 Oct 2012 10:05:05 +0000 (10:05 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 11 Oct 2012 10:05:05 +0000 (10:05 +0000)
src/java/netxms-client/src/main/java/org/netxms/client/Table.java

index 266a8c8..e43a72a 100644 (file)
@@ -103,6 +103,38 @@ public class Table
                }\r
        }\r
 \r
+       /**\r
+        * Fill NXCP message with table's data\r
+        * \r
+        * @param msg NXCP message\r
+        */\r
+       public void fillMessage(final NXCPMessage msg)\r
+       {\r
+               msg.setVariable(NXCPCodes.VID_TABLE_TITLE, title);\r
+               if (instanceColumn != null)\r
+                       msg.setVariable(NXCPCodes.VID_INSTANCE_COLUMN, instanceColumn);\r
+               \r
+               int columnCount = columnNames.size();\r
+               msg.setVariableInt32(NXCPCodes.VID_TABLE_NUM_COLS, columnCount);\r
+               long varId = NXCPCodes.VID_TABLE_COLUMN_INFO_BASE;\r
+               for(int i = 0; i < columnCount; i++, varId += 8L)\r
+               {\r
+                       msg.setVariable(varId++, columnNames.get(i));\r
+                       msg.setVariableInt32(varId++, columnFormats.get(i));\r
+               }\r
+               \r
+               msg.setVariableInt32(NXCPCodes.VID_TABLE_NUM_ROWS, data.size());\r
+               varId = NXCPCodes.VID_TABLE_DATA_BASE;\r
+               for(int row = 0; row < data.size(); row++)\r
+               {\r
+                       final List<String> rowData = data.get(row);\r
+                       for(int col = 0; col < columnCount; col++)\r
+                       {\r
+                               msg.setVariable(varId++, rowData.get(col));\r
+                       }\r
+               }\r
+       }\r
+\r
        /**\r
         * Get number of columns in table\r
         *\r
@@ -274,4 +306,28 @@ public class Table
        {\r
                data.addAll(src.data);\r
        }\r
+\r
+       /**\r
+        * Add new row\r
+        */\r
+       public void addRow()\r
+       {\r
+               List<String> row = new ArrayList<String>(columnNames.size());\r
+               for(int i = 0; i < columnNames.size(); i++)\r
+                       row.add("");\r
+               data.add(row);\r
+       }\r
+       \r
+       /**\r
+        * Set cell value\r
+        * \r
+        * @param row\r
+        * @param col\r
+        * @param value\r
+        */\r
+       public void setCell(int row, int col, String value)\r
+       {\r
+               if ((row >= 0) && (row < data.size()) && (col >= 0) && (col < columnNames.size()))\r
+                       data.get(row).set(col, value);\r
+       }\r
 }\r