add multi-selection in waveform viewer

This commit is contained in:
2020-07-15 21:43:07 +02:00
parent 611cfc7b46
commit 26968b8521
8 changed files with 209 additions and 207 deletions

View File

@ -1,7 +1,6 @@
package com.minres.scviewer.e4.application.elements;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
@ -34,22 +33,46 @@ public class WaveformPopupMenuContribution {
final TrackEntry nullEntry = new TrackEntry(null);
private boolean selHasBitVector(ISelection sel, boolean checkForDouble) {
if(!sel.isEmpty() && sel instanceof IStructuredSelection) {
for(Object elem:(IStructuredSelection)sel) {
if(elem instanceof TrackEntry) {
TrackEntry e = (TrackEntry) elem;
if(e.waveform instanceof ISignal<?>) {
Object o = ((ISignal<?>) e.waveform).getEvents().firstEntry().getValue();
if(checkForDouble && o instanceof Double)
return true;
else if(o instanceof BitVector && ((BitVector)o).getWidth()>1)
return true;
else
return false;
}
}
}
}
return false;
}
private TrackEntry getSingleTrackEntry(ISelection sel) {
TrackEntry entry=null;
if(!sel.isEmpty() && sel instanceof IStructuredSelection) {
for(Object elem:(IStructuredSelection)sel) {
if(elem instanceof TrackEntry) {
if(entry != null)
return null;
entry = (TrackEntry) elem;
}
}
}
return entry;
}
@Evaluate
public boolean evaluate() {
Object obj = activePart.getObject();
if(obj instanceof WaveformViewer){
WaveformViewer wfv = (WaveformViewer)obj;
ISelection sel = wfv.getSelection();
if(!sel.isEmpty() && sel instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection)sel).getFirstElement();
if(selected instanceof ISignal<?>) {
Object x = ((ISignal<?>) selected).getEvents().firstEntry().getValue();
if((x instanceof BitVector) && ((BitVector)x).getWidth()==1) {
return false;
} else
return true;
}
}
return selHasBitVector(wfv.getSelection(), true);
}
return false;
}
@ -60,39 +83,24 @@ public class WaveformPopupMenuContribution {
if(obj instanceof WaveformViewer){
WaveformViewer wfv = (WaveformViewer)obj;
ISelection sel = wfv.getSelection();
if(!sel.isEmpty() && sel instanceof IStructuredSelection) {
Iterator<?> it = ((IStructuredSelection)sel).iterator();
Object first = it.next();
Object second=null;
if(it.hasNext()) second=it.next();
if(first instanceof ISignal<?>) {
Object o = ((ISignal<?>) first).getEvents().firstEntry().getValue();
//com.minres.scviewer.e4.application.menu.mulitvaluesettings
if((o instanceof Double) || (o instanceof BitVector)) {
TrackEntry entry=nullEntry;
if(second instanceof TrackEntry)
entry=(TrackEntry)second;
if(o instanceof BitVector) {
addValueMenuItem(items, application, modelService, "hex", TrackEntry.ValueDisplay.DEFAULT, entry.valueDisplay);
addValueMenuItem(items, application, modelService, "unsigned", TrackEntry.ValueDisplay.UNSIGNED, entry.valueDisplay);
addValueMenuItem(items, application, modelService, "signed", TrackEntry.ValueDisplay.SIGNED, entry.valueDisplay);
items.add(MMenuFactory.INSTANCE.createMenuSeparator());
addWaveMenuItem(items, application, modelService, "bit vector", TrackEntry.WaveDisplay.DEFAULT, entry.waveDisplay);
}
addWaveMenuItem(items, application, modelService, "analog step-wise", TrackEntry.WaveDisplay.STEP_WISE, entry.waveDisplay);
addWaveMenuItem(items, application, modelService, "analog continous", TrackEntry.WaveDisplay.CONTINOUS, entry.waveDisplay);
}
}
}
TrackEntry elem = getSingleTrackEntry(sel);
if(selHasBitVector(sel, false)) {
addValueMenuItem(items, application, modelService, "hex", TrackEntry.ValueDisplay.DEFAULT, elem);
addValueMenuItem(items, application, modelService, "unsigned", TrackEntry.ValueDisplay.UNSIGNED, elem);
addValueMenuItem(items, application, modelService, "signed", TrackEntry.ValueDisplay.SIGNED, elem);
items.add(MMenuFactory.INSTANCE.createMenuSeparator());
addWaveMenuItem(items, application, modelService, "bit vector", TrackEntry.WaveDisplay.DEFAULT, elem);
}
addWaveMenuItem(items, application, modelService, "analog step-wise", TrackEntry.WaveDisplay.STEP_WISE, elem);
addWaveMenuItem(items, application, modelService, "analog continous", TrackEntry.WaveDisplay.CONTINOUS, elem);
}
}
private void addValueMenuItem(List<MMenuElement> items, MApplication application, EModelService modelService,
String label, TrackEntry.ValueDisplay value, TrackEntry.ValueDisplay actual) {
String label, TrackEntry.ValueDisplay value, TrackEntry elem) {
MHandledMenuItem item = MMenuFactory.INSTANCE.createHandledMenuItem();
item.setType(ItemType.RADIO);
item.setSelected(value==actual);
item.setSelected(elem != null && elem.valueDisplay == value);
item.setLabel("Show as "+label);
item.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application");
List<MCommand> cmds = modelService.findElements(application, "com.minres.scviewer.e4.application.command.changevaluedisplay", MCommand.class, null);
@ -106,10 +114,10 @@ public class WaveformPopupMenuContribution {
}
private void addWaveMenuItem(List<MMenuElement> items, MApplication application, EModelService modelService,
String label, TrackEntry.WaveDisplay value, TrackEntry.WaveDisplay actual) {
String label, TrackEntry.WaveDisplay value, TrackEntry elem) {
MHandledMenuItem item = MMenuFactory.INSTANCE.createHandledMenuItem();
item.setType(ItemType.RADIO);
item.setSelected(value==actual);
item.setSelected(elem != null && elem.waveDisplay==value);
item.setLabel("Render "+label);
item.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application");
List<MCommand> cmds = modelService.findElements(application, "com.minres.scviewer.e4.application.command.changewavedisplay", MCommand.class, null);

View File

@ -1,8 +1,6 @@
package com.minres.scviewer.e4.application.handlers;
import java.util.Iterator;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.CanExecute;
@ -34,18 +32,14 @@ public class ChangeValueDisplay {
WaveformViewer wfv = (WaveformViewer)obj;
ISelection sel = wfv.getSelection();
if(!sel.isEmpty() && sel instanceof IStructuredSelection) {
Iterator<?> it = ((IStructuredSelection)sel).iterator();
it.next();
if(it.hasNext()) {
Object second = it.next();
if(second instanceof TrackEntry) {
TrackEntry.ValueDisplay val = TrackEntry.ValueDisplay.valueOf(param);
((TrackEntry)second).valueDisplay=val;
wfv.update();
}
for(Object elem:(IStructuredSelection)sel) {
if(elem instanceof TrackEntry) {
TrackEntry.ValueDisplay val= TrackEntry.ValueDisplay.valueOf(param);
((TrackEntry)elem).valueDisplay=val;
}
}
wfv.update();
}
}
}
}

View File

@ -1,8 +1,6 @@
package com.minres.scviewer.e4.application.handlers;
import java.util.Iterator;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.CanExecute;
@ -34,16 +32,13 @@ public class ChangeWaveformDisplay {
WaveformViewer wfv = (WaveformViewer)obj;
ISelection sel = wfv.getSelection();
if(!sel.isEmpty() && sel instanceof IStructuredSelection) {
Iterator<?> it = ((IStructuredSelection)sel).iterator();
it.next();
if(it.hasNext()) {
Object second = it.next();
if(second instanceof TrackEntry) {
TrackEntry.WaveDisplay val= TrackEntry.WaveDisplay.valueOf(param);
((TrackEntry)second).waveDisplay=val;
wfv.update();
}
for(Object elem:(IStructuredSelection)sel) {
if(elem instanceof TrackEntry) {
TrackEntry.WaveDisplay val= TrackEntry.WaveDisplay.valueOf(param);
((TrackEntry)elem).waveDisplay=val;
}
}
wfv.update();
}
}
}

View File

@ -17,23 +17,30 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
import org.eclipse.jface.viewers.IStructuredSelection;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.e4.application.parts.WaveformViewer;
public class DeleteWaveformHandler {
@SuppressWarnings("unchecked")
@CanExecute
public Boolean canExecute(ESelectionService selectionService){
Object o = selectionService.getSelection();
return o instanceof IStructuredSelection && ((IStructuredSelection)o).getFirstElement() instanceof IWaveform;
if(o instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) o;
if(sel.size()>0)
return sel.toList().stream().allMatch(e-> e instanceof TrackEntry);
else
return false;
} else
return false;
}
@Execute
public void execute(ESelectionService selectionService, MPart activePart) {
Object o = activePart.getObject();
Object sel = selectionService.getSelection();
if(o instanceof WaveformViewer && ((IStructuredSelection)sel).getFirstElement() instanceof IWaveform){
((WaveformViewer)o).removeStreamFromList((IWaveform) ((IStructuredSelection)sel).getFirstElement());
if(o instanceof WaveformViewer){
((WaveformViewer)o).removeSelectedStreamsFromList();
}
}
}

View File

@ -90,16 +90,16 @@ import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory;
import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.swt.Constants;
import com.minres.scviewer.database.swt.ToolTipContentProvider;
import com.minres.scviewer.database.swt.ToolTipHelpTextProvider;
import com.minres.scviewer.database.swt.WaveformViewFactory;
import com.minres.scviewer.database.ui.GotoDirection;
import com.minres.scviewer.database.ui.ICursor;
import com.minres.scviewer.database.ui.IWaveformView;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.TrackEntry.ValueDisplay;
import com.minres.scviewer.database.ui.TrackEntry.WaveDisplay;
import com.minres.scviewer.database.ui.swt.Constants;
import com.minres.scviewer.database.ui.swt.ToolTipContentProvider;
import com.minres.scviewer.database.ui.swt.ToolTipHelpTextProvider;
import com.minres.scviewer.database.ui.swt.WaveformViewFactory;
import com.minres.scviewer.database.ui.WaveformColors;
import com.minres.scviewer.e4.application.Messages;
import com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl;
@ -1005,55 +1005,13 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
setFocus();
}
/**
* Removes the stream from list.
*
* @param stream the stream
*/
public void removeStreamFromList(IWaveform stream) {
TrackEntry trackEntry = waveformPane.getEntryForStream(stream);
List<TrackEntry> streams = waveformPane.getStreamList();
ISelection sel = waveformPane.getSelection();
TrackEntry newSelection=null;
if(sel instanceof IStructuredSelection && ((IStructuredSelection) sel).size()==2) {
Iterator<?> it = ((IStructuredSelection)sel).iterator();
it.next();
int idx = streams.indexOf(it.next());
if(idx==streams.size()-1) {
//last stream gets deleted, no more selection
if(idx==0) {
newSelection=null;
}
//more than 1 stream left, last gets deleted, selection jumps to new last stream
else {
newSelection=streams.get(idx-1);
}
}
//more than 1 stream left, any stream but the last gets deleted, selection jumps to the next stream
else {
newSelection=streams.get(idx+1);
}
}
waveformPane.setSelection(new StructuredSelection());
streams.remove(trackEntry);
if(newSelection!=null) {
Object[] o = {newSelection};
waveformPane.setSelection(new StructuredSelection(o));
}
public void removeSelectedStreamsFromList() {
waveformPane.deleteSelectedTracks();
}
/**
* Removes the streams from list.
*
* @param iWaveforms the i waveforms
*/
public void removeStreamsFromList(IWaveform[] iWaveforms) {
for (IWaveform stream : iWaveforms)
removeStreamFromList(stream);
public void removeStreamFromList(ISelection sel) {
waveformPane.deleteSelectedTracks();
}
/**
* Move selected.
*