package org.eclipse.tracecompass.tmf.ui.project.model;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.editors.ITmfEventsEditorConstants;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
/**
* Implementation of TMF Experiment Model Element.
* <p>
+ *
* @version 1.0
* @author Francois Chouinard
*
// ------------------------------------------------------------------------
// Property View stuff
- private static final String sfInfoCategory = "Info"; //$NON-NLS-1$
- private static final String sfName = "name"; //$NON-NLS-1$
- private static final String sfPath = "path"; //$NON-NLS-1$
- private static final String sfLocation = "location"; //$NON-NLS-1$
- private static final String sfFolderSuffix = "_exp"; //$NON-NLS-1$
- private static final String sfExperimentType = "type"; //$NON-NLS-1$
-
- private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
- private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath);
- private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation,
- sfLocation);
- private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfExperimentType, sfExperimentType);
-
- private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor,
- sfLocationDescriptor, sfTypeDescriptor };
+ private static final String INFO_CATEGORY = "Info"; //$NON-NLS-1$
+ private static final String NAME = "name"; //$NON-NLS-1$
+ private static final String PATH = "path"; //$NON-NLS-1$
+ private static final String LOCATION = "location"; //$NON-NLS-1$
+ private static final String FOLDER_SUFFIX = "_exp"; //$NON-NLS-1$
+ private static final String EXPERIMENT_TYPE = "type"; //$NON-NLS-1$
+
+ private static final ReadOnlyTextPropertyDescriptor NAME_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(NAME, NAME);
+ private static final ReadOnlyTextPropertyDescriptor PATH_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(PATH, PATH);
+ private static final ReadOnlyTextPropertyDescriptor LOCATION_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(LOCATION,
+ LOCATION);
+ private static final ReadOnlyTextPropertyDescriptor TYPE_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(EXPERIMENT_TYPE, EXPERIMENT_TYPE);
+
+ private static final IPropertyDescriptor[] DESCRIPTORS = { NAME_DESCRIPTOR, PATH_DESCRIPTOR,
+ LOCATION_DESCRIPTOR, TYPE_DESCRIPTOR };
static {
- sfNameDescriptor.setCategory(sfInfoCategory);
- sfPathDescriptor.setCategory(sfInfoCategory);
- sfLocationDescriptor.setCategory(sfInfoCategory);
- sfTypeDescriptor.setCategory(sfInfoCategory);
+ NAME_DESCRIPTOR.setCategory(INFO_CATEGORY);
+ PATH_DESCRIPTOR.setCategory(INFO_CATEGORY);
+ LOCATION_DESCRIPTOR.setCategory(INFO_CATEGORY);
+ TYPE_DESCRIPTOR.setCategory(INFO_CATEGORY);
}
// The mapping of available trace type IDs to their corresponding
// configuration element
- private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<>();
- private static final Map<String, IConfigurationElement> sfTraceTypeUIAttributes = new HashMap<>();
- private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<>();
+ private static final Map<String, IConfigurationElement> TRACE_TYPE_ATTRIBUTES = new HashMap<>();
+ private static final Map<String, IConfigurationElement> TRACE_TYPE_UI_ATTRIBUTES = new HashMap<>();
+ private static final Map<String, IConfigurationElement> TRACE_CATEGORIES = new HashMap<>();
// ------------------------------------------------------------------------
// Static initialization
String elementName = ce.getName();
if (elementName.equals(TmfTraceType.EXPERIMENT_ELEM)) {
String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
- sfTraceTypeAttributes.put(traceTypeId, ce);
+ TRACE_TYPE_ATTRIBUTES.put(traceTypeId, ce);
} else if (elementName.equals(TmfTraceType.CATEGORY_ELEM)) {
String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
- sfTraceCategories.put(categoryId, ce);
+ TRACE_CATEGORIES.put(categoryId, ce);
}
}
String elemName = ce.getName();
if (TmfTraceTypeUIUtils.EXPERIMENT_ELEM.equals(elemName)) {
String traceType = ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR);
- sfTraceTypeUIAttributes.put(traceType, ce);
+ TRACE_TYPE_UI_ATTRIBUTES.put(traceType, ce);
}
}
}
// ------------------------------------------------------------------------
/**
* Constructor
- * @param name The name of the experiment
- * @param folder The folder reference
- * @param parent The experiment folder reference.
+ *
+ * @param name
+ * The name of the experiment
+ * @param folder
+ * The folder reference
+ * @param parent
+ * The experiment folder reference.
*/
public TmfExperimentElement(String name, IFolder folder, TmfExperimentFolder parent) {
super(name, folder, parent);
@Override
public IFolder getResource() {
- return (IFolder) fResource;
+ return (IFolder) super.getResource();
}
+ /**
+ * @since 2.0
+ */
@Override
- void refreshChildren() {
+ protected void refreshChildren() {
IFolder folder = getResource();
/* Update the trace children of this experiment */
childrenMap.remove(elementPath);
} else {
element = new TmfTraceElement(name, resource, this);
+ addChild(element);
}
}
if (experiment == null) {
return;
}
+
+ /* super.refreshChildren() above should have set this */
+ TmfViewsElement viewsElement = checkNotNull(getChildElementViews());
+
Map<String, TmfAnalysisElement> analysisMap = new HashMap<>();
for (TmfAnalysisElement analysis : getAvailableAnalysis()) {
analysisMap.put(analysis.getAnalysisId(), analysis);
}
for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules().values()) {
if (!analysisMap.containsKey(module.getId()) && module.appliesToExperiment() && (experiment.getAnalysisModule(module.getId()) != null)) {
- IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(fResource.getFullPath().append(module.getId()));
- TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, this, module);
+ IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(getResource().getFullPath().append(module.getId()));
+ TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, viewsElement, module);
+ viewsElement.addChild(analysis);
analysis.refreshChildren();
analysisMap.put(module.getId(), analysis);
}
return list;
}
+ /**
+ * @since 2.0
+ */
+ @Override
+ public @NonNull Image getIcon() {
+ Image icon = super.getIcon();
+ return (icon == null ? TmfProjectModelIcons.DEFAULT_EXPERIMENT_ICON : icon);
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getLabelText() {
+ return getName() + " [" + getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
/**
* Returns a list of TmfTraceElements contained in this experiment.
+ *
* @return a list of TmfTraceElements
*/
@Override
/**
* Adds a trace to the experiment
*
- * @param trace The trace element to add
+ * @param trace
+ * The trace element to add
*/
public void addTrace(TmfTraceElement trace) {
addTrace(trace, true);
/**
* Adds a trace to the experiment
*
- * @param trace The trace element to add
- * @param refresh Flag for refreshing the project
+ * @param trace
+ * The trace element to add
+ * @param refresh
+ * Flag for refreshing the project
*/
public void addTrace(TmfTraceElement trace, boolean refresh) {
/**
/**
* Removes a trace from an experiment
*
- * @param trace The trace to remove
- * @throws CoreException exception
+ * @param trace
+ * The trace to remove
+ * @throws CoreException
+ * exception
*/
public void removeTrace(TmfTraceElement trace) throws CoreException {
- // Close the experiment if open
- closeEditors();
+ // Close editors in UI Thread
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ closeEditors();
+ }
+ });
- /* Finally, remove the trace from experiment*/
+ /* Finally, remove the trace from experiment */
removeChild(trace);
deleteTraceResource(trace.getResource());
deleteSupplementaryResources();
public String getEditorId() {
/* See if a default editor was set for this experiment type */
if (getTraceType() != null) {
- IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType());
+ IConfigurationElement ce = TRACE_TYPE_UI_ATTRIBUTES.get(getTraceType());
if (ce != null) {
IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM);
if (defaultEditorCE.length == 1) {
if (getTraceType() != null) {
- IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
+ IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType());
if (ce == null) {
return null;
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors() {
- return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
+ return Arrays.copyOf(DESCRIPTORS, DESCRIPTORS.length);
}
@Override
public Object getPropertyValue(Object id) {
- if (sfName.equals(id)) {
+ if (NAME.equals(id)) {
return getName();
}
- if (sfPath.equals(id)) {
+ if (PATH.equals(id)) {
return getPath().toString();
}
- if (sfLocation.equals(id)) {
+ if (LOCATION.equals(id)) {
return getLocation().toString();
}
- if (sfExperimentType.equals(id)) {
+ if (EXPERIMENT_TYPE.equals(id)) {
if (getTraceType() != null) {
- IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
+ IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType());
if (ce == null) {
return ""; //$NON-NLS-1$
}
String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
if (categoryId != null) {
- IConfigurationElement category = sfTraceCategories.get(categoryId);
+ IConfigurationElement category = TRACE_CATEGORIES.get(categoryId);
if (category != null) {
return category.getAttribute(TmfTraceType.NAME_ATTR) + ':' + ce.getAttribute(TmfTraceType.NAME_ATTR);
}
/**
* Return the suffix for resource names
+ *
* @return The folder suffix
*/
@Override
public String getSuffix() {
- return sfFolderSuffix;
+ return FOLDER_SUFFIX;
}
}