Refactor viewer sessions and selections and optimize transaction queries
This commit is contained in:
1 parent
4824d48828
commit
589762b220
42 files changed
+1118
-720
No files matched your search
+6
-9
@@ -32,7 +32,7 @@ import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.RelationTypeFactory;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.ui.WaveformSelection;
|
||||
import com.minres.scviewer.e4.application.Messages;
|
||||
import com.minres.scviewer.e4.application.parts.PartListener;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewer;
|
||||
@@ -130,14 +130,11 @@ public class RelationTypeToolControl extends PartListener implements ISelectionC
|
||||
*/
|
||||
protected void checkSelection(ISelection selection) {
|
||||
if (disposed || comboViewer == null || comboViewer.getCombo().isDisposed()) return;
|
||||
if( selection instanceof IStructuredSelection) {
|
||||
Object object= ((IStructuredSelection)selection).getFirstElement();
|
||||
if(object instanceof ITx && waveformViewerPart!=null){
|
||||
comboViewer.getCombo().setEnabled(true);
|
||||
comboViewer.setInput(waveformViewerPart.getSelectionRelationTypes());//getAllRelationTypes());
|
||||
comboViewer.setSelection(new StructuredSelection(waveformViewerPart.getRelationTypeFilter()));
|
||||
return;
|
||||
}
|
||||
if (WaveformSelection.from(selection).transaction() != null && waveformViewerPart != null) {
|
||||
comboViewer.getCombo().setEnabled(true);
|
||||
comboViewer.setInput(waveformViewerPart.getSelectionRelationTypes());
|
||||
comboViewer.setSelection(new StructuredSelection(waveformViewerPart.getRelationTypeFilter()));
|
||||
return;
|
||||
}
|
||||
if(comboViewer!=null && !comboViewer.getCombo().isDisposed()) comboViewer.getCombo().setEnabled(false);
|
||||
}
|
||||
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package com.minres.scviewer.e4.application.internal.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
||||
/** Owns session replacement, callback validity, and reload monitoring, without SWT. */
|
||||
public final class DatabaseSessionManager implements AutoCloseable {
|
||||
private final IWaveformDbFactory factory;
|
||||
private final Consumer<Runnable> dispatch;
|
||||
private final Consumer<IWaveformDb> updated;
|
||||
private final Consumer<IWaveformDb> filesChanged;
|
||||
private final FileMonitor monitor;
|
||||
private final long checkInterval;
|
||||
private IWaveformDb database;
|
||||
private DatabaseLoadSession session;
|
||||
private List<File> files = List.of();
|
||||
private IFileChangeListener watcher;
|
||||
private IModificationChecker checker;
|
||||
private long watchGeneration;
|
||||
private boolean loading;
|
||||
private boolean reloadEnabled;
|
||||
private boolean closed;
|
||||
|
||||
public DatabaseSessionManager(IWaveformDbFactory factory, Consumer<Runnable> dispatch,
|
||||
Consumer<IWaveformDb> updated, Consumer<IWaveformDb> filesChanged, long checkInterval) {
|
||||
this.factory = factory;
|
||||
this.dispatch = dispatch;
|
||||
this.updated = updated;
|
||||
this.filesChanged = filesChanged;
|
||||
this.checkInterval = checkInterval;
|
||||
this.monitor = new FileMonitor();
|
||||
database = factory.getDatabase();
|
||||
}
|
||||
|
||||
/** Controller methods and dispatched callbacks run on the owning thread. */
|
||||
public IWaveformDb load(List<File> input, long delay, Consumer<IStatus> completion) {
|
||||
if (closed) throw new IllegalStateException("Database sessions are closed");
|
||||
stopWatching();
|
||||
if (session != null) {
|
||||
session.close();
|
||||
database = factory.getDatabase();
|
||||
}
|
||||
files = List.copyOf(input);
|
||||
IWaveformDb requested = database;
|
||||
requested.setName(files.stream().map(File::getName).collect(java.util.stream.Collectors.joining(",")));
|
||||
loading = true;
|
||||
session = new DatabaseLoadSession(requested, files, event -> dispatch.accept(() -> {
|
||||
if (isCurrent(requested)) updated.accept(requested);
|
||||
}), status -> dispatch.accept(() -> {
|
||||
if (!isCurrent(requested)) return;
|
||||
loading = false;
|
||||
completion.accept(status);
|
||||
if (isCurrent(requested) && status.isOK()) startWatching();
|
||||
}));
|
||||
session.schedule(delay);
|
||||
return requested;
|
||||
}
|
||||
|
||||
public IWaveformDb database() { return database; }
|
||||
|
||||
public boolean isCurrent(IWaveformDb requested) { return !closed && database == requested; }
|
||||
|
||||
public void setReloadEnabled(boolean enabled) {
|
||||
reloadEnabled = enabled;
|
||||
startWatching();
|
||||
}
|
||||
|
||||
public void checkFiles() {
|
||||
if (checker != null) checker.check();
|
||||
}
|
||||
|
||||
private void stopWatching() {
|
||||
++watchGeneration;
|
||||
if (watcher != null) monitor.removeFileChangeListener(watcher);
|
||||
watcher = null;
|
||||
checker = null;
|
||||
}
|
||||
|
||||
private void startWatching() {
|
||||
stopWatching();
|
||||
if (closed || loading || !reloadEnabled || session == null || !database.isLoaded()) return;
|
||||
long generation = watchGeneration;
|
||||
IWaveformDb requested = database;
|
||||
watcher = changed -> dispatch.accept(() -> {
|
||||
if (!isCurrent(requested) || !reloadEnabled || generation != watchGeneration) return;
|
||||
stopWatching();
|
||||
try { filesChanged.accept(requested); }
|
||||
finally {
|
||||
// Declining a reload acknowledges the current timestamps and resumes polling.
|
||||
if (isCurrent(requested)) startWatching();
|
||||
}
|
||||
});
|
||||
checker = monitor.addFileChangeListener(watcher, files, checkInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
stopWatching();
|
||||
monitor.dispose();
|
||||
if (session != null) session.close();
|
||||
else Job.create("Close Database", progress -> {
|
||||
database.close();
|
||||
return org.eclipse.core.runtime.Status.OK_STATUS;
|
||||
}).schedule();
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.minres.scviewer.e4.application.internal.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITransactionProvider;
|
||||
import com.minres.scviewer.database.tx.TransactionLists;
|
||||
|
||||
/** Cached transaction headers; attribute values are visited only on explicit request. */
|
||||
public final class TransactionQuery {
|
||||
public record Attribute(String name, DataType type) {}
|
||||
private final IWaveform waveform;
|
||||
private volatile List<ITx> transactions;
|
||||
private List<Attribute> attributes;
|
||||
|
||||
public TransactionQuery(IWaveform waveform) { this.waveform = waveform; }
|
||||
|
||||
public List<ITx> transactions(BooleanSupplier cancelled) {
|
||||
check(cancelled);
|
||||
List<ITx> result = transactions;
|
||||
if (result == null) {
|
||||
synchronized (this) {
|
||||
result = transactions;
|
||||
if (result == null) {
|
||||
try {
|
||||
result = waveform instanceof ITransactionProvider indexed ? indexed.getTransactionList()
|
||||
: TransactionLists.fromEvents(waveform.getEvents(), cancelled);
|
||||
} catch (java.util.concurrent.CancellationException e) { throw new OperationCanceledException(); }
|
||||
check(cancelled);
|
||||
transactions = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
check(cancelled);
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ITx> filter(Predicate<ITx> predicate, BooleanSupplier cancelled) {
|
||||
List<ITx> result = new ArrayList<>();
|
||||
for (ITx transaction : transactions(cancelled)) {
|
||||
check(cancelled);
|
||||
if (predicate.test(transaction)) result.add(transaction);
|
||||
}
|
||||
return List.copyOf(result);
|
||||
}
|
||||
|
||||
public synchronized List<Attribute> discoverAttributes(BooleanSupplier cancelled) {
|
||||
check(cancelled);
|
||||
if (attributes != null) return attributes;
|
||||
Map<String, DataType> types = new TreeMap<>();
|
||||
for (ITx transaction : transactions(cancelled)) {
|
||||
check(cancelled);
|
||||
transaction.getAttributes().forEach(attribute -> types.putIfAbsent(attribute.getName(), attribute.getDataType()));
|
||||
}
|
||||
check(cancelled);
|
||||
attributes = types.entrySet().stream().map(e -> new Attribute(e.getKey(), e.getValue())).toList();
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static void check(BooleanSupplier cancelled) {
|
||||
if (cancelled.getAsBoolean()) throw new OperationCanceledException();
|
||||
}
|
||||
}
|
||||
+84
-11
@@ -1,8 +1,12 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
package com.minres.scviewer.e4.application.internal.util;
|
||||
|
||||
import static com.minres.scviewer.e4.application.parts.WaveformViewer.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Properties;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -18,17 +22,84 @@ import com.minres.scviewer.database.ui.TrackEntry.ValueDisplay;
|
||||
import com.minres.scviewer.database.ui.TrackEntry.WaveDisplay;
|
||||
|
||||
/** Validates the existing properties format before any viewer state is changed. */
|
||||
record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale, Long baseline,
|
||||
Long transactionId, String transactionTrack, Boolean detailsShown) {
|
||||
record Track(String name, WaveformType type, ValueDisplay valueDisplay, WaveDisplay waveDisplay, boolean selected) {}
|
||||
public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale, Long baseline,
|
||||
Long transactionId, String transactionTrack, Boolean detailsShown, List<File> files) {
|
||||
public static final String DATABASE_FILE = "DATABASE_FILE";
|
||||
public static final String SHOWN_WAVEFORM = "SHOWN_WAVEFORM";
|
||||
public static final String WAVEFORM_TYPE = ".WAVEFORM_TYPE";
|
||||
public static final String VALUE_DISPLAY = ".VALUE_DISPLAY";
|
||||
public static final String WAVE_DISPLAY = ".WAVE_DISPLAY";
|
||||
public static final String SHOWN_CURSOR = "SHOWN_CURSOR";
|
||||
public static final String SCALING_FACTOR = "SCALING_FACTOR";
|
||||
public static final String BASE_LINE_TIME = "BASE_LINE_TIME";
|
||||
public static final String SELECTED_TX_ID = "SELECTED_TX_ID";
|
||||
public static final String SELECTED_TRACKENTRY_NAME = "SELECTED_TRACKENTRY_NAME";
|
||||
public static final String WAVEFORM_SELECTED = ".WAVEFORM_SELECTED";
|
||||
public static final String TX_DETAILS_SHOWN = "TX_DETAILS_SHOWN";
|
||||
|
||||
static ViewerSettings parse(Map<String, String> state) {
|
||||
public record Track(String name, WaveformType type, ValueDisplay valueDisplay, WaveDisplay waveDisplay, boolean selected) {}
|
||||
|
||||
public ViewerSettings {
|
||||
tracks = List.copyOf(tracks);
|
||||
cursors = List.copyOf(cursors);
|
||||
files = List.copyOf(files);
|
||||
}
|
||||
|
||||
public static ViewerSettings read(Path path) throws IOException {
|
||||
Properties properties = new Properties();
|
||||
try (java.io.InputStream input = Files.newInputStream(path)) { properties.load(input); }
|
||||
Map<String, String> state = new HashMap<>();
|
||||
properties.stringPropertyNames().forEach(key -> state.put(key, properties.getProperty(key)));
|
||||
return parse(state);
|
||||
}
|
||||
|
||||
public void write(Path path) throws IOException {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(toMap());
|
||||
try (java.io.OutputStream output = Files.newOutputStream(path)) { properties.store(output, "Written by SCViewer"); }
|
||||
}
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
Map<String, String> state = new HashMap<>();
|
||||
state.put(DATABASE_FILE + "S", Integer.toString(files.size()));
|
||||
for (int i = 0; i < files.size(); i++) state.put(DATABASE_FILE + i, files.get(i).getAbsolutePath());
|
||||
state.put(SHOWN_WAVEFORM + "S", Integer.toString(tracks.size()));
|
||||
for (int i = 0; i < tracks.size(); i++) {
|
||||
Track track = tracks.get(i);
|
||||
String key = SHOWN_WAVEFORM + i;
|
||||
state.put(key, track.name());
|
||||
if (track.type() != null) state.put(key + WAVEFORM_TYPE, track.type().name());
|
||||
state.put(key + WAVEFORM_SELECTED, Boolean.toString(track.selected()));
|
||||
state.put(key + VALUE_DISPLAY, track.valueDisplay().name());
|
||||
state.put(key + WAVE_DISPLAY, track.waveDisplay().name());
|
||||
}
|
||||
state.put(SHOWN_CURSOR + "S", Integer.toString(cursors.size()));
|
||||
for (int i = 0; i < cursors.size(); i++) state.put(SHOWN_CURSOR + i, cursors.get(i).toString());
|
||||
if (scale != null) state.put(SCALING_FACTOR, scale.toString());
|
||||
if (baseline != null) state.put(BASE_LINE_TIME, baseline.toString());
|
||||
if (transactionId != null && transactionTrack != null) {
|
||||
state.put(SELECTED_TX_ID, transactionId.toString());
|
||||
state.put(SELECTED_TRACKENTRY_NAME, transactionTrack);
|
||||
}
|
||||
if (detailsShown != null) state.put(TX_DETAILS_SHOWN, detailsShown.toString());
|
||||
return state;
|
||||
}
|
||||
|
||||
public void replaceState(Map<String, String> state) {
|
||||
state.keySet().removeIf(key -> key.startsWith(DATABASE_FILE) || key.startsWith(SHOWN_WAVEFORM)
|
||||
|| key.startsWith(SHOWN_CURSOR) || key.equals(SCALING_FACTOR) || key.equals(BASE_LINE_TIME)
|
||||
|| key.equals(SELECTED_TX_ID) || key.equals(SELECTED_TRACKENTRY_NAME) || key.equals(TX_DETAILS_SHOWN));
|
||||
state.putAll(toMap());
|
||||
}
|
||||
|
||||
public static ViewerSettings parse(Map<String, String> state) {
|
||||
List<Track> tracks = new ArrayList<>();
|
||||
int count = count(state, SHOWN_WAVEFORM + "S");
|
||||
for (int i = 0; i < count; i++) {
|
||||
String key = SHOWN_WAVEFORM + i;
|
||||
String name = required(state, key);
|
||||
WaveformType type = enumeration(state, key + WAVEFORM_TYPE, WaveformType.class, null);
|
||||
WaveformType type = "TRANSACTION".equals(state.get(key + WAVEFORM_TYPE)) ? WaveformType.STREAM
|
||||
: enumeration(state, key + WAVEFORM_TYPE, WaveformType.class, null);
|
||||
tracks.add(new Track(name, type,
|
||||
enumeration(state, key + VALUE_DISPLAY, ValueDisplay.class, ValueDisplay.DEFAULT),
|
||||
enumeration(state, key + WAVE_DISPLAY, WaveDisplay.class, WaveDisplay.DEFAULT),
|
||||
@@ -47,17 +118,17 @@ record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale, Long b
|
||||
String track = state.get(SELECTED_TRACKENTRY_NAME);
|
||||
if (tx != null) required(state, SELECTED_TRACKENTRY_NAME);
|
||||
return new ViewerSettings(List.copyOf(tracks), List.copyOf(cursors), scale, baseline,
|
||||
tx, track, bool(state, TX_DETAILS_SHOWN));
|
||||
tx, track, bool(state, TX_DETAILS_SHOWN), List.copyOf(databaseFiles(state)));
|
||||
}
|
||||
|
||||
static List<File> databaseFiles(Map<String, String> state) {
|
||||
public static List<File> databaseFiles(Map<String, String> state) {
|
||||
List<File> files = new ArrayList<>();
|
||||
for (int i = 0, n = count(state, DATABASE_FILE + "S"); i < n; i++)
|
||||
files.add(new File(required(state, DATABASE_FILE + i)));
|
||||
return files;
|
||||
}
|
||||
|
||||
static IWaveform resolveWaveform(IWaveformDb database, String name) {
|
||||
public static IWaveform resolveWaveform(IWaveformDb database, String name) {
|
||||
IWaveform waveform = database.getStreamByName(name);
|
||||
if (waveform != null) return waveform;
|
||||
int separator = name.lastIndexOf('.');
|
||||
@@ -68,7 +139,9 @@ record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale, Long b
|
||||
.filter(child -> name.substring(separator + 1).equals(child.getName())).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
static ITx findTransaction(IWaveform waveform, long id) {
|
||||
public static ITx findTransaction(IWaveform waveform, long id) {
|
||||
if (waveform instanceof com.minres.scviewer.database.tx.ITransactionProvider indexed)
|
||||
return indexed.getTransaction(id);
|
||||
for (EventEntry entry : waveform.getEvents().entrySet()) {
|
||||
if (entry.events == null) continue;
|
||||
for (IEvent event : entry.events)
|
||||
+3
-4
@@ -54,6 +54,7 @@ import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.ui.WaveformSelection;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.e4.application.Messages;
|
||||
import com.minres.scviewer.e4.application.parts.txTableTree.AbstractTransactionTreeContentProvider;
|
||||
@@ -393,10 +394,8 @@ public class TransactionDetails {
|
||||
MPart part = partService.getActivePart();
|
||||
if( part == null || ! (part.getObject() instanceof WaveformViewer ) || part.getObject() != waveformViewerPart)
|
||||
return;
|
||||
if(treeViewer!=null && selection!=null && !treeViewer.getTree().isDisposed() &&
|
||||
selection instanceof IStructuredSelection && !selection.isEmpty()) {
|
||||
setInput(selection.getFirstElement());
|
||||
}
|
||||
if (treeViewer != null && !treeViewer.getTree().isDisposed())
|
||||
setInput(WaveformSelection.from(selection).transaction());
|
||||
}
|
||||
}
|
||||
|
||||
+198
-277
@@ -1,316 +1,237 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.databinding.observable.list.ObservableList;
|
||||
import org.eclipse.core.databinding.observable.list.WritableList;
|
||||
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.ComboViewer;
|
||||
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ILazyContentProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.TableViewerColumn;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.EventEntry;
|
||||
import com.minres.scviewer.database.EventKind;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IEvent;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
import com.minres.scviewer.database.ui.TrackEntry;
|
||||
import com.minres.scviewer.database.ui.WaveformSelection;
|
||||
import com.minres.scviewer.e4.application.internal.util.LatestJob;
|
||||
import com.minres.scviewer.e4.application.parts.txTableTree.AbstractTransactionTreeContentProvider;
|
||||
import com.minres.scviewer.e4.application.internal.util.TransactionQuery;
|
||||
import com.minres.scviewer.e4.application.internal.util.TransactionQuery.Attribute;
|
||||
import com.minres.scviewer.e4.application.parts.txTableTree.AttributeLabelProvider;
|
||||
import com.minres.scviewer.e4.application.parts.txTableTree.TransactionTreeNode;
|
||||
import com.minres.scviewer.e4.application.parts.txTableTree.TransactionTreeNodeType;
|
||||
import com.minres.scviewer.e4.application.parts.txTableTree.TxFilter;
|
||||
|
||||
public class TransactionList extends Composite {
|
||||
public class AttributeNameBean {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public DataType getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(DataType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public AttributeNameBean(String name, DataType type) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
String name;
|
||||
DataType type;
|
||||
private final ComboViewer searchProperty;
|
||||
private final ComboViewer viewProperty;
|
||||
private final Text searchValue;
|
||||
private final TableViewer tableViewer;
|
||||
private final Button loadProperties;
|
||||
private final AttributeLabelProvider valueProvider;
|
||||
private final LatestJob<List<ITx>> rowsJob;
|
||||
private record PropertyDiscovery(List<Attribute> attributes, RuntimeException error) {}
|
||||
private final LatestJob<PropertyDiscovery> attributesJob;
|
||||
private final TxFilter filter = new TxFilter();
|
||||
private final Runnable applyFilter = this::refreshTransactions;
|
||||
private List<ITx> rows = List.of();
|
||||
private List<Attribute> attributes = List.of();
|
||||
private IWaveform stream;
|
||||
private TrackEntry track;
|
||||
private TransactionQuery query;
|
||||
|
||||
}
|
||||
public TransactionList(Composite parent, int style, WaveformViewer waveformViewer) {
|
||||
super(parent, style);
|
||||
parent.setLayout(new FillLayout());
|
||||
setLayout(new GridLayout(6, false));
|
||||
label("Property to match:");
|
||||
searchProperty = propertiesCombo();
|
||||
searchValue = new Text(this, SWT.BORDER);
|
||||
searchValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
||||
label("Property to show:");
|
||||
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);
|
||||
|
||||
private ComboViewer searchPropComboViewer = null;
|
||||
tableViewer = new TableViewer(this, SWT.VIRTUAL | SWT.FULL_SELECTION | SWT.BORDER);
|
||||
tableViewer.setUseHashlookup(true);
|
||||
tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1));
|
||||
tableViewer.getTable().setHeaderVisible(true);
|
||||
tableViewer.getTable().setLinesVisible(true);
|
||||
tableViewer.setContentProvider(new ILazyContentProvider() {
|
||||
@Override public void updateElement(int index) {
|
||||
if (index < rows.size()) tableViewer.replace(rows.get(index), index);
|
||||
}
|
||||
@Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
||||
@Override public void dispose() {}
|
||||
});
|
||||
column("Tx ID", 160, new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.NAME));
|
||||
column("Start time", 150, new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.TX_TIME));
|
||||
valueProvider = new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.VALUE);
|
||||
column("Property Value", 180, valueProvider);
|
||||
|
||||
private ComboViewer viewPropComboViewer = null;
|
||||
Display display = getDisplay();
|
||||
rowsJob = new LatestJob<>(task -> { if (!display.isDisposed()) display.asyncExec(task); }, result -> {
|
||||
if (isDisposed()) return;
|
||||
rows = result;
|
||||
tableViewer.setInput(rows);
|
||||
tableViewer.setItemCount(rows.size());
|
||||
});
|
||||
attributesJob = new LatestJob<>(task -> { if (!display.isDisposed()) display.asyncExec(task); }, result -> {
|
||||
if (isDisposed()) return;
|
||||
loadProperties.setEnabled(query != null);
|
||||
loadProperties.setText("Load properties");
|
||||
if (result.error() != null) {
|
||||
MessageDialog.openError(getShell(), "Cannot load properties", result.error().toString());
|
||||
return;
|
||||
}
|
||||
Object selected = ((IStructuredSelection) searchProperty.getSelection()).getFirstElement();
|
||||
String displayedProperty = valueProvider.getShowProp();
|
||||
attributes = result.attributes();
|
||||
searchProperty.setInput(attributes);
|
||||
viewProperty.setInput(attributes);
|
||||
if (attributes.contains(selected)) searchProperty.setSelection(new StructuredSelection(selected));
|
||||
else if (!attributes.isEmpty()) searchProperty.setSelection(new StructuredSelection(attributes.get(0)));
|
||||
attributes.stream().filter(attribute -> attribute.name().equals(displayedProperty)).findFirst()
|
||||
.ifPresent(attribute -> viewProperty.setSelection(new StructuredSelection(attribute)));
|
||||
loadProperties.setEnabled(query != null);
|
||||
});
|
||||
addListener(SWT.Show, event -> {
|
||||
getDisplay().timerExec(-1, applyFilter);
|
||||
refreshTransactions();
|
||||
});
|
||||
searchValue.addModifyListener(event -> requestFilter(200));
|
||||
searchProperty.addSelectionChangedListener(event -> {
|
||||
if (event.getSelection() instanceof IStructuredSelection selected && selected.getFirstElement() instanceof Attribute attribute) {
|
||||
filter.setSearchProp(attribute.name(), attribute.type());
|
||||
requestFilter(0);
|
||||
}
|
||||
});
|
||||
viewProperty.addSelectionChangedListener(event -> {
|
||||
if (event.getSelection() instanceof IStructuredSelection selected && selected.getFirstElement() instanceof Attribute attribute) {
|
||||
valueProvider.setShowProp(attribute.name());
|
||||
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 -> {
|
||||
if (event.getSelection() instanceof IStructuredSelection selected && selected.getFirstElement() instanceof ITx tx)
|
||||
waveformViewer.setSelection(WaveformSelection.of(tx, track));
|
||||
});
|
||||
addDisposeListener(event -> {
|
||||
display.timerExec(-1, applyFilter);
|
||||
rowsJob.close();
|
||||
attributesJob.close();
|
||||
});
|
||||
}
|
||||
|
||||
private Text searchPropValue;
|
||||
private void label(String text) { new Label(this, SWT.NONE).setText(text); }
|
||||
|
||||
private TableViewer tableViewer = null;
|
||||
private ComboViewer propertiesCombo() {
|
||||
ComboViewer combo = new ComboViewer(this, SWT.READ_ONLY);
|
||||
combo.setContentProvider(ArrayContentProvider.getInstance());
|
||||
combo.setLabelProvider(new LabelProvider() {
|
||||
@Override public String getText(Object element) {
|
||||
Attribute attribute = (Attribute) element;
|
||||
return attribute.name() + " [" + attribute.type() + "]";
|
||||
}
|
||||
});
|
||||
GridData layout = new GridData(SWT.FILL, SWT.CENTER, false, false);
|
||||
layout.widthHint = 140;
|
||||
combo.getCombo().setLayoutData(layout);
|
||||
return combo;
|
||||
}
|
||||
|
||||
private LatestJob<TransactionData> updateJob;
|
||||
private void column(String name, int width, AttributeLabelProvider provider) {
|
||||
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
|
||||
column.getColumn().setText(name);
|
||||
column.getColumn().setWidth(width);
|
||||
column.setLabelProvider(new DelegatingStyledCellLabelProvider(provider));
|
||||
}
|
||||
|
||||
private record TransactionData(List<ITx> transactions, List<AttributeNameBean> attributes) {}
|
||||
public void setInput(TrackEntry requestedTrack) {
|
||||
track = requestedTrack;
|
||||
IWaveform requestedStream = track != null && track.waveform.getType().isTransaction() ? track.waveform : null;
|
||||
if (requestedStream != null && stream == requestedStream) return;
|
||||
getDisplay().timerExec(-1, applyFilter);
|
||||
rowsJob.cancel();
|
||||
attributesJob.cancel();
|
||||
stream = requestedStream;
|
||||
query = stream == null ? null : new TransactionQuery(stream);
|
||||
rows = List.of();
|
||||
attributes = List.of();
|
||||
searchProperty.setInput(attributes);
|
||||
viewProperty.setInput(attributes);
|
||||
valueProvider.setShowProp(null);
|
||||
filter.setSearchProp(null, null);
|
||||
tableViewer.setInput(rows);
|
||||
tableViewer.setItemCount(0);
|
||||
loadProperties.setEnabled(query != null);
|
||||
loadProperties.setText("Load properties");
|
||||
requestFilter(0);
|
||||
}
|
||||
|
||||
private TableColumn valueColumn = null;
|
||||
private void requestFilter(int delay) {
|
||||
rowsJob.cancel();
|
||||
getDisplay().timerExec(-1, applyFilter);
|
||||
if (!getVisible()) return;
|
||||
if (delay == 0) refreshTransactions();
|
||||
else getDisplay().timerExec(delay, applyFilter);
|
||||
}
|
||||
|
||||
private AttributeLabelProvider valueLabelProvider = null;
|
||||
private void refreshTransactions() {
|
||||
if (isDisposed() || query == null) return;
|
||||
TransactionQuery requested = query;
|
||||
filter.setSearchValue(searchValue.getText());
|
||||
java.util.function.Predicate<ITx> predicate = filter.snapshot();
|
||||
boolean unfiltered = searchValue.getText().isEmpty();
|
||||
rowsJob.schedule("Read transactions", monitor -> unfiltered ? requested.transactions(monitor::isCanceled)
|
||||
: requested.filter(predicate, monitor::isCanceled));
|
||||
}
|
||||
|
||||
private IWaveform stream;
|
||||
|
||||
private ObservableList<AttributeNameBean> attrNames = new WritableList<>();
|
||||
|
||||
private List<ITx> emptyList = new ArrayList<>();
|
||||
|
||||
TxFilter txFilter;
|
||||
|
||||
/**
|
||||
* Create the composite.
|
||||
* @param parent
|
||||
* @param style
|
||||
*/
|
||||
public TransactionList(Composite parent, int style, WaveformViewer waveformViewer) {
|
||||
super(parent, style);
|
||||
parent.setLayout(new FillLayout());
|
||||
|
||||
setLayout(new GridLayout(5, false));
|
||||
txFilter = new TxFilter();
|
||||
|
||||
Label lbl1 = new Label(this, SWT.NONE);
|
||||
lbl1.setAlignment(SWT.RIGHT);
|
||||
lbl1.setText("Property to match:");
|
||||
lbl1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
|
||||
searchPropComboViewer = new ComboViewer(this, SWT.NONE);
|
||||
searchPropComboViewer.setLabelProvider(new LabelProvider() {
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
AttributeNameBean entry = (AttributeNameBean) element;
|
||||
return entry.getName()+" ["+entry.getType().toString()+"]";
|
||||
}
|
||||
});
|
||||
searchPropComboViewer.setContentProvider(new ObservableListContentProvider<AttributeNameBean>());
|
||||
searchPropComboViewer.setInput(attrNames);
|
||||
Combo searchPropCombo = searchPropComboViewer.getCombo();
|
||||
GridData gdSearchProp = new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1);
|
||||
gdSearchProp.widthHint=100;
|
||||
searchPropCombo.setLayoutData(gdSearchProp);
|
||||
searchPropCombo.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
extracted(searchPropCombo);
|
||||
}
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
extracted(searchPropCombo);
|
||||
}
|
||||
private void extracted(Combo searchPropCombo) {
|
||||
int idx = searchPropCombo.getSelectionIndex();
|
||||
if(idx<0) return;
|
||||
AttributeNameBean sel = attrNames.get(idx);
|
||||
txFilter.setSearchProp(sel.getName(), sel.getType());
|
||||
tableViewer.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
searchPropValue = new Text(this, SWT.BORDER);
|
||||
GridData gdSearchPropValue = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
||||
gdSearchPropValue.minimumWidth = 50;
|
||||
searchPropValue.setLayoutData(gdSearchPropValue);
|
||||
searchPropValue.addModifyListener(e -> {
|
||||
txFilter.setSearchValue(((Text) e.widget).getText());
|
||||
tableViewer.refresh();
|
||||
});
|
||||
|
||||
Label lbl2 = new Label(this, SWT.NONE);
|
||||
lbl2.setAlignment(SWT.RIGHT);
|
||||
lbl2.setText("Property to show:");
|
||||
lbl2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
|
||||
viewPropComboViewer = new ComboViewer(this, SWT.NONE);
|
||||
viewPropComboViewer.setLabelProvider(new LabelProvider() {
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
AttributeNameBean entry = (AttributeNameBean) element;
|
||||
return entry.getName()+" ["+entry.getType().toString()+"]";
|
||||
}
|
||||
});
|
||||
viewPropComboViewer.setContentProvider(new ObservableListContentProvider<AttributeNameBean>());
|
||||
viewPropComboViewer.setInput(attrNames);
|
||||
Combo viewPropCombo = viewPropComboViewer.getCombo();
|
||||
GridData gdviewProp = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
||||
gdviewProp.widthHint=100;
|
||||
viewPropCombo.setLayoutData(gdviewProp);
|
||||
viewPropCombo.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int idx = viewPropCombo.getSelectionIndex();
|
||||
if(idx<0) return;
|
||||
valueLabelProvider.setShowProp(attrNames.get(idx).getName());
|
||||
tableViewer.refresh(true);
|
||||
}
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) { /* do nothing */ }
|
||||
});
|
||||
|
||||
tableViewer = new TableViewer(this);
|
||||
tableViewer.setContentProvider(new AbstractTransactionTreeContentProvider(waveformViewer) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
if (inputElement instanceof List<?>) {
|
||||
return ((List<ITx>) inputElement).stream().map(tx-> new TransactionTreeNode(tx, TransactionTreeNodeType.TX)).collect(Collectors.toList()).toArray();
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
});
|
||||
tableViewer.addFilter(txFilter);
|
||||
tableViewer.addSelectionChangedListener(event -> {
|
||||
ISelection treeSelection = event.getSelection();
|
||||
if(treeSelection instanceof IStructuredSelection) {
|
||||
Object selected = ((IStructuredSelection)treeSelection).getFirstElement();
|
||||
if(selected instanceof ITx){
|
||||
waveformViewer.setSelection(new StructuredSelection(selected));
|
||||
} else if(selected instanceof TransactionTreeNode && ((TransactionTreeNode)selected).type == TransactionTreeNodeType.TX) {
|
||||
waveformViewer.setSelection(new StructuredSelection(((TransactionTreeNode)selected).element));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Table table = tableViewer.getTable();
|
||||
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
||||
|
||||
TableViewerColumn nameColumnViewer = new TableViewerColumn(tableViewer, SWT.NONE);
|
||||
TableColumn nameColumn = nameColumnViewer.getColumn();
|
||||
nameColumn.setWidth(200);
|
||||
nameColumn.setText("Tx ID");
|
||||
nameColumn.setResizable(true);
|
||||
nameColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.NAME)));
|
||||
|
||||
TableViewerColumn timeColumnViewer = new TableViewerColumn(tableViewer, SWT.NONE);
|
||||
TableColumn timeColumn = timeColumnViewer.getColumn();
|
||||
timeColumn.setAlignment(SWT.RIGHT);
|
||||
timeColumn.setWidth(150);
|
||||
timeColumn.setText("Start time");
|
||||
timeColumn.setResizable(true);
|
||||
timeColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.TX_TIME)));
|
||||
|
||||
TableViewerColumn valueColumnViewer = new TableViewerColumn(tableViewer, SWT.NONE);
|
||||
valueColumn = valueColumnViewer.getColumn();
|
||||
valueColumn.setWidth(150);
|
||||
valueColumn.setText("Property Value");
|
||||
valueColumn.setResizable(true);
|
||||
valueLabelProvider= new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.VALUE);
|
||||
valueColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(valueLabelProvider));
|
||||
|
||||
// Turn on the header and the lines
|
||||
table.setHeaderVisible(true);
|
||||
table.setLinesVisible(true);
|
||||
final Display display = getDisplay();
|
||||
updateJob = new LatestJob<>(task -> {
|
||||
if (!display.isDisposed()) display.asyncExec(task);
|
||||
}, data -> {
|
||||
if (isDisposed()) return;
|
||||
attrNames.addAll(data.attributes());
|
||||
if (!attrNames.isEmpty()) {
|
||||
txFilter.setSearchProp(attrNames.get(0).getName(), attrNames.get(0).getType());
|
||||
txFilter.setSearchValue(searchPropValue.getText());
|
||||
}
|
||||
tableViewer.setInput(data.transactions());
|
||||
searchPropComboViewer.refresh();
|
||||
viewPropComboViewer.refresh();
|
||||
});
|
||||
addDisposeListener(event -> {
|
||||
updateJob.close();
|
||||
attrNames.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
public void setInput(TrackEntry trackEntry) {
|
||||
final IWaveform requestedStream = trackEntry != null && trackEntry.waveform.getType().isTransaction()
|
||||
? trackEntry.waveform : null;
|
||||
if (requestedStream != null && stream == requestedStream) return;
|
||||
updateJob.cancel();
|
||||
stream = requestedStream;
|
||||
attrNames.clear();
|
||||
tableViewer.setInput(emptyList);
|
||||
if (requestedStream == null) return;
|
||||
|
||||
updateJob.schedule("Read transactions", monitor -> {
|
||||
final Map<String, DataType> propNames = new HashMap<>();
|
||||
final List<ITx> txList = new ArrayList<>();
|
||||
if (monitor.isCanceled()) throw new OperationCanceledException();
|
||||
for (EventEntry entry : requestedStream.getEvents().entrySet()) {
|
||||
if (monitor.isCanceled()) throw new OperationCanceledException();
|
||||
if (entry.events == null) continue;
|
||||
for (IEvent event : entry.events) {
|
||||
if (monitor.isCanceled()) throw new OperationCanceledException();
|
||||
if (event.getKind() == EventKind.BEGIN || event.getKind() == EventKind.SINGLE) {
|
||||
ITx tx = ((ITxEvent) event).getTransaction();
|
||||
tx.getAttributes().forEach(attr -> propNames.put(attr.getName(), attr.getDataType()));
|
||||
txList.add(tx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (monitor.isCanceled()) throw new OperationCanceledException();
|
||||
txList.sort((t1, t2) -> Long.compare(t1.getBeginTime(), t2.getBeginTime()));
|
||||
final List<AttributeNameBean> newAttrNames = propNames.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(e -> new AttributeNameBean(e.getKey(), e.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
return new TransactionData(txList, newAttrNames);
|
||||
});
|
||||
}
|
||||
|
||||
public void focusSearch() {
|
||||
if (isDisposed()) return;
|
||||
searchPropValue.setFocus();
|
||||
searchPropValue.selectAll();
|
||||
}
|
||||
|
||||
public void setSearchProps(String propName, DataType type, String propValue) {
|
||||
for (int i = 0; i < attrNames.size(); i++) {
|
||||
if (propName.equals(attrNames.get(i).getName())) {
|
||||
searchPropComboViewer.setSelection(new StructuredSelection(attrNames.get(i)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
txFilter.setSearchProp(propName, type);
|
||||
txFilter.setSearchValue(propValue);
|
||||
searchPropValue.setText(propValue);
|
||||
tableViewer.refresh();
|
||||
}
|
||||
public void focusSearch() {
|
||||
if (isDisposed()) return;
|
||||
searchValue.setFocus();
|
||||
searchValue.selectAll();
|
||||
}
|
||||
|
||||
public void setSearchProps(String name, DataType type, String value) {
|
||||
Attribute property = new Attribute(name, type);
|
||||
if (!attributes.contains(property)) {
|
||||
java.util.ArrayList<Attribute> known = new java.util.ArrayList<>(attributes);
|
||||
known.add(property);
|
||||
attributes = List.copyOf(known);
|
||||
searchProperty.setInput(attributes);
|
||||
viewProperty.setInput(attributes);
|
||||
}
|
||||
searchProperty.setSelection(new StructuredSelection(property));
|
||||
filter.setSearchProp(name, type);
|
||||
searchValue.setText(value);
|
||||
requestFilter(0);
|
||||
}
|
||||
}
|
||||
+2
-15
@@ -15,7 +15,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.minres.scviewer.database.ui.TrackEntry;
|
||||
import com.minres.scviewer.database.ui.WaveformSelection;
|
||||
|
||||
public class TransactionListView {
|
||||
private WaveformViewer waveformViewer;
|
||||
@@ -60,20 +60,7 @@ public class TransactionListView {
|
||||
MPart part = partService.getActivePart();
|
||||
if( part == null || ! (part.getObject() instanceof WaveformViewer ) || part.getObject() != waveformViewer)
|
||||
return;
|
||||
if(selection==null || selection.isEmpty())
|
||||
transactionList.setInput(null);
|
||||
else if(selection instanceof IStructuredSelection) {
|
||||
TrackEntry e = findTrackEntry(selection.toArray());
|
||||
if(e!=null)
|
||||
transactionList.setInput(e);
|
||||
}
|
||||
}
|
||||
|
||||
private TrackEntry findTrackEntry(Object[] elems) {
|
||||
for(Object o: elems)
|
||||
if(o instanceof TrackEntry)
|
||||
return (TrackEntry)o;
|
||||
return null;
|
||||
transactionList.setInput(WaveformSelection.from(selection).track());
|
||||
}
|
||||
|
||||
public TransactionList getControl() {
|
||||
|
||||
+57
-241
@@ -11,16 +11,12 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -76,7 +72,6 @@ import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.EmptyWaveform;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
@@ -91,18 +86,17 @@ import com.minres.scviewer.database.ui.ICursor;
|
||||
import com.minres.scviewer.database.ui.IWaveformView;
|
||||
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.ZoomKind;
|
||||
import com.minres.scviewer.database.ui.swt.Constants;
|
||||
import com.minres.scviewer.database.ui.swt.IToolTipContentProvider;
|
||||
import com.minres.scviewer.database.ui.swt.IToolTipHelpTextProvider;
|
||||
import com.minres.scviewer.database.ui.swt.WaveformViewFactory;
|
||||
import com.minres.scviewer.e4.application.AppModelId;
|
||||
import com.minres.scviewer.e4.application.internal.util.ViewerSettings;
|
||||
import com.minres.scviewer.e4.application.internal.util.DatabaseSessionManager;
|
||||
import com.minres.scviewer.e4.application.Messages;
|
||||
import com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl;
|
||||
import com.minres.scviewer.e4.application.internal.util.DatabaseLoadSession;
|
||||
import com.minres.scviewer.e4.application.internal.util.FileMonitor;
|
||||
import com.minres.scviewer.e4.application.internal.util.IFileChangeListener;
|
||||
import com.minres.scviewer.e4.application.internal.util.IModificationChecker;
|
||||
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
|
||||
|
||||
/**
|
||||
@@ -116,42 +110,6 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
/** The Constant ADD_WAVEFORM. */
|
||||
public static final String ADD_WAVEFORM = "AddWaveform"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant DATABASE_FILE. */
|
||||
protected static final String DATABASE_FILE = "DATABASE_FILE"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant SHOWN_WAVEFORM. */
|
||||
protected static final String SHOWN_WAVEFORM = "SHOWN_WAVEFORM"; //$NON-NLS-1$
|
||||
|
||||
protected static final String WAVEFORM_TYPE = ".WAVEFORM_TYPE"; //$NON-NLS-1$
|
||||
|
||||
protected static final String VALUE_DISPLAY = ".VALUE_DISPLAY"; //$NON-NLS-1$
|
||||
|
||||
protected static final String WAVE_DISPLAY = ".WAVE_DISPLAY"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant SHOWN_CURSOR. */
|
||||
protected static final String SHOWN_CURSOR = "SHOWN_CURSOR"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant ZOOM_LEVEL. */
|
||||
protected static final String SCALING_FACTOR = "SCALING_FACTOR"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant BASE_LINE_TIME. */
|
||||
protected static final String BASE_LINE_TIME = "BASE_LINE_TIME"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant SELECTED_TX_ID. */
|
||||
protected static final String SELECTED_TX_ID = "SELECTED_TX_ID"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant SELECTED_TRACKENTRY_NAME. */
|
||||
protected static final String SELECTED_TRACKENTRY_NAME = "SELECTED_TRACKENTRY_NAME"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant WAVEFORM_SELECTED. */
|
||||
protected static final String WAVEFORM_SELECTED = ".WAVEFORM_SELECTED"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant FILE_CHECK_INTERVAL. */
|
||||
protected static final long FILE_CHECK_INTERVAL = 60000;
|
||||
|
||||
/** The Constant TX_DETAILS_SHOWN. */
|
||||
protected static final String TX_DETAILS_SHOWN = "TX_DETAILS_SHOWN"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant ID. */
|
||||
public static final String ID = "com.minres.scviewer.ui.TxEditorPart"; //$NON-NLS-1$
|
||||
|
||||
@@ -198,26 +156,16 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
|
||||
IEclipsePreferences store = null;
|
||||
|
||||
/** The database. */
|
||||
private IWaveformDb database;
|
||||
|
||||
private volatile DatabaseLoadSession loadSession;
|
||||
private DatabaseSessionManager sessions;
|
||||
|
||||
private volatile boolean disposed;
|
||||
|
||||
private boolean loadingDatabase;
|
||||
|
||||
/** The check for updates. */
|
||||
private volatile boolean checkForUpdates;
|
||||
private boolean checkForUpdates;
|
||||
|
||||
private IEclipsePreferences observedPreferences;
|
||||
|
||||
private PartListener partListener;
|
||||
|
||||
private IFileChangeListener fileChangeListener;
|
||||
|
||||
private long fileWatchGeneration;
|
||||
|
||||
/** The my part. */
|
||||
@Inject private MPart myPart;
|
||||
|
||||
@@ -241,11 +189,6 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
/** The navigation relation type. */
|
||||
private RelationType navigationRelationType=IWaveformView.NEXT_PREV_IN_STREAM ;
|
||||
|
||||
/** The file monitor. */
|
||||
FileMonitor fileMonitor = new FileMonitor();
|
||||
|
||||
/** The file checker. */
|
||||
IModificationChecker fileChecker;
|
||||
|
||||
@Inject IWaveformDbFactory dbFactory;
|
||||
|
||||
@@ -276,12 +219,14 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
myParent = parent;
|
||||
store=prefs;
|
||||
showHover=hover;
|
||||
database = dbFactory.getDatabase();
|
||||
sessions = new DatabaseSessionManager(dbFactory, task -> sync.asyncExec(task),
|
||||
db -> { if (!isViewerDisposed()) waveformPane.setMaxTime(db.getMaxTime()); },
|
||||
db -> { if (!isViewerDisposed() && confirmReload()) reloadDatabase(); }, 60000);
|
||||
parent.setLayout(new FillLayout(SWT.HORIZONTAL));
|
||||
|
||||
IEclipseContext ctx = myPart.getContext();
|
||||
ctx.set(WaveformViewer.class, this);
|
||||
ctx.set(IWaveformDb.class, database);
|
||||
ctx.set(IWaveformDb.class, getDatabase());
|
||||
|
||||
topSash = new SashForm(parent, SWT.BORDER | SWT.SMOOTH | SWT.HORIZONTAL);
|
||||
Composite left = new Composite(topSash, SWT.NONE);
|
||||
@@ -390,6 +335,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
});
|
||||
|
||||
checkForUpdates = store.getBoolean(PreferenceConstants.DATABASE_RELOAD, true);
|
||||
sessions.setReloadEnabled(checkForUpdates);
|
||||
filesToLoad = new ArrayList<>();
|
||||
persistedState = part.getPersistedState();
|
||||
try {
|
||||
@@ -406,8 +352,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
@Override
|
||||
public void partActivated(MPart part) {
|
||||
if (part == myPart && !disposed) {
|
||||
if (fileChecker != null)
|
||||
fileChecker.check();
|
||||
sessions.checkFiles();
|
||||
updateAll();
|
||||
}
|
||||
}
|
||||
@@ -515,8 +460,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
public void closeDatabase() {
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
stopFileMonitoring();
|
||||
fileMonitor.dispose();
|
||||
if (sessions != null) sessions.close();
|
||||
if (observedPreferences != null) {
|
||||
observedPreferences.removePreferenceChangeListener(this);
|
||||
observedPreferences = null;
|
||||
@@ -525,8 +469,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
ePartService.removePartListener(partListener);
|
||||
partListener = null;
|
||||
}
|
||||
fileChecker = null;
|
||||
if (loadSession != null) loadSession.close();
|
||||
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -555,7 +498,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
@Optional
|
||||
public void reactOnReloadDatabaseChange(@Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE, value = PreferenceConstants.DATABASE_RELOAD) Boolean enabled) {
|
||||
checkForUpdates = Boolean.TRUE.equals(enabled);
|
||||
if (!disposed && waveformPane != null) sync.asyncExec(this::startFileMonitoring);
|
||||
if (!disposed && sessions != null) sync.asyncExec(() -> sessions.setReloadEnabled(checkForUpdates));
|
||||
}
|
||||
|
||||
protected boolean isViewerDisposed() {
|
||||
@@ -566,34 +509,6 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
return MessageDialog.openQuestion(myParent.getShell(), Messages.WaveformViewer_17, Messages.WaveformViewer_18);
|
||||
}
|
||||
|
||||
private void stopFileMonitoring() {
|
||||
++fileWatchGeneration;
|
||||
if (fileChangeListener != null) fileMonitor.removeFileChangeListener(fileChangeListener);
|
||||
fileChangeListener = null;
|
||||
fileChecker = null;
|
||||
}
|
||||
|
||||
private void startFileMonitoring() {
|
||||
stopFileMonitoring();
|
||||
if (disposed || loadingDatabase || !checkForUpdates || database == null || !database.isLoaded()
|
||||
|| loadSession == null || loadSession.isCancelled()) return;
|
||||
final long generation = fileWatchGeneration;
|
||||
final DatabaseLoadSession requestedSession = loadSession;
|
||||
fileChangeListener = files -> sync.asyncExec(() -> {
|
||||
if (isViewerDisposed() || !checkForUpdates
|
||||
|| loadSession != requestedSession || generation != fileWatchGeneration) return;
|
||||
stopFileMonitoring();
|
||||
boolean reload = false;
|
||||
try {
|
||||
reload = confirmReload();
|
||||
} finally {
|
||||
if (!reload && loadSession == requestedSession) startFileMonitoring();
|
||||
}
|
||||
if (reload && !disposed && loadSession == requestedSession) reloadDatabase();
|
||||
});
|
||||
fileChecker = fileMonitor.addFileChangeListener(fileChangeListener, List.copyOf(filesToLoad), FILE_CHECK_INTERVAL);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
|
||||
*/
|
||||
@@ -613,53 +528,28 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
|
||||
protected void loadDatabase(final Map<String, String> state, long delay) {
|
||||
if (disposed) return;
|
||||
stopFileMonitoring();
|
||||
if (loadSession != null) {
|
||||
setSelection(null);
|
||||
loadSession.close();
|
||||
waveformPane.getStreamList().clear();
|
||||
waveformPane.update();
|
||||
database = dbFactory.getDatabase();
|
||||
}
|
||||
loadingDatabase = true;
|
||||
final IWaveformDb requestedDatabase = database;
|
||||
final List<File> requestedFiles = List.copyOf(filesToLoad);
|
||||
setSelection(null);
|
||||
waveformPane.getStreamList().clear();
|
||||
waveformPane.update();
|
||||
final Map<String, String> requestedState = state == null ? Map.of() : new HashMap<>(state);
|
||||
final String requestedConfig = partConfig;
|
||||
// An input configuration applies once; reloads preserve the current layout.
|
||||
partConfig = "";
|
||||
requestedDatabase.setName(requestedFiles.stream().map(File::getName).collect(java.util.stream.Collectors.joining(",")));
|
||||
myPart.getContext().set(IWaveformDb.class, requestedDatabase);
|
||||
loadSession = new DatabaseLoadSession(requestedDatabase, requestedFiles, event -> {
|
||||
if (IHierNode.WAVEFORMS.equals(event.getPropertyName())
|
||||
|| IHierNode.LOADING_FINISHED.equals(event.getPropertyName())) {
|
||||
sync.asyncExec(() -> {
|
||||
if (isCurrentDatabase(requestedDatabase))
|
||||
waveformPane.setMaxTime(requestedDatabase.getMaxTime());
|
||||
});
|
||||
}
|
||||
}, result -> sync.asyncExec(() -> {
|
||||
if (!isCurrentDatabase(requestedDatabase)) return;
|
||||
loadingDatabase = false;
|
||||
IWaveformDb requested = sessions.load(filesToLoad, delay, result -> {
|
||||
IWaveformDb current = sessions.database();
|
||||
if (isViewerDisposed()) return;
|
||||
if (!result.isOK()) {
|
||||
MessageDialog.openWarning(myParent.getShell(), "Error loading database", result.getMessage());
|
||||
ePartService.hidePart(myPart, true);
|
||||
return;
|
||||
}
|
||||
waveformPane.setMaxTime(requestedDatabase.getMaxTime());
|
||||
waveformPane.setMaxTime(current.getMaxTime());
|
||||
if (!requestedState.isEmpty()) restoreWaveformViewerState(requestedState);
|
||||
if (!isCurrentDatabase(requestedDatabase)) return;
|
||||
if (isViewerDisposed() || !sessions.isCurrent(current)) return;
|
||||
if (requestedConfig != null && !requestedConfig.isEmpty()) loadState(requestedConfig);
|
||||
if (!isCurrentDatabase(requestedDatabase)) return;
|
||||
if (designBrowser != null) designBrowser.setWaveformDb(requestedDatabase);
|
||||
startFileMonitoring();
|
||||
}));
|
||||
loadSession.schedule(delay);
|
||||
}
|
||||
|
||||
private boolean isCurrentDatabase(IWaveformDb requestedDatabase) {
|
||||
return !disposed && !myParent.isDisposed() && database == requestedDatabase
|
||||
&& loadSession != null && !loadSession.isCancelled();
|
||||
if (isViewerDisposed() || !sessions.isCurrent(current)) return;
|
||||
if (designBrowser != null) designBrowser.setWaveformDb(current);
|
||||
});
|
||||
myPart.getContext().set(IWaveformDb.class, requested);
|
||||
}
|
||||
|
||||
public void reloadDatabase() {
|
||||
@@ -704,44 +594,19 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
*/
|
||||
@PersistState
|
||||
public void saveState(MPart part) {
|
||||
// save changes
|
||||
Map<String, String> persistingState = part.getPersistedState();
|
||||
persistingState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); //$NON-NLS-1$
|
||||
Integer index = 0;
|
||||
for (File file : filesToLoad) {
|
||||
persistingState.put(DATABASE_FILE + index, file.getAbsolutePath());
|
||||
index++;
|
||||
}
|
||||
saveWaveformViewerState(persistingState);
|
||||
captureSettings().replaceState(part.getPersistedState());
|
||||
}
|
||||
|
||||
public void saveState(String fileName){
|
||||
Map<String, String> persistingState = new HashMap<>();
|
||||
persistingState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); //$NON-NLS-1$
|
||||
Integer index = 0;
|
||||
for (File file : filesToLoad) {
|
||||
persistingState.put(DATABASE_FILE + index, file.getAbsolutePath());
|
||||
index++;
|
||||
}
|
||||
saveWaveformViewerState(persistingState);
|
||||
Properties props = new Properties();
|
||||
props.putAll(persistingState);
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(fileName)) {
|
||||
props.store(out, "Written by SCViewer"); //$NON-NLS-1$
|
||||
} catch (IOException e) {
|
||||
public void saveState(String fileName) {
|
||||
try { captureSettings().write(Path.of(fileName)); }
|
||||
catch (IOException | IllegalArgumentException e) {
|
||||
reportSettingsError("Cannot save settings", fileName + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void loadState(String fileName) {
|
||||
try (FileInputStream in = new FileInputStream(fileName)) {
|
||||
Properties props = new Properties();
|
||||
props.load(in);
|
||||
Map<String, String> state = new HashMap<>();
|
||||
for (String key : props.stringPropertyNames()) state.put(key, props.getProperty(key));
|
||||
applySettings(ViewerSettings.parse(state));
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
try { applySettings(ViewerSettings.read(Path.of(fileName))); }
|
||||
catch (IOException | IllegalArgumentException e) {
|
||||
reportSettingsError("Cannot load settings", fileName + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -757,63 +622,22 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
*
|
||||
* @param persistingState the persisted state
|
||||
*/
|
||||
protected void saveWaveformViewerState(Map<String, String> persistingState) {
|
||||
persistingState.put(SHOWN_WAVEFORM + "S", Integer.toString(waveformPane.getStreamList().size())); //$NON-NLS-1$
|
||||
Integer index = 0;
|
||||
for (TrackEntry trackEntry : waveformPane.getStreamList()) {
|
||||
persistingState.put(SHOWN_WAVEFORM + index, trackEntry.waveform.getFullName());
|
||||
persistingState.put(SHOWN_WAVEFORM + index + WAVEFORM_TYPE, trackEntry.waveform.getType().toString());
|
||||
persistingState.put(SHOWN_WAVEFORM + index + WAVEFORM_SELECTED, String.valueOf(trackEntry.selected).toUpperCase());
|
||||
if (trackEntry.waveform.getType()!=WaveformType.EMPTY) {
|
||||
persistingState.put(SHOWN_WAVEFORM + index + VALUE_DISPLAY, trackEntry.valueDisplay.toString());
|
||||
persistingState.put(SHOWN_WAVEFORM + index + WAVE_DISPLAY, trackEntry.waveDisplay.toString());
|
||||
}
|
||||
index++;
|
||||
}
|
||||
List<ICursor> cursors = waveformPane.getCursorList();
|
||||
persistingState.put(SHOWN_CURSOR + "S", Integer.toString(cursors.size())); //$NON-NLS-1$
|
||||
index = 0;
|
||||
for (ICursor cursor : cursors) {
|
||||
persistingState.put(SHOWN_CURSOR + index, Long.toString(cursor.getTime()));
|
||||
index++;
|
||||
}
|
||||
persistingState.put(SCALING_FACTOR, Long.toString(waveformPane.getWaveformZoom().getScale()));
|
||||
persistingState.put(BASE_LINE_TIME, Long.toString(waveformPane.getWaveformZoom().getMinVisibleTime()));
|
||||
|
||||
persistingState.remove(SELECTED_TX_ID);
|
||||
persistingState.remove(SELECTED_TRACKENTRY_NAME);
|
||||
// get selected transaction of a stream
|
||||
ISelection selection = waveformPane.getSelection();
|
||||
if (!selection.isEmpty()) {
|
||||
List<Object> sel = getISelection(selection);
|
||||
if(sel.size()>1 && sel.get(0) instanceof ITx && sel.get(1) instanceof TrackEntry) {
|
||||
ITx tx = (ITx) sel.get(0);
|
||||
TrackEntry te = (TrackEntry) sel.get(1);
|
||||
// get transaction id
|
||||
persistingState.put(SELECTED_TX_ID, Long.toString(tx.getId()));
|
||||
//get TrackEntry name
|
||||
String name = te.waveform.getFullName();
|
||||
persistingState.put(SELECTED_TRACKENTRY_NAME, name);
|
||||
}
|
||||
}
|
||||
persistingState.put(TX_DETAILS_SHOWN, Boolean.toString(store.getBoolean(PreferenceConstants.SHOW_TX_DETAILS, false)));
|
||||
protected void saveWaveformViewerState(Map<String, String> state) {
|
||||
captureSettings().replaceState(state);
|
||||
}
|
||||
|
||||
protected List<Object> getISelection(ISelection selection){
|
||||
List<Object> result = new LinkedList<> ();
|
||||
|
||||
if ( selection instanceof IStructuredSelection ) {
|
||||
Iterator<?> i = ((IStructuredSelection)selection).iterator();
|
||||
while (i.hasNext()){
|
||||
Object o = i.next ();
|
||||
if (o == null) {
|
||||
continue;
|
||||
}
|
||||
result.add(o);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private ViewerSettings captureSettings() {
|
||||
List<ViewerSettings.Track> tracks = waveformPane.getStreamList().stream()
|
||||
.map(t -> new ViewerSettings.Track(t.waveform.getFullName(), t.waveform.getType(),
|
||||
t.valueDisplay, t.waveDisplay, t.selected)).toList();
|
||||
WaveformSelection selection = WaveformSelection.from(waveformPane.getSelection());
|
||||
boolean selectedTransaction = selection.transaction() != null && selection.track() != null;
|
||||
return new ViewerSettings(tracks, waveformPane.getCursorList().stream().map(ICursor::getTime).toList(),
|
||||
waveformPane.getWaveformZoom().getScale(), waveformPane.getWaveformZoom().getMinVisibleTime(),
|
||||
selectedTransaction ? selection.transaction().getId() : null,
|
||||
selectedTransaction ? selection.track().waveform.getFullName() : null,
|
||||
store.getBoolean(PreferenceConstants.SHOW_TX_DETAILS, false), List.copyOf(filesToLoad));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore waveform viewer state.
|
||||
@@ -838,7 +662,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
IWaveform selectedWaveform = null;
|
||||
for (ViewerSettings.Track track : settings.tracks()) {
|
||||
IWaveform waveform = track.type() == WaveformType.EMPTY ? new EmptyWaveform(track.name())
|
||||
: ViewerSettings.resolveWaveform(database, track.name());
|
||||
: ViewerSettings.resolveWaveform(getDatabase(), track.name());
|
||||
if (waveform == null) {
|
||||
missing.add(track.name());
|
||||
continue;
|
||||
@@ -870,7 +694,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
if (settings.detailsShown() != null) showTxDetails(settings.detailsShown());
|
||||
waveformPane.update();
|
||||
if (selectedTransaction != null && transactionTrack != null)
|
||||
waveformPane.setSelection(new StructuredSelection(new Object[] {selectedTransaction, transactionTrack}));
|
||||
waveformPane.setSelection(WaveformSelection.of(selectedTransaction, transactionTrack));
|
||||
else waveformPane.setSelection(new StructuredSelection(selectedTracks));
|
||||
updateAll();
|
||||
if (!missing.isEmpty() && !disposed && !myParent.isDisposed())
|
||||
@@ -957,7 +781,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
* @return the database
|
||||
*/
|
||||
public IWaveformDb getDatabase() {
|
||||
return database;
|
||||
return sessions == null ? null : sessions.database();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1149,7 +973,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
public List<RelationType> getAllRelationTypes() {
|
||||
List<RelationType> res =new ArrayList<>();
|
||||
res.add(IWaveformView.NEXT_PREV_IN_STREAM);
|
||||
res.addAll(database.getAllRelationTypes());
|
||||
res.addAll(getDatabase().getAllRelationTypes());
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1161,20 +985,12 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
public List<RelationType> getSelectionRelationTypes() {
|
||||
List<RelationType> res =new ArrayList<>();
|
||||
res.add(IWaveformView.NEXT_PREV_IN_STREAM);
|
||||
ISelection selection = waveformPane.getSelection();
|
||||
if(selection instanceof IStructuredSelection && !selection.isEmpty()){
|
||||
IStructuredSelection sel=(IStructuredSelection) selection;
|
||||
if(sel.getFirstElement() instanceof ITx){
|
||||
ITx tx = (ITx) sel.getFirstElement();
|
||||
for(ITxRelation rel:tx.getIncomingRelations()){
|
||||
if(!res.contains(rel.getRelationType()))
|
||||
res.add(rel.getRelationType());
|
||||
}
|
||||
for(ITxRelation rel:tx.getOutgoingRelations()){
|
||||
if(!res.contains(rel.getRelationType()))
|
||||
res.add(rel.getRelationType());
|
||||
}
|
||||
}
|
||||
ITx transaction = WaveformSelection.from(waveformPane.getSelection()).transaction();
|
||||
if (transaction != null) {
|
||||
for (ITxRelation relation : transaction.getIncomingRelations())
|
||||
if (!res.contains(relation.getRelationType())) res.add(relation.getRelationType());
|
||||
for (ITxRelation relation : transaction.getOutgoingRelations())
|
||||
if (!res.contains(relation.getRelationType())) res.add(relation.getRelationType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
+9
@@ -57,6 +57,14 @@ public class TxFilter extends ViewerFilter {
|
||||
}
|
||||
}
|
||||
|
||||
/** A worker receives an independent filter, never mutable UI state. */
|
||||
public java.util.function.Predicate<ITx> snapshot() {
|
||||
TxFilter copy = new TxFilter();
|
||||
copy.setSearchProp(searchProp, searchType);
|
||||
copy.setSearchValue(searchValue);
|
||||
return transaction -> copy.select(null, null, transaction);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@@ -70,6 +78,7 @@ public class TxFilter extends ViewerFilter {
|
||||
else if(element instanceof TransactionTreeNode && ((TransactionTreeNode)element).type == TransactionTreeNodeType.TX)
|
||||
iTx = ((TransactionTreeNode)element).element;
|
||||
if(iTx==null) return true;
|
||||
if (searchProp == null || searchType == null) return true;
|
||||
List<ITxAttribute> res = iTx.getAttributes().stream().filter(a -> searchProp.equals(a.getName())).collect(Collectors.toList());
|
||||
if(res.size()==1) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user