MasterEx commented on a change in pull request #2169: URL: https://github.com/apache/netbeans/pull/2169#discussion_r467320062
########## File path: ide/db.dataview/src/org/netbeans/modules/db/dataview/output/dataexport/DataExportUtils.java ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.db.dataview.output.dataexport; + +import java.sql.SQLException; +import javax.swing.JTable; +import org.netbeans.modules.db.dataview.util.FileBackedClob; +import org.openide.util.Exceptions; + +/** + * Data export utility methods. + * + * @author Periklis Ntanasis <[email protected]> + */ +public class DataExportUtils { + + /** + * Returns the filename file type extension in lower case. The extension is + * the part after the last dot character (.). Example: for filename + * "foo.java" it will return "java". + * + * @param filename + * @return The filename extension (part after the last .) in lower case. + */ + public static String getExtension(String filename) { + String[] tokens = filename.split("\\."); + return tokens[tokens.length - 1].toLowerCase(); + } + + /** + * Returns the column names of a JTable as an array of strings. + * + * @param table A JTable. + * @return String[] populated with the column names. + */ + public static String[] getColumnNames(JTable table) { + String[] header = new String[table.getColumnCount()]; + for (int i = 0; i < table.getColumnCount(); i++) { + header[i] = table.getColumnName(i); + } + return header; + } + + /** + * Returns the contents of a JTable as a two dimensional Object array. + * + * @param table A JTable. + * @return Object[][] populated with the table contents. + */ + public static Object[][] getTableContents(JTable table) { + Object[][] contents = new Object[table.getRowCount()][table.getColumnCount()]; + for (int i = 0; i < table.getRowCount(); i++) { + for (int j = 0; j < table.getColumnCount(); j++) { + if (table.getValueAt(i, j) instanceof FileBackedClob) { + FileBackedClob lob = (FileBackedClob) table.getValueAt(i, j); + try { + contents[i][j] = lob.getSubString(1, (int) lob.length()); + } catch (SQLException ex) { + Exceptions.printStackTrace(ex); + } + } else { + contents[i][j] = table.getValueAt(i, j); + } + } + } + return contents; Review comment: I am still looking into it. Until now what I have found out is that when rows are selected to be copied, the rows are copied into clipboard in a similar way (see `copyRowValues()` in `ResultSetJXTable`). Also, I was thinking that my original intention as described in https://issues.apache.org/jira/browse/NETBEANS-4415 was to "export the results displayed in the table as a file". Based on that, if we want to export the table as the user sees it (keep the order of the results etc.) then probably we have to read the data from the `JTable`. Anyway, as I have said I am still looking into it. If you have any suggestion it is very welcome. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
