Refactor viewer sessions and selections and optimize transaction queries

This commit is contained in:
eyck committed 2026-11-15 10:08:36 +01:00
1 parent 4824d48828
commit 589762b220
42 files changed
+1118 -720

No files matched your search

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@@ -101,4 +101,4 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=17
@@ -0,0 +1,47 @@
package com.minres.scviewer.database.ui;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import com.minres.scviewer.database.tx.ITx;
/** The selected transaction and tracks, with JFace conversion at the UI boundary. */
public record WaveformSelection(ITx transaction, List<TrackEntry> tracks) {
public WaveformSelection {
tracks = tracks.stream().filter(java.util.Objects::nonNull).toList();
}
public static WaveformSelection from(ISelection selection) {
if (!(selection instanceof IStructuredSelection structured)) return new WaveformSelection(null, List.of());
ITx transaction = null;
List<TrackEntry> tracks = new ArrayList<>();
for (Object element : structured.toArray()) {
if (element instanceof ITx tx && transaction == null) transaction = tx;
if (element instanceof TrackEntry track) tracks.add(track);
}
return new WaveformSelection(transaction, tracks);
}
public TrackEntry track() {
if (transaction == null) return tracks.isEmpty() ? null : tracks.get(0);
return tracks.stream().filter(t -> t.waveform == transaction.getStream()
|| t.waveform == transaction.getGenerator()).findFirst().orElse(null);
}
public IStructuredSelection toSelection() {
List<Object> elements = new ArrayList<>();
if (transaction != null) elements.add(transaction);
TrackEntry primary = track();
if (primary != null) elements.add(primary);
for (TrackEntry track : tracks) if (track != primary) elements.add(track);
return new StructuredSelection(elements);
}
public static IStructuredSelection of(ITx transaction, TrackEntry track) {
return new WaveformSelection(transaction, track == null ? List.of() : List.of(track)).toSelection();
}
}
@@ -19,7 +19,6 @@ import java.util.Map.Entry;
import java.util.Optional;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
@@ -46,6 +45,7 @@ import com.minres.scviewer.database.ui.IWaveformStyleProvider;
import com.minres.scviewer.database.ui.IWaveformView;
import com.minres.scviewer.database.ui.IWaveformZoom;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.WaveformSelection;
import com.minres.scviewer.database.ui.ZoomKind;
import com.minres.scviewer.database.ui.swt.Constants;
import com.minres.scviewer.database.ui.swt.internal.slider.ZoomBar;
@@ -458,17 +458,12 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
}
public void setSelected(ISelection selection) {
if(selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection)selection;
Object[] selList = structuredSelection.toArray();
currentSelectedTrack = (selList.length> 1 && selList[1] instanceof TrackEntry) ? (TrackEntry) selList[1] : null;
currentSelectedTx = (selList.length> 0 && selList[0] instanceof ITx)? (ITx) selList[0] : null;
if(currentSelectedTx != null)
reveal(currentSelectedTx);
arrowPainter.updateSelection();
if(!isDisposed())
redraw();
}
WaveformSelection selected = WaveformSelection.from(selection);
currentSelectedTrack = selected.track();
currentSelectedTx = selected.transaction();
if (currentSelectedTx != null) reveal(currentSelectedTx);
arrowPainter.updateSelection();
if (!isDisposed()) redraw();
}
public void reveal(ITx tx) {
@@ -91,6 +91,7 @@ import com.minres.scviewer.database.ui.IWaveformView;
import com.minres.scviewer.database.ui.IWaveformZoom;
import com.minres.scviewer.database.ui.IWaveformviewEventListener;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.WaveformSelection;
import com.minres.scviewer.database.ui.TrackEntry.HierState;
import com.minres.scviewer.database.ui.swt.internal.slider.ZoomBar;
@@ -806,12 +807,7 @@ public class WaveformView implements IWaveformView {
*/
@Override
public ISelection getSelection() {
ArrayList<Object> sel = new ArrayList<>();
if (currentTxSelection != null) {
sel.add(currentTxSelection);
}
sel.addAll(currentWaveformSelection);
return new StructuredSelection(sel.toArray());
return new WaveformSelection(currentTxSelection, currentWaveformSelection).toSelection();
}
/*
@@ -851,62 +847,38 @@ public class WaveformView implements IWaveformView {
}
public void setSelection(ISelection selection, boolean add, boolean addIfNeeded) {
boolean selectionChanged = false;
currentWaveformSelection.forEach(e -> {if(e!=null) e.selected = false;});
if (selection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) selection;
if (sel.size() == 0) {
selectionChanged = currentTxSelection != null || currentWaveformSelection != null;
currentTxSelection = null;
currentWaveformSelection.clear();
} else {
if (!add)
currentWaveformSelection.clear();
List<?> selList = sel.toList();
for(Object o: selList) {
if (o instanceof ITx) {
ITx txSel = (ITx) o;
TrackEntry trackEntry = selList.size() == 2 && selList.get(1) instanceof TrackEntry
? (TrackEntry) selList.get(1)
: null;
if (trackEntry == null) {
trackEntry = getEntryFor(txSel);
if (trackEntry == null && addIfNeeded) {
IWaveform stream = txSel.getStream();
Optional<TrackEntry> te = streams.stream().filter(e -> stream.equals(e.waveform)).findFirst();
if (te.isEmpty()) { // add stream only if really needed
trackEntry = new TrackEntry(txSel.getStream(), styleProvider);
streams.add(trackEntry);
}
}
}
currentTxSelection = txSel;
currentWaveformSelection.clear();
currentWaveformSelection.add(trackEntry);
selectionChanged = true;
} else if (o instanceof TrackEntry) {
TrackEntry e = (TrackEntry)o;
if(!currentWaveformSelection.contains(e))
currentWaveformSelection.add(e);
selectionChanged = true;
}
WaveformSelection requested = WaveformSelection.from(selection);
currentWaveformSelection.forEach(e -> e.selected = false);
if (!add || (requested.transaction() == null && requested.tracks().isEmpty())) {
currentWaveformSelection.clear();
currentTxSelection = null;
}
if (requested.transaction() != null) {
ITx transaction = requested.transaction();
TrackEntry track = requested.track();
if (track == null) track = getEntryFor(transaction);
if (track == null && addIfNeeded) {
track = getEntryFor(transaction.getStream());
if (track == null) {
track = new TrackEntry(transaction.getStream(), styleProvider);
streams.add(track);
}
}
} else {
if (currentTxSelection != null || !currentWaveformSelection.isEmpty())
selectionChanged = true;
currentTxSelection = null;
currentWaveformSelection.clear();
if (track != null) currentWaveformSelection.add(track);
currentTxSelection = track == null ? null : transaction;
} else {
for (TrackEntry track : requested.tracks())
if (!currentWaveformSelection.contains(track)) currentWaveformSelection.add(track);
}
currentWaveformSelection.forEach(e -> {if(e!=null)e.selected = true;});
if (selectionChanged) {
currentWaveformSelection.forEach(e -> waveformCanvas.reveal(e.waveform));
waveformCanvas.setSelected(getSelection());
valueList.redraw();
nameList.redraw();
fireSelectionChanged();
}
currentWaveformSelection.forEach(e -> {
e.selected = true;
waveformCanvas.reveal(e.waveform);
});
waveformCanvas.setSelected(getSelection());
valueList.redraw();
nameList.redraw();
fireSelectionChanged();
}
protected void fireSelectionChanged() {