tmf-rcp: Fix NPE at startup with --open (bug 436239)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tracing.rcp.ui / src / org / eclipse / linuxtools / internal / tracing / rcp / ui / ApplicationWorkbenchWindowAdvisor.java
index 88a5e8f0e7694bbdc83d067c2b0fd75a8fc371ab..5e8f830446f47adee8e339db2b0f42176417e390 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 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
  **********************************************************************/
 package org.eclipse.linuxtools.internal.tracing.rcp.ui;
 
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.linuxtools.internal.tracing.rcp.ui.messages.Messages;
+import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.CliParser;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
 import org.eclipse.ui.IPerspectiveDescriptor;
 import org.eclipse.ui.IPerspectiveListener;
 import org.eclipse.ui.IWorkbenchPage;
@@ -59,15 +64,15 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
 //        "org.eclipse.debug.ui.profileActionSet"
     };
 
-
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
     /**
      * Standard constructor
+     *
      * @param configurer
-     *              - the workbench window configurer
+     *            - the workbench window configurer
      */
     public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
         super(configurer);
@@ -87,15 +92,30 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
         configurer.setShowCoolBar(false);
         configurer.setShowStatusLine(true);
         configurer.setShowProgressIndicator(true);
-        configurer.setTitle(Messages.ApplicationWorkbenchWindowAdvisor_WindowTitle);
     }
 
     @Override
     public void postWindowCreate() {
         super.postWindowOpen();
         TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener());
-        createDefaultProject();
+        IProject defaultProject = createDefaultProject();
         hideActionSets();
+        openTraceIfNecessary(defaultProject);
+    }
+
+
+
+    private static void openTraceIfNecessary(IProject project) {
+        String traceToOpen = TracingRcpPlugin.getDefault().getCli().getArgument(CliParser.OPEN_FILE_LOCATION);
+        if (traceToOpen != null) {
+            try {
+                TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
+                TmfOpenTraceHelper.openTraceFromPath(destinationFolder, traceToOpen, TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
+            } catch (CoreException e) {
+                TracingRcpPlugin.getDefault().logError(e.getMessage());
+            }
+
+        }
     }
 
     // ------------------------------------------------------------------------
@@ -114,18 +134,19 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
         }
     }
 
-    private static void createDefaultProject() {
-        TmfProjectRegistry.createProject(Messages.ApplicationWorkbenchWindowAdvisor_DefaultProjectName, null, new NullProgressMonitor());
+    private static IProject createDefaultProject() {
+        return TmfProjectRegistry.createProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor());
     }
 
     /**
-     *  A perspective listener implementation
-     *  @author Bernd Hufmann
+     * A perspective listener implementation
+     *
+     * @author Bernd Hufmann
      */
     public class PerspectiveListener implements IPerspectiveListener {
 
         /**
-         *  Default Constructor
+         * Default Constructor
          */
         public PerspectiveListener() {
         }
This page took 0.025117 seconds and 5 git commands to generate.