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;
public abstract class AbstractXmlViewInfo {
private final String fViewId;
+ private @Nullable String fViewName;
/**
* Constructor
*/
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
*/
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;
}
/**
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;
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
*/
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;
}
/**
* "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
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;
}
}
});
-
fFactory = TmfXmlReadOnlyModelFactory.getInstance();
}
+ @Override
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ fViewInfo.setName(NonNullUtils.checkNotNull(getViewSite().getSecondaryId()));
+ }
+
private void loadNewXmlView() {
rebuild();
}
@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.
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;
}
});
- setViewTitle();
}
private void setViewTitle() {
});
}
+ @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);
@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;