[Tmf][Ctf] Add descriptive fail to import messages.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTrace.java
index d81825d3a39f6830d5487758d024017505ee126e..c4263d0f419aff2a24c71a8585f8199d047eb76d 100644 (file)
@@ -15,8 +15,11 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
@@ -34,27 +37,24 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
  */
 public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
 
-
-    //-------------------------------------------
-    //        Constants
-    //-------------------------------------------
+    // -------------------------------------------
+    // Constants
+    // -------------------------------------------
     /**
      * Default cache size for CTF traces
      */
     protected static final int DEFAULT_CACHE_SIZE = 50000;
 
-    //-------------------------------------------
-    //        Fields
-    //-------------------------------------------
+    // -------------------------------------------
+    // Fields
+    // -------------------------------------------
 
     /* Reference to the CTF Trace */
     private CTFTrace fTrace;
 
-
-
-    //-------------------------------------------
-    //        TmfTrace Overrides
-    //-------------------------------------------
+    // -------------------------------------------
+    // TmfTrace Overrides
+    // -------------------------------------------
     /**
      * Method initTrace.
      *
@@ -88,7 +88,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
             /* Set the start and (current) end times for this trace */
             ctx = (CtfTmfContext) seekEvent(0L);
             CtfTmfEvent event = getNext(ctx);
-            if((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
+            if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
                 /* Handle the case where the trace is empty */
                 this.setStartTime(TmfTimestamp.BIG_BANG);
             } else {
@@ -107,7 +107,9 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
         }
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     *
      * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#dispose()
      */
     @Override
@@ -122,26 +124,34 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
 
     /**
      * Method validate.
-     * @param project IProject
-     * @param path String
-     * @return boolean
+     *
+     * @param project
+     *            IProject
+     * @param path
+     *            String
+     * @return IStatus IStatus.error or Status.OK_STATUS
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(IProject, String)
+     * @since 2.0
      */
     @Override
-    public boolean validate(final IProject project, final String path) {
+    public IStatus validate(final IProject project, final String path) {
+        IStatus validTrace = Status.OK_STATUS;
         try {
             final CTFTrace temp = new CTFTrace(path);
             boolean valid = temp.majortIsSet(); // random test
             temp.dispose();
-            return valid;
+            if (!valid) {
+                validTrace = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
+            }
         } catch (final CTFReaderException e) {
-            /* Nope, not a CTF trace we can read */
-            return false;
+            validTrace = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError +": " + e.toString()); //$NON-NLS-1$
         }
+        return validTrace;
     }
 
     /**
      * Method getCurrentLocation. This is not applicable in CTF
+     *
      * @return null, since the trace has no knowledge of the current location
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation()
      */
@@ -156,7 +166,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
         final CtfTmfContext context = new CtfTmfContext(this);
         context.setLocation(curLocation);
         context.seek(curLocation.getLocationInfo());
-        final CtfLocationInfo currentTime = ((CtfLocationInfo)context.getLocation().getLocationInfo());
+        final CtfLocationInfo currentTime = ((CtfLocationInfo) context.getLocation().getLocationInfo());
         final long startTime = getIterator(this, context).getStartTime();
         final long endTime = getIterator(this, context).getEndTime();
         return ((double) currentTime.getTimestamp() - startTime)
@@ -165,7 +175,9 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
 
     /**
      * Method seekEvent.
-     * @param location ITmfLocation<?>
+     *
+     * @param location
+     *            ITmfLocation<?>
      * @return ITmfContext
      */
     @Override
@@ -196,13 +208,12 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
                 currentLocation = new CtfLocation(event.getTimestamp().getValue(), 0);
             }
         }
-        if(context.getRank() != 0) {
+        if (context.getRank() != 0) {
             context.setRank(ITmfContext.UNKNOWN_RANK);
         }
         return context;
     }
 
-
     @Override
     public synchronized ITmfContext seekEvent(double ratio) {
         CtfTmfContext context = new CtfTmfContext(this);
@@ -222,7 +233,9 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
 
     /**
      * Method readNextEvent.
-     * @param context ITmfContext
+     *
+     * @param context
+     *            ITmfContext
      * @return CtfTmfEvent
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
      */
@@ -251,16 +264,16 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
 
     /**
      * gets the CTFtrace that this is wrapping
+     *
      * @return the CTF trace
      */
     public CTFTrace getCTFTrace() {
         return fTrace;
     }
 
-
-    //-------------------------------------------
-    //        Environment Parameters
-    //-------------------------------------------
+    // -------------------------------------------
+    // Environment Parameters
+    // -------------------------------------------
     /**
      * Method getNbEnvVars.
      *
@@ -291,24 +304,25 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
         return this.fTrace.getEnvironment().get(key);
     }
 
-    //-------------------------------------------
-    //        Clocks
-    //-------------------------------------------
+    // -------------------------------------------
+    // Clocks
+    // -------------------------------------------
 
     /**
      * gets the clock offset
+     *
      * @return the clock offset in ns
      */
-    public long getOffset(){
-        if( fTrace != null ) {
+    public long getOffset() {
+        if (fTrace != null) {
             return fTrace.getOffset();
         }
         return 0;
     }
 
-    //-------------------------------------------
-    //        Parser
-    //-------------------------------------------
+    // -------------------------------------------
+    // Parser
+    // -------------------------------------------
 
     @Override
     public CtfTmfEvent parseEvent(ITmfContext context) {
@@ -327,11 +341,11 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
         setCacheSize(DEFAULT_CACHE_SIZE);
     }
 
-    //-------------------------------------------
-    //          Helpers
-    //-------------------------------------------
+    // -------------------------------------------
+    // Helpers
+    // -------------------------------------------
 
-    private static CtfIterator getIterator(CtfTmfTrace trace,  CtfTmfContext context) {
+    private static CtfIterator getIterator(CtfTmfTrace trace, CtfTmfContext context) {
         return CtfIteratorManager.getIterator(trace, context);
     }
 
@@ -341,7 +355,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
      * @return an iterator to the trace
      * @since 2.0
      */
-    public CtfIterator createIterator(){
+    public CtfIterator createIterator() {
         return new CtfIterator(this);
     }
 }
This page took 0.026484 seconds and 5 git commands to generate.