You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/07/30 17:29:01 UTC

[GitHub] [netbeans] matthiasblaesing commented on a change in pull request #2169: [NETBEANS-4415] Export dataview results to file

matthiasblaesing commented on a change in pull request #2169:
URL: https://github.com/apache/netbeans/pull/2169#discussion_r458352232



##########
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 <pn...@gmail.com>
+ */
+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:
       This operates on the JTable and thus must be called from the EDT. I feel uncomfortable with that, as the EDT should not be blocked for long times. Could you please check if a copy / read-only version of the data is available without touching Swing or only shortly?

##########
File path: ide/db.dataview/external/commons-collections4-4.4-license.txt
##########
@@ -0,0 +1,208 @@
+Name: Apache Commons Collections
+Version: 4.4
+License: Apache-2.0
+Description: The Apache Commons Collections package contains types that extend and augment the Java Collections Framework.
+Origin: Apache Software Foundation
+URL: https://commons.apache.org/proper/commons-collections/

Review comment:
       Please add "Type" with the value "compile-time" here to indicate, that the dependency is not used at runtime, but only at compile/test time.
   
   For all dependencies, that are ALv2 licenses, please check if a NOTICE file exists. The ALv2 requires users to include the info of that file in the same file when redistributing. The NOTICE file from the library needs to be checked whether or not the information is relevant.

##########
File path: ide/db.dataview/src/org/netbeans/modules/db/dataview/output/Bundle.properties
##########
@@ -80,6 +80,8 @@ TOOLTIP_commit_all=Commit Record(s)
 
 TOOLTIP_print_data=Print Table Data
 
+TOOLTIP_export_data=Export Table Data

Review comment:
       I had a WTF moment as this is the text for the menuitem, but it follows the existing convention, so this is fine.

##########
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 <pn...@gmail.com>
+ */
+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("\\.");

Review comment:
       This splits at the first dot, not the last. Would it make sense to use a [FileObject#getExt](http://bits.netbeans.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/FileObject.html#getExt--)?

##########
File path: ide/db.dataview/src/org/netbeans/modules/db/dataview/output/dataexport/CSVCommonsDataExporter.java
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * Exports the given data to the target file in the provided CSV format.
+ *
+ * @author Periklis Ntanasis <pn...@gmail.com>
+ */
+public interface CSVCommonsDataExporter {
+
+    default void exportData(String[] headers, Object[][] contents, File file, CSVFormat format) {

Review comment:
       My gut feeling is, that this is one of the cases where an abstract base class is a better fit for this case. But this is discussable.  If we ever get an SPI where modules can supply their own serializers, we need to rethink this anyway.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists