[Tmf][Ctf] Add descriptive fail to import messages.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / ImportTraceWizardPage.java
index 5c11c66203097e9cd598a5d83cb15d56ca5528f3..91b720a42c596a537a538d2d85247d7fa7b843e0 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010, 2011, 2012 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson and others.
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -10,6 +10,7 @@
  *   Francois Chouinard - Initial API and implementation
  *   Francois Chouinard - Got rid of dependency on internal platform class
  *   Francois Chouinard - Complete re-design
+ *   Anna Dushistova(Montavista) - [383047] NPE while importing a CFT trace
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.wizards;
@@ -53,6 +54,7 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefin
 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
 import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
@@ -88,11 +90,12 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation;
  * A variant of the standard resource import wizard with the following changes:
  * <ul>
  * <li>A folder/file combined checkbox tree viewer to select traces
- * <li>Cherry-picking of traces in the file structure without re-creating the file hierarchy
+ * <li>Cherry-picking of traces in the file structure without re-creating the
+ * file hierarchy
  * <li>A trace types dropbox for optional characterization
  * </ul>
- * For our purpose, a trace can either be a single file or a whole directory sub-tree, whichever is reached first from
- * the root directory.
+ * For our purpose, a trace can either be a single file or a whole directory
+ * sub-tree, whichever is reached first from the root directory.
  * <p>
  *
  * @version 1.0
@@ -130,11 +133,12 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
     // ------------------------------------------------------------------------
 
     /**
-     * Constructor.
-     * Creates the trace wizard page.
+     * Constructor. Creates the trace wizard page.
      *
-     * @param name The name of the page.
-     * @param selection The current selection
+     * @param name
+     *            The name of the page.
+     * @param selection
+     *            The current selection
      */
     protected ImportTraceWizardPage(String name, IStructuredSelection selection) {
         super(name, selection);
@@ -142,8 +146,11 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /**
      * Constructor
-     * @param workbench The workbench reference.
-     * @param selection The current selection
+     *
+     * @param workbench
+     *            The workbench reference.
+     * @param selection
+     *            The current selection
      */
     public ImportTraceWizardPage(IWorkbench workbench, IStructuredSelection selection) {
         this(IMPORT_WIZARD_PAGE, selection);
@@ -181,7 +188,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
     // ------------------------------------------------------------------------
     /*
      * (non-Javadoc)
-     * @see org.eclipse.ui.dialogs.WizardResourceImportPage#createControl(org.eclipse.swt.widgets.Composite)
+     *
+     * @see
+     * org.eclipse.ui.dialogs.WizardResourceImportPage#createControl(org.eclipse
+     * .swt.widgets.Composite)
      */
     @Override
     public void createControl(Composite parent) {
@@ -195,7 +205,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.ui.dialogs.WizardResourceImportPage#createSourceGroup(org.eclipse.swt.widgets.Composite)
+     *
+     * @see
+     * org.eclipse.ui.dialogs.WizardResourceImportPage#createSourceGroup(org
+     * .eclipse.swt.widgets.Composite)
      */
     @Override
     protected void createSourceGroup(Composite parent) {
@@ -207,7 +220,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.ui.dialogs.WizardResourceImportPage#createFileSelectionGroup(org.eclipse.swt.widgets.Composite)
+     *
+     * @see
+     * org.eclipse.ui.dialogs.WizardResourceImportPage#createFileSelectionGroup
+     * (org.eclipse.swt.widgets.Composite)
      */
     @Override
     protected void createFileSelectionGroup(Composite parent) {
@@ -254,6 +270,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
+     *
      * @see org.eclipse.ui.dialogs.WizardResourceImportPage#getFolderProvider()
      */
     @Override
@@ -263,6 +280,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
+     *
      * @see org.eclipse.ui.dialogs.WizardResourceImportPage#getFileProvider()
      */
     @Override
@@ -312,7 +330,9 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.ui.dialogs.WizardResourceImportPage#getSelectedResources()
+     *
+     * @see
+     * org.eclipse.ui.dialogs.WizardResourceImportPage#getSelectedResources()
      */
     @Override
     protected List<FileSystemElement> getSelectedResources() {
@@ -342,7 +362,9 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /**
      * creates the directory selection group.
-     * @param parent the parent composite
+     *
+     * @param parent
+     *            the parent composite
      */
     protected void createDirectorySelectionGroup(Composite parent) {
 
@@ -419,7 +441,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.ui.dialogs.WizardResourceImportPage#handleEvent(org.eclipse.swt.widgets.Event)
+     *
+     * @see
+     * org.eclipse.ui.dialogs.WizardResourceImportPage#handleEvent(org.eclipse
+     * .swt.widgets.Event)
      */
     @Override
     public void handleEvent(Event event) {
@@ -587,7 +612,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
         fTraceTypes.addSelectionListener(new SelectionListener() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                validateSourceGroup();
+                updateWidgetEnablements();
             }
 
             @Override
@@ -596,7 +621,8 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
         });
     }
 
-    // The mapping of available trace type IDs to their corresponding configuration element
+    // The mapping of available trace type IDs to their corresponding
+    // configuration element
     private final Map<String, IConfigurationElement> fTraceTypeAttributes = new HashMap<String, IConfigurationElement>();
     private final Map<String, IConfigurationElement> fTraceCategories = new HashMap<String, IConfigurationElement>();
     private final Map<String, IConfigurationElement> fTraceAttributes = new HashMap<String, IConfigurationElement>();
@@ -660,7 +686,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.ui.dialogs.WizardDataTransferPage#createOptionsGroupButtons(org.eclipse.swt.widgets.Group)
+     *
+     * @see
+     * org.eclipse.ui.dialogs.WizardDataTransferPage#createOptionsGroupButtons
+     * (org.eclipse.swt.widgets.Group)
      */
     @Override
     protected void createOptionsGroupButtons(Group optionsGroup) {
@@ -693,6 +722,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /*
      * (non-Javadoc)
+     *
      * @see org.eclipse.ui.dialogs.WizardDataTransferPage#validateSourceGroup()
      */
     @Override
@@ -734,19 +764,23 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
         // Perform trace validation
         String traceTypeName = fTraceTypes.getText();
         if (traceTypeName != null && !"".equals(traceTypeName) && //$NON-NLS-1$
-            !traceTypeName.startsWith(CUSTOM_TXT_CATEGORY) && !traceTypeName.startsWith(CUSTOM_XML_CATEGORY)) {
+                !traceTypeName.startsWith(CUSTOM_TXT_CATEGORY) && !traceTypeName.startsWith(CUSTOM_XML_CATEGORY)) {
 
             List<File> traces = isolateTraces();
             for (File trace : traces) {
-                ITmfTrace<?> tmfTrace = null;
+                ITmfTrace tmfTrace = null;
+
                 try {
                     IConfigurationElement ce = fTraceAttributes.get(traceTypeName);
-                    tmfTrace = (ITmfTrace<?>) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
-                    if (tmfTrace != null && !tmfTrace.validate(fProject, trace.getAbsolutePath())) {
-                        setMessage(null);
-                        setErrorMessage(Messages.ImportTraceWizard_TraceValidationFailed);
-                        tmfTrace.dispose();
-                        return false;
+                    tmfTrace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
+                    if (tmfTrace != null) {
+                        IStatus status = tmfTrace.validate(fProject, trace.getAbsolutePath());
+                        if (!status.isOK()) {
+                            setMessage(null);
+                            setErrorMessage(Messages.ImportTraceWizard_TraceValidationFailed);
+                            tmfTrace.dispose();
+                            return false;
+                        }
                     }
                 } catch (CoreException e) {
                 } finally {
@@ -799,6 +833,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
 
     /**
      * Finish the import.
+     *
      * @return <code>true</code> if successful else false
      */
     public boolean finish() {
@@ -809,9 +844,8 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
             return false;
         }
 
-        String sourceDirPath;
         try {
-            sourceDirPath = sourceDir.getCanonicalPath();
+            sourceDir.getCanonicalPath();
         } catch (IOException e) {
             MessageDialog.openInformation(getContainer().getShell(), Messages.ImportTraceWizard_Information,
                     Messages.ImportTraceWizard_InvalidTraceDirectory);
@@ -824,7 +858,8 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
         List<FileSystemElement> selectedResources = getSelectedResources();
         Iterator<FileSystemElement> resources = selectedResources.iterator();
 
-        // Use a map to end up with unique resources (getSelectedResources() can return duplicates)
+        // Use a map to end up with unique resources (getSelectedResources() can
+        // return duplicates)
         Map<String, File> fileSystemObjects = new HashMap<String, File>();
         while (resources.hasNext()) {
             File file = (File) resources.next().getFileSystemObject();
@@ -833,7 +868,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
         }
 
         if (fileSystemObjects.size() > 0) {
-            boolean ok = importResources(sourceDirPath, fileSystemObjects);
+            boolean ok = importResources(fileSystemObjects);
             String traceBundle = null;
             String traceTypeId = null;
             String traceIcon = null;
@@ -893,10 +928,13 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
                                 resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, traceBundle);
                                 resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceTypeId);
                                 resource.setPersistentProperty(TmfCommonConstants.TRACEICON, traceIcon);
-                                for (TmfTraceElement traceElement : TmfProjectRegistry.getProject(resource.getProject()).getTracesFolder().getTraces()) {
-                                    if (traceElement.getName().equals(resource.getName())) {
-                                        traceElement.refreshTraceType();
-                                        break;
+                                TmfProjectElement tmfProject = TmfProjectRegistry.getProject(resource.getProject());
+                                if (tmfProject != null) {
+                                    for (TmfTraceElement traceElement : tmfProject.getTracesFolder().getTraces()) {
+                                        if (traceElement.getName().equals(resource.getName())) {
+                                            traceElement.refreshTraceType();
+                                            break;
+                                        }
                                     }
                                 }
                             } catch (CoreException e) {
@@ -914,7 +952,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
         return false;
     }
 
-    private boolean importResources(String rootDirectory, Map<String, File> fileSystemObjects) {
+    private boolean importResources(Map<String, File> fileSystemObjects) {
 
         // Determine the sorted canonical list of items to import
         List<File> fileList = new ArrayList<File>();
@@ -930,8 +968,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
             }
         });
 
-        // Perform a distinct import operation for everything that has the same prefix
-        // (distinct prefixes correspond to traces - we don't want to re-create parent structures)
+        // Perform a distinct import operation for everything that has the same
+        // prefix
+        // (distinct prefixes correspond to traces - we don't want to re-create
+        // parent structures)
         boolean ok = true;
         boolean isLinked = createLinksInWorkspaceButton.getSelection();
         for (int i = 0; i < fileList.size(); i++) {
This page took 0.027839 seconds and 5 git commands to generate.