import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.TimeoutException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfViewsElement;
import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
import org.eclipse.tracecompass.tmf.ui.tests.stubs.analysis.TestAnalysisUi;
import org.junit.After;
public void testPopulate() {
TmfTraceElement trace = getTraceElement();
- /* Make sure the analysis list is not empty */
- List<ITmfProjectModelElement> analysisList = trace.getChildren();
- assertFalse(analysisList.isEmpty());
+ /* Make sure the list of views is there and not empty */
+ Optional<TmfViewsElement> possibleViewsElem = trace.getChildren()
+ .stream()
+ .filter(child -> child instanceof TmfViewsElement)
+ .map(elem -> (TmfViewsElement) elem)
+ .findFirst();
+ assertTrue(possibleViewsElem.isPresent());
+ TmfViewsElement viewsElem = possibleViewsElem.get();
/* Make sure TestAnalysisUi is there */
- TmfAnalysisElement analysis = null;
- for (ITmfProjectModelElement element : analysisList) {
- if (element instanceof TmfAnalysisElement) {
- TmfAnalysisElement analysisElement = (TmfAnalysisElement) element;
- if (analysisElement.getAnalysisId().equals(MODULE_UI)) {
- analysis = analysisElement;
- }
- }
- }
- assertNotNull(analysis);
-
- assertEquals("Test analysis in UI", analysis.getName());
+ Optional<TmfAnalysisElement> possibleAnalysisElem = viewsElem.getChildren().stream()
+ .filter(child -> child instanceof TmfAnalysisElement)
+ .map(elem -> (TmfAnalysisElement) elem)
+ .filter(analysisElem -> analysisElem.getAnalysisId().equals(MODULE_UI))
+ .findFirst();
+ assertTrue(possibleAnalysisElem.isPresent());
+ assertEquals("Test analysis in UI", possibleAnalysisElem.get().getName());
}
/**
public void testInstantiate() {
TmfTraceElement traceElement = getTraceElement();
- TmfAnalysisElement analysis = null;
- for (TmfAnalysisElement analysisElement : traceElement.getAvailableAnalysis()) {
- if (analysisElement.getAnalysisId().equals(MODULE_UI)) {
- analysis = analysisElement;
- }
- }
- assertNotNull(analysis);
+ TmfAnalysisElement analysis = traceElement.getAvailableAnalysis().stream()
+ .filter(availableAnalysis -> availableAnalysis.getAnalysisId().equals(MODULE_UI))
+ .findFirst().get();
/* Instantiate an analysis on a trace that is closed */
traceElement.closeEditors();
- analysis.activateParent();
+ analysis.activateParentTrace();
try {
ProjectModelTestData.delayUntilTraceOpened(traceElement);
TmfAnalysisElement analysis = getTestAnalysisUi();
/* To get the list of outputs the trace needs to be opened */
- analysis.activateParent();
+ analysis.activateParentTrace();
try {
ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
} catch (TimeoutException e) {
public void testOpenView() {
TmfAnalysisElement analysis = getTestAnalysisUi();
- analysis.activateParent();
+ analysis.activateParentTrace();
try {
ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
} catch (TimeoutException e) {
/** Trace text */
public static String TmfTraceElement_TypeName;
+
+ /** Name of the "Views" element
+ * @since 2.0*/
+ public static String TmfViewsElement_Name;
+
/**
* The title for the select trace type dialog */
public static String TmfTraceType_SelectTraceType;
* Parent of the analysis
* @param module
* The analysis module helper
- * @since 1.0
+ * @since 2.0
*/
- protected TmfAnalysisElement(String name, IResource resource, ITmfProjectModelElement parent, @NonNull IAnalysisModuleHelper module) {
+ protected TmfAnalysisElement(String name, IResource resource,
+ TmfViewsElement parent, @NonNull IAnalysisModuleHelper module) {
super(name, resource, parent);
fAnalysisHelper = module;
}
// TmfProjectModelElement
// ------------------------------------------------------------------------
+ /**
+ * @since 2.0
+ */
+ @Override
+ public TmfViewsElement getParent() {
+ /* Type enforced at constructor */
+ return (TmfViewsElement) super.getParent();
+ }
+
/**
* @since 2.0
*/
* We can get a list of available outputs once the analysis is
* instantiated when the trace is opened
*/
- ITmfProjectModelElement parent = getParent();
- if (parent instanceof TmfCommonProjectElement) {
- ITmfTrace trace = ((TmfCommonProjectElement) parent).getTrace();
- if (trace == null) {
- deleteOutputs();
- return;
- }
+ TmfCommonProjectElement parentTraceElement = getParent().getParent();
- IAnalysisModule module = trace.getAnalysisModule(fAnalysisHelper.getId());
- if (module == null) {
- deleteOutputs();
- /*
- * Trace is opened, but the analysis is null, so it does not
- * apply
- */
- fCanExecute = false;
- return;
- }
+ ITmfTrace trace = parentTraceElement.getTrace();
+ if (trace == null) {
+ deleteOutputs();
+ return;
+ }
- for (IAnalysisOutput output : module.getOutputs()) {
- TmfAnalysisOutputElement outputElement = childrenMap.remove(output.getName());
- if (outputElement == null) {
- IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(output.getName()));
- outputElement = new TmfAnalysisOutputElement(output.getName(), newresource, this, output);
- addChild(outputElement);
- }
- outputElement.refreshChildren();
- }
+ IAnalysisModule module = trace.getAnalysisModule(fAnalysisHelper.getId());
+ if (module == null) {
+ deleteOutputs();
+ /*
+ * Trace is opened, but the analysis is null, so it does not
+ * apply
+ */
+ fCanExecute = false;
+ return;
+ }
+ for (IAnalysisOutput output : module.getOutputs()) {
+ TmfAnalysisOutputElement outputElement = childrenMap.remove(output.getName());
+ if (outputElement == null) {
+ IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(output.getName()));
+ outputElement = new TmfAnalysisOutputElement(output.getName(), newresource, this, output);
+ addChild(outputElement);
+ }
+ outputElement.refreshChildren();
}
+
/* Remove outputs that are not children of this analysis anymore */
for (TmfAnalysisOutputElement output : childrenMap.values()) {
removeChild(output);
* @return The help message
*/
public String getHelpMessage() {
- ITmfProjectModelElement parent = getParent();
+ TmfCommonProjectElement parentTrace = getParent().getParent();
ITmfTrace trace = null;
- if (parent instanceof TmfTraceElement) {
- TmfTraceElement traceElement = (TmfTraceElement) parent;
+ if (parentTrace instanceof TmfTraceElement) {
+ TmfTraceElement traceElement = (TmfTraceElement) parentTrace;
trace = traceElement.getTrace();
if (trace != null) {
IAnalysisModule module = trace.getAnalysisModule(fAnalysisHelper.getId());
/**
* Make sure the trace this analysis is associated to is the currently
* selected one
+ * @since 2.0
*/
- public void activateParent() {
- ITmfProjectModelElement parent = getParent();
+ public void activateParentTrace() {
+ TmfCommonProjectElement parentTrace = getParent().getParent();
- if (parent instanceof TmfTraceElement) {
- TmfTraceElement traceElement = (TmfTraceElement) parent;
+ if (parentTrace instanceof TmfTraceElement) {
+ TmfTraceElement traceElement = (TmfTraceElement) parentTrace;
TmfOpenTraceHelper.openTraceFromElement(traceElement);
}
}
* Parent analysis of the view
* @param output
* The output object
+ * @since 2.0
*/
- protected TmfAnalysisOutputElement(String name, IResource resource, ITmfProjectModelElement parent, IAnalysisOutput output) {
+ protected TmfAnalysisOutputElement(String name, IResource resource, TmfAnalysisElement parent, IAnalysisOutput output) {
super(name, resource, parent);
fOutput = output;
}
public void outputAnalysis() {
ITmfProjectModelElement parent = getParent();
if (parent instanceof TmfAnalysisElement) {
- ((TmfAnalysisElement) parent).activateParent();
+ ((TmfAnalysisElement) parent).activateParentTrace();
fOutput.requestOutput();
}
}
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
+import java.util.stream.Collectors;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.editors.ITmfEventsEditorConstants;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
-import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
-import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
// Attributes
// ------------------------------------------------------------------------
- // This trace type ID as defined in plugin.xml
- private String fTraceTypeId = null;
-
private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
+ private TmfViewsElement fViewsElement = null;
+
+ /** This trace type ID as defined in plugin.xml */
+ private String fTraceTypeId = null;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
*/
@Override
protected void refreshChildren() {
-
- /* Refreshes the analysis under this trace */
- Map<String, TmfAnalysisElement> childrenMap = new HashMap<>();
- for (TmfAnalysisElement analysis : getAvailableAnalysis()) {
- childrenMap.put(analysis.getAnalysisId(), analysis);
- }
-
- TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType());
-
- Class<@NonNull ? extends ITmfTrace> traceClass = null;
-
- if (helper != null) {
- traceClass = helper.getTraceClass();
- }
-
- /* Remove all analysis and return */
- if (traceClass == null) {
- for (TmfAnalysisElement analysis : childrenMap.values()) {
- removeChild(analysis);
- }
- return;
- }
-
- /** Get the base path to put the resource to */
- IPath path = getResource().getFullPath();
-
- /* Add all new analysis modules or refresh outputs of existing ones */
- for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules(traceClass).values()) {
-
- /* If the analysis is not a child of the trace, create it */
- TmfAnalysisElement analysis = childrenMap.remove(module.getId());
- if (analysis == null) {
- /**
- * No need for the resource to exist, nothing will be done with
- * it
- */
- IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(module.getId()));
- analysis = new TmfAnalysisElement(module.getName(), newresource, this, module);
- addChild(analysis);
- }
- analysis.refreshChildren();
- }
-
- /* Remove analysis that are not children of this trace anymore */
- for (TmfAnalysisElement analysis : childrenMap.values()) {
- removeChild(analysis);
+ /* Get the base path to put the resource to */
+ IPath tracePath = getResource().getFullPath();
+
+ if (fViewsElement == null) {
+ /* Add the "Views" node */
+ IFolder viewsNodeRes = ResourcesPlugin.getWorkspace().getRoot().getFolder(tracePath.append(TmfViewsElement.PATH_ELEMENT));
+ fViewsElement = new TmfViewsElement(viewsNodeRes, this);
+ addChild(fViewsElement);
}
+ fViewsElement.refreshChildren();
}
/**
// Operations
// ------------------------------------------------------------------------
+ /**
+ * Get the child element "Views". There should always be one.
+ *
+ * @return The child element
+ * @since 2.0
+ */
+ protected TmfViewsElement getChildElementViews() {
+ return fViewsElement;
+ }
+
/**
* Returns the trace type ID.
*
* @return Array of analysis elements
*/
public List<TmfAnalysisElement> getAvailableAnalysis() {
- List<ITmfProjectModelElement> children = getChildren();
- List<TmfAnalysisElement> analysis = new ArrayList<>();
- for (ITmfProjectModelElement child : children) {
- if (child instanceof TmfAnalysisElement) {
- analysis.add((TmfAnalysisElement) child);
- }
- }
- return analysis;
+ return getChildElementViews().getChildren().stream()
+ .map(elem -> (TmfAnalysisElement) elem)
+ .collect(Collectors.toList());
}
// ------------------------------------------------------------------------
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;
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(getResource().getFullPath().append(module.getId()));
- TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, this, module);
- addChild(analysis);
+ TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, viewsElement, module);
+ viewsElement.addChild(analysis);
analysis.refreshChildren();
analysisMap.put(module.getId(), analysis);
}
public static final @NonNull Image DEFAULT_EXPERIMENT_ICON;
public static final @NonNull Image DEFAULT_ANALYSIS_ICON;
public static final @NonNull Image DEFAULT_VIEW_ICON;
+
public static final @NonNull Image FOLDER_ICON;
+ public static final @NonNull Image VIEWS_ICON;
public static final WorkbenchLabelProvider WORKSPACE_LABEL_PROVIDER = new WorkbenchLabelProvider();
// ------------------------------------------------------------------------
static {
- FOLDER_ICON = checkNotNull(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ FOLDER_ICON = checkNotNull(sharedImages.getImage(ISharedImages.IMG_OBJ_FOLDER));
+ VIEWS_ICON = checkNotNull(sharedImages.getImage(ISharedImages.IMG_OBJ_ELEMENT));
Bundle bundle = Activator.getDefault().getBundle();
DEFAULT_TRACE_ICON = checkNotNull(loadIcon(bundle, TRACE_ICON_FILE));
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.project.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
+import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+
+/**
+ * Project model element for the "Views" node.
+ *
+ * For now it contains the list of the standard analyses, with their outputs
+ * (views) under each. The plan is to eventually only show the views under this
+ * node, since the user cannot really interact with the analyses themselves.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public class TmfViewsElement extends TmfProjectModelElement {
+
+ /**
+ * Element of the resource path
+ */
+ public static final String PATH_ELEMENT = ".views"; //$NON-NLS-1$
+
+ private static final String ELEMENT_NAME = Messages.TmfViewsElement_Name;
+
+ /**
+ * Constructor
+ *
+ * @param resource
+ * The resource to be associated with this element
+ * @param parent
+ * The parent element
+ */
+ protected TmfViewsElement(IResource resource, TmfCommonProjectElement parent) {
+ super(ELEMENT_NAME, resource, parent);
+ }
+
+ // ------------------------------------------------------------------------
+ // TmfProjectModelElement
+ // ------------------------------------------------------------------------
+
+ @Override
+ public TmfCommonProjectElement getParent() {
+ /* Type enforced at constructor */
+ return (TmfCommonProjectElement) super.getParent();
+ }
+
+ @Override
+ protected void refreshChildren() {
+ /* Refreshes the analysis under this trace */
+ Map<String, TmfAnalysisElement> childrenMap = new HashMap<>();
+ for (TmfAnalysisElement analysis : getParent().getAvailableAnalysis()) {
+ childrenMap.put(analysis.getAnalysisId(), analysis);
+ }
+
+ TraceTypeHelper helper = TmfTraceType.getTraceType(getParent().getTraceType());
+
+ Class<@NonNull ? extends ITmfTrace> traceClass = null;
+
+ if (helper != null) {
+ traceClass = helper.getTraceClass();
+ }
+
+ /* Remove all analysis and return */
+ if (traceClass == null) {
+ for (TmfAnalysisElement analysis : childrenMap.values()) {
+ removeChild(analysis);
+ }
+ return;
+ }
+
+ IPath nodePath = getResource().getFullPath();
+
+ /* Add all new analysis modules or refresh outputs of existing ones */
+ for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules(traceClass).values()) {
+
+ /* If the analysis is not a child of the trace, create it */
+ TmfAnalysisElement analysis = childrenMap.remove(module.getId());
+ if (analysis == null) {
+ IFolder analysisRes = ResourcesPlugin.getWorkspace().getRoot().getFolder(nodePath.append(module.getId()));
+ analysis = new TmfAnalysisElement(module.getName(), analysisRes, this, module);
+ addChild(analysis);
+ }
+ analysis.refreshChildren();
+ }
+
+ /* Remove analysis that are not children of this trace anymore */
+ for (TmfAnalysisElement analysis : childrenMap.values()) {
+ removeChild(analysis);
+ }
+ }
+
+ @Override
+ public Image getIcon() {
+ return TmfProjectModelIcons.VIEWS_ICON;
+ }
+}
TmfTraceElement_FolderSizeOverflowString=At least {0} bytes in more than {1} files
TmfTraceElement_TypeName=Trace
TmfTraceType_SelectTraceType=Select Trace Type
+TmfViewsElement_Name=Views
# Open trace error messages
TmfOpenTraceHelper_ErrorOpeningElement=Error opening {0}