ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / parsers / wizards / CustomTxtParserOutputWizardPage.java
index e6e464cb2018340ed3121e273aaac1ec8b0854dc..b93f94c3bca6843f08a2938123adc23f99573066 100644 (file)
@@ -1,3 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
 package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
 
 import java.io.File;
@@ -10,12 +22,15 @@ import java.util.List;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.internal.tmf.ui.Messages;
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventTableColumns;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace;
+import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.SashForm;
 import org.eclipse.swt.custom.ScrolledComposite;
@@ -28,25 +43,32 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Text;
 
+/**
+ * Output wizard page for custom text trace parsers.
+ *
+ * @author Patrick Tasse
+ */
 public class CustomTxtParserOutputWizardPage extends WizardPage {
 
-    private static final Image upImage = Activator.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$
-    private static final Image downImage = Activator.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$
+    private static final Image UP_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$
+    private static final Image DOWN_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$
     private final CustomTxtParserWizard wizard;
     private CustomTxtTraceDefinition definition;
-    List<Output> outputs = new ArrayList<Output>();
-    //    Output messageOutput;
-    Composite container;
-    SashForm sash;
-    //    Text timestampFormatText;
-    //    Text timestampPreviewText;
-    ScrolledComposite outputsScrolledComposite;
-    Composite outputsContainer;
-    //    ScrolledComposite inputScrolledComposite;
-    Composite tableContainer;
-    CustomEventsTable previewTable;
-    File tmpFile;
-
+    private List<Output> outputs = new ArrayList<>();
+    private Composite container;
+    private SashForm sash;
+    private ScrolledComposite outputsScrolledComposite;
+    private Composite outputsContainer;
+    private Composite tableContainer;
+    private TmfEventsTable previewTable;
+    private File tmpFile;
+
+    /**
+     * Constructor
+     *
+     * @param wizard
+     *            The wizard to which this page belongs
+     */
     protected CustomTxtParserOutputWizardPage(final CustomTxtParserWizard wizard) {
         super("CustomParserOutputWizardPage"); //$NON-NLS-1$
         setTitle(wizard.inputPage.getTitle());
@@ -84,7 +106,7 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
         tableLayout.marginHeight = 0;
         tableLayout.marginWidth = 0;
         tableContainer.setLayout(tableLayout);
-        previewTable = new CustomEventsTable(new CustomTxtTraceDefinition(), tableContainer, 0);
+        previewTable = new TmfEventsTable(tableContainer, 0, CustomEventTableColumns.generateColumns(new CustomTxtTraceDefinition()));
         previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
         if (wizard.definition != null) {
@@ -100,16 +122,13 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
         super.dispose();
     }
 
-    private void loadDefinition(final CustomTxtTraceDefinition definition) {
-        for (final OutputColumn outputColumn : definition.outputs) {
+    private void loadDefinition(final CustomTxtTraceDefinition def) {
+        for (final OutputColumn outputColumn : def.outputs) {
             final Output output = new Output(outputsContainer, outputColumn.name);
             outputs.add(output);
         }
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
-     */
     @Override
     public void setVisible(final boolean visible) {
         if (visible) {
@@ -197,28 +216,39 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
     private void updatePreviewTable() {
         final int CACHE_SIZE = 50;
         definition.outputs = extractOutputs();
+        tmpFile = Activator.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
 
-        try {
-            tmpFile = Activator.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
-            final FileWriter writer = new FileWriter(tmpFile);
+        try (final FileWriter writer = new FileWriter(tmpFile);) {
             writer.write(wizard.inputPage.getInputText());
-            writer.close();
+        } catch (final IOException e) {
+            Activator.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$
+        }
 
-            final ITmfTrace trace = new CustomTxtTrace(null, definition, tmpFile.getAbsolutePath(), CACHE_SIZE);
+        try {
+            final CustomTxtTrace trace = new CustomTxtTrace(null, definition, tmpFile.getAbsolutePath(), CACHE_SIZE) {
+                @Override
+                protected ITmfTraceIndexer createIndexer(int interval) {
+                    return new TmfCheckpointIndexer(this, interval);
+                }
+            };
+            trace.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, false);
             previewTable.dispose();
-            previewTable = new CustomEventsTable(definition, tableContainer, CACHE_SIZE);
+            previewTable = new TmfEventsTable(tableContainer, CACHE_SIZE, CustomEventTableColumns.generateColumns(definition));
             previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
             previewTable.setTrace(trace, true);
         } catch (final TmfTraceException e) {
             Activator.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$
-        } catch (final IOException e) {
-            Activator.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$
         }
 
         tableContainer.layout();
         container.layout();
     }
 
+    /**
+     * Extract the list of output columns from the page's contents.
+     *
+     * @return The output columns
+     */
     public List<OutputColumn> extractOutputs() {
         int numColumns = 0;
         for (int i = 0; i < outputs.size(); i++) {
@@ -226,7 +256,7 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
                 numColumns++;
             }
         }
-        final List<OutputColumn> outputColumns = new ArrayList<OutputColumn>(numColumns);
+        final List<OutputColumn> outputColumns = new ArrayList<>(numColumns);
         numColumns = 0;
         for (int i = 0; i < outputs.size(); i++) {
             final Output output = outputs.get(i);
@@ -268,7 +298,7 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
             nameLabel.moveBelow(enabledButton);
 
             upButton = new Button(parent, SWT.PUSH);
-            upButton.setImage(upImage);
+            upButton.setImage(UP_IMAGE);
             upButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_moveBefore);
             upButton.addSelectionListener(new SelectionAdapter() {
                 @Override
@@ -279,7 +309,7 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
             upButton.moveBelow(nameLabel);
 
             downButton = new Button(parent, SWT.PUSH);
-            downButton.setImage(downImage);
+            downButton.setImage(DOWN_IMAGE);
             downButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_moveAfter);
             downButton.addSelectionListener(new SelectionAdapter() {
                 @Override
@@ -298,6 +328,11 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
         }
     }
 
+    /**
+     * Get the trace definition.
+     *
+     * @return The trace definition
+     */
     public CustomTxtTraceDefinition getDefinition() {
         return definition;
     }
This page took 0.027124 seconds and 5 git commands to generate.