fix selection handling in viewer and Sonarlint warnings

This commit is contained in:
Eyck Jentzsch 2021-01-09 13:43:11 +01:00
parent 9d2e2e7f64
commit abacae42d7
5 changed files with 58 additions and 57 deletions

View File

@ -23,6 +23,7 @@ import org.eclipse.swt.widgets.Control;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.RelationTypeFactory; import com.minres.scviewer.database.RelationTypeFactory;
import com.minres.scviewer.database.tx.ITx;
public interface IWaveformView extends PropertyChangeListener, ISelectionProvider{ public interface IWaveformView extends PropertyChangeListener, ISelectionProvider{
@ -64,7 +65,7 @@ public interface IWaveformView extends PropertyChangeListener, ISelectionProvide
public List<TrackEntry> getStreamList(); public List<TrackEntry> getStreamList();
public TrackEntry getEntryForStream(IWaveform source); public TrackEntry getEntryFor(ITx source);
public List<Object> getElementsAt(Point pt); public List<Object> getElementsAt(Point pt);

View File

@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -696,30 +697,36 @@ public class WaveformView implements IWaveformView {
boolean selectionChanged = false; boolean selectionChanged = false;
currentWaveformSelection.forEach(e->e.selected=false); currentWaveformSelection.forEach(e->e.selected=false);
if (selection instanceof IStructuredSelection) { if (selection instanceof IStructuredSelection) {
if(((IStructuredSelection) selection).size()==0){ IStructuredSelection sel = (IStructuredSelection) selection;
if(sel.size()==0){
selectionChanged = currentTxSelection!=null||currentWaveformSelection!=null; selectionChanged = currentTxSelection!=null||currentWaveformSelection!=null;
currentTxSelection = null; currentTxSelection = null;
currentWaveformSelection .clear(); currentWaveformSelection .clear();
} else { } else {
if(!add) currentWaveformSelection.clear(); if(!add) currentWaveformSelection.clear();
for(Object sel:((IStructuredSelection) selection).toArray()){ List<?> selList = sel.toList();
if (sel instanceof ITx){ if(selList.get(0) instanceof ITx) {
ITx txSel = (ITx) sel; ITx txSel = (ITx) selList.get(0);
TrackEntry trackEntry = getEntryForStream(txSel.getStream()); 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){ if(trackEntry==null && addIfNeeded){
trackEntry=new TrackEntry(txSel.getStream(), styleProvider); trackEntry=new TrackEntry(txSel.getStream(), styleProvider);
streams.add(trackEntry); streams.add(trackEntry);
} }
currentTxSelection = txSel;
currentWaveformSelection.clear();
currentWaveformSelection.add(trackEntry);
selectionChanged = true;
} else if (sel instanceof TrackEntry && !currentWaveformSelection.contains(sel)) {
currentWaveformSelection.add((TrackEntry)sel);
if(currentTxSelection!=null && !selectionChanged)
currentTxSelection=null;
selectionChanged = true;
} }
currentTxSelection = txSel;
currentWaveformSelection.clear();
currentWaveformSelection.add(trackEntry);
selectionChanged = true;
} else if(selList.size()==1 && selList.get(0) instanceof TrackEntry) {
currentWaveformSelection.add((TrackEntry)selList.get(0));
if(currentTxSelection!=null)
currentTxSelection=null;
selectionChanged = true;
} else {
System.err.println("Invalid selection");
} }
} }
} else { } else {
@ -773,7 +780,7 @@ public class WaveformView implements IWaveformView {
public void moveSelection(GotoDirection direction, RelationType relationType) { public void moveSelection(GotoDirection direction, RelationType relationType) {
if(currentWaveformSelection.size() !=1 && currentTxSelection==null) return; if(currentWaveformSelection.size() !=1 && currentTxSelection==null) return;
TrackEntry selectedWaveform=currentWaveformSelection.size() == 1? TrackEntry selectedWaveform=currentWaveformSelection.size() == 1?
currentWaveformSelection.get(0) : getEntryForStream(currentTxSelection.getStream()); currentWaveformSelection.get(0) : getEntryFor(currentTxSelection);
if(selectedWaveform.waveform.getType()==WaveformType.TRANSACTION && currentTxSelection!=null) { if(selectedWaveform.waveform.getType()==WaveformType.TRANSACTION && currentTxSelection!=null) {
if(relationType.equals(IWaveformView.NEXT_PREV_IN_STREAM)){ if(relationType.equals(IWaveformView.NEXT_PREV_IN_STREAM)){
ITx transaction = null; ITx transaction = null;
@ -1167,9 +1174,13 @@ public class WaveformView implements IWaveformView {
}); });
} }
public TrackEntry getEntryForStream(IWaveform source) { public TrackEntry getEntryFor(ITx source) {
for(TrackEntry trackEntry:streams) Optional<TrackEntry> optGen = streams.stream().filter(e->source.getGenerator().equals(e.waveform)).findFirst();
if(trackEntry.waveform.isSame(source)) return trackEntry; if(optGen.isPresent())
return optGen.get();
Optional<TrackEntry> optStr = streams.stream().filter(e->source.getStream().equals(e.waveform)).findFirst();
if(optStr.isPresent())
return optStr.get();
return null; return null;
} }

View File

@ -10,7 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database; package com.minres.scviewer.database;
// TODO: Auto-generated Javadoc
/** /**
* The Enum AssociationType. * The Enum AssociationType.
*/ */

View File

@ -100,15 +100,9 @@ public class DesignBrowser {
/** The tree viewer. */ /** The tree viewer. */
private TreeViewer treeViewer; private TreeViewer treeViewer;
/** The name filter of the design browser tree. */
private Text treeNameFilter;
/** The attribute filter. */ /** The attribute filter. */
StreamTTreeFilter treeAttributeFilter; StreamTTreeFilter treeAttributeFilter;
/** The name filter. */
private Text tableNameFilter;
/** The attribute filter. */ /** The attribute filter. */
StreamTableFilter tableAttributeFilter; StreamTableFilter tableAttributeFilter;
@ -116,34 +110,30 @@ public class DesignBrowser {
private TableViewer txTableViewer; private TableViewer txTableViewer;
/** The append all item. */ /** The append all item. */
ToolItem appendItem, insertItem; ToolItem appendItem;
ToolItem insertItem;
/** The other selection count. */ /** The other selection count. */
int thisSelectionCount=0, otherSelectionCount=0; int thisSelectionCount=0;
int otherSelectionCount=0;
/** The waveform viewer part. */
private WaveformViewer waveformViewerPart;
/** The tree viewer pcl. */ /** The tree viewer pcl. */
private PropertyChangeListener treeViewerPCL = evt -> { private PropertyChangeListener treeViewerPCL = evt -> {
if("CHILDS".equals(evt.getPropertyName())){ //$NON-NLS-1$ if("CHILDS".equals(evt.getPropertyName())){ //$NON-NLS-1$
treeViewer.getTree().getDisplay().asyncExec(new Runnable() { treeViewer.getTree().getDisplay().asyncExec(() -> treeViewer.refresh());
@Override
public void run() {
treeViewer.refresh();
}
});
} else if("WAVEFORMS".equals(evt.getPropertyName())) { } else if("WAVEFORMS".equals(evt.getPropertyName())) {
treeViewer.getTree().getDisplay().asyncExec(new Runnable() { treeViewer.getTree().getDisplay().asyncExec(() -> {
@Override IWaveformDb database = waveformViewerPart.getDatabase();
public void run() { treeViewer.setInput(Arrays.asList(database.isLoaded()?new IWaveformDb[]{database}:new IWaveformDb[]{new LoadingWaveformDb()}));
IWaveformDb database = waveformViewerPart.getDatabase();
treeViewer.setInput(Arrays.asList(database.isLoaded()?new IWaveformDb[]{database}:new IWaveformDb[]{new LoadingWaveformDb()}));
}
}); });
} }
}; };
/** The waveform viewer part. */
private WaveformViewer waveformViewerPart;
/** The sash paint listener. */ /** The sash paint listener. */
protected PaintListener sashPaintListener= e -> { protected PaintListener sashPaintListener= e -> {
int size=Math.min(e.width, e.height)-1; int size=Math.min(e.width, e.height)-1;
@ -192,7 +182,7 @@ public class DesignBrowser {
public void createTreeViewerComposite(Composite parent) { public void createTreeViewerComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false)); parent.setLayout(new GridLayout(1, false));
treeNameFilter = new Text(parent, SWT.BORDER); Text treeNameFilter = new Text(parent, SWT.BORDER);
treeNameFilter.setMessage(Messages.DesignBrowser_3); treeNameFilter.setMessage(Messages.DesignBrowser_3);
treeNameFilter.addModifyListener( e -> { treeNameFilter.addModifyListener( e -> {
treeAttributeFilter.setSearchText(((Text) e.widget).getText()); treeAttributeFilter.setSearchText(((Text) e.widget).getText());
@ -233,7 +223,7 @@ public class DesignBrowser {
public void createTableComposite(Composite parent) { public void createTableComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false)); parent.setLayout(new GridLayout(1, false));
tableNameFilter = new Text(parent, SWT.BORDER); Text tableNameFilter = new Text(parent, SWT.BORDER);
tableNameFilter.setMessage(Messages.DesignBrowser_2); tableNameFilter.setMessage(Messages.DesignBrowser_2);
tableNameFilter.addModifyListener(e -> { tableNameFilter.addModifyListener(e -> {
tableAttributeFilter.setSearchText(((Text) e.widget).getText()); tableAttributeFilter.setSearchText(((Text) e.widget).getText());

View File

@ -181,17 +181,6 @@ public class TransactionDetails {
treeViewer.refresh(); treeViewer.refresh();
} }
}); });
// Add the type column
col2 = new TreeViewerColumn(treeViewer, SWT.NONE);
col2.getColumn().setText(Messages.TransactionDetails_2);
col2.getColumn().setResizable(true);
col2.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.TYPE)));
col2.getColumn().addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_SECOND);
treeViewer.refresh();
}
});
// Add the value column // Add the value column
col3 = new TreeViewerColumn(treeViewer, SWT.NONE); col3 = new TreeViewerColumn(treeViewer, SWT.NONE);
col3.getColumn().setText(Messages.TransactionDetails_3); col3.getColumn().setText(Messages.TransactionDetails_3);
@ -203,6 +192,17 @@ public class TransactionDetails {
treeViewer.refresh(); treeViewer.refresh();
} }
}); });
// Add the type column
col2 = new TreeViewerColumn(treeViewer, SWT.NONE);
col2.getColumn().setText(Messages.TransactionDetails_2);
col2.getColumn().setResizable(true);
col2.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.TYPE)));
col2.getColumn().addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_SECOND);
treeViewer.refresh();
}
});
// Pack the columns // Pack the columns
// for (int i = 0, n = table.getColumnCount(); i < n; i++) { // for (int i = 0, n = table.getColumnCount(); i < n; i++) {
// table.getColumn(i).pack(); // table.getColumn(i).pack();