TMF: Strike-out analyses that cannot be executed
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 8 May 2014 17:21:36 +0000 (13:21 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Sat, 24 May 2014 05:53:05 +0000 (01:53 -0400)
Also add an interface, ITmfStylecProjectModelElement to allow elements to
change the style of their text.

Change-Id: Iab0fa42b91539d5dbdd4a69917a2b35b3346ca05
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/26293
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/ITmfStyledProjectModelElement.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfAnalysisElement.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java

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 (file)
index 0000000..67d9541
--- /dev/null
@@ -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();
+
+}
index c697266c9bb2e22d6c6f5f8f91745cc59e7dc57c..3855d6649821698c29154f45f836c61d6ca988d4 100644 (file)
@@ -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<String, TmfAnalysisOutputElement> 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);
         }
     }
+
 }
index 4e9d5fc43b0c1df025a6bee538452121eafa53f6..a12fb76bc042f1be4dae7ef9661f4ae80a9f422d 100644 (file)
@@ -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;
+    }
+
 }
This page took 0.038437 seconds and 5 git commands to generate.