- added conext menu

- added option to remove waves
- fixed painting errors
This commit is contained in:
ejentzsx 2015-01-29 11:02:03 +01:00
parent 8c60a53ebe
commit 310c9bbb8f
9 changed files with 537 additions and 219 deletions

View File

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database.swt; package com.minres.scviewer.database.swt;
import java.awt.PageAttributes.OriginType;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.HashMap; import java.util.HashMap;
@ -29,6 +30,15 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseEvent;
@ -50,6 +60,7 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.wb.swt.SWTResourceManager;
import swing2swt.layout.BorderLayout; import swing2swt.layout.BorderLayout;
@ -69,10 +80,10 @@ import com.minres.scviewer.database.swt.internal.StreamPainter;
import com.minres.scviewer.database.swt.internal.TrackPainter; import com.minres.scviewer.database.swt.internal.TrackPainter;
import com.minres.scviewer.database.swt.internal.WaveformCanvas; import com.minres.scviewer.database.swt.internal.WaveformCanvas;
public class TxDisplay implements PropertyChangeListener, ISelectionProvider, MouseListener{ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, MouseListener {
private ListenerList listeners = new ListenerList(); private ListenerList listeners = new ListenerList();
private static final String SELECTION="selection"; private static final String SELECTION = "selection";
private ITx currentSelection; private ITx currentSelection;
private IWaveform<? extends IWaveformEvent> currentWaveformSelection; private IWaveform<? extends IWaveformEvent> currentWaveformSelection;
@ -92,51 +103,56 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
private Ruler ruler; private Ruler ruler;
TreeMap<Integer, IWaveform<? extends IWaveformEvent>> trackVerticalOffset; TreeMap<Integer, IWaveform<? extends IWaveformEvent>> trackVerticalOffset;
HashMap<IWaveform<? extends IWaveformEvent>, String> actualValues; HashMap<IWaveform<? extends IWaveformEvent>, String> actualValues;
// private long maxTime=0; // private long maxTime=0;
private Font nameFont, nameFontB; private Font nameFont, nameFontB;
public TxDisplay(Composite parent) { public TxDisplay(Composite parent) {
trackVerticalOffset = new TreeMap<Integer, IWaveform<? extends IWaveformEvent>>(); trackVerticalOffset = new TreeMap<Integer, IWaveform<? extends IWaveformEvent>>();
actualValues= new HashMap<IWaveform<? extends IWaveformEvent>, String>(); actualValues = new HashMap<IWaveform<? extends IWaveformEvent>, String>();
cursorPainters=new Vector<CursorPainter>(); cursorPainters = new Vector<CursorPainter>();
nameFont = parent.getDisplay().getSystemFont(); nameFont = parent.getDisplay().getSystemFont();
nameFontB = SWTResourceManager.getBoldFont(nameFont); nameFontB = SWTResourceManager.getBoldFont(nameFont);
streams=new ObservableList<IWaveform<? extends IWaveformEvent>>(); streams = new ObservableList<IWaveform<? extends IWaveformEvent>>();
streams.addPropertyChangeListener(this); streams.addPropertyChangeListener(this);
top = new Composite(parent, SWT.NONE); top = new Composite(parent, SWT.NONE);
top.setLayout(new FillLayout(SWT.HORIZONTAL)); top.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm topSash = new SashForm(top, SWT.SMOOTH); SashForm topSash = new SashForm(top, SWT.SMOOTH);
topSash.setBackground(topSash.getDisplay().getSystemColor( SWT.COLOR_GRAY)); topSash.setBackground(topSash.getDisplay().getSystemColor(
SWT.COLOR_GRAY));
Composite composite = new Composite(topSash, SWT.NONE); Composite composite = new Composite(topSash, SWT.NONE);
composite.setLayout(new FillLayout(SWT.HORIZONTAL)); composite.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm leftSash = new SashForm(composite, SWT.SMOOTH); SashForm leftSash = new SashForm(composite, SWT.SMOOTH);
leftSash.setBackground(leftSash.getDisplay().getSystemColor( SWT.COLOR_GRAY)); leftSash.setBackground(leftSash.getDisplay().getSystemColor(
SWT.COLOR_GRAY));
Composite namePane = createTextPane(leftSash, "Name"); Composite namePane = createTextPane(leftSash, "Name");
namePane.setBackground(namePane.getDisplay().getSystemColor( SWT.COLOR_WIDGET_BACKGROUND)); namePane.setBackground(namePane.getDisplay().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
nameListScrolled = new ScrolledComposite(namePane, SWT.H_SCROLL | SWT.V_SCROLL); nameListScrolled = new ScrolledComposite(namePane, SWT.H_SCROLL
nameListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); | SWT.V_SCROLL);
nameListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true, 1, 1));
nameListScrolled.setExpandHorizontal(true); nameListScrolled.setExpandHorizontal(true);
nameListScrolled.setExpandVertical(true); nameListScrolled.setExpandVertical(true);
nameListScrolled.setAlwaysShowScrollBars(true); nameListScrolled.setAlwaysShowScrollBars(true);
nameListScrolled.addControlListener(new ControlAdapter(){ nameListScrolled.addControlListener(new ControlAdapter() {
@Override @Override
public void controlResized(ControlEvent e) { public void controlResized(ControlEvent e) {
nameListScrolled.getVerticalBar().setVisible(false); nameListScrolled.getVerticalBar().setVisible(false);
} }
}); });
nameList = new Canvas(nameListScrolled, SWT.NONE){ nameList = new Canvas(nameListScrolled, SWT.NONE) {
@Override @Override
public Point computeSize(int wHint, int hHint, boolean changed) { public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle bounds= super.getClientArea(); Rectangle bounds = super.getClientArea();
return new Point(bounds.width, bounds.height); return new Point(bounds.width, bounds.height);
} }
}; };
@ -144,7 +160,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@Override @Override
public void handleEvent(Event event) { public void handleEvent(Event event) {
GC gc = event.gc; GC gc = event.gc;
Rectangle rect = ((Canvas)event.widget).getClientArea(); Rectangle rect = ((Canvas) event.widget).getClientArea();
paintNames(gc, rect); paintNames(gc, rect);
} }
}); });
@ -152,23 +168,26 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
nameListScrolled.setContent(nameList); nameListScrolled.setContent(nameList);
Composite valuePane = createTextPane(leftSash, "Value"); Composite valuePane = createTextPane(leftSash, "Value");
valuePane.setBackground(valuePane.getDisplay().getSystemColor( SWT.COLOR_WIDGET_BACKGROUND)); valuePane.setBackground(valuePane.getDisplay().getSystemColor(
valueListScrolled = new ScrolledComposite(valuePane, SWT.H_SCROLL | SWT.V_SCROLL); SWT.COLOR_WIDGET_BACKGROUND));
valueListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); valueListScrolled = new ScrolledComposite(valuePane, SWT.H_SCROLL
| SWT.V_SCROLL);
valueListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true, 1, 1));
valueListScrolled.setExpandHorizontal(true); valueListScrolled.setExpandHorizontal(true);
valueListScrolled.setExpandVertical(true); valueListScrolled.setExpandVertical(true);
valueListScrolled.setAlwaysShowScrollBars(true); valueListScrolled.setAlwaysShowScrollBars(true);
valueListScrolled.addControlListener(new ControlAdapter(){ valueListScrolled.addControlListener(new ControlAdapter() {
@Override @Override
public void controlResized(ControlEvent e) { public void controlResized(ControlEvent e) {
valueListScrolled.getVerticalBar().setVisible(false); valueListScrolled.getVerticalBar().setVisible(false);
} }
}); });
valueList = new Canvas(valueListScrolled, SWT.NONE){ valueList = new Canvas(valueListScrolled, SWT.NONE) {
@Override @Override
public Point computeSize(int wHint, int hHint, boolean changed) { public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle bounds= super.getClientArea(); Rectangle bounds = super.getClientArea();
return new Point(bounds.width, bounds.height); return new Point(bounds.width, bounds.height);
} }
}; };
@ -176,7 +195,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@Override @Override
public void handleEvent(Event event) { public void handleEvent(Event event) {
GC gc = event.gc; GC gc = event.gc;
Rectangle rect = ((Canvas)event.widget).getClientArea(); Rectangle rect = ((Canvas) event.widget).getClientArea();
paintValues(gc, rect); paintValues(gc, rect);
} }
}); });
@ -193,23 +212,28 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
trackList.setStreams(streams); trackList.setStreams(streams);
trackList.setRuler(ruler); trackList.setRuler(ruler);
trackList.addPainter(new TrackPainter(trackList)); trackList.addPainter(new TrackPainter(trackList));
CursorPainter cp = new CursorPainter(trackList, trackList.getScaleFactor()*10); CursorPainter cp = new CursorPainter(trackList,
trackList.getScaleFactor() * 10);
trackList.addPainter(cp); trackList.addPainter(cp);
cursorPainters.add(cp); cursorPainters.add(cp);
trackList.setMaxTime(1); trackList.setMaxTime(1);
trackList.addMouseListener(this); trackList.addMouseListener(this);
nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { nameListScrolled.getVerticalBar().addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int y = ((ScrollBar) e.widget).getSelection(); int y = ((ScrollBar) e.widget).getSelection();
valueListScrolled.setOrigin(valueListScrolled.getOrigin().x, y); valueListScrolled.setOrigin(
valueListScrolled.getOrigin().x, y);
trackList.scrollToY(y); trackList.scrollToY(y);
} }
}); });
valueListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { valueListScrolled.getVerticalBar().addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int y = ((ScrollBar) e.widget).getSelection(); int y = ((ScrollBar) e.widget).getSelection();
nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y); nameListScrolled.setOrigin(
nameListScrolled.getOrigin().x, y);
trackList.scrollToY(y); trackList.scrollToY(y);
} }
}); });
@ -220,12 +244,15 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
valueListScrolled.setOrigin(valueListScrolled.getOrigin().x, y); valueListScrolled.setOrigin(valueListScrolled.getOrigin().x, y);
} }
}); });
topSash.setWeights(new int[] {30, 70}); topSash.setWeights(new int[] { 30, 70 });
leftSash.setWeights(new int[] {75, 25}); leftSash.setWeights(new int[] { 75, 25 });
createDragSource(nameList);
createDragSource(valueList);
createDropTarget(nameList);
createDropTarget(valueList);
} }
private Composite createTextPane(SashForm leftSash, String text) { private Composite createTextPane(SashForm leftSash, String text) {
Composite namePane = new Composite(leftSash, SWT.NONE); Composite namePane = new Composite(leftSash, SWT.NONE);
GridLayout gl_namePane = new GridLayout(1, false); GridLayout gl_namePane = new GridLayout(1, false);
@ -236,15 +263,17 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
namePane.setLayout(gl_namePane); namePane.setLayout(gl_namePane);
CLabel nameLabel = new CLabel(namePane, SWT.NONE); CLabel nameLabel = new CLabel(namePane, SWT.NONE);
GridData gd_nameLabel = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1); GridData gd_nameLabel = new GridData(SWT.CENTER, SWT.CENTER, true,
gd_nameLabel.heightHint = Ruler.height-2; false, 1, 1);
gd_nameLabel.heightHint = Ruler.height - 2;
nameLabel.setLayoutData(gd_nameLabel); nameLabel.setLayoutData(gd_nameLabel);
nameLabel.setText(text); nameLabel.setText(text);
Label nameSep = new Label(namePane, SWT.SEPARATOR | SWT.HORIZONTAL); Label nameSep = new Label(namePane, SWT.SEPARATOR | SWT.HORIZONTAL);
nameSep.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY)); nameSep.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
nameSep.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK)); nameSep.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
GridData gd_nameSep = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); GridData gd_nameSep = new GridData(SWT.FILL, SWT.CENTER, true, false,
1, 1);
gd_nameSep.heightHint = 2; gd_nameSep.heightHint = 2;
nameSep.setLayoutData(gd_nameSep); nameSep.setLayoutData(gd_nameSep);
return namePane; return namePane;
@ -252,59 +281,64 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@Override @Override
public void propertyChange(PropertyChangeEvent pce) { public void propertyChange(PropertyChangeEvent pce) {
if("size".equals(pce.getPropertyName())) { if ("size".equals(pce.getPropertyName())) {
updateTracklist(); updateTracklist();
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void updateTracklist() { protected void updateTracklist() {
int yoffs=0; int yoffs = 0;
int nameMaxWidth=0; int nameMaxWidth = 0;
int previousHeight=trackVerticalOffset.size()==0?0: trackVerticalOffset.lastKey();
IWaveformPainter painter=null; IWaveformPainter painter = null;
trackVerticalOffset.clear(); trackVerticalOffset.clear();
actualValues.clear(); actualValues.clear();
trackList.clearAllWavefromPainter(); trackList.clearAllWavefromPainter();
boolean even=true; boolean even = true;
TextLayout tl = new TextLayout(trackList.getDisplay()); TextLayout tl = new TextLayout(trackList.getDisplay());
tl.setFont(nameFontB); tl.setFont(nameFontB);
for(IWaveform<? extends IWaveformEvent> waveform:streams){ for (IWaveform<? extends IWaveformEvent> waveform : streams) {
int height=trackList.getTrackHeight(); int height = trackList.getTrackHeight();
if(waveform instanceof ITxStream<?>){ if (waveform instanceof ITxStream<?>) {
height*=((ITxStream<? extends ITxEvent>)waveform).getMaxConcurrency(); height *= ((ITxStream<? extends ITxEvent>) waveform).getMaxConcurrency();
painter= new StreamPainter(trackList, even, height, (ITxStream<? extends ITxEvent>) waveform); painter = new StreamPainter(trackList, even, height, (ITxStream<? extends ITxEvent>) waveform);
actualValues.put(waveform, ""); actualValues.put(waveform, "");
} else if(waveform instanceof ISignal<?>){ } else if (waveform instanceof ISignal<?>) {
painter= new SignalPainter(trackList, even, height, (ISignal<?>) waveform); painter = new SignalPainter(trackList, even, height,
(ISignal<?>) waveform);
actualValues.put(waveform, "---"); actualValues.put(waveform, "---");
} }
trackList.addWavefromPainter(yoffs, painter); trackList.addWavefromPainter(yoffs, painter);
trackVerticalOffset.put(yoffs, waveform); trackVerticalOffset.put(yoffs, waveform);
tl.setText(waveform.getFullName()); tl.setText(waveform.getFullName());
nameMaxWidth=Math.max(nameMaxWidth, tl.getBounds().width); nameMaxWidth = Math.max(nameMaxWidth, tl.getBounds().width);
yoffs+=height; yoffs += height;
even=!even; even = !even;
} }
nameList.setSize(nameMaxWidth+15, yoffs); nameList.setSize(nameMaxWidth + 15, yoffs);
nameListScrolled.setMinSize(nameMaxWidth+15, yoffs); nameListScrolled.setMinSize(nameMaxWidth + 15, yoffs);
valueList.setSize(calculateValueWidth(), yoffs); valueList.setSize(calculateValueWidth(), yoffs);
valueListScrolled.setMinSize(calculateValueWidth(), yoffs); valueListScrolled.setMinSize(calculateValueWidth(), yoffs);
nameList.redraw(); nameList.redraw();
valueList.redraw(); valueList.redraw();
trackList.redraw(); trackList.redraw();
top.layout(new Control[]{valueList, nameList, trackList}); top.layout(new Control[] { valueList, nameList, trackList });
if(previousHeight>trackVerticalOffset.lastKey()){
trackList.scrollToY(trackList.getOrigin().y-(previousHeight-trackVerticalOffset.lastKey()));
}
setSelection(new StructuredSelection());
} }
private int calculateValueWidth() { private int calculateValueWidth() {
TextLayout tl = new TextLayout(trackList.getDisplay()); TextLayout tl = new TextLayout(trackList.getDisplay());
tl.setFont(nameFontB); tl.setFont(nameFontB);
int valueMaxWidth=0; int valueMaxWidth = 0;
for(String v:actualValues.values()){ for (String v : actualValues.values()) {
tl.setText(v); tl.setText(v);
valueMaxWidth=Math.max(valueMaxWidth, tl.getBounds().width); valueMaxWidth = Math.max(valueMaxWidth, tl.getBounds().width);
} }
return valueMaxWidth+15; return valueMaxWidth + 15;
} }
@Override @Override
@ -313,15 +347,20 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
} }
@Override @Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) { public void removeSelectionChangedListener(
ISelectionChangedListener listener) {
listeners.remove(listener); listeners.remove(listener);
} }
public Control getControl(){
return top;
}
@Override @Override
public ISelection getSelection() { public ISelection getSelection() {
if(currentSelection!=null) if (currentSelection != null)
return new StructuredSelection(currentSelection); return new StructuredSelection(currentSelection);
else if(currentWaveformSelection!=null) else if (currentWaveformSelection != null)
return new StructuredSelection(currentWaveformSelection); return new StructuredSelection(currentWaveformSelection);
else else
return null; return null;
@ -330,24 +369,29 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void setSelection(ISelection selection) { public void setSelection(ISelection selection) {
boolean selectionChanged=false; boolean selectionChanged = false;
if(selection instanceof IStructuredSelection){ if (selection instanceof IStructuredSelection) {
Object sel =((IStructuredSelection)selection).getFirstElement(); Object sel = ((IStructuredSelection) selection).getFirstElement();
if(sel instanceof ITx && currentSelection!=sel){ if (sel instanceof ITx && currentSelection != sel) {
currentSelection=(ITx) sel; currentSelection = (ITx) sel;
currentWaveformSelection = currentSelection.getStream(); currentWaveformSelection = currentSelection.getStream();
selectionChanged=true; selectionChanged = true;
} else if(sel instanceof IWaveform<?> && currentWaveformSelection!=sel){ } else if (sel instanceof IWaveform<?>
currentSelection=null; && currentWaveformSelection != sel) {
currentSelection = null;
currentWaveformSelection = (IWaveform<? extends IWaveformEvent>) sel; currentWaveformSelection = (IWaveform<? extends IWaveformEvent>) sel;
selectionChanged=true; selectionChanged = true;
} }
} else { } else {
if(currentSelection!=null || currentWaveformSelection!=null) selectionChanged=true; if (currentSelection != null || currentWaveformSelection != null)
currentSelection=null; selectionChanged = true;
currentSelection = null;
currentWaveformSelection = null; currentWaveformSelection = null;
} }
if(selectionChanged){ if(currentWaveformSelection!=null && !streams.contains(currentWaveformSelection)){
streams.add(currentWaveformSelection);
}
if (selectionChanged) {
trackList.setSelected(currentSelection, currentWaveformSelection); trackList.setSelected(currentSelection, currentWaveformSelection);
nameList.setData(SELECTION, currentWaveformSelection); nameList.setData(SELECTION, currentWaveformSelection);
valueList.redraw(); valueList.redraw();
@ -361,36 +405,36 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void moveSelection(GotoDirection direction) { public void moveSelection(GotoDirection direction) {
if(currentWaveformSelection instanceof ITxStream<?>){ if (currentWaveformSelection instanceof ITxStream<?>) {
ITxStream<ITxEvent> stream = (ITxStream<ITxEvent>) currentWaveformSelection; ITxStream<ITxEvent> stream = (ITxStream<ITxEvent>) currentWaveformSelection;
ITx transaction=null; ITx transaction = null;
if(direction==GotoDirection.NEXT){ if (direction == GotoDirection.NEXT) {
Entry<Long, List<ITxEvent>> entry = stream.getEvents().higherEntry(currentSelection.getBeginTime()); Entry<Long, List<ITxEvent>> entry = stream.getEvents().higherEntry(currentSelection.getBeginTime());
if(entry!=null) if (entry != null)
do { do {
for(ITxEvent evt:entry.getValue()){ for (ITxEvent evt : entry.getValue()) {
if(evt.getType()==ITxEvent.Type.BEGIN){ if (evt.getType() == ITxEvent.Type.BEGIN) {
transaction=evt.getTransaction(); transaction = evt.getTransaction();
break; break;
} }
} }
if(transaction==null) if (transaction == null)
entry=stream.getEvents().higherEntry(entry.getKey()); entry = stream.getEvents().higherEntry(entry.getKey());
}while(entry!=null && transaction==null); } while (entry != null && transaction == null);
}else if(direction==GotoDirection.PREV){ } else if (direction == GotoDirection.PREV) {
Entry<Long, List<ITxEvent>> entry = stream.getEvents().lowerEntry(currentSelection.getBeginTime()); Entry<Long, List<ITxEvent>> entry = stream.getEvents().lowerEntry(currentSelection.getBeginTime());
if(entry!=null) if (entry != null)
do { do {
for(ITxEvent evt:entry.getValue()){ for (ITxEvent evt : entry.getValue()) {
if(evt.getType()==ITxEvent.Type.BEGIN) if (evt.getType() == ITxEvent.Type.BEGIN)
transaction=evt.getTransaction(); transaction = evt.getTransaction();
break; break;
} }
if(transaction==null) if (transaction == null)
entry=stream.getEvents().lowerEntry(entry.getKey()); entry = stream.getEvents().lowerEntry(entry.getKey());
}while(entry!=null && transaction==null); } while (entry != null && transaction == null);
} }
if(transaction!=null){ if (transaction != null) {
setSelection(new StructuredSelection(transaction)); setSelection(new StructuredSelection(transaction));
} }
} }
@ -402,45 +446,61 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@Override @Override
public void mouseDown(MouseEvent e) { public void mouseDown(MouseEvent e) {
if(e.widget==trackList){ if(e.button==1 || e.button==3){
if (e.widget == trackList) {
Object o = trackList.getClicked(new Point(e.x, e.y)); Object o = trackList.getClicked(new Point(e.x, e.y));
if(o !=null) if (o != null)
setSelection(new StructuredSelection(o)); setSelection(new StructuredSelection(o));
}else if(e.widget==valueList || e.widget==nameList){ } else if (e.widget == valueList || e.widget == nameList) {
Entry<Integer, IWaveform<? extends IWaveformEvent>> entry = trackVerticalOffset.floorEntry(e.y); Entry<Integer, IWaveform<? extends IWaveformEvent>> entry = trackVerticalOffset
if(entry!=null) .floorEntry(e.y);
if (entry != null)
setSelection(new StructuredSelection(entry.getValue())); setSelection(new StructuredSelection(entry.getValue()));
} }
} }
if(e.button==3){
top.getMenu().setVisible(true);
}
}
@Override @Override
public void mouseUp(MouseEvent e) { public void mouseUp(MouseEvent e) {
} }
public List<IWaveform<? extends IWaveformEvent>> getStreamList(){ public List<IWaveform<? extends IWaveformEvent>> getStreamList() {
return streams; return streams;
} }
protected void paintNames(GC gc, Rectangle rect) { protected void paintNames(GC gc, Rectangle rect) {
if(streams.size()>0){ if (streams.size() > 0) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList.getData(SELECTION); IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList
Integer firstKey=trackVerticalOffset.floorKey(rect.y); .getData(SELECTION);
if(firstKey==null) firstKey=trackVerticalOffset.firstKey(); Integer firstKey = trackVerticalOffset.floorKey(rect.y);
Integer lastKey = trackVerticalOffset.floorKey(rect.y+rect.height); if (firstKey == null)
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, trackList.getTrackHeight()); firstKey = trackVerticalOffset.firstKey();
if(lastKey==firstKey){ Integer lastKey = trackVerticalOffset
IWaveform<? extends IWaveformEvent> w = trackVerticalOffset.get(firstKey); .floorKey(rect.y + rect.height);
if(w instanceof ITxStream<?>) Rectangle subArea = new Rectangle(rect.x, 0, rect.width,
subArea.height*=((ITxStream<?>)w).getMaxConcurrency(); trackList.getTrackHeight());
drawTextFormat(gc, subArea, firstKey, w.getFullName(), wave!=null && w.getId()==wave.getId()); if (lastKey == firstKey) {
}else{ IWaveform<? extends IWaveformEvent> w = trackVerticalOffset
for(Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()){ .get(firstKey);
if (w instanceof ITxStream<?>)
subArea.height *= ((ITxStream<?>) w).getMaxConcurrency();
drawTextFormat(gc, subArea, firstKey, w.getFullName(),
wave != null && w.getId() == wave.getId());
} else {
for (Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset
.subMap(firstKey, true, lastKey, true).entrySet()) {
IWaveform<? extends IWaveformEvent> w = entry.getValue(); IWaveform<? extends IWaveformEvent> w = entry.getValue();
subArea.height=trackList.getTrackHeight(); subArea.height = trackList.getTrackHeight();
if(w instanceof ITxStream<?>) if (w instanceof ITxStream<?>)
subArea.height*=((ITxStream<?>)w).getMaxConcurrency(); subArea.height *= ((ITxStream<?>) w)
drawTextFormat(gc, subArea, entry.getKey(), w.getFullName(), wave!=null && w.getId()==wave.getId()); .getMaxConcurrency();
drawTextFormat(gc, subArea, entry.getKey(),
w.getFullName(),
wave != null && w.getId() == wave.getId());
} }
} }
} }
@ -448,42 +508,62 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void paintValues(GC gc, Rectangle rect) { protected void paintValues(GC gc, Rectangle rect) {
if(streams.size()>0){ if (streams.size() > 0) {
IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList.getData(SELECTION); IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList
Integer firstKey=trackVerticalOffset.floorKey(rect.y); .getData(SELECTION);
if(firstKey==null) firstKey=trackVerticalOffset.firstKey(); Integer firstKey = trackVerticalOffset.floorKey(rect.y);
Integer lastKey = trackVerticalOffset.floorKey(rect.y+rect.height); if (firstKey == null)
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, trackList.getTrackHeight()); firstKey = trackVerticalOffset.firstKey();
if(lastKey==firstKey){ Integer lastKey = trackVerticalOffset
IWaveform<? extends IWaveformEvent> w = trackVerticalOffset.get(firstKey); .floorKey(rect.y + rect.height);
if(w instanceof ITxStream<?>) Rectangle subArea = new Rectangle(rect.x, 0, rect.width,
subArea.height*=((ITxStream<?>)w).getMaxConcurrency(); trackList.getTrackHeight());
drawTextFormat(gc, subArea, firstKey, actualValues.get(w), wave!=null && w.getId()==wave.getId()); if (lastKey == firstKey) {
}else{ IWaveform<? extends IWaveformEvent> w = trackVerticalOffset
for(Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()){ .get(firstKey);
if (w instanceof ITxStream<?>)
subArea.height *= ((ITxStream<?>) w).getMaxConcurrency();
drawTextFormat(gc, subArea, firstKey, actualValues.get(w),
wave != null && w.getId() == wave.getId());
} else {
for (Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset
.subMap(firstKey, true, lastKey, true).entrySet()) {
IWaveform<? extends IWaveformEvent> w = entry.getValue(); IWaveform<? extends IWaveformEvent> w = entry.getValue();
subArea.height=trackList.getTrackHeight(); subArea.height = trackList.getTrackHeight();
if(w instanceof ITxStream<?>) if (w instanceof ITxStream<?>)
subArea.height*=((ITxStream<?>)w).getMaxConcurrency(); subArea.height *= ((ITxStream<?>) w)
drawTextFormat(gc, subArea, entry.getKey(), actualValues.get(w), wave!=null && w.getId()==wave.getId()); .getMaxConcurrency();
drawTextFormat(gc, subArea, entry.getKey(),
actualValues.get(w), wave != null
&& w.getId() == wave.getId());
} }
} }
} }
} }
protected void drawTextFormat(GC gc, Rectangle subArea, int yOffset, String value, boolean highlite) { protected void drawTextFormat(GC gc, Rectangle subArea, int yOffset,
String value, boolean highlite) {
Point size = gc.textExtent(value); Point size = gc.textExtent(value);
if(highlite){ if (highlite) {
gc.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION)); gc.setBackground(SWTResourceManager
gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT)); .getColor(SWT.COLOR_LIST_SELECTION));
gc.fillRectangle(subArea.x, subArea.y+yOffset, subArea.width, subArea.height); gc.setForeground(SWTResourceManager
.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
gc.fillRectangle(subArea.x, subArea.y + yOffset, subArea.width,
subArea.height);
gc.setFont(nameFontB); gc.setFont(nameFontB);
}else{ } else {
gc.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND)); gc.setBackground(SWTResourceManager
gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_FOREGROUND)); .getColor(SWT.COLOR_LIST_BACKGROUND));
gc.setForeground(SWTResourceManager
.getColor(SWT.COLOR_LIST_FOREGROUND));
gc.setFont(nameFont); gc.setFont(nameFont);
} }
gc.drawText(value, subArea.x+5, subArea.y + yOffset+(trackList.getTrackHeight()-size.y)/2, true); gc.drawText(
value,
subArea.x + 5,
subArea.y + yOffset + (trackList.getTrackHeight() - size.y) / 2,
true);
} }
public long getMaxTime() { public long getMaxTime() {
@ -501,7 +581,66 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
public int getZoomLevel() { public int getZoomLevel() {
return trackList.getZoomLevel(); return trackList.getZoomLevel();
} }
// public long getScaleFactor(){
// return trackList.getScaleFactor(); private void createDragSource(final Canvas sourceText) {
// } Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
DragSource dragSource = new DragSource(sourceText, DND.DROP_MOVE);
dragSource.setTransfer(types);
dragSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
if (event.y < trackVerticalOffset.lastKey() + trackList.getTrackHeight()) {
// event.data = trackVerticalOffset.floorEntry(event.y).getValue().getFullName();
event.doit = true;
// System.out.println("dragStart at location "+new Point(event.x, event.y));
}
}
public void dragSetData(DragSourceEvent event) {
event.data = trackVerticalOffset.floorEntry(event.y).getValue().getFullName();
// System.out.println("dragSetData with data " + event.data);
}
public void dragFinished(DragSourceEvent event) {
// do nothing
}
});
}
private void createDropTarget(final Canvas targetText) {
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
DropTarget dropTarget = new DropTarget(targetText, DND.DROP_MOVE);
dropTarget.setTransfer(types);
dropTarget.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
Object data = event.data;
DropTarget tgt = (DropTarget) event.widget;
Point dropPoint = ((Canvas)tgt.getControl()).toControl(event.x, event.y);
String fullname1 = trackVerticalOffset.floorEntry(dropPoint.y).getValue().getFullName();
// System.out.println("drop with data '" + event.data +"' at location "+dropPoint + " and origin " + nameListScrolled.getOrigin());
// System.out.println("drop on " + fullname1);
}
public void dropAccept(DropTargetEvent event) {
if (event.detail != DND.DROP_MOVE || event.y > trackVerticalOffset.lastKey() + trackList.getTrackHeight()) {
event.detail = DND.DROP_NONE;
}
}
});
}
} }

View File

@ -102,7 +102,9 @@ public class StreamPainter implements IWaveformPainter{
(int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+upper, (int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+upper,
(int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight); (int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight);
if(bb.x+bb.width<area.x || bb.x>area.x+area.width) return; if(bb.x+bb.width<area.x || bb.x>area.x+area.width) return;
if(bb.width<10){ if(bb.width==0){
gc.drawLine(bb.x, bb.y, bb.x, bb.y+bb.height);
} else if(bb.width<10){
gc.fillRectangle(bb); gc.fillRectangle(bb);
gc.drawRectangle(bb); gc.drawRectangle(bb);
} else { } else {
@ -129,6 +131,14 @@ public class StreamPainter implements IWaveformPainter{
return stream; return stream;
} }
public ITxStream<? extends ITxEvent> getStream() {
return stream;
}
public void setStream(ITxStream<? extends ITxEvent> stream) {
this.stream = stream;
}
protected ITx getTxFromEntry(int lane, Entry<Long, List<ITxEvent>> firstTx) { protected ITx getTxFromEntry(int lane, Entry<Long, List<ITxEvent>> firstTx) {
for(ITxEvent evt:firstTx.getValue()){ for(ITxEvent evt:firstTx.getValue()){
if(evt.getType()==ITxEvent.Type.BEGIN && evt.getTransaction().getConcurrencyIndex()==lane){ if(evt.getType()==ITxEvent.Type.BEGIN && evt.getTransaction().getConcurrencyIndex()==lane){

View File

@ -12,6 +12,7 @@ package com.minres.scviewer.database.swt.internal;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
@ -30,6 +31,9 @@ public class TrackPainter implements IPainter {
} }
public void paintArea(GC gc, Rectangle area) { public void paintArea(GC gc, Rectangle area) {
gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TRACK_BG_EVEN.ordinal()]);
gc.setFillRule(SWT.FILL_EVEN_ODD);
gc.fillRectangle(area);
if(this.waveCanvas.streams.size()>0){ if(this.waveCanvas.streams.size()>0){
Integer firstKey=this.waveCanvas.trackVerticalOffset.floorKey(area.y); Integer firstKey=this.waveCanvas.trackVerticalOffset.floorKey(area.y);
if(firstKey==null) firstKey=this.waveCanvas.trackVerticalOffset.firstKey(); if(firstKey==null) firstKey=this.waveCanvas.trackVerticalOffset.firstKey();

View File

@ -144,7 +144,7 @@ public class WaveformCanvas extends Canvas {
this.ruler=ruler; this.ruler=ruler;
} }
public Object getOrigin() { public Point getOrigin() {
return origin; return origin;
} }
@ -350,19 +350,31 @@ public class WaveformCanvas extends Canvas {
public void setSelected(ITx currentSelection, IWaveform<? extends IWaveformEvent> currentWaveformSelection) { public void setSelected(ITx currentSelection, IWaveform<? extends IWaveformEvent> currentWaveformSelection) {
this.currentSelection=currentSelection; this.currentSelection=currentSelection;
this.currentWaveformSelection=currentWaveformSelection; this.currentWaveformSelection=currentWaveformSelection;
if(currentSelection!=null) reveal(currentSelection.getBeginTime(), currentSelection.getEndTime()); if(currentSelection!=null) reveal(currentSelection);
redraw(); redraw();
} }
public void reveal(Long beginTime, Long endTime) { public void reveal(ITx tx){
int lower = (int) (beginTime/scaleFactor); int lower = (int) (tx.getBeginTime()/scaleFactor);
int higher=(int) (endTime/scaleFactor); int higher=(int) (tx.getEndTime()/scaleFactor);
Point size = getSize(); Point size = getSize();
if(lower<-origin.x){ if(lower<-origin.x){
scrollToX(lower); scrollToX(lower);
} else if(higher>(size.x-origin.x)){ } else if(higher>(size.x-origin.x)){
scrollToX(higher-size.x); scrollToX(higher-size.x);
} }
for(Entry<Integer, IWaveformPainter> entry:trackVerticalOffset.entrySet()){
if(entry.getValue() instanceof StreamPainter && ((StreamPainter)entry.getValue()).getStream()==tx.getStream()){
int top = entry.getKey()+trackHeight*tx.getConcurrencyIndex();
int bottom = top+trackHeight*(tx.getConcurrencyIndex()+1);
if(top<-origin.y){
scrollToY(bottom);
} else if(bottom>(size.y-origin.y)){
scrollToY(bottom-size.y);
}
}
}
} }
} }

View File

@ -4,4 +4,5 @@ org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -289,6 +289,70 @@
</parameter> </parameter>
</command> </command>
</menuContribution> </menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:com.minres.scviewer.ui.TxEditorPart">
<command
commandId="com.minres.scviewer.ui.removeWave"
label="Remove"
style="push"
tooltip="Go to next event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomin"
label="Zoom in"
style="push"
tooltip="Zoom into">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomout"
label="Zoom out"
style="push"
tooltip="Zoom out of">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.gotoPrev"
label="Prev"
style="push"
tooltip="Go to previous event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.gotoNext"
label="Next"
style="push"
tooltip="Go to next event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.commands"> point="org.eclipse.ui.commands">
@ -321,6 +385,10 @@
id="com.minres.scviewer.ui.zoomout" id="com.minres.scviewer.ui.zoomout"
name="Zoom out"> name="Zoom out">
</command> </command>
<command
id="com.minres.scviewer.ui.removeWave"
name="Remove wave">
</command>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.handlers"> point="org.eclipse.ui.handlers">
@ -329,7 +397,7 @@
commandId="com.minres.scviewer.ui.gotoPrev"> commandId="com.minres.scviewer.ui.gotoPrev">
<enabledWhen> <enabledWhen>
<reference <reference
definitionId="com.minres.scviewer.ui.oneElementSeleted"> definitionId="com.minres.scviewer.ui.oneTxSeleted">
</reference> </reference>
</enabledWhen> </enabledWhen>
</handler> </handler>
@ -338,7 +406,7 @@
commandId="com.minres.scviewer.ui.gotoNext"> commandId="com.minres.scviewer.ui.gotoNext">
<enabledWhen> <enabledWhen>
<reference <reference
definitionId="com.minres.scviewer.ui.oneElementSeleted"> definitionId="com.minres.scviewer.ui.oneTxSeleted">
</reference> </reference>
</enabledWhen> </enabledWhen>
</handler> </handler>
@ -360,11 +428,35 @@
</reference> </reference>
</enabledWhen> </enabledWhen>
</handler> </handler>
<handler
class="com.minres.scviewer.ui.handler.RemoveHandler"
commandId="com.minres.scviewer.ui.removeWave">
<enabledWhen>
<reference
definitionId="com.minres.scviewer.ui.oneWaveSeleted">
</reference>
</enabledWhen>
</handler>
</extension> </extension>
<extension <extension
point="org.eclipse.core.expressions.definitions"> point="org.eclipse.core.expressions.definitions">
<definition <definition
id="com.minres.scviewer.ui.oneElementSeleted"> id="com.minres.scviewer.ui.oneWaveSeleted">
<with
variable="selection">
<and>
<count
value="1">
</count>
<iterate
operator="or">
<instanceof value="com.minres.scviewer.database.IWaveform"/>
</iterate>
</and>
</with>
</definition>
<definition
id="com.minres.scviewer.ui.oneTxSeleted">
<with <with
variable="selection"> variable="selection">
<and> <and>
@ -412,6 +504,10 @@
commandId="com.minres.scviewer.ui.zoomout" commandId="com.minres.scviewer.ui.zoomout"
icon="res/images/zoom_out.png"> icon="res/images/zoom_out.png">
</image> </image>
<image
commandId="com.minres.scviewer.ui.removeWave"
icon="res/images/cross.png">
</image>
</extension> </extension>
</plugin> </plugin>

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

View File

@ -22,11 +22,13 @@ import java.util.regex.Pattern;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineContributionItem; import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars; import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IEditorSite;
@ -110,6 +112,18 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
} }
}).run(); }).run();
zoomStatusLineItem.setText("Zoom level: "+zoomLevel[txDisplay.getZoomLevel()]); zoomStatusLineItem.setText("Zoom level: "+zoomLevel[txDisplay.getZoomLevel()]);
MenuManager menuMgr = new MenuManager("#PopupMenu");
// menuMgr.setRemoveAllWhenShown(true);
// menuMgr.addMenuListener(new IMenuListener() {
// public void menuAboutToShow(IMenuManager manager) {
// fillContextMenu(manager);
// }
// });
Menu menu = menuMgr.createContextMenu(txDisplay.getControl());
txDisplay.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, txDisplay);
} }
/* /*
@ -332,6 +346,10 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
}); });
} }
public ISelection getSelection(){
return txDisplay.getSelection();
}
@Override @Override
public String getContributorId() { public String getContributorId() {
return getSite().getId(); return getSite().getId();
@ -353,4 +371,9 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
return txDisplay.getZoomLevel(); return txDisplay.getZoomLevel();
} }
public void removeSelected() {
// TODO Auto-generated method stub
}
} }

View File

@ -0,0 +1,33 @@
package com.minres.scviewer.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.internal.misc.StringMatcher;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.ui.TxEditorPart;
public class RemoveHandler extends AbstractHandler {
@SuppressWarnings("unchecked")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if(editor instanceof TxEditorPart){
TxEditorPart editorPart = (TxEditorPart) editor;
ISelection selection =editorPart.getSelection();
if(selection instanceof StructuredSelection && ((StructuredSelection)selection).getFirstElement() instanceof IWaveform<?>){
editorPart.removeStreamFromList((IWaveform<? extends IWaveformEvent>) ((StructuredSelection)selection).getFirstElement());
editorPart.setSelection(new StructuredSelection());
}
}
return null;
}
}