From: Geneviève Bastien Date: Thu, 8 May 2014 17:21:36 +0000 (-0400) Subject: TMF: Strike-out analyses that cannot be executed X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=d5278aa50996486676c5492d5a4925c00cbe6748;p=deliverable%2Ftracecompass.git TMF: Strike-out analyses that cannot be executed Also add an interface, ITmfStylecProjectModelElement to allow elements to change the style of their text. Change-Id: Iab0fa42b91539d5dbdd4a69917a2b35b3346ca05 Signed-off-by: Geneviève Bastien Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/26293 Tested-by: Hudson CI --- diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/ITmfStyledProjectModelElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/ITmfStyledProjectModelElement.java new file mode 100644 index 0000000000..67d9541098 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/ITmfStyledProjectModelElement.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * 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 + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.project.model; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jface.viewers.StyledString.Styler; + +/** + * This interface can be implemented by elements to a style to their text. + * + * @author Geneviève Bastien + * @since 3.0 + */ +public interface ITmfStyledProjectModelElement { + + /** + * Return the styler who will apply its style to the text string. + * + * @return The style object, or 'null' for no special style + */ + @Nullable + Styler getStyler(); + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfAnalysisElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfAnalysisElement.java index c697266c9b..3855d66498 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfAnalysisElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfAnalysisElement.java @@ -22,11 +22,13 @@ 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.jface.viewers.StyledString.Styler; import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisOutput; import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.swt.graphics.TextStyle; import org.osgi.framework.Bundle; /** @@ -35,9 +37,17 @@ import org.osgi.framework.Bundle; * @author Geneviève Bastien * @since 3.0 */ -public class TmfAnalysisElement extends TmfProjectModelElement { +public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfStyledProjectModelElement { + + private static final Styler ANALYSIS_CANT_EXECUTE_STYLER = new Styler() { + @Override + public void applyStyles(TextStyle textStyle) { + textStyle.strikeout = true; + } + }; private final String fAnalysisId; + private boolean fCanExecute = true; /** * Constructor @@ -63,6 +73,8 @@ public class TmfAnalysisElement extends TmfProjectModelElement { @Override void refreshChildren() { + fCanExecute = true; + /* Refresh the outputs of this analysis */ Map childrenMap = new HashMap<>(); for (TmfAnalysisOutputElement output : getAvailableOutputs()) { @@ -96,6 +108,11 @@ public class TmfAnalysisElement extends TmfProjectModelElement { IAnalysisModule module = trace.getAnalysisModule(fAnalysisId); if (module == null) { deleteOutputs(); + /* + * Trace is opened, but the analysis is null, so it does not + * apply + */ + fCanExecute = false; return; } @@ -107,6 +124,7 @@ public class TmfAnalysisElement extends TmfProjectModelElement { } outputElement.refreshChildren(); } + } /* Remove outputs that are not children of this analysis anymore */ for (TmfAnalysisOutputElement output : childrenMap.values()) { @@ -114,6 +132,18 @@ public class TmfAnalysisElement extends TmfProjectModelElement { } } + // ------------------------------------------------------------------------ + // TmfProjectModelElement + // ------------------------------------------------------------------------ + + @Override + public Styler getStyler() { + if (!fCanExecute) { + return ANALYSIS_CANT_EXECUTE_STYLER; + } + return null; + } + // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ @@ -151,13 +181,14 @@ public class TmfAnalysisElement extends TmfProjectModelElement { public String getHelpMessage() { ITmfProjectModelElement parent = getParent(); + ITmfTrace trace = null; if (parent instanceof TmfTraceElement) { TmfTraceElement traceElement = (TmfTraceElement) parent; - ITmfTrace trace = traceElement.getTrace(); + trace = traceElement.getTrace(); if (trace != null) { IAnalysisModule module = trace.getAnalysisModule(fAnalysisId); if (module != null) { - return module.getHelpText(); + return module.getHelpText(trace); } } } @@ -215,4 +246,5 @@ public class TmfAnalysisElement extends TmfProjectModelElement { TmfOpenTraceHelper.openTraceFromElement(traceElement); } } + } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java index 4e9d5fc43b..a12fb76bc0 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java @@ -19,7 +19,10 @@ import org.eclipse.core.runtime.CoreException; 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.linuxtools.internal.tmf.ui.Activator; import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; @@ -38,7 +41,7 @@ import org.osgi.framework.Bundle; * @version 1.0 * @author Francois Chouinard */ -public class TmfNavigatorLabelProvider implements ICommonLabelProvider { +public class TmfNavigatorLabelProvider implements ICommonLabelProvider, IStyledLabelProvider { // ------------------------------------------------------------------------ // Constants @@ -247,4 +250,22 @@ public class TmfNavigatorLabelProvider implements ICommonLabelProvider { public void init(ICommonContentExtensionSite aConfig) { } + /** + * @since 3.0 + */ + @Override + public StyledString getStyledText(Object element) { + String text = getText(element); + if (text != null) { + if (element instanceof ITmfStyledProjectModelElement) { + Styler styler = ((ITmfStyledProjectModelElement) element).getStyler(); + if (styler != null) { + return new StyledString(text, styler); + } + } + return new StyledString(text); + } + return null; + } + }