tmf: Use a common method to get opened tmf projects
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Wed, 30 Oct 2013 01:19:29 +0000 (21:19 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 31 Oct 2013 15:46:05 +0000 (11:46 -0400)
Change-Id: I2caf2ef68ab336c1263e2b2bd883648cde081fa5
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/17867
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/ImportDialog.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceUtils.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPageOptions.java

index 03eae31441cedd79f1a656fbacbb27acd75c76b6..45e3683e31e6db412672c9486fc2c4b3e11ace56 100644 (file)
@@ -9,6 +9,7 @@
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
  *   Bernd Hufmann - Added handling of streamed traces
+ *   Marc-Andre Laperle - Use common method to get opened tmf projects
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
 
@@ -17,8 +18,6 @@ import java.util.List;
 
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
@@ -31,8 +30,8 @@ import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy;
-import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.linuxtools.tmf.ui.project.model.TraceUtils;
 import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType;
 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
 import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
@@ -181,9 +180,6 @@ public class ImportDialog extends Dialog implements IImportDialog {
 
         try {
             createRemoteComposite();
-        } catch (CoreException e) {
-            createErrorComposite(parent, e.fillInStackTrace());
-            return fDialogComposite;
         } catch (SystemMessageException e) {
             createErrorComposite(parent, e.fillInStackTrace());
             return fDialogComposite;
@@ -333,7 +329,7 @@ public class ImportDialog extends Dialog implements IImportDialog {
         errorText.setLayoutData(new GridData(GridData.FILL_BOTH));
     }
 
-    private void createRemoteComposite() throws CoreException, SystemMessageException{
+    private void createRemoteComposite() throws SystemMessageException{
         Group contextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
         contextGroup.setText(Messages.TraceControl_ImportDialogTracesGroupName);
         GridLayout layout = new GridLayout(1, true);
@@ -399,11 +395,9 @@ public class ImportDialog extends Dialog implements IImportDialog {
         fProjects = new ArrayList<IProject>();
         List<String> projectNames = new ArrayList<String>();
 
-        for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
-            if (project.isOpen() && project.hasNature(TmfProjectNature.ID)) {
-                fProjects.add(project);
-                projectNames.add(project.getName());
-            }
+        for (IProject project : TraceUtils.getOpenedTmfProjects()) {
+            fProjects.add(project);
+            projectNames.add(project.getName());
         }
 
         fCombo = new CCombo(projectGroup, SWT.READ_ONLY);
index ba5dce5dc7cd342f240e28f313cbf287437f4c6c..2fe7b859a13002e7a89749726adb8de8e375119c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 École Polytechnique de Montréal
+ * Copyright (c) 2013 École Polytechnique de Montréal 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
@@ -8,10 +8,19 @@
  *
  * Contributors:
  *   Geneviève Bastien - Initial API and implementation
+ *   Marc-Andre Laperle - Add method to get opened tmf projects
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.model;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.PlatformUI;
@@ -42,4 +51,25 @@ public class TraceUtils {
             }
         });
     }
+
+    /**
+     * Get the opened (accessible) projects with Tmf nature
+     *
+     * @return the Tmf projects
+     * @since 2.2
+     */
+    public static List<IProject> getOpenedTmfProjects() {
+        IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+        List<IProject> tmfProjects = new ArrayList<IProject>();
+        for (IProject project : projects) {
+            try {
+                if (project.isAccessible() && project.getNature(TmfProjectNature.ID) != null) {
+                    tmfProjects.add(project);
+                }
+            } catch (CoreException e) {
+                Activator.getDefault().logError("Error getting opened tmf projects", e); //$NON-NLS-1$
+            }
+        }
+        return tmfProjects;
+    }
 }
index ae8a5bdb05a3c9c8239dfe546282f48789babe06..85ba72219832ce27a4a8356022cf565b3ef5d3fc 100644 (file)
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Matthew Khouzam - Initial API and implementation
+ *   Marc-Andre Laperle - Use common method to get opened tmf projects
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace;
@@ -17,10 +18,8 @@ import java.util.Map;
 
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
+import org.eclipse.linuxtools.tmf.ui.project.model.TraceUtils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
@@ -66,21 +65,13 @@ public class ImportTraceWizardPageOptions extends AbstractImportTraceWizardPage
         optionPane.setLayout(new GridLayout());
         optionPane.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
 
-        IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
-
         fProjects = new List(optionPane, SWT.NONE);
         fProjects.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
-        for (IProject project : projects) {
-            try {
-                if (project.getNature(TmfProjectNature.ID) != null) {
-                    final String name = project.getName();
-                    fProjectsMap.put(name, project);
-                    fProjects.add(name);
-                }
-            } catch (CoreException e) {
-                // TODO: add a logger to activator and then log it
-            }
+        for (IProject project : TraceUtils.getOpenedTmfProjects()) {
+            final String name = project.getName();
+            fProjectsMap.put(name, project);
+            fProjects.add(name);
         }
 
         fProjects.getSelection();
This page took 0.047034 seconds and 5 git commands to generate.