fixes TransactionList behavior with automatic property loading
This commit is contained in:
1 parent
3e863a6e05
commit
80616e9d96
6 files changed
+305
-62
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ import com.minres.scviewer.database.tx.ITx;
|
|||||||
import com.minres.scviewer.database.tx.ITransactionProvider;
|
import com.minres.scviewer.database.tx.ITransactionProvider;
|
||||||
import com.minres.scviewer.database.tx.TransactionLists;
|
import com.minres.scviewer.database.tx.TransactionLists;
|
||||||
|
|
||||||
/** Cached transaction headers; attribute values are visited only on explicit request. */
|
/** Cached transaction headers and property discovery for a selected track. */
|
||||||
public final class TransactionQuery {
|
public final class TransactionQuery {
|
||||||
public record Attribute(String name, DataType type) {}
|
public record Attribute(String name, DataType type) {}
|
||||||
private final IWaveform waveform;
|
private final IWaveform waveform;
|
||||||
|
|||||||
+56
-30
@@ -18,7 +18,6 @@ import org.eclipse.swt.SWT;
|
|||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.layout.FillLayout;
|
import org.eclipse.swt.layout.FillLayout;
|
||||||
import org.eclipse.swt.widgets.Button;
|
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
@@ -40,7 +39,6 @@ public class TransactionList extends Composite {
|
|||||||
private final ComboViewer viewProperty;
|
private final ComboViewer viewProperty;
|
||||||
private final Text searchValue;
|
private final Text searchValue;
|
||||||
private final TableViewer tableViewer;
|
private final TableViewer tableViewer;
|
||||||
private final Button loadProperties;
|
|
||||||
private final AttributeLabelProvider valueProvider;
|
private final AttributeLabelProvider valueProvider;
|
||||||
private final LatestJob<List<ITx>> rowsJob;
|
private final LatestJob<List<ITx>> rowsJob;
|
||||||
private record PropertyDiscovery(List<Attribute> attributes, RuntimeException error) {}
|
private record PropertyDiscovery(List<Attribute> attributes, RuntimeException error) {}
|
||||||
@@ -52,25 +50,24 @@ public class TransactionList extends Composite {
|
|||||||
private IWaveform stream;
|
private IWaveform stream;
|
||||||
private TrackEntry track;
|
private TrackEntry track;
|
||||||
private TransactionQuery query;
|
private TransactionQuery query;
|
||||||
|
private boolean propertiesRequested;
|
||||||
|
private String lastSelectedDisplayProperty;
|
||||||
|
private boolean restoringDisplayProperty;
|
||||||
|
|
||||||
public TransactionList(Composite parent, int style, WaveformViewer waveformViewer) {
|
public TransactionList(Composite parent, int style, WaveformViewer waveformViewer) {
|
||||||
super(parent, style);
|
super(parent, style);
|
||||||
parent.setLayout(new FillLayout());
|
parent.setLayout(new FillLayout());
|
||||||
setLayout(new GridLayout(6, false));
|
setLayout(new GridLayout(5, false));
|
||||||
label("Property to match:");
|
label("Property to match:");
|
||||||
searchProperty = propertiesCombo();
|
searchProperty = propertiesCombo();
|
||||||
searchValue = new Text(this, SWT.BORDER);
|
searchValue = new Text(this, SWT.BORDER);
|
||||||
searchValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
searchValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
||||||
label("Property to show:");
|
label("Property to show:");
|
||||||
viewProperty = propertiesCombo();
|
viewProperty = propertiesCombo();
|
||||||
loadProperties = new Button(this, SWT.PUSH);
|
|
||||||
loadProperties.setText("Load properties");
|
|
||||||
loadProperties.setToolTipText("Discover property names in this track; values are otherwise loaded only when needed.");
|
|
||||||
loadProperties.setEnabled(false);
|
|
||||||
|
|
||||||
tableViewer = new TableViewer(this, SWT.VIRTUAL | SWT.FULL_SELECTION | SWT.BORDER);
|
tableViewer = new TableViewer(this, SWT.VIRTUAL | SWT.FULL_SELECTION | SWT.BORDER);
|
||||||
tableViewer.setUseHashlookup(true);
|
tableViewer.setUseHashlookup(true);
|
||||||
tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1));
|
tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
||||||
tableViewer.getTable().setHeaderVisible(true);
|
tableViewer.getTable().setHeaderVisible(true);
|
||||||
tableViewer.getTable().setLinesVisible(true);
|
tableViewer.getTable().setLinesVisible(true);
|
||||||
tableViewer.setContentProvider(new ILazyContentProvider() {
|
tableViewer.setContentProvider(new ILazyContentProvider() {
|
||||||
@@ -94,26 +91,44 @@ public class TransactionList extends Composite {
|
|||||||
});
|
});
|
||||||
attributesJob = new LatestJob<>(task -> { if (!display.isDisposed()) display.asyncExec(task); }, result -> {
|
attributesJob = new LatestJob<>(task -> { if (!display.isDisposed()) display.asyncExec(task); }, result -> {
|
||||||
if (isDisposed()) return;
|
if (isDisposed()) return;
|
||||||
loadProperties.setEnabled(query != null);
|
|
||||||
loadProperties.setText("Load properties");
|
|
||||||
if (result.error() != null) {
|
if (result.error() != null) {
|
||||||
MessageDialog.openError(getShell(), "Cannot load properties", result.error().toString());
|
MessageDialog.openError(getShell(), "Cannot load properties", result.error().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object selected = ((IStructuredSelection) searchProperty.getSelection()).getFirstElement();
|
Object selected = ((IStructuredSelection) searchProperty.getSelection()).getFirstElement();
|
||||||
String displayedProperty = valueProvider.getShowProp();
|
String displayedProperty = lastSelectedDisplayProperty != null
|
||||||
attributes = result.attributes();
|
? lastSelectedDisplayProperty : valueProvider.getShowProp();
|
||||||
|
// A details-panel search may add a known property while discovery is running.
|
||||||
|
java.util.Map<String, Attribute> known = new java.util.TreeMap<>();
|
||||||
|
attributes.forEach(attribute -> known.put(attribute.name(), attribute));
|
||||||
|
result.attributes().forEach(attribute -> known.put(attribute.name(), attribute));
|
||||||
|
attributes = List.copyOf(known.values());
|
||||||
searchProperty.setInput(attributes);
|
searchProperty.setInput(attributes);
|
||||||
viewProperty.setInput(attributes);
|
viewProperty.setInput(attributes);
|
||||||
if (attributes.contains(selected)) searchProperty.setSelection(new StructuredSelection(selected));
|
if (selected != null && attributes.contains(selected)) searchProperty.setSelection(new StructuredSelection(selected));
|
||||||
else if (!attributes.isEmpty()) searchProperty.setSelection(new StructuredSelection(attributes.get(0)));
|
else if (!attributes.isEmpty()) searchProperty.setSelection(new StructuredSelection(attributes.get(0)));
|
||||||
attributes.stream().filter(attribute -> attribute.name().equals(displayedProperty)).findFirst()
|
Attribute displayed = attributes.stream().filter(attribute -> attribute.name().equals(displayedProperty))
|
||||||
.ifPresent(attribute -> viewProperty.setSelection(new StructuredSelection(attribute)));
|
.findFirst().orElse(attributes.isEmpty() ? null : attributes.get(0));
|
||||||
loadProperties.setEnabled(query != null);
|
if (displayed != null) showProperty(displayed);
|
||||||
|
else {
|
||||||
|
valueProvider.setShowProp(null);
|
||||||
|
tableViewer.refresh();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
addListener(SWT.Show, event -> {
|
addListener(SWT.Show, event -> {
|
||||||
getDisplay().timerExec(-1, applyFilter);
|
getDisplay().timerExec(-1, applyFilter);
|
||||||
refreshTransactions();
|
// SWT sends Show before updating the control's visibility flag.
|
||||||
|
display.asyncExec(() -> {
|
||||||
|
if (isDisposed() || !getVisible()) return;
|
||||||
|
refreshTransactions();
|
||||||
|
discoverProperties();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
addListener(SWT.Hide, event -> {
|
||||||
|
getDisplay().timerExec(-1, applyFilter);
|
||||||
|
rowsJob.cancel();
|
||||||
|
attributesJob.cancel();
|
||||||
|
propertiesRequested = false;
|
||||||
});
|
});
|
||||||
searchValue.addModifyListener(event -> requestFilter(200));
|
searchValue.addModifyListener(event -> requestFilter(200));
|
||||||
searchProperty.addSelectionChangedListener(event -> {
|
searchProperty.addSelectionChangedListener(event -> {
|
||||||
@@ -124,21 +139,11 @@ public class TransactionList extends Composite {
|
|||||||
});
|
});
|
||||||
viewProperty.addSelectionChangedListener(event -> {
|
viewProperty.addSelectionChangedListener(event -> {
|
||||||
if (event.getSelection() instanceof IStructuredSelection selected && selected.getFirstElement() instanceof Attribute attribute) {
|
if (event.getSelection() instanceof IStructuredSelection selected && selected.getFirstElement() instanceof Attribute attribute) {
|
||||||
|
if (!restoringDisplayProperty) lastSelectedDisplayProperty = attribute.name();
|
||||||
valueProvider.setShowProp(attribute.name());
|
valueProvider.setShowProp(attribute.name());
|
||||||
tableViewer.refresh();
|
tableViewer.refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
loadProperties.addListener(SWT.Selection, event -> {
|
|
||||||
TransactionQuery requested = query;
|
|
||||||
if (requested == null) return;
|
|
||||||
loadProperties.setEnabled(false);
|
|
||||||
loadProperties.setText("Loading properties…");
|
|
||||||
attributesJob.schedule("Discover transaction properties", monitor -> {
|
|
||||||
try { return new PropertyDiscovery(requested.discoverAttributes(monitor::isCanceled), null); }
|
|
||||||
catch (OperationCanceledException e) { throw e; }
|
|
||||||
catch (RuntimeException e) { return new PropertyDiscovery(List.of(), e); }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
tableViewer.addSelectionChangedListener(event -> {
|
tableViewer.addSelectionChangedListener(event -> {
|
||||||
if (event.getSelection() instanceof IStructuredSelection selected && selected.getFirstElement() instanceof ITx tx)
|
if (event.getSelection() instanceof IStructuredSelection selected && selected.getFirstElement() instanceof ITx tx)
|
||||||
waveformViewer.setSelection(WaveformSelection.of(tx, track));
|
waveformViewer.setSelection(WaveformSelection.of(tx, track));
|
||||||
@@ -150,6 +155,26 @@ public class TransactionList extends Composite {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Automatic defaults must not replace the user's preference when a stream lacks it. */
|
||||||
|
private void showProperty(Attribute property) {
|
||||||
|
restoringDisplayProperty = true;
|
||||||
|
try { viewProperty.setSelection(new StructuredSelection(property)); }
|
||||||
|
finally { restoringDisplayProperty = false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void discoverProperties() {
|
||||||
|
TransactionQuery requested = query;
|
||||||
|
if (requested == null || !getVisible() || propertiesRequested) return;
|
||||||
|
propertiesRequested = true;
|
||||||
|
attributesJob.schedule("Discover transaction properties", monitor -> {
|
||||||
|
try {
|
||||||
|
List<Attribute> discovered = requested.discoverAttributes(monitor::isCanceled);
|
||||||
|
return new PropertyDiscovery(discovered, null);
|
||||||
|
} catch (OperationCanceledException e) { throw e; }
|
||||||
|
catch (RuntimeException e) { return new PropertyDiscovery(List.of(), e); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void label(String text) { new Label(this, SWT.NONE).setText(text); }
|
private void label(String text) { new Label(this, SWT.NONE).setText(text); }
|
||||||
|
|
||||||
private ComboViewer propertiesCombo() {
|
private ComboViewer propertiesCombo() {
|
||||||
@@ -191,9 +216,9 @@ public class TransactionList extends Composite {
|
|||||||
filter.setSearchProp(null, null);
|
filter.setSearchProp(null, null);
|
||||||
tableViewer.setInput(rows);
|
tableViewer.setInput(rows);
|
||||||
tableViewer.setItemCount(0);
|
tableViewer.setItemCount(0);
|
||||||
loadProperties.setEnabled(query != null);
|
propertiesRequested = false;
|
||||||
loadProperties.setText("Load properties");
|
|
||||||
requestFilter(0);
|
requestFilter(0);
|
||||||
|
discoverProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestFilter(int delay) {
|
private void requestFilter(int delay) {
|
||||||
@@ -230,6 +255,7 @@ public class TransactionList extends Composite {
|
|||||||
viewProperty.setInput(attributes);
|
viewProperty.setInput(attributes);
|
||||||
}
|
}
|
||||||
searchProperty.setSelection(new StructuredSelection(property));
|
searchProperty.setSelection(new StructuredSelection(property));
|
||||||
|
if (valueProvider.getShowProp() == null) showProperty(property);
|
||||||
filter.setSearchProp(name, type);
|
filter.setSearchProp(name, type);
|
||||||
searchValue.setText(value);
|
searchValue.setText(value);
|
||||||
requestFilter(0);
|
requestFilter(0);
|
||||||
|
|||||||
+5
-29
@@ -1,16 +1,9 @@
|
|||||||
package com.minres.scviewer.e4.application.parts;
|
package com.minres.scviewer.e4.application.parts;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import org.eclipse.e4.core.di.annotations.Optional;
|
import org.eclipse.e4.core.di.annotations.Optional;
|
||||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
|
||||||
import org.eclipse.e4.ui.di.Focus;
|
import org.eclipse.e4.ui.di.Focus;
|
||||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
|
||||||
import org.eclipse.e4.ui.services.IServiceConstants;
|
|
||||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
|
||||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
@@ -18,21 +11,8 @@ import org.eclipse.swt.widgets.Composite;
|
|||||||
import com.minres.scviewer.database.ui.WaveformSelection;
|
import com.minres.scviewer.database.ui.WaveformSelection;
|
||||||
|
|
||||||
public class TransactionListView {
|
public class TransactionListView {
|
||||||
private WaveformViewer waveformViewer;
|
|
||||||
|
|
||||||
private TransactionList transactionList;
|
private TransactionList transactionList;
|
||||||
|
|
||||||
/** The event broker. */
|
|
||||||
@Inject IEventBroker eventBroker;
|
|
||||||
|
|
||||||
/** The selection service. */
|
|
||||||
@Inject ESelectionService selectionService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the composite.
|
|
||||||
* @param parent
|
|
||||||
* @param style
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Creates the composite.
|
* Creates the composite.
|
||||||
*
|
*
|
||||||
@@ -40,7 +20,6 @@ public class TransactionListView {
|
|||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void createComposite(final Composite parent, @Optional WaveformViewer waveformViewer) {
|
public void createComposite(final Composite parent, @Optional WaveformViewer waveformViewer) {
|
||||||
this.waveformViewer=waveformViewer;
|
|
||||||
transactionList = new TransactionList(parent, SWT.BORDER, waveformViewer);
|
transactionList = new TransactionList(parent, SWT.BORDER, waveformViewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,17 +29,14 @@ public class TransactionListView {
|
|||||||
transactionList.setFocus();
|
transactionList.setFocus();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Sets the selection.
|
* Receives selections directly from the owning waveform pane, independently of
|
||||||
|
* the workbench's active part and global selection injection.
|
||||||
*
|
*
|
||||||
* @param selection the new selection
|
* @param selection the new selection
|
||||||
*/
|
*/
|
||||||
@Inject
|
public void setSelection(IStructuredSelection selection) {
|
||||||
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){
|
if (transactionList != null && !transactionList.isDisposed())
|
||||||
// only react if selection is actually from the WaveformViewer and nothing else
|
transactionList.setInput(WaveformSelection.from(selection).track());
|
||||||
MPart part = partService.getActivePart();
|
|
||||||
if( part == null || ! (part.getObject() instanceof WaveformViewer ) || part.getObject() != waveformViewer)
|
|
||||||
return;
|
|
||||||
transactionList.setInput(WaveformSelection.from(selection).track());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionList getControl() {
|
public TransactionList getControl() {
|
||||||
|
|||||||
+3
-2
@@ -267,8 +267,9 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
|||||||
});
|
});
|
||||||
|
|
||||||
waveformPane.addSelectionChangedListener(event -> {
|
waveformPane.addSelectionChangedListener(event -> {
|
||||||
if (event.getSelection() instanceof IStructuredSelection) {
|
if (event.getSelection() instanceof IStructuredSelection selection) {
|
||||||
selectionService.setSelection(event.getSelection());
|
transactionList.setSelection(selection);
|
||||||
|
selectionService.setSelection(selection);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+24
@@ -34,6 +34,30 @@ public class TransactionQueryTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void discoveryIncludesLatePropertiesAndCachesTheCompleteSchema() {
|
||||||
|
AtomicInteger reads = new AtomicInteger();
|
||||||
|
Waveform wave = new Waveform();
|
||||||
|
ITxAttribute lateAttribute = (ITxAttribute) Proxy.newProxyInstance(getClass().getClassLoader(),
|
||||||
|
new Class<?>[]{ITxAttribute.class}, (p, m, a) -> switch (m.getName()) {
|
||||||
|
case "getName" -> "late";
|
||||||
|
case "getDataType" -> DataType.STRING;
|
||||||
|
default -> "later value";
|
||||||
|
});
|
||||||
|
ITx late = (ITx) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{ITx.class},
|
||||||
|
(p, m, a) -> {
|
||||||
|
if (m.getName().equals("getAttributes")) { reads.incrementAndGet(); return List.of(lateAttribute); }
|
||||||
|
return 3L;
|
||||||
|
});
|
||||||
|
wave.transactions = List.of(transaction(1, reads), transaction(2, reads), late);
|
||||||
|
TransactionQuery query = new TransactionQuery(wave);
|
||||||
|
assertEquals(List.of(new TransactionQuery.Attribute("field", DataType.STRING),
|
||||||
|
new TransactionQuery.Attribute("late", DataType.STRING)), query.discoverAttributes(() -> false));
|
||||||
|
assertEquals(3, reads.get());
|
||||||
|
query.discoverAttributes(() -> false);
|
||||||
|
assertEquals(3, reads.get());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerQueriesAndIndexedRestorationNeverReadAttributesOrEvents() {
|
public void headerQueriesAndIndexedRestorationNeverReadAttributesOrEvents() {
|
||||||
AtomicInteger reads = new AtomicInteger();
|
AtomicInteger reads = new AtomicInteger();
|
||||||
|
|||||||
+216
@@ -0,0 +1,216 @@
|
|||||||
|
package com.minres.scviewer.e4.application.parts;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
|
import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.widgets.Button;
|
||||||
|
import org.eclipse.swt.widgets.Combo;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.swt.widgets.Event;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.eclipse.swt.widgets.Table;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.minres.scviewer.database.DataType;
|
||||||
|
import com.minres.scviewer.database.EmptyWaveform;
|
||||||
|
import com.minres.scviewer.database.IEventList;
|
||||||
|
import com.minres.scviewer.database.WaveformType;
|
||||||
|
import com.minres.scviewer.database.tx.ITx;
|
||||||
|
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||||
|
import com.minres.scviewer.database.tx.ITransactionProvider;
|
||||||
|
import com.minres.scviewer.database.ui.TrackEntry;
|
||||||
|
|
||||||
|
public class TransactionListPropertiesTest {
|
||||||
|
private static class Stream extends EmptyWaveform implements ITransactionProvider {
|
||||||
|
List<ITx> transactions;
|
||||||
|
@Override public WaveformType getType() { return WaveformType.STREAM; }
|
||||||
|
@Override public List<ITx> getTransactionList() { return transactions; }
|
||||||
|
@Override public ITx getTransaction(long id) { return transactions.stream().filter(tx -> tx.getId() == id).findFirst().orElse(null); }
|
||||||
|
@Override public IEventList getEvents() { throw new AssertionError("Property discovery must use indexed headers"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private Display display;
|
||||||
|
private Shell shell;
|
||||||
|
private WaveformViewer viewer;
|
||||||
|
private TransactionList list;
|
||||||
|
private TransactionListView listView;
|
||||||
|
private Combo search;
|
||||||
|
private Combo shown;
|
||||||
|
private Table table;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void createControls() {
|
||||||
|
assumeTrue("GTK integration tests require DISPLAY", !"gtk".equals(SWT.getPlatform()) || System.getenv("DISPLAY") != null);
|
||||||
|
display = new Display();
|
||||||
|
shell = new Shell(display);
|
||||||
|
shell.setSize(1000, 500);
|
||||||
|
viewer = new WaveformViewer() {
|
||||||
|
@Override public String getScaledTime(Long time) { return time.toString(); }
|
||||||
|
};
|
||||||
|
listView = new TransactionListView();
|
||||||
|
listView.createComposite(shell, viewer);
|
||||||
|
list = listView.getControl();
|
||||||
|
var combos = Arrays.stream(list.getChildren()).filter(Combo.class::isInstance).map(Combo.class::cast).toList();
|
||||||
|
search = combos.get(0); shown = combos.get(1);
|
||||||
|
table = Arrays.stream(list.getChildren()).filter(Table.class::isInstance).map(Table.class::cast).findFirst().orElseThrow();
|
||||||
|
assertFalse(Arrays.stream(list.getChildren()).anyMatch(Button.class::isInstance));
|
||||||
|
shell.layout(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void disposeControls() {
|
||||||
|
if (display == null) return;
|
||||||
|
try {
|
||||||
|
if (shell != null && !shell.isDisposed()) shell.dispose();
|
||||||
|
if (viewer != null) viewer.closeDatabase();
|
||||||
|
while (display.readAndDispatch()) {}
|
||||||
|
} finally { display.dispose(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void await(BooleanSupplier condition) throws Exception {
|
||||||
|
long deadline = System.nanoTime() + 10_000_000_000L;
|
||||||
|
while (!condition.getAsBoolean()) {
|
||||||
|
while (display.readAndDispatch()) {}
|
||||||
|
if (System.nanoTime() > deadline) fail("Timed out waiting for transaction properties");
|
||||||
|
Thread.sleep(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITxAttribute attribute(String name, String value) {
|
||||||
|
return (ITxAttribute) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{ITxAttribute.class},
|
||||||
|
(p, m, a) -> switch (m.getName()) {
|
||||||
|
case "getName" -> name;
|
||||||
|
case "getDataType" -> DataType.STRING;
|
||||||
|
case "getValue" -> value;
|
||||||
|
default -> null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITx transaction(long id, ITxAttribute... attributes) {
|
||||||
|
return (ITx) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{ITx.class},
|
||||||
|
(p, m, a) -> switch (m.getName()) {
|
||||||
|
case "getId" -> id;
|
||||||
|
case "getBeginTime" -> 0L;
|
||||||
|
case "getEndTime" -> 1L;
|
||||||
|
case "getAttributes" -> List.of(attributes);
|
||||||
|
case "hashCode" -> System.identityHashCode(p);
|
||||||
|
case "equals" -> p == a[0];
|
||||||
|
case "toString" -> "tx#" + id;
|
||||||
|
default -> null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void input(ITx... transactions) {
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.transactions = List.of(transactions);
|
||||||
|
listView.setSelection(new StructuredSelection(new TrackEntry(stream, null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void automaticDiscoveryPreservesPropertyChosenByDetailsSearch() throws Exception {
|
||||||
|
List<ITx> transactions = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 32; i++) transactions.add(transaction(i, attribute("alpha", "first")));
|
||||||
|
transactions.add(transaction(32, attribute("late", "last")));
|
||||||
|
input(transactions.toArray(new ITx[0]));
|
||||||
|
list.setSearchProps("late", DataType.STRING, "last");
|
||||||
|
await(() -> shown.getItemCount() == 2 && table.getItemCount() == 1);
|
||||||
|
assertEquals("late [STRING]", search.getText());
|
||||||
|
assertEquals("late [STRING]", shown.getText());
|
||||||
|
assertEquals("last", table.getItem(0).getText(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void selectingTrackAutomaticallyShowsPropertyNamesAndValues() throws Exception {
|
||||||
|
input(transaction(1, attribute("address", "value")));
|
||||||
|
await(() -> shown.getSelectionIndex() >= 0 && table.getItemCount() == 1);
|
||||||
|
assertEquals("address [STRING]", shown.getText());
|
||||||
|
assertEquals("address [STRING]", search.getText());
|
||||||
|
assertEquals("value", table.getItem(0).getText(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void automaticDiscoveryFindsPropertiesBeyondTheFirst32Transactions() throws Exception {
|
||||||
|
List<ITx> transactions = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 32; i++) transactions.add(transaction(i, attribute("alpha", "first"), attribute("beta", "second")));
|
||||||
|
transactions.add(transaction(32, attribute("late", "last")));
|
||||||
|
input(transactions.toArray(new ITx[0]));
|
||||||
|
await(() -> shown.getItemCount() == 3 && table.getItemCount() == 33);
|
||||||
|
shown.select(1); shown.notifyListeners(SWT.Selection, new Event());
|
||||||
|
assertEquals("second", table.getItem(0).getText(2));
|
||||||
|
assertTrue(Arrays.asList(shown.getItems()).contains("late [STRING]"));
|
||||||
|
list.setVisible(false);
|
||||||
|
list.setVisible(true);
|
||||||
|
await(() -> table.getItemCount() == 33);
|
||||||
|
assertEquals("beta [STRING]", shown.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void remembersDisplayPropertyAcrossStreamsAndMissingProperties() throws Exception {
|
||||||
|
input(transaction(1, attribute("alpha", "first"), attribute("beta", "chosen")));
|
||||||
|
await(() -> shown.getItemCount() == 2 && table.getItemCount() == 1);
|
||||||
|
shown.select(1); shown.notifyListeners(SWT.Selection, new Event());
|
||||||
|
assertEquals("chosen", table.getItem(0).getText(2));
|
||||||
|
|
||||||
|
// The preferred property is no longer the second entry in the new stream.
|
||||||
|
input(transaction(2, attribute("aardvark", "a"), attribute("alpha", "b"), attribute("beta", "restored")));
|
||||||
|
await(() -> shown.getItemCount() == 3 && table.getItemCount() == 1);
|
||||||
|
assertEquals("beta [STRING]", shown.getText());
|
||||||
|
assertEquals("restored", table.getItem(0).getText(2));
|
||||||
|
|
||||||
|
// A temporary fallback and a separator must not erase the user's preference.
|
||||||
|
input(transaction(3, attribute("other", "fallback")));
|
||||||
|
await(() -> shown.getText().equals("other [STRING]") && table.getItemCount() == 1);
|
||||||
|
assertEquals("fallback", table.getItem(0).getText(2));
|
||||||
|
listView.setSelection(new StructuredSelection(new TrackEntry(new EmptyWaveform(), null)));
|
||||||
|
input(transaction(4, attribute("alpha", "default"), attribute("beta", "remembered")));
|
||||||
|
await(() -> shown.getItemCount() == 2 && table.getItemCount() == 1);
|
||||||
|
assertEquals("beta [STRING]", shown.getText());
|
||||||
|
assertEquals("remembered", table.getItem(0).getText(2));
|
||||||
|
|
||||||
|
// A subsequent explicit choice replaces the remembered preference.
|
||||||
|
shown.select(0); shown.notifyListeners(SWT.Selection, new Event());
|
||||||
|
input(transaction(5, attribute("aardvark", "default"), attribute("alpha", "new preference"), attribute("beta", "old")));
|
||||||
|
await(() -> shown.getItemCount() == 3 && table.getItemCount() == 1);
|
||||||
|
assertEquals("alpha [STRING]", shown.getText());
|
||||||
|
assertEquals("new preference", table.getItem(0).getText(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hiddenViewDefersLoadingUntilShown() throws Exception {
|
||||||
|
list.setVisible(false);
|
||||||
|
input(transaction(1, attribute("address", "value")));
|
||||||
|
// Pump queued work: selecting a track while hidden must not start discovery.
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
while (display.readAndDispatch()) {}
|
||||||
|
Thread.sleep(5);
|
||||||
|
}
|
||||||
|
assertEquals(0, shown.getItemCount());
|
||||||
|
assertEquals(0, table.getItemCount());
|
||||||
|
list.setVisible(true);
|
||||||
|
await(() -> shown.getItemCount() == 1 && table.getItemCount() == 1);
|
||||||
|
assertEquals("address [STRING]", shown.getText());
|
||||||
|
assertEquals("value", table.getItem(0).getText(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void switchingTracksReplacesPropertiesAndSeparatorClearsThem() throws Exception {
|
||||||
|
input(transaction(1, attribute("old", "old value")));
|
||||||
|
input(transaction(2, attribute("new", "new value")));
|
||||||
|
await(() -> shown.getText().equals("new [STRING]") && table.getItemCount() == 1);
|
||||||
|
assertEquals("new value", table.getItem(0).getText(2));
|
||||||
|
listView.setSelection(new StructuredSelection(new TrackEntry(new EmptyWaveform(), null)));
|
||||||
|
assertEquals(0, shown.getItemCount());
|
||||||
|
assertEquals(0, search.getItemCount());
|
||||||
|
assertEquals(0, table.getItemCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user