summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMarc-Andre Laperle2013-10-02 15:17:35 (EDT)
committer Alexandre Montplaisir2013-10-04 18:59:42 (EDT)
commit8537d1ebd1d1b85213c91474cc94efbfcf88bed8 (patch)
treede0241d5391d595ba0502db91c8c9bc95aa23a14
parent9032ab2626618dcaf0d55910324d1066f7d33bd0 (diff)
downloadorg.eclipse.linuxtools-8537d1ebd1d1b85213c91474cc94efbfcf88bed8.zip
org.eclipse.linuxtools-8537d1ebd1d1b85213c91474cc94efbfcf88bed8.tar.gz
org.eclipse.linuxtools-8537d1ebd1d1b85213c91474cc94efbfcf88bed8.tar.bz2
[TMF] Handle custom traces in TmfTraceType in a more consistent wayrefs/changes/77/16977/6
Instead of storing the custom trace types by human readable name, store them by traceId like the other trace types. The trace Id is the canonical name + the definition name. This makes it consistent with TmfTraceElement.getTraceType. Also, consolidate code that can reuse TmfTraceType.setTraceType. Change-Id: Iac81c8d4fdf18eb83a84052c4c47d70d94cd64d5 Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/16977 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java38
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java9
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java52
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java82
4 files changed, 58 insertions, 123 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java
index f20b6cd..a1a3fa8 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java
@@ -305,16 +305,16 @@ public final class TmfTraceType {
// add the custom trace types
for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
- String traceTypeName = CUSTOM_TXT_CATEGORY + SEPARATOR + def.definitionName;
- TraceTypeHelper tt = new TraceTypeHelper(traceTypeName, CUSTOM_TXT_CATEGORY, def.definitionName, new CustomTxtTrace(def));
- fTraceTypes.put(traceTypeName, tt);
- traceTypes.add(traceTypeName);
+ String traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + def.definitionName;
+ TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, CUSTOM_TXT_CATEGORY, def.definitionName, new CustomTxtTrace(def));
+ fTraceTypes.put(traceTypeId, tt);
+ traceTypes.add(traceTypeId);
}
for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
- String traceTypeName = CUSTOM_XML_CATEGORY + SEPARATOR + def.definitionName;
- TraceTypeHelper tt = new TraceTypeHelper(traceTypeName, CUSTOM_XML_CATEGORY, def.definitionName, new CustomXmlTrace(def));
- fTraceTypes.put(traceTypeName, tt);
- traceTypes.add(traceTypeName);
+ String traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + def.definitionName;
+ TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, CUSTOM_XML_CATEGORY, def.definitionName, new CustomXmlTrace(def));
+ fTraceTypes.put(traceTypeId, tt);
+ traceTypes.add(traceTypeId);
}
return traceTypes;
}
@@ -563,6 +563,23 @@ public final class TmfTraceType {
}
/**
+ * Is the trace type id a custom (user-defined) trace type. These are the traces
+ * like : text and xml defined by the custom trace wizard.
+ *
+ * @param traceTypeId
+ * the trace type id
+ * @return true if the trace is a custom type
+ */
+ private static boolean isCustomTraceId(String traceTypeId) {
+ TraceTypeHelper traceType = getInstance().getTraceType(traceTypeId);
+ if (traceType != null) {
+ return isCustomTrace(traceType.getCategoryName() + SEPARATOR + traceType.getName());
+ }
+
+ return false;
+ }
+
+ /**
* Gets the custom trace type ID from the custom trace name
*
* @param traceType
@@ -650,7 +667,7 @@ public final class TmfTraceType {
* Only return the leaves of the trace types. Ignore custom trace types.
*/
private static boolean isUnique(TraceTypeHelper trace, List<TraceTypeHelper> set) {
- if (TmfTraceType.isCustomTrace(trace.getCanonicalName())) {
+ if (TmfTraceType.isCustomTraceId(trace.getCanonicalName())) {
return true;
}
// check if the trace type is the leaf. we make an instance of the trace
@@ -721,8 +738,7 @@ public final class TmfTraceType {
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
String TRACE_NAME = path.lastSegment();
String traceBundle = null, traceTypeId = traceType.getCanonicalName(), traceIcon = null;
- if (TmfTraceType.isCustomTrace(traceTypeId)) {
- traceTypeId = TmfTraceType.getCustomTraceTypeId(traceTypeId);
+ if (TmfTraceType.isCustomTraceId(traceTypeId)) {
traceBundle = Activator.getDefault().getBundle().getSymbolicName();
traceIcon = DEFAULT_TRACE_ICON_PATH;
} else {
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java
index baf7023..ea48fcf 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java
@@ -12,8 +12,6 @@
package org.eclipse.linuxtools.tmf.ui.project.model;
-import java.io.File;
-
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -90,8 +88,6 @@ public class TraceTypeHelper {
boolean valid = false;
if (fTrace != null) {
valid = standardValidate(path);
- } else if (fCategoryName.equals(TmfTraceType.CUSTOM_TXT_CATEGORY) || fCategoryName.equals(TmfTraceType.CUSTOM_XML_CATEGORY)) {
- valid = customValidate(path);
}
return valid;
}
@@ -110,11 +106,6 @@ public class TraceTypeHelper {
return valid;
}
- private static boolean customValidate(String path) {
- File f = new File(path);
- return f.exists() && f.isFile();
- }
-
@Override
public String toString() {
return fName;
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java
index 2a5a918..602ed3c 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java
@@ -32,7 +32,6 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -47,16 +46,14 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfImportHelper;
-import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
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;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.ui.project.model.TraceTypeHelper;
import org.eclipse.linuxtools.tmf.ui.project.model.TraceValidationHelper;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.IOverwriteQuery;
@@ -80,7 +77,6 @@ public class BatchImportTraceWizard extends ImportTraceWizard {
// -----------------
private static final int MAX_FILES = TOTALWORK - 1;
- private static final String DEFAULT_TRACE_ICON_PATH = "icons/elcl16/trace.gif"; //$NON-NLS-1$
private static final String BATCH_IMPORT_WIZARD = "BatchImportTraceWizard"; //$NON-NLS-1$
// ------------------
@@ -320,47 +316,13 @@ public class BatchImportTraceWizard extends ImportTraceWizard {
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (resource != null) {
try {
- // Set the trace properties for this resource
- boolean traceTypeOK = false;
- String traceBundle = null, traceTypeId = null, traceIcon = null;
- traceTypeId = traceToImport.getTraceTypeId();
- IConfigurationElement ce = TmfTraceType.getInstance().getTraceAttributes(traceTypeId);
- if ((ce != null) && (ce.getContributor() != null)) {
- traceTypeOK = true;
- traceBundle = ce.getContributor().getName();
- traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
- traceIcon = ce.getAttribute(TmfTraceType.ICON_ATTR);
- }
- final String traceType = traceTypeId;
- final boolean startsWithTxt = traceType.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY);
- final boolean startsWithXML = traceType.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY);
- if (!traceTypeOK && (startsWithTxt || startsWithXML)) {
- final char SEPARATOR = ':';
- // do custom trace stuff here
- traceTypeOK = true;
- String traceTypeToken[] = traceType.split(":", 2); //$NON-NLS-1$
- if (traceTypeToken.length == 2) {
- traceBundle =
- Activator.getDefault().getBundle().getSymbolicName();
- if (startsWithTxt) {
- traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + traceTypeToken[1];
- }
- else {
- traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + traceTypeToken[1];
- }
- traceIcon = DEFAULT_TRACE_ICON_PATH;
- } else {
- traceTypeOK = false;
- }
- }
- if (traceTypeOK) {
- resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE,
- traceBundle);
- resource.setPersistentProperty(TmfCommonConstants.TRACETYPE,
- traceTypeId);
- resource.setPersistentProperty(TmfCommonConstants.TRACEICON,
- traceIcon);
+ // Set the trace type for this resource
+ String traceTypeId = traceToImport.getTraceTypeId();
+ TraceTypeHelper traceType = TmfTraceType.getInstance().getTraceType(traceTypeId);
+ if (traceType != null) {
+ TmfTraceType.setTraceType(path, traceType);
}
+
TmfProjectElement tmfProject =
TmfProjectRegistry.getProject(resource.getProject());
if (tmfProject != null) {
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java
index 116035d..41e7af6 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java
@@ -36,7 +36,6 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
@@ -49,17 +48,13 @@ import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
-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.CustomXmlTrace;
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
-import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
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;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.ui.project.model.TraceTypeHelper;
import org.eclipse.linuxtools.tmf.ui.project.wizards.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
@@ -128,7 +123,6 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
// ------------------------------------------------------------------------
private static final String IMPORT_WIZARD_PAGE = "ImportTraceWizardPage"; //$NON-NLS-1$
- private static final String DEFAULT_TRACE_ICON_PATH = "icons/elcl16/trace.gif"; //$NON-NLS-1$
private static final FileSystemElementComparator FILE_SYSTEM_ELEMENT_COMPARATOR = new FileSystemElementComparator();
// ------------------------------------------------------------------------
@@ -726,61 +720,35 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
if (fileSystemObjects.size() > 0) {
boolean ok = importResources(fileSystemObjects);
- String traceBundle = null;
- String traceTypeId = null;
- String traceIcon = null;
- String traceType = fTraceTypes.getText();
+ String traceTypeName = fTraceTypes.getText();
boolean traceTypeOK = false;
- if (traceType.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY)) {
- for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
- if (traceType.equals(TmfTraceType.CUSTOM_TXT_CATEGORY + SEPARATOR + def.definitionName)) {
- traceTypeOK = true;
- traceBundle = Activator.getDefault().getBundle().getSymbolicName();
- traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + def.definitionName;
- traceIcon = DEFAULT_TRACE_ICON_PATH;
- break;
- }
- }
- } else if (traceType.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY)) {
- for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
- if (traceType.equals(TmfTraceType.CUSTOM_XML_CATEGORY + SEPARATOR + def.definitionName)) {
- traceTypeOK = true;
- traceBundle = Activator.getDefault().getBundle().getSymbolicName();
- traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + def.definitionName;
- traceIcon = DEFAULT_TRACE_ICON_PATH;
- break;
- }
+ TraceTypeHelper traceTypeHelper = null;
+
+ if (!traceTypeName.isEmpty()) {
+ // Trace type was selected
+ String temp[] = traceTypeName.split(SEPARATOR, 2);
+ if (temp.length < 2) {
+ Activator.getDefault().logError("Error with trace type " + traceTypeName); //$NON-NLS-1$
+ return false;
}
- } else {
- if (!traceType.equals("")) { //$NON-NLS-1$
- // Trace type was selected
- String temp[] = traceType.split(SEPARATOR, 2);
- if (temp.length < 2) {
- Activator.getDefault().logError("Error with trace type " + traceType); //$NON-NLS-1$
- return false;
- }
- final String traceId = TmfTraceType.getInstance().getTraceTypeId(temp[0], temp[1]);
- if (traceId != null) {
- if (!TmfTraceType.getInstance().validateTrace(traceId, getSelectedResources())) {
- setMessage(null);
- setErrorMessage(Messages.ImportTraceWizard_TraceValidationFailed);
- return false;
- }
- } else {
+ final String traceId = TmfTraceType.getInstance().getTraceTypeId(temp[0], temp[1]);
+ if (traceId != null) {
+ traceTypeHelper = TmfTraceType.getInstance().getTraceType(traceId);
+ if (traceTypeHelper == null || !TmfTraceType.getInstance().validateTrace(traceId, getSelectedResources())) {
setMessage(null);
setErrorMessage(Messages.ImportTraceWizard_TraceValidationFailed);
return false;
}
- IConfigurationElement ce = TmfTraceType.getInstance().getTraceAttributes(traceId);
- if (ce != null) {
- traceTypeOK = true;
- traceBundle = ce.getContributor().getName();
- traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
- traceIcon = ce.getAttribute(TmfTraceType.ICON_ATTR);
- }
+
+ traceTypeOK = true;
+ } else {
+ setMessage(null);
+ setErrorMessage(Messages.ImportTraceWizard_TraceValidationFailed);
+ return false;
}
}
- if (ok && traceTypeOK && !traceType.equals("")) { //$NON-NLS-1$
+
+ if (ok && traceTypeOK) {
// Tag the selected traces with their type
List<String> files = new ArrayList<String>(fileSystemObjects.keySet());
Collections.sort(files, new Comparator<String>() {
@@ -801,10 +769,8 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
IResource resource = fTargetFolder.findMember(file.getName());
if (resource != null) {
try {
- // Set the trace properties for this resource
- resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, traceBundle);
- resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceTypeId);
- resource.setPersistentProperty(TmfCommonConstants.TRACEICON, traceIcon);
+ TmfTraceType.setTraceType(resource.getFullPath(), traceTypeHelper);
+
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(resource.getProject());
if (tmfProject != null) {
for (TmfTraceElement traceElement : tmfProject.getTracesFolder().getTraces()) {