tmf: Bug 460036: Fix multiple XML views when reopening TraceCompass
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 30 Jun 2016 08:39:27 +0000 (10:39 +0200)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 7 Jul 2016 19:28:22 +0000 (15:28 -0400)
Save the XML view data in persistent store per secondary ID so the multiple
views remain when reopening the trace.

Change-Id: I1ef9abe668c76e72a51f74c818768996fa8a1e20
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/76526
Reviewed-by: Hudson CI
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/AbstractXmlViewInfo.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/XmlViewInfo.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYView.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java

index 864ebdce5b2efe637dc1ae1047ae90e7a50cdf60..ac707e0630e259901825339d10331c4068071097 100644 (file)
@@ -9,6 +9,7 @@
 package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
@@ -21,6 +22,7 @@ import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalys
 public abstract class AbstractXmlViewInfo {
 
     private final String fViewId;
+    private @Nullable String fViewName;
 
     /**
      * Constructor
@@ -30,11 +32,32 @@ public abstract class AbstractXmlViewInfo {
      */
     public AbstractXmlViewInfo(String viewId) {
         fViewId = viewId;
+        fViewName = null;
+    }
+
+    /**
+     * Set the view's name, which should correspond to a secondary ID
+     *
+     * @param name
+     *            The view's name
+     */
+    public void setName(@NonNull String name) {
+        fViewName = name;
+    }
+
+    /**
+     * Get the name of the view, which should correspond to the view's secondary
+     * ID. If this name is not null, it will never be null again
+     *
+     * @return The name of the view
+     */
+    protected @Nullable String getName() {
+        return fViewName;
     }
 
     /**
      * Get this view property section from the settings. The property section is
-     * per view ID.
+     * per view ID and view name if available.
      *
      * @return The property section
      */
@@ -44,10 +67,21 @@ public abstract class AbstractXmlViewInfo {
         if (section == null) {
             section = settings.addNewSection(fViewId);
             if (section == null) {
-                throw new IllegalStateException("The persistent property section could not be added"); //$NON-NLS-1$
+                throw new IllegalStateException("The persistent property section could not be added " + fViewId); //$NON-NLS-1$
+            }
+        }
+        if (fViewName == null) {
+            return section;
+        }
+        // FIXME: when a file is removed from TraceCompass, its view section should also be deleted
+        IDialogSettings subSection = section.getSection(fViewName);
+        if (subSection == null) {
+            subSection = section.addNewSection(fViewName);
+            if (subSection == null) {
+                throw new IllegalStateException("The persistent property section could not be added: " + fViewName); //$NON-NLS-1$
             }
         }
-        return section;
+        return subSection;
     }
 
     /**
index 2ae9d6d2dafcfaeafb9faca9df4b3ac5215b910d..fba67abab4e5ff52278cfeb020db1368d4f00afa 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.CountDownLatch;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -35,9 +36,13 @@ public class XmlViewInfo extends AbstractXmlViewInfo {
     private static final String XML_VIEW_ID_PROPERTY = "XmlViewId"; //$NON-NLS-1$
     private static final String XML_VIEW_FILE_PROPERTY = "XmlViewFile"; //$NON-NLS-1$
 
+    /* Initialization is completed when name is set */
+    private final CountDownLatch fInitialized = new CountDownLatch(1);
     /** This is the ID of the view described in the XML file */
     private @Nullable String fId = null;
     private @Nullable String fFilePath = null;
+    // If true, properties were set but not saved to persistent storage
+    private boolean fIsDirty = false;
 
     /**
      * Constructor
@@ -47,10 +52,22 @@ public class XmlViewInfo extends AbstractXmlViewInfo {
      */
     public XmlViewInfo(String viewId) {
         super(viewId);
+        /* Cannot get the properties yet, need to wait for the name */
+    }
 
-        IDialogSettings settings = getPersistentPropertyStore();
-        fId = settings.get(XML_VIEW_ID_PROPERTY);
-        fFilePath = settings.get(XML_VIEW_FILE_PROPERTY);
+    /**
+     * Waits for the view info's initialization to be completed. This happens
+     * once the name has been set
+     *
+     * @return Whether the initialization has completed successfully
+     */
+    public boolean waitForInitialization() {
+        try {
+            fInitialized.await();
+        } catch (InterruptedException e) {
+            return false;
+        }
+        return true;
     }
 
     /**
@@ -63,11 +80,29 @@ public class XmlViewInfo extends AbstractXmlViewInfo {
      *            "path of the file containing the XML element"
      */
     @Override
-    public void setViewData(String data) {
+    public synchronized void setViewData(String data) {
         String[] idFile = data.split(TmfXmlAnalysisOutputSource.DATA_SEPARATOR);
         fId = (idFile.length > 0) ? idFile[0] : null;
         fFilePath = (idFile.length > 1) ? idFile[1] : null;
-        savePersistentData();
+        String viewName = getName();
+        if (viewName != null) {
+            savePersistentData();
+        } else {
+            fIsDirty = true;
+        }
+    }
+
+    @Override
+    public synchronized void setName(String name) {
+        super.setName(name);
+        if (fIsDirty) {
+            savePersistentData();
+        } else {
+            IDialogSettings settings = getPersistentPropertyStore();
+            fId = settings.get(XML_VIEW_ID_PROPERTY);
+            fFilePath = settings.get(XML_VIEW_FILE_PROPERTY);
+        }
+        fInitialized.countDown();
     }
 
     @Override
index 41b3c9a50d20b7432f38fa92ddd35fd8a0e9f61a..54add752e09085606b87355b7eb7fe80a4a19f3a 100644 (file)
@@ -31,7 +31,9 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
@@ -128,10 +130,15 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
                 }
             }
         });
-
         fFactory = TmfXmlReadOnlyModelFactory.getInstance();
     }
 
+    @Override
+    public void createPartControl(Composite parent) {
+        super.createPartControl(parent);
+        fViewInfo.setName(NonNullUtils.checkNotNull(getViewSite().getSecondaryId()));
+    }
+
     private void loadNewXmlView() {
         rebuild();
     }
@@ -223,6 +230,9 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
     @Override
     protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
 
+        if (!fViewInfo.waitForInitialization()) {
+            return;
+        }
         /*
          * Get the view element from the XML file. If the element can't be
          * found, return.
index 8487aaf119ddcd1194359d48728a6f2566458ddc..17a805a91b31921e16c19afa9bbe11339fb3e15b 100644 (file)
@@ -17,6 +17,7 @@ import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo;
 import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer;
@@ -65,7 +66,6 @@ public class XmlXYView extends TmfChartView {
             }
 
         });
-        setViewTitle();
     }
 
     private void setViewTitle() {
@@ -91,6 +91,13 @@ public class XmlXYView extends TmfChartView {
         });
     }
 
+    @Override
+    public void createPartControl(@Nullable Composite parent) {
+        super.createPartControl(parent);
+        fViewInfo.setName(NonNullUtils.checkNotNull(getViewSite().getSecondaryId()));
+        setViewTitle();
+    }
+
     @Override
     protected TmfXYChartViewer createChartViewer(@Nullable Composite parent) {
         return new XmlXYViewer(parent, fViewInfo);
index 31c7cae0af15d24aa6f78d9e4469fa6140d76d8a..7b5af2fd57d43167f674432704c8ba360be09c04 100644 (file)
@@ -218,6 +218,10 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
     @Override
     protected void updateData(long start, long end, int nb, @Nullable IProgressMonitor monitor) {
 
+        if (!fViewInfo.waitForInitialization()) {
+            return;
+        }
+
         ITmfXmlStateAttribute display = fDisplay;
         ITmfXmlStateAttribute seriesNameAttrib = fSeriesName;
         XmlXYEntry entry = fEntry;
This page took 0.029772 seconds and 5 git commands to generate.