replace TreeViewer with TableViewer in TransactionList

This commit is contained in:
Eyck Jentzsch 2020-11-11 17:55:10 +01:00
parent d47db29b93
commit 90249dadb9
8 changed files with 88 additions and 60 deletions

View File

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name Bundle-Name: %Bundle-Name
Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true
Bundle-Version: 2.9.1.qualifier Bundle-Version: 2.9.2.qualifier
Bundle-Vendor: %Bundle-Vendor Bundle-Vendor: %Bundle-Vendor
Require-Bundle: javax.inject;bundle-version="1.0.0", Require-Bundle: javax.inject;bundle-version="1.0.0",
org.eclipse.core.runtime;bundle-version="3.11.1", org.eclipse.core.runtime;bundle-version="3.11.1",

View File

@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>com.minres.scviewer.e4.application</artifactId> <artifactId>com.minres.scviewer.e4.application</artifactId>
<version>2.9.1-SNAPSHOT</version> <version>2.9.2-SNAPSHOT</version>
<parent> <parent>
<groupId>com.minres.scviewer</groupId> <groupId>com.minres.scviewer</groupId>
<artifactId>com.minres.scviewer.parent</artifactId> <artifactId>com.minres.scviewer.parent</artifactId>

View File

@ -12,11 +12,12 @@ import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyListener;
@ -26,9 +27,10 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
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 org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import com.minres.scviewer.database.DataType; import com.minres.scviewer.database.DataType;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
@ -73,11 +75,11 @@ public class TransactionList extends Composite {
private Text searchPropValue; private Text searchPropValue;
private TreeViewer treeViewer = null; private TableViewer tableViewer = null;
private TreeColumn valueColumn = null; private TableColumn valueColumn = null;
private AttributeLabelProvider nameLabelProvider = null; private AttributeLabelProvider valueLabelProvider = null;
private ITxStream<? extends ITxEvent> stream; private ITxStream<? extends ITxEvent> stream;
@ -96,9 +98,14 @@ public class TransactionList extends Composite {
*/ */
public TransactionList(Composite parent, int style, WaveformViewer waveformViewer) { public TransactionList(Composite parent, int style, WaveformViewer waveformViewer) {
super(parent, style); super(parent, style);
setLayout(new GridLayout(3, false)); setLayout(new GridLayout(5, false));
txFilter = new TxFilter(); 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 = new ComboViewer(this, SWT.NONE);
searchPropComboViewer.setLabelProvider(new LabelProvider() { searchPropComboViewer.setLabelProvider(new LabelProvider() {
public String getText(Object element) { public String getText(Object element) {
@ -116,27 +123,34 @@ public class TransactionList extends Composite {
int idx = searchPropCombo.getSelectionIndex(); int idx = searchPropCombo.getSelectionIndex();
AttributeNameBean sel = attrNames.get(idx); AttributeNameBean sel = attrNames.get(idx);
txFilter.setSearchProp(sel.getName(), sel.getType()); txFilter.setSearchProp(sel.getName(), sel.getType());
treeViewer.refresh(); tableViewer.refresh();
} }
@Override @Override
public void widgetDefaultSelected(SelectionEvent e) { public void widgetDefaultSelected(SelectionEvent e) {
int idx = searchPropCombo.getSelectionIndex(); int idx = searchPropCombo.getSelectionIndex();
AttributeNameBean sel = attrNames.get(idx); AttributeNameBean sel = attrNames.get(idx);
txFilter.setSearchProp(sel.getName(), sel.getType()); txFilter.setSearchProp(sel.getName(), sel.getType());
treeViewer.refresh(); tableViewer.refresh();
} }
}); });
searchPropValue = new Text(this, SWT.BORDER); searchPropValue = new Text(this, SWT.BORDER);
searchPropValue.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); GridData gd_searchPropValue = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
gd_searchPropValue.minimumWidth = 50;
searchPropValue.setLayoutData(gd_searchPropValue);
searchPropValue.addModifyListener(new ModifyListener() { searchPropValue.addModifyListener(new ModifyListener() {
@Override @Override
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
txFilter.setSearchValue(((Text) e.widget).getText()); txFilter.setSearchValue(((Text) e.widget).getText());
treeViewer.refresh(); 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 = new ComboViewer(this, SWT.NONE);
viewPropComboViewer.setLabelProvider(new LabelProvider() { viewPropComboViewer.setLabelProvider(new LabelProvider() {
public String getText(Object element) { public String getText(Object element) {
@ -152,15 +166,15 @@ public class TransactionList extends Composite {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int idx = viewPropCombo.getSelectionIndex(); int idx = viewPropCombo.getSelectionIndex();
nameLabelProvider.setShowProp(attrNames.get(idx).getName()); valueLabelProvider.setShowProp(attrNames.get(idx).getName());
treeViewer.refresh(true); tableViewer.refresh(true);
} }
@Override @Override
public void widgetDefaultSelected(SelectionEvent e) { } public void widgetDefaultSelected(SelectionEvent e) { }
}); });
treeViewer = new TreeViewer(this); tableViewer = new TableViewer(this);
treeViewer.setContentProvider(new AbstractTransactionTreeContentProvider(waveformViewer) { tableViewer.setContentProvider(new AbstractTransactionTreeContentProvider(waveformViewer) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@ -171,66 +185,65 @@ public class TransactionList extends Composite {
return new Object[0]; return new Object[0];
} }
}); });
treeViewer.addFilter(txFilter); tableViewer.addFilter(txFilter);
treeViewer.addDoubleClickListener(new IDoubleClickListener() { tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override @Override
public void doubleClick(DoubleClickEvent event) { public void doubleClick(DoubleClickEvent event) {
ITreeSelection treeSelection = treeViewer.getStructuredSelection(); ISelection treeSelection = tableViewer.getSelection();
Object selected = treeSelection.getFirstElement(); if(treeSelection instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection)treeSelection).getFirstElement();
if(selected instanceof ITx){ if(selected instanceof ITx){
waveformViewer.setSelection(new StructuredSelection(selected)); waveformViewer.setSelection(new StructuredSelection(selected));
} else if(selected instanceof TransactionTreeNode && ((TransactionTreeNode)selected).type == TransactionTreeNodeType.TX) { } else if(selected instanceof TransactionTreeNode && ((TransactionTreeNode)selected).type == TransactionTreeNodeType.TX) {
waveformViewer.setSelection(new StructuredSelection(((TransactionTreeNode)selected).element)); waveformViewer.setSelection(new StructuredSelection(((TransactionTreeNode)selected).element));
} }
} }
}
}); });
Tree tree = treeViewer.getTree(); Table table = tableViewer.getTable();
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
TreeViewerColumn nameColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE); TableViewerColumn nameColumnViewer = new TableViewerColumn(tableViewer, SWT.NONE);
TreeColumn nameColumn = nameColumnViewer.getColumn(); TableColumn nameColumn = nameColumnViewer.getColumn();
nameColumn.setWidth(200); nameColumn.setWidth(200);
nameColumn.setText("Tx ID"); nameColumn.setText("Tx ID");
nameColumn.setResizable(true); nameColumn.setResizable(true);
nameColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.NAME))); nameColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.NAME)));
TreeViewerColumn timeColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE); TableViewerColumn timeColumnViewer = new TableViewerColumn(tableViewer, SWT.NONE);
TreeColumn timeColumn = timeColumnViewer.getColumn(); TableColumn timeColumn = timeColumnViewer.getColumn();
timeColumn.setAlignment(SWT.RIGHT); timeColumn.setAlignment(SWT.RIGHT);
timeColumn.setWidth(150); timeColumn.setWidth(150);
timeColumn.setText("Start time"); timeColumn.setText("Start time");
timeColumn.setResizable(true); timeColumn.setResizable(true);
timeColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.TX_TIME))); timeColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.TX_TIME)));
TreeViewerColumn typeColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE); TableViewerColumn valueColumnViewer = new TableViewerColumn(tableViewer, SWT.NONE);
TreeColumn typeColumn = typeColumnViewer.getColumn();
typeColumn.setAlignment(SWT.RIGHT);
typeColumn.setWidth(150);
typeColumn.setText("Type");
typeColumn.setResizable(true);
typeColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.TYPE)));
TreeViewerColumn valueColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE);
valueColumn = valueColumnViewer.getColumn(); valueColumn = valueColumnViewer.getColumn();
valueColumn.setWidth(150); valueColumn.setWidth(150);
valueColumn.setText("Value"); valueColumn.setText("Property Value");
valueColumn.setResizable(true); valueColumn.setResizable(true);
nameLabelProvider= new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.VALUE); valueLabelProvider= new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.VALUE);
valueColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(nameLabelProvider)); valueColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(valueLabelProvider));
// Turn on the header and the lines // Turn on the header and the lines
tree.setHeaderVisible(true); table.setHeaderVisible(true);
tree.setLinesVisible(true); table.setLinesVisible(true);
new Label(this, SWT.NONE);
new Label(this, SWT.NONE);
new Label(this, SWT.NONE);
new Label(this, SWT.NONE);
new Label(this, SWT.NONE);
} }
public void setInput(TrackEntry trackEntry) { public void setInput(TrackEntry trackEntry) {
if(trackEntry==null || !trackEntry.isStream()) { if(trackEntry==null || !trackEntry.isStream()) {
attrNames.clear(); attrNames.clear();
treeViewer.setInput(emptyList); tableViewer.setInput(emptyList);
} else { } else {
stream=trackEntry.getStream(); stream=trackEntry.getStream();
treeViewer.setInput(emptyList); tableViewer.setInput(emptyList);
new Thread() { new Thread() {
private ConcurrentHashMap<String, DataType> propNames=new ConcurrentHashMap<String, DataType>(); private ConcurrentHashMap<String, DataType> propNames=new ConcurrentHashMap<String, DataType>();
@ -257,7 +270,7 @@ public class TransactionList extends Composite {
getDisplay().asyncExec(new Runnable() { getDisplay().asyncExec(new Runnable() {
@Override @Override
public void run() { public void run() {
treeViewer.setInput(eventList); tableViewer.setInput(eventList);
attrNames.clear(); attrNames.clear();
attrNames.addAll(getEntries()); attrNames.addAll(getEntries());
searchPropComboViewer.getCombo().select(0); searchPropComboViewer.getCombo().select(0);
@ -266,7 +279,7 @@ public class TransactionList extends Composite {
searchPropComboViewer.setInput(attrNames); searchPropComboViewer.setInput(attrNames);
searchPropComboViewer.setSelection(new StructuredSelection(searchPropComboViewer.getElementAt(0))); searchPropComboViewer.setSelection(new StructuredSelection(searchPropComboViewer.getElementAt(0)));
} }
treeViewer.refresh(true); tableViewer.refresh(true);
} }
}); });
} }

View File

@ -72,6 +72,13 @@ public class AttributeLabelProvider extends LabelProvider implements IStyledLabe
return new StyledString(iTx.getId().toString()); return new StyledString(iTx.getId().toString());
case TX_TIME: case TX_TIME:
return new StyledString(waveformViewerPart.getScaledTime(iTx.getBeginTime())); return new StyledString(waveformViewerPart.getScaledTime(iTx.getBeginTime()));
case TYPE:
if(showProp!=null){
List<ITxAttribute> res = iTx.getAttributes().stream().filter(a -> showProp.equals(a.getName())).collect(Collectors.toList());
if(res.size()==1)
return new StyledString(res.get(0).getDataType().toString());
}
return new StyledString("");
case VALUE: case VALUE:
if(showProp!=null){ if(showProp!=null){
List<ITxAttribute> res = iTx.getAttributes().stream().filter(a -> showProp.equals(a.getName())).collect(Collectors.toList()); List<ITxAttribute> res = iTx.getAttributes().stream().filter(a -> showProp.equals(a.getName())).collect(Collectors.toList());
@ -95,13 +102,21 @@ public class AttributeLabelProvider extends LabelProvider implements IStyledLabe
} else } else
return new StyledString(element.toString()); return new StyledString(element.toString());
case TYPE: case TYPE:
if (element instanceof ITxAttribute) { if(element instanceof TransactionTreeNode) {
if(showProp!=null){
ITx iTx = ((TransactionTreeNode) element).element;
List<ITxAttribute> res = iTx.getAttributes().stream().filter(a -> showProp.equals(a.getName())).collect(Collectors.toList());
if(res.size()==1)
return new StyledString(res.get(0).getDataType().toString());
}
return new StyledString("");
} else if (element instanceof ITxAttribute) {
ITxAttribute attribute = (ITxAttribute) element; ITxAttribute attribute = (ITxAttribute) element;
return new StyledString(attribute.getDataType().toString()); return new StyledString(attribute.getDataType().toString());
}else if(element instanceof Object[]){ } else if(element instanceof Object[]){
Object[] elements = (Object[]) element; Object[] elements = (Object[]) element;
return new StyledString(elements[field].toString()); return new StyledString(elements[field].toString());
}else } else
return new StyledString(""); //$NON-NLS-1$ return new StyledString(""); //$NON-NLS-1$
case TX_TIME: case TX_TIME:
if(element instanceof TransactionTreeNode) { if(element instanceof TransactionTreeNode) {
@ -120,7 +135,7 @@ public class AttributeLabelProvider extends LabelProvider implements IStyledLabe
} else if (element instanceof ITxAttribute) { } else if (element instanceof ITxAttribute) {
ITxAttribute attribute = (ITxAttribute) element; ITxAttribute attribute = (ITxAttribute) element;
return getAttrValueAsStyledString(attribute); return getAttrValueAsStyledString(attribute);
}else if(element instanceof Object[]){ } else if(element instanceof Object[]){
Object[] elements = (Object[]) element; Object[] elements = (Object[]) element;
Object o = elements[field]; Object o = elements[field];
if(o instanceof ITx) { if(o instanceof ITx) {

View File

@ -10,7 +10,7 @@
<relativePath>../..</relativePath> <relativePath>../..</relativePath>
</parent> </parent>
<artifactId>com.minres.scviewer.e4.product</artifactId> <artifactId>com.minres.scviewer.e4.product</artifactId>
<version>2.9.1-SNAPSHOT</version> <version>2.9.2-SNAPSHOT</version>
<packaging>eclipse-repository</packaging> <packaging>eclipse-repository</packaging>
<groupId>com.minres.scviewer</groupId> <groupId>com.minres.scviewer</groupId>
<build> <build>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?> <?pde version="3.5"?>
<product name="SCViewer" uid="product" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.9.1.qualifier" useFeatures="true" includeLaunchers="true"> <product name="SCViewer" uid="product" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.9.2.qualifier" useFeatures="true" includeLaunchers="true">
<configIni use="default"> <configIni use="default">
</configIni> </configIni>

View File

@ -10,7 +10,7 @@
<relativePath>../..</relativePath> <relativePath>../..</relativePath>
</parent> </parent>
<artifactId>com.minres.scviewer.e4.product_slim</artifactId> <artifactId>com.minres.scviewer.e4.product_slim</artifactId>
<version>2.9.1-SNAPSHOT</version> <version>2.9.2-SNAPSHOT</version>
<packaging>eclipse-repository</packaging> <packaging>eclipse-repository</packaging>
<groupId>com.minres.scviewer</groupId> <groupId>com.minres.scviewer</groupId>
<build> <build>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?> <?pde version="3.5"?>
<product name="SCViewer" uid="product_slim" id="com.minres.scviewer.e4.application.product_slim" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.9.1.qualifier" useFeatures="false" includeLaunchers="true"> <product name="SCViewer" uid="product_slim" id="com.minres.scviewer.e4.application.product_slim" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.9.2.qualifier" useFeatures="false" includeLaunchers="true">
<configIni use="default"> <configIni use="default">
</configIni> </configIni>