import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.swt.graphics.Image;
/**
* The TMF project model interface.
*/
void refresh();
+ /**
+ * Returns the icon of this element.
+ *
+ * @return The icon
+ * @since 2.0
+ */
+ Image getIcon();
+
+ /**
+ * Returns the text of the label of this element.
+ *
+ * @return The label text
+ * @since 2.0
+ */
+ default String getLabelText() {
+ return getName();
+ }
+
/**
* Returns whether this model element has children or not.
*
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jface.viewers.StyledString.Styler;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
}
}
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Image getIcon() {
+ String iconFile = getIconFile();
+ if (iconFile != null) {
+ Bundle bundle = getBundle();
+ if (bundle != null) {
+ Image icon = TmfProjectModelIcons.loadIcon(bundle, iconFile);
+ if (icon != null) {
+ return icon;
+ }
+ }
+ }
+ return TmfProjectModelIcons.DEFAULT_ANALYSIS_ICON;
+ }
+
// ------------------------------------------------------------------------
// TmfProjectModelElement
// ------------------------------------------------------------------------
fOutput = output;
}
- /**
- * Gets the icon of the view, if applicable
- *
- * @return The view icon or null if output is not a view
- */
+ @Override
public Image getIcon() {
if (fOutput instanceof TmfAnalysisViewOutput) {
IViewDescriptor descr = PlatformUI.getWorkbench().getViewRegistry().find(
icon = descr.getImageDescriptor().createImage();
bundle.getImageRegistry().put(key, icon);
}
- return icon;
+ if (icon != null) {
+ return icon;
+ }
}
}
- return null;
+ return TmfProjectModelIcons.DEFAULT_VIEW_ICON;
}
/**
package org.eclipse.tracecompass.tmf.ui.project.model;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
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.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+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.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.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;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;
+import org.osgi.framework.Bundle;
/**
* Base class for tracing project elements: it implements the common behavior of
}
}
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Image getIcon() {
+ String traceType = getTraceType();
+ if (traceType == null || TmfTraceType.getTraceType(traceType) == null) {
+ // request the label to the Eclipse platform
+ Image icon = TmfProjectModelIcons.WORKSPACE_LABEL_PROVIDER.getImage(getResource());
+ return (icon == null ? TmfProjectModelIcons.DEFAULT_TRACE_ICON : icon);
+ }
+
+ IConfigurationElement traceUIAttributes = TmfTraceTypeUIUtils.getTraceUIAttributes(traceType,
+ (this instanceof TmfTraceElement) ? TraceElementType.TRACE : TraceElementType.EXPERIMENT);
+ if (traceUIAttributes != null) {
+ String iconAttr = traceUIAttributes.getAttribute(TmfTraceTypeUIUtils.ICON_ATTR);
+ if (iconAttr != null) {
+ String name = traceUIAttributes.getContributor().getName();
+ if (name != null) {
+ Bundle bundle = Platform.getBundle(name);
+ if (bundle != null) {
+ Image image = TmfProjectModelIcons.loadIcon(bundle, iconAttr);
+ if (image != null) {
+ return image;
+ }
+ }
+ }
+ }
+ }
+ /* Let subclasses specify an icon */
+ return null;
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
*
* @return The element path
*/
- public String getElementPath() {
+ public @NonNull String getElementPath() {
ITmfProjectModelElement parent = getParent();
while (!(parent instanceof TmfTracesFolder || parent instanceof TmfExperimentElement || parent instanceof TmfExperimentFolder)) {
parent = parent.getParent();
}
IPath path = getResource().getFullPath().makeRelativeTo(parent.getPath());
- return path.toString();
+ return checkNotNull(path.toString());
}
/**
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;
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
// ------------------------------------------------------------------------
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource2;
}
}
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Image getIcon() {
+ return TmfProjectModelIcons.FOLDER_ICON;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getLabelText() {
+ return getName() + " [" + getChildren().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
package org.eclipse.tracecompass.tmf.ui.project.model;
-import java.net.URL;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.tracecompass.internal.tmf.ui.Activator;
-import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
-import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType;
import org.eclipse.ui.IMemento;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
import org.eclipse.ui.navigator.ICommonLabelProvider;
-import org.osgi.framework.Bundle;
/**
* The TMF project label provider for the tree viewer in the project explorer view.
*/
public class TmfNavigatorLabelProvider implements ICommonLabelProvider, IStyledLabelProvider {
- // ------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------
-
- private static final Image FOLDER_ICON = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
- private static final String TRACE_ICON_FILE = "icons/elcl16/trace.gif"; //$NON-NLS-1$
- private static final String EXPERIMENT_ICON_FILE = "icons/elcl16/experiment.gif"; //$NON-NLS-1$
- private static final String ANALYSIS_ICON_FILE = "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$
- private static final String VIEW_ICON_FILE = "icons/obj16/node_obj.gif"; //$NON-NLS-1$
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private final Image fDefaultTraceIcon;
- private final Image fExperimentIcon;
- private final Image fDefaultAnalysisIcon;
- private final Image fDefaultViewIcon;
-
- private final WorkbenchLabelProvider fWorkspaceLabelProvider = new WorkbenchLabelProvider();
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Constructor.
- *
- * Creates the TMF navigator content provider.
- */
- public TmfNavigatorLabelProvider() {
- Bundle bundle = Activator.getDefault().getBundle();
- fDefaultTraceIcon = loadIcon(bundle, TRACE_ICON_FILE);
- fExperimentIcon = loadIcon(bundle, EXPERIMENT_ICON_FILE);
- fDefaultAnalysisIcon = loadIcon(bundle, ANALYSIS_ICON_FILE);
- fDefaultViewIcon = loadIcon(bundle, VIEW_ICON_FILE);
- }
-
- private static Image loadIcon(Bundle bundle, String url) {
- Activator plugin = Activator.getDefault();
- String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$
- Image icon = plugin.getImageRegistry().get(key);
- if (icon == null) {
- URL imageURL = bundle.getResource(url);
- ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
- if (descriptor != null) {
- icon = descriptor.createImage();
- plugin.getImageRegistry().put(key, icon);
- }
- }
- return icon;
- }
-
// ------------------------------------------------------------------------
// ICommonLabelProvider
// ------------------------------------------------------------------------
@Override
public Image getImage(Object element) {
-
- if (element instanceof TmfCommonProjectElement) {
- TmfCommonProjectElement trace = (TmfCommonProjectElement) element;
- String traceType = trace.getTraceType();
- if (traceType == null || TmfTraceType.getTraceType(traceType) == null) {
- // request the label to the Eclipse platform
- return fWorkspaceLabelProvider.getImage(((TmfCommonProjectElement) element).getResource());
- }
-
- IConfigurationElement traceUIAttributes = TmfTraceTypeUIUtils.getTraceUIAttributes(traceType, (element instanceof TmfTraceElement) ? TraceElementType.TRACE : TraceElementType.EXPERIMENT);
- if (traceUIAttributes != null) {
- String iconAttr = traceUIAttributes.getAttribute(TmfTraceTypeUIUtils.ICON_ATTR);
- if (iconAttr != null) {
- String name = traceUIAttributes.getContributor().getName();
- if (name != null) {
- Bundle bundle = Platform.getBundle(name);
- if (bundle != null) {
- Image image = loadIcon(bundle, iconAttr);
- if (image != null) {
- return image;
- }
- }
- }
- }
-
- }
- if (element instanceof TmfTraceElement) {
- return fDefaultTraceIcon;
- }
- return fExperimentIcon;
- }
-
- if (element instanceof TmfExperimentFolder) {
- return FOLDER_ICON;
- }
-
- if (element instanceof TmfTraceFolder) {
- return FOLDER_ICON;
- }
-
- if (element instanceof TmfAnalysisOutputElement) {
- TmfAnalysisOutputElement output = (TmfAnalysisOutputElement) element;
- Image icon = output.getIcon();
- if (icon == null) {
- return fDefaultViewIcon;
- }
- return icon;
- }
-
- if (element instanceof TmfAnalysisElement) {
- TmfAnalysisElement analysis = (TmfAnalysisElement) element;
- String iconFile = analysis.getIconFile();
- if (iconFile != null) {
- Bundle bundle = analysis.getBundle();
- if (bundle != null) {
- Image icon = loadIcon(bundle, iconFile);
- return icon;
- }
- }
- return fDefaultAnalysisIcon;
+ if (element instanceof ITmfProjectModelElement) {
+ return ((ITmfProjectModelElement) element).getIcon();
}
-
return null;
}
@Override
public String getText(Object element) {
-
- if (element instanceof TmfTracesFolder) {
- TmfTracesFolder folder = (TmfTracesFolder) element;
- return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (element instanceof TmfTraceFolder) {
- TmfTraceFolder folder = (TmfTraceFolder) element;
- int nbTraces = folder.getTraces().size();
- if (nbTraces > 0) {
- return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- return folder.getName();
- }
-
- if (element instanceof TmfTraceElement) {
- TmfTraceElement trace = (TmfTraceElement) element;
- if (trace.getParent() instanceof TmfExperimentElement) {
- return trace.getElementPath();
- }
- return trace.getName();
- }
-
- if (element instanceof TmfExperimentElement) {
- TmfExperimentElement folder = (TmfExperimentElement) element;
- return folder.getName() + " [" + folder.getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (element instanceof TmfExperimentFolder) {
- TmfExperimentFolder folder = (TmfExperimentFolder) element;
- return folder.getName() + " [" + folder.getChildren().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Catch all
if (element instanceof ITmfProjectModelElement) {
- return ((ITmfProjectModelElement) element).getName();
+ return ((ITmfProjectModelElement) element).getLabelText();
}
-
return null;
}
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.swt.graphics.Image;
/**
* The implementation of TMF project model element.
public TmfProjectElement getProject() {
return this;
}
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Image getIcon() {
+ return null;
+ }
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2010, 2016 Ericsson, EfficiOS Inc. 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.project.model;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.net.URL;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.internal.tmf.ui.Activator;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.osgi.framework.Bundle;
+
+/**
+ * Facilities to load icons used in the Project View.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+final class TmfProjectModelIcons {
+
+ private TmfProjectModelIcons() {}
+
+ public static final @NonNull Image DEFAULT_TRACE_ICON;
+ 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 WorkbenchLabelProvider WORKSPACE_LABEL_PROVIDER = new WorkbenchLabelProvider();
+
+ private static final String TRACE_ICON_FILE = "icons/elcl16/trace.gif"; //$NON-NLS-1$
+ private static final String EXPERIMENT_ICON_FILE = "icons/elcl16/experiment.gif"; //$NON-NLS-1$
+ private static final String ANALYSIS_ICON_FILE = "icons/ovr16/experiment_folder_ovr.png"; //$NON-NLS-1$
+ private static final String VIEW_ICON_FILE = "icons/obj16/node_obj.gif"; //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Initialization
+ // ------------------------------------------------------------------------
+
+ static {
+ FOLDER_ICON = checkNotNull(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
+
+ Bundle bundle = Activator.getDefault().getBundle();
+ DEFAULT_TRACE_ICON = checkNotNull(loadIcon(bundle, TRACE_ICON_FILE));
+ DEFAULT_EXPERIMENT_ICON = checkNotNull(loadIcon(bundle, EXPERIMENT_ICON_FILE));
+ DEFAULT_ANALYSIS_ICON = checkNotNull(loadIcon(bundle, ANALYSIS_ICON_FILE));
+ DEFAULT_VIEW_ICON = checkNotNull(loadIcon(bundle, VIEW_ICON_FILE));
+ }
+
+ public static @Nullable Image loadIcon(Bundle bundle, String url) {
+ Activator plugin = Activator.getDefault();
+ String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$
+ Image icon = plugin.getImageRegistry().get(key);
+ if (icon == null) {
+ URL imageURL = bundle.getResource(url);
+ ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
+ if (descriptor != null) {
+ icon = descriptor.createImage();
+ plugin.getImageRegistry().put(key, icon);
+ }
+ }
+ return icon;
+ }
+}
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.URIUtil;
+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;
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 2.0
+ */
+ @Override
+ public @NonNull Image getIcon() {
+ Image icon = super.getIcon();
+ return (icon == null ? TmfProjectModelIcons.DEFAULT_TRACE_ICON : icon);
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getLabelText() {
+ if (getParent() instanceof TmfExperimentElement) {
+ return getElementPath();
+ }
+ return getName();
+ }
+
/**
* Instantiate a <code>ITmfTrace</code> object based on the trace type and
* the corresponding extension.
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
}
}
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Image getIcon() {
+ return TmfProjectModelIcons.FOLDER_ICON;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getLabelText() {
+ int nbTraces = getTraces().size();
+ if (nbTraces > 0) {
+ return (getName() + " [" + nbTraces + ']'); //$NON-NLS-1$
+ }
+ return getName();
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
super(name, resource, parent);
}
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getLabelText() {
+ return getName() + " [" + getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
}