tmf: update batch import wizard to show file sizes
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 17 Oct 2013 15:37:15 +0000 (11:37 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 18 Nov 2013 19:18:31 +0000 (14:18 -0500)
Change-Id: I970c569860f81a2bd33a3ab227aa7ff3db2679b8
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/17690
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPageOptions.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardScanPage.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/messages.properties

index ef95beba65897119d73d48861305317476f633c7..5ab1d47b70342b36d08b81acdc77fd09d0286c53 100644 (file)
@@ -462,7 +462,8 @@ public final class TmfTraceType {
      */
     public boolean validate(String traceTypeName, String fileName) {
         if (traceTypeName != null && !traceTypeName.isEmpty()) {
-            if (!fTraceTypes.get(traceTypeName).validate(fileName)) {
+            final TraceTypeHelper traceTypeHelper = fTraceTypes.get(traceTypeName);
+            if (!traceTypeHelper.validate(fileName)) {
                 return false;
             }
         }
index 93e29cbf49059b1e3d0e7831afab760f2f0c3e45..0ac5582bb5041f55647729c41a52dec156e555e4 100644 (file)
@@ -65,7 +65,7 @@ public class ImportTraceWizardPageOptions extends AbstractImportTraceWizardPage
         optionPane.setLayout(new GridLayout());
         optionPane.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
 
-        fProjects = new List(optionPane, SWT.NONE);
+        fProjects = new List(optionPane, SWT.V_SCROLL);
         fProjects.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
         for (IProject project : TraceUtils.getOpenedTmfProjects()) {
index 41d0e409746dd4104750af3a927db9776bc49c4e..775dd15dd0561c6cf1cb9a6360eaf24f86af323c 100644 (file)
@@ -13,6 +13,7 @@
 package org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace;
 
 import java.io.File;
+import java.text.DecimalFormat;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 
@@ -142,7 +143,7 @@ public class ImportTraceWizardScanPage extends AbstractImportTraceWizardPage {
         // --------------------
 
         column = new TreeViewerColumn(traceTypeViewer, SWT.NONE);
-        column.getColumn().setWidth(COL_WIDTH);
+        column.getColumn().setWidth(500);
         column.getColumn().setText(Messages.ImportTraceWizardImportCaption);
         column.setLabelProvider(new ColumnLabelProvider() {
             @Override
@@ -154,6 +155,73 @@ public class ImportTraceWizardScanPage extends AbstractImportTraceWizardPage {
                 return null;
             }
         });
+        // --------------------
+        // Column 3
+        // --------------------
+
+        column = new TreeViewerColumn(traceTypeViewer, SWT.NONE);
+
+        column.getColumn().setWidth(80);
+        column.getColumn().setText(Messages.ImportTraceWizardScanPageSize);
+        column.getColumn().setAlignment(SWT.RIGHT);
+        column.setLabelProvider(new ColumnLabelProvider() {
+
+            @Override
+            public String getText(Object element) {
+                if (element instanceof FileAndName) {
+
+                    FileAndName elem = (FileAndName) element;
+                    long len = recurseSize(elem.getFile());
+                    if (len > 0) {
+                        double sizeb10 = Math.log10(len);
+                        DecimalFormat df = new DecimalFormat();
+                        df.setMaximumFractionDigits(2);
+                        df.setMinimumFractionDigits(0);
+                        if (sizeb10 > 12) {
+                            final double tbSize = len / 1024.0 / 1024 / 1024 / 1024;
+                            return df.format(tbSize) + Messages.ImportTraceWizardScanPageTerabyte;
+                        }
+                        if (sizeb10 > 9) {
+                            final double gbSize = len / 1024.0 / 1024 / 1024;
+                            return df.format(gbSize) + Messages.ImportTraceWizardScanPageGigabyte;
+                        }
+                        if (sizeb10 > 6) {
+                            final double mbSize = len / 1024.0 / 1024;
+                            return df.format(mbSize) + Messages.ImportTraceWizardScanPageMegabyte;
+                        }
+                        if (sizeb10 > 3) {
+                            final double kbSize = len / 1024.0;
+                            return df.format(kbSize) + Messages.ImportTraceWizardScanPageKilobyte;
+                        }
+                    }
+                    return Long.toString(len) + Messages.ImportTraceWizardScanPagebyte;
+
+                }
+                return null;
+            }
+
+            private long recurseSize(File file) {
+                if (file.isFile() && file.canRead()) {
+                    return file.length();
+                }
+                long size = 0;
+                if (file.exists() && file.isDirectory() && file.canRead()) {
+                    final File[] listFiles = file.listFiles();
+                    if (listFiles != null) {
+                        for (File child : listFiles) {
+                            if (child.isFile() && child.canRead()) {
+                                size += child.length();
+                            } else if (child.isDirectory()) {
+                                size += recurseSize(child);
+                            } else {
+                                Activator.getDefault().logError("Unknown \"file\" type for " + child + ' ' + child.toString()); //$NON-NLS-1$
+                            }
+                        }
+                    }
+                }
+                return size;
+            }
+        });
 
         init();
         getBatchWizard().setTracesToScan(fTracesToScan);
index 35b1e1a51dd80949cec9c6bb8c79ab57606e8f44..d08fc67fc2a28ee1f8deedfeb2362c300f7a06fc 100644 (file)
@@ -34,9 +34,42 @@ public class Messages extends NLS {
     public static String ImportTraceWizardRemove;
     public static String ImportTraceWizardDirectoryTitle;
     public static String ImportTraceWizardDirectoryHint;
+    /**
+     * @since 2.2
+     */
+    public static String ImportTraceWizardScanPagebyte;
+
+    /**
+     * @since 2.2
+     */
+    public static String ImportTraceWizardScanPageGigabyte;
+
+    /**
+     * @since 2.2
+     */
+    public static String ImportTraceWizardScanPageKilobyte;
+
+    /**
+     * @since 2.2
+     */
+    public static String ImportTraceWizardScanPageMegabyte;
+
     public static String ImportTraceWizardScanPageRenameError;
+    /**
+     * @since 2.2
+     */
     public static String ImportTraceWizardScanPageSelectAtleastOne;
+
+    /**
+     * @since 2.2
+     */
+    public static String ImportTraceWizardScanPageSize;
     public static String ImportTraceWizardSelectAll;
+    /**
+     * @since 2.2
+     */
+    public static String ImportTraceWizardScanPageTerabyte;
+
     public static String ImportTraceWizardScanPageTitle;
     public static String ImportTraceWizardSelectTraceTypePageTitle;
     public static String ImportTraceWizardPageOptionsTitle;
index 3d7d0b4990d7e8dfba1109c838d3cbd2a9bd4145..ba1870d6240791bd4305fbf796bde5c8ed8e9ff7 100644 (file)
@@ -20,9 +20,15 @@ ImportTraceWizardAddDirectory=Add Directory...
 ImportTraceWizardRemove=Remove
 ImportTraceWizardDirectoryTitle=Pick directories and files to scan
 ImportTraceWizardDirectoryHint=Select at least one file or directory to scan
+ImportTraceWizardScanPagebyte=\ B
+ImportTraceWizardScanPageGigabyte=\ GB
+ImportTraceWizardScanPageKilobyte=\ KB
+ImportTraceWizardScanPageMegabyte=\ MB
 ImportTraceWizardScanPageRenameError=Each selected trace must have a unique name, please rename.
 ImportTraceWizardScanPageSelectAtleastOne=Select at least one trace to import
+ImportTraceWizardScanPageSize=Size
 ImportTraceWizardSelectAll=Select All
+ImportTraceWizardScanPageTerabyte=\ TB
 ImportTraceWizardScanPageTitle=Valid traces
 ImportTraceWizardSelectTraceTypePageTitle=Available trace types
 ImportTraceWizardPageOptionsTitle=Select Target Project
This page took 0.029787 seconds and 5 git commands to generate.