diff --git a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/RelationTypeFactory.java b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/RelationTypeFactory.java deleted file mode 100644 index 1248433..0000000 --- a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/RelationTypeFactory.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 MINRES Technologies GmbH and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * MINRES Technologies GmbH - initial API and implementation - *******************************************************************************/ -package com.minres.scviewer.database.sqlite; - -import java.util.HashMap; - -import com.minres.scviewer.database.RelationType; - -class RelationTypeFactory { - - HashMap registry=new HashMap(); - - public RelationType getRelationType(String name) { - if(registry.containsKey(name)) return registry.get(name); - RelationType rt = new RelationType(name); - registry.put(name, rt); - return rt; - } - -} diff --git a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java index 934e06b..8e92ad0 100644 --- a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java +++ b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java @@ -16,12 +16,14 @@ import java.io.FileInputStream; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDbLoader; import com.minres.scviewer.database.IWaveformEvent; +import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.sqlite.db.IDatabase; import com.minres.scviewer.database.sqlite.db.SQLiteDatabase; import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler; @@ -33,7 +35,7 @@ public class SQLiteDbLoader implements IWaveformDbLoader { protected IDatabase database; - private RelationTypeFactory rtf = new RelationTypeFactory(); + private List usedRelationsList = new ArrayList<>(); private IWaveformDb db; @@ -64,7 +66,7 @@ public class SQLiteDbLoader implements IWaveformDbLoader { try { for(ScvStream scvStream:handler.selectObjects()){ TxStream stream = new TxStream(database, db, scvStream); - stream.setRelationTypeFactory(rtf); + stream.setRelationTypeList(usedRelationsList); streams.add(stream); } } catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException @@ -102,4 +104,10 @@ public class SQLiteDbLoader implements IWaveformDbLoader { } return false; } + + @Override + public Collection getAllRelationTypes(){ + return usedRelationsList; + } + } diff --git a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxStream.java b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxStream.java index 952da48..98eba3e 100644 --- a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxStream.java +++ b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxStream.java @@ -55,7 +55,7 @@ public class TxStream extends HierNode implements ITxStream { private TreeMap> events; - private RelationTypeFactory relationMap; + private List usedRelationsList; public TxStream(IDatabase database, IWaveformDb waveformDb, ScvStream scvStream) { super(scvStream.getName()); @@ -181,14 +181,14 @@ public class TxStream extends HierNode implements ITxStream { return getEvents().get(time); } - public void setRelationTypeFactory(RelationTypeFactory rtf) { - this.relationMap=rtf; - + public void setRelationTypeList(List usedRelationsList){ + this.usedRelationsList=usedRelationsList; } - + public RelationType getRelationType(String name) { - if(relationMap!=null) return relationMap.getRelationType(name); - return null; + RelationType relType=RelationType.create(name); + if(!usedRelationsList.contains(relType)) usedRelationsList.add(relType); + return relType; } @Override diff --git a/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy b/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy index 1abd546..5ee1689 100644 --- a/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy +++ b/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy @@ -10,6 +10,8 @@ *******************************************************************************/ package com.minres.scviewer.database.text; +import java.util.Collection; + import com.minres.scviewer.database.AssociationType import com.minres.scviewer.database.DataType import com.minres.scviewer.database.ITxGenerator @@ -145,7 +147,7 @@ public class TextDbLoader implements IWaveformDbLoader{ Tx tr2= transactionsById[Integer.parseInt(tokens[2])] Tx tr1= transactionsById[Integer.parseInt(tokens[3])] def relType=tokens[1][1..-2] - if(!relationTypes.containsKey(relType)) relationTypes[relType]=new RelationType(relType) + if(!relationTypes.containsKey(relType)) relationTypes[relType]=RelationType.create(relType) def rel = new TxRelation(relationTypes[relType], tr1, tr2) tr1.outgoingRelations< stream.getMaxConcurrency() } } + + + public Collection getAllRelationTypes(){ + return relationTypes.values(); + } + } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java index 5ca340d..4834914 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java @@ -25,127 +25,154 @@ import org.eclipse.swt.widgets.Display; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITxRelation; import com.minres.scviewer.database.ITxStream; +import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.ui.WaveformColors; public class ArrowPainter implements IPainter { - - private final int xCtrlOffset=50; - private final int yCtrlOffset=30; + private final int xCtrlOffset = 50; + + private final int yCtrlOffset = 30; private WaveformCanvas waveCanvas; private ITx tx; - private List iRect; + private List iRect; - private List oRect; + private List oRect; private Rectangle txRectangle; - + + private RelationType highlightType; + long scaleFactor; - + boolean deferredUpdate; - public ArrowPainter(WaveformCanvas waveCanvas) { + public ArrowPainter(WaveformCanvas waveCanvas, RelationType relationType) { this.waveCanvas = waveCanvas; + highlightType=relationType; setTx(null); } + public RelationType getHighlightType() { + return highlightType; + } + + public void setHighlightType(RelationType highlightType) { + this.highlightType = highlightType; + } + public ITx getTx() { return tx; } public void setTx(ITx newTx) { this.tx = newTx; - iRect=new LinkedList<>(); - oRect=new LinkedList<>(); - scaleFactor=waveCanvas.getScaleFactor(); - if(tx!=null){ + iRect = new LinkedList<>(); + oRect = new LinkedList<>(); + scaleFactor = waveCanvas.getScaleFactor(); + if (tx != null) { calculateGeometries(); } } protected void calculateGeometries() { - deferredUpdate=false; - ITxStream stream=tx.getStream(); - IWaveformPainter painter=waveCanvas.wave2painterMap.get(stream); - if(painter==null){ // stream has been added but painter not yet created - deferredUpdate=true; + deferredUpdate = false; + ITxStream stream = tx.getStream(); + IWaveformPainter painter = waveCanvas.wave2painterMap.get(stream); + if (painter == null) { // stream has been added but painter not yet + // created + deferredUpdate = true; return; } - int laneHeight=painter.getHeight()/stream.getMaxConcurrency(); - txRectangle = new Rectangle( - (int)(tx.getBeginTime()/scaleFactor), - waveCanvas.rulerHeight+painter.getVerticalOffset()+laneHeight*tx.getConcurrencyIndex(), - (int)((tx.getEndTime()-tx.getBeginTime())/scaleFactor), - laneHeight); + int laneHeight = painter.getHeight() / stream.getMaxConcurrency(); + txRectangle = new Rectangle((int) (tx.getBeginTime() / scaleFactor), + waveCanvas.rulerHeight + painter.getVerticalOffset() + laneHeight * tx.getConcurrencyIndex(), + (int) ((tx.getEndTime() - tx.getBeginTime()) / scaleFactor), laneHeight); deriveGeom(tx.getIncomingRelations(), iRect, false); deriveGeom(tx.getOutgoingRelations(), oRect, true); } - protected void deriveGeom(Collection relations, List res, boolean useTarget) { - for(ITxRelation iTxRelation: relations){ - ITx otherTx = useTarget?iTxRelation.getTarget():iTxRelation.getSource(); - if(waveCanvas.wave2painterMap.containsKey(otherTx.getStream())){ - ITxStream stream=otherTx.getStream(); - IWaveformPainter painter=waveCanvas.wave2painterMap.get(stream); - int laneHeight=painter.getHeight()/stream.getMaxConcurrency(); - Rectangle bb = new Rectangle( - (int)(otherTx.getBeginTime()/scaleFactor), - waveCanvas.rulerHeight+painter.getVerticalOffset()+laneHeight*otherTx.getConcurrencyIndex(), - (int)((otherTx.getEndTime()-otherTx.getBeginTime())/scaleFactor), - laneHeight); - res.add(bb); + protected void deriveGeom(Collection relations, List res, boolean useTarget) { + for (ITxRelation iTxRelation : relations) { + ITx otherTx = useTarget ? iTxRelation.getTarget() : iTxRelation.getSource(); + if (waveCanvas.wave2painterMap.containsKey(otherTx.getStream())) { + ITxStream stream = otherTx.getStream(); + IWaveformPainter painter = waveCanvas.wave2painterMap.get(stream); + int laneHeight = painter.getHeight() / stream.getMaxConcurrency(); + Rectangle bb = new Rectangle((int) (otherTx.getBeginTime() / scaleFactor), + waveCanvas.rulerHeight + painter.getVerticalOffset() + + laneHeight * otherTx.getConcurrencyIndex(), + (int) ((otherTx.getEndTime() - otherTx.getBeginTime()) / scaleFactor), laneHeight); + res.add(new LinkEntry(bb, iTxRelation.getRelationType())); } } } @Override public void paintArea(GC gc, Rectangle area) { - Color fgColor=waveCanvas.colors[WaveformColors.REL_ARROW.ordinal()]; - if(deferredUpdate || (tx!=null && waveCanvas.getScaleFactor()!=scaleFactor)){ - scaleFactor=waveCanvas.getScaleFactor(); + Color fgColor = waveCanvas.colors[WaveformColors.REL_ARROW.ordinal()]; + Color highliteColor = waveCanvas.colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()]; + + if (deferredUpdate || (tx != null && waveCanvas.getScaleFactor() != scaleFactor)) { + scaleFactor = waveCanvas.getScaleFactor(); calculateGeometries(); } - for(Rectangle srcRectangle:iRect){ - Point target = drawPath(gc, fgColor, srcRectangle, txRectangle); - gc.drawLine(target.x-8,target.y-5, target.x,target.y); - gc.drawLine(target.x-8,target.y+5, target.x,target.y); + for (LinkEntry entry : iRect) { + Point target = drawPath(gc, highlightType.equals(entry.relationType) ? highliteColor : fgColor, + entry.rectangle, txRectangle); + drawArrow(gc, target); } - for(Rectangle tgtRectangle:oRect){ - Point target = drawPath(gc, fgColor, txRectangle, tgtRectangle); - gc.drawLine(target.x-8,target.y-5, target.x,target.y); - gc.drawLine(target.x-8,target.y+5, target.x,target.y); + for (LinkEntry entry : oRect) { + Point target = drawPath(gc, highlightType.equals(entry.relationType) ? highliteColor : fgColor, txRectangle, + entry.rectangle); + drawArrow(gc, target); } } + protected void drawArrow(GC gc, Point target) { + gc.drawLine(target.x - 8, target.y - 5, target.x, target.y); + gc.drawLine(target.x - 8, target.y + 5, target.x, target.y); + } + protected Point drawPath(GC gc, Color fgColor, Rectangle srcRectangle, Rectangle tgtRectangle) { - Point point1=new Point(0, srcRectangle.y+srcRectangle.height/2); - Point point2=new Point(0, tgtRectangle.y+tgtRectangle.height/2); + Point point1 = new Point(0, srcRectangle.y + srcRectangle.height / 2); + Point point2 = new Point(0, tgtRectangle.y + tgtRectangle.height / 2); point1.x = srcRectangle.x; point2.x = tgtRectangle.x; - if(point2.x>point1.x+srcRectangle.width) point1.x+=srcRectangle.width; - if(point1.x>point2.x+tgtRectangle.width) point2.x+=tgtRectangle.width; + if (point2.x > point1.x + srcRectangle.width) + point1.x += srcRectangle.width; + if (point1.x > point2.x + tgtRectangle.width) + point2.x += tgtRectangle.width; - Path path=new Path(Display.getCurrent()); - path.moveTo(point1.x,point1.y); - if(point1.y==point2.y){ - Point center=new Point((point1.x+point2.x)/2, point1.y-yCtrlOffset); - path.cubicTo(point1.x+xCtrlOffset, point1.y, - center.x-xCtrlOffset, center.y, - center.x, center.y); - path.cubicTo(center.x+xCtrlOffset, center.y, - point2.x-xCtrlOffset, point2.y, - point2.x, point2.y); + Path path = new Path(Display.getCurrent()); + path.moveTo(point1.x, point1.y); + if (point1.y == point2.y) { + Point center = new Point((point1.x + point2.x) / 2, point1.y - yCtrlOffset); + path.cubicTo(point1.x + xCtrlOffset, point1.y, center.x - xCtrlOffset, center.y, center.x, center.y); + path.cubicTo(center.x + xCtrlOffset, center.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y); } else - path.cubicTo(point1.x+xCtrlOffset, point1.y, point2.x-xCtrlOffset, point2.y, point2.x, point2.y); + path.cubicTo(point1.x + xCtrlOffset, point1.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y); gc.setAntialias(SWT.ON); gc.setForeground(fgColor); gc.drawPath(path); path.dispose(); return point2; } + + class LinkEntry { + public Rectangle rectangle; + public RelationType relationType; + + public LinkEntry(Rectangle rectangle, RelationType relationType) { + super(); + this.rectangle = rectangle; + this.relationType = relationType; + } + } + } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java index afbf147..8b9f0bd 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java @@ -40,6 +40,8 @@ import com.google.common.collect.Lists; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformEvent; +import com.minres.scviewer.database.RelationType; +import com.minres.scviewer.database.ui.IWaveformViewer; import com.minres.scviewer.database.ui.WaveformColors; public class WaveformCanvas extends Canvas { @@ -115,7 +117,7 @@ public class WaveformCanvas extends Canvas { painterList.add(trackAreaPainter); rulerPainter=new RulerPainter(this); painterList.add(rulerPainter); - arrowPainter=new ArrowPainter(this); + arrowPainter=new ArrowPainter(this, IWaveformViewer.NEXT_PREV_IN_STREAM); painterList.add(arrowPainter); CursorPainter cp = new CursorPainter(this, scaleFactor * 10, cursorPainters.size()-1); painterList.add(cp); @@ -159,10 +161,19 @@ public class WaveformCanvas extends Canvas { colors[WaveformColors.CURSOR_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); colors[WaveformColors.MARKER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY); colors[WaveformColors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); - colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_YELLOW); + colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_MAGENTA); + colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()] = SWTResourceManager.getColor(255, 128, 255); } } + public void setHighliteRelation(RelationType relationType){ + if(arrowPainter!=null){ + boolean redraw = arrowPainter.getHighlightType()!=relationType; + arrowPainter.setHighlightType(relationType); + if(redraw) redraw(); + } + } + public Point getOrigin() { return origin; } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java index 0605572..d6f365f 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java @@ -13,6 +13,7 @@ package com.minres.scviewer.database.swt.internal; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -73,9 +74,11 @@ import com.minres.scviewer.database.ISignalChangeMulti; import com.minres.scviewer.database.ISignalChangeSingle; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITxEvent; +import com.minres.scviewer.database.ITxRelation; import com.minres.scviewer.database.ITxStream; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformEvent; +import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.ui.GotoDirection; import com.minres.scviewer.database.ui.ICursor; import com.minres.scviewer.database.ui.IWaveformViewer; @@ -83,39 +86,39 @@ import com.minres.scviewer.database.ui.TrackEntry; import com.minres.scviewer.database.ui.WaveformColors; public class WaveformViewer implements IWaveformViewer { - - private ListenerList selectionChangedListeners = new ListenerList(); - + + private ListenerList selectionChangedListeners = new ListenerList(); + private PropertyChangeSupport pcs; private ITx currentTxSelection; - + private TrackEntry currentWaveformSelection; private ScrolledComposite nameListScrolled; - + private ScrolledComposite valueListScrolled; private Control namePaneHeader; private Canvas nameList; - + private Canvas valueList; - + WaveformCanvas waveformCanvas; private Composite top; protected ObservableList streams; - + int selectedMarker = 0; - + private int trackVerticalHeight; - + private TreeMap trackVerticalOffset; - + private HashMap, String> actualValues; - + private Font nameFont, nameFontB; protected MouseListener nameValueMouseListener = new MouseAdapter() { @@ -136,7 +139,7 @@ public class WaveformViewer implements IWaveformViewer { protected MouseListener waveformMouseListener = new MouseAdapter(){ Point start; List initialSelected; - + @Override public void mouseDown(MouseEvent e) { start=new Point(e.x, e.y); @@ -462,10 +465,10 @@ public class WaveformViewer implements IWaveformViewer { if(firstTx!=null){ do { for(ITxEvent evt:firstTx.getValue()){ - ITx tx=evt.getTransaction(); + ITx tx=evt.getTransaction(); if(evt.getType()==ITxEvent.Type.BEGIN && tx.getBeginTime()<=time && tx.getEndTime()>=time){ if(resultsList[tx.getConcurrencyIndex()]==null) - resultsList[tx.getConcurrencyIndex()]= evt.getTransaction(); + resultsList[tx.getConcurrencyIndex()]= evt.getTransaction(); } } firstTx=stream.getEvents().lowerEntry(firstTx.getKey()); @@ -480,7 +483,7 @@ public class WaveformViewer implements IWaveformViewer { } entry.setValue(value); } - } + } } valueList.redraw(); } @@ -491,7 +494,7 @@ public class WaveformViewer implements IWaveformViewer { } return true; } - + /* (non-Javadoc) * @see com.minres.scviewer.database.swt.IWaveformPanel#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) */ @@ -560,7 +563,7 @@ public class WaveformViewer implements IWaveformViewer { public void setSelection(ISelection selection) { setSelection(selection, false); } - + /* (non-Javadoc) * @see com.minres.scviewer.database.swt.IWaveformPanel#setSelection(org.eclipse.jface.viewers.ISelection, boolean) */ @@ -613,10 +616,10 @@ public class WaveformViewer implements IWaveformViewer { IStructuredSelection selection=currentTxSelection!=null? new StructuredSelection(new Object[]{currentTxSelection, currentWaveformSelection.waveform}): new StructuredSelection(currentWaveformSelection.waveform); - Object[] list = selectionChangedListeners.getListeners(); - for (int i = 0; i < list.length; i++) { - ((ISelectionChangedListener) list[i]).selectionChanged(new SelectionChangedEvent(this, selection)); - } + Object[] list = selectionChangedListeners.getListeners(); + for (int i = 0; i < list.length; i++) { + ((ISelectionChangedListener) list[i]).selectionChanged(new SelectionChangedEvent(this, selection)); + } } /* (non-Javadoc) @@ -624,63 +627,91 @@ public class WaveformViewer implements IWaveformViewer { */ @Override public void moveSelection(GotoDirection direction) { - if (currentWaveformSelection.isStream()) { - ITxStream stream = currentWaveformSelection.getStream(); - ITx transaction = null; - if (direction == GotoDirection.NEXT) { - List thisEntryList = stream.getEvents().get(currentTxSelection.getBeginTime()); - boolean meFound=false; - for (ITxEvent evt : thisEntryList) { - if (evt.getType() == ITxEvent.Type.BEGIN) { - if(meFound){ - transaction = evt.getTransaction(); - break; - } - meFound|= evt.getTransaction().equals(currentTxSelection); - } - } - if (transaction == null){ - Entry> entry = stream.getEvents().higherEntry(currentTxSelection.getBeginTime()); - if (entry != null) do { - for (ITxEvent evt : entry.getValue()) { - if (evt.getType() == ITxEvent.Type.BEGIN) { + moveSelection(direction, NEXT_PREV_IN_STREAM) ; + } + + /* (non-Javadoc) + * @see com.minres.scviewer.database.swt.IWaveformPanel#moveSelection(com.minres.scviewer.database.swt.GotoDirection, com.minres.scviewer.database.RelationType) + */ + @Override + public void moveSelection(GotoDirection direction, RelationType relationType) { + if (currentWaveformSelection!=null && currentWaveformSelection.isStream() && currentTxSelection!=null) { + if(relationType.equals(IWaveformViewer.NEXT_PREV_IN_STREAM)){ + ITxStream stream = currentWaveformSelection.getStream(); + ITx transaction = null; + if (direction == GotoDirection.NEXT) { + List thisEntryList = stream.getEvents().get(currentTxSelection.getBeginTime()); + boolean meFound=false; + for (ITxEvent evt : thisEntryList) { + if (evt.getType() == ITxEvent.Type.BEGIN) { + if(meFound){ transaction = evt.getTransaction(); break; } + meFound|= evt.getTransaction().equals(currentTxSelection); } - if (transaction == null) - entry = stream.getEvents().higherEntry(entry.getKey()); - } while (entry != null && transaction == null); - } - } else if (direction == GotoDirection.PREV) { - List thisEntryList = stream.getEvents().get(currentTxSelection.getBeginTime()); - boolean meFound=false; - for (ITxEvent evt : Lists.reverse(thisEntryList)) { - if (evt.getType() == ITxEvent.Type.BEGIN) { - if(meFound){ - transaction = evt.getTransaction(); - break; - } - meFound|= evt.getTransaction().equals(currentTxSelection); } - } - if (transaction == null){ - Entry> entry = stream.getEvents().lowerEntry(currentTxSelection.getBeginTime()); - if (entry != null) - do { - for (ITxEvent evt : Lists.reverse(entry.getValue())) { + if (transaction == null){ + Entry> entry = stream.getEvents().higherEntry(currentTxSelection.getBeginTime()); + if (entry != null) do { + for (ITxEvent evt : entry.getValue()) { if (evt.getType() == ITxEvent.Type.BEGIN) { transaction = evt.getTransaction(); break; } } if (transaction == null) - entry = stream.getEvents().lowerEntry(entry.getKey()); + entry = stream.getEvents().higherEntry(entry.getKey()); } while (entry != null && transaction == null); + } + } else if (direction == GotoDirection.PREV) { + List thisEntryList = stream.getEvents().get(currentTxSelection.getBeginTime()); + boolean meFound=false; + for (ITxEvent evt : Lists.reverse(thisEntryList)) { + if (evt.getType() == ITxEvent.Type.BEGIN) { + if(meFound){ + transaction = evt.getTransaction(); + break; + } + meFound|= evt.getTransaction().equals(currentTxSelection); + } + } + if (transaction == null){ + Entry> entry = stream.getEvents().lowerEntry(currentTxSelection.getBeginTime()); + if (entry != null) + do { + for (ITxEvent evt : Lists.reverse(entry.getValue())) { + if (evt.getType() == ITxEvent.Type.BEGIN) { + transaction = evt.getTransaction(); + break; + } + } + if (transaction == null) + entry = stream.getEvents().lowerEntry(entry.getKey()); + } while (entry != null && transaction == null); + } + } + if (transaction != null) { + setSelection(new StructuredSelection(transaction)); + } + } else { + if (direction == GotoDirection.NEXT) { + Collection outRel=currentTxSelection.getOutgoingRelations(); + for(ITxRelation rel:outRel){ + if(relationType.equals(rel.getRelationType())){ + setSelection(new StructuredSelection(rel.getTarget()), true); + return; + } + } + } else if (direction == GotoDirection.PREV) { + Collection inRel=currentTxSelection.getIncomingRelations(); + for(ITxRelation rel:inRel){ + if(relationType.equals(rel.getRelationType())){ + setSelection(new StructuredSelection(rel.getSource()), true); + return; + } + } } - } - if (transaction != null) { - setSelection(new StructuredSelection(transaction)); } } } @@ -706,7 +737,7 @@ public class WaveformViewer implements IWaveformViewer { waveformCanvas.redraw(); } } - + } /* (non-Javadoc) @@ -721,7 +752,7 @@ public class WaveformViewer implements IWaveformViewer { * @see com.minres.scviewer.database.swt.IWaveformPanel#moveSelected(int) */ @Override - public void moveSelected(int i) { + public void moveSelectedTrack(int i) { if(currentWaveformSelection!=null){ ITx selectedTx=currentTxSelection; TrackEntry selectedWaveform=currentWaveformSelection; @@ -815,6 +846,11 @@ public class WaveformViewer implements IWaveformViewer { gc.drawText(value, subArea.x + 5, subArea.y + yOffset + (waveformCanvas.getTrackHeight() - size.y) / 2, true); } + + public void setHighliteRelation(RelationType relationType){ + this.waveformCanvas.setHighliteRelation(relationType); + } + /* (non-Javadoc) * @see com.minres.scviewer.database.swt.IWaveformPanel#getMaxTime() */ @@ -885,7 +921,7 @@ public class WaveformViewer implements IWaveformViewer { public long getSelectedMarkerTime(){ return getMarkerTime(selectedMarker); } - + @Override public List getCursorList(){ List cursors = new LinkedList<>(); diff --git a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java index cde0a8c..75dc95b 100644 --- a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java +++ b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java @@ -21,11 +21,15 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Control; import com.minres.scviewer.database.IWaveform; +import com.minres.scviewer.database.RelationType; public interface IWaveformViewer extends PropertyChangeListener, ISelectionProvider{ String CURSOR_PROPERTY = "cursor_time"; + String MARKER_PROPERTY = "marker_time"; + + public static final RelationType NEXT_PREV_IN_STREAM = RelationType.create("Prev/Next in stream"); public void addSelectionChangedListener(ISelectionChangedListener listener); @@ -47,13 +51,17 @@ public interface IWaveformViewer extends PropertyChangeListener, ISelectionProvi public void moveSelection(GotoDirection direction); + public void moveSelection(GotoDirection direction, RelationType relationType); + public void moveCursor(GotoDirection direction); public List getStreamList(); public TrackEntry getEntryForStream(IWaveform source); - public void moveSelected(int i); + public void moveSelectedTrack(int i); + + public void setHighliteRelation(RelationType relationType); public long getMaxTime(); diff --git a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java index 26b219e..c46ec0c 100644 --- a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java +++ b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java @@ -16,5 +16,5 @@ public enum WaveformColors { TX_BG, TX_BG_HIGHLITE, TX_BORDER, SIGNAL0, SIGNAL1, SIGNALZ, SIGNALX, SIGNAL_TEXT, CURSOR, CURSOR_DRAG, CURSOR_TEXT, - MARKER, MARKER_TEXT, REL_ARROW + MARKER, MARKER_TEXT, REL_ARROW, REL_ARROW_HIGHLITE } \ No newline at end of file diff --git a/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java b/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java index e43db10..45fdd38 100644 --- a/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java +++ b/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java @@ -12,6 +12,8 @@ package com.minres.scviewer.database.vcd; import java.io.File; import java.io.FileInputStream; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Stack; import java.util.TreeMap; @@ -27,6 +29,7 @@ import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDbLoader; import com.minres.scviewer.database.IWaveformEvent; import com.minres.scviewer.database.InputFormatException; +import com.minres.scviewer.database.RelationType; // TODO: Auto-generated Javadoc /** @@ -176,5 +179,10 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder { ((VCDSignal)signal).values.put(time, new VCDSignalChangeMulti(time, decodedValues)); } } + + @Override + public Collection getAllRelationTypes(){ + return Collections.emptyList(); + } } diff --git a/com.minres.scviewer.database/.classpath b/com.minres.scviewer.database/.classpath index 46cec6e..f2156e9 100644 --- a/com.minres.scviewer.database/.classpath +++ b/com.minres.scviewer.database/.classpath @@ -1,7 +1,7 @@ - - + + diff --git a/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDb.java b/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDb.java index 6694d38..928c376 100644 --- a/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDb.java +++ b/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDb.java @@ -22,6 +22,8 @@ public interface IWaveformDb extends IHierNode { public List> getAllWaves(); + public List getAllRelationTypes(); + public boolean load(File inp) throws Exception; public boolean isLoaded(); diff --git a/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDbLoader.java b/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDbLoader.java index 0e2aaba..53bdd3c 100644 --- a/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDbLoader.java +++ b/com.minres.scviewer.database/src/com/minres/scviewer/database/IWaveformDbLoader.java @@ -11,6 +11,7 @@ package com.minres.scviewer.database; import java.io.File; +import java.util.Collection; import java.util.List; public interface IWaveformDbLoader { @@ -21,4 +22,6 @@ public interface IWaveformDbLoader { public List> getAllWaves() ; + public Collection getAllRelationTypes() ; + } diff --git a/com.minres.scviewer.database/src/com/minres/scviewer/database/RelationType.java b/com.minres.scviewer.database/src/com/minres/scviewer/database/RelationType.java index 812a082..95d365c 100644 --- a/com.minres.scviewer.database/src/com/minres/scviewer/database/RelationType.java +++ b/com.minres.scviewer.database/src/com/minres/scviewer/database/RelationType.java @@ -10,11 +10,26 @@ *******************************************************************************/ package com.minres.scviewer.database; +import java.util.HashMap; + public class RelationType { + private static HashMap registry = new HashMap<>(); + private String name; - public RelationType(String name) { + public static RelationType create(String name){ + if(registry.containsKey(name)){ + return registry.get(name); + }else{ + RelationType relType = new RelationType(name); + registry.put(name, relType); + return relType; + } + + } + + private RelationType(String name) { super(); this.name = name; } @@ -30,4 +45,9 @@ public class RelationType { public String toString(){ return name; } + + @Override + public int hashCode() { + return name.hashCode(); + } } diff --git a/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java b/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java index 10fe6a2..8d6b199 100644 --- a/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java +++ b/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java @@ -29,6 +29,7 @@ import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDbLoader; import com.minres.scviewer.database.IWaveformEvent; import com.minres.scviewer.database.InputFormatException; +import com.minres.scviewer.database.RelationType; public class WaveformDb extends HierNode implements IWaveformDb { @@ -38,6 +39,8 @@ public class WaveformDb extends HierNode implements IWaveformDb { private List childNodes; + private List relationTypes; + private Map> waveforms; private Long maxTime; @@ -59,6 +62,7 @@ public class WaveformDb extends HierNode implements IWaveformDb { public WaveformDb() { super(); waveforms = new HashMap>(); + relationTypes=new ArrayList<>(); maxTime=0L; } @@ -89,6 +93,7 @@ public class WaveformDb extends HierNode implements IWaveformDb { } if(name==null) name=getFileBasename(inp.getName()); buildHierarchyNodes() ; + relationTypes.addAll(loader.getAllRelationTypes()); pcs.firePropertyChange("WAVEFORMS", null, waveforms); pcs.firePropertyChange("CHILDS", null, childNodes); loaded = true; @@ -185,4 +190,9 @@ public class WaveformDb extends HierNode implements IWaveformDb { } return sb.toString(); } + + @Override + public List getAllRelationTypes() { + return relationTypes; + } } diff --git a/com.minres.scviewer.e4.application/.settings/org.eclipse.jdt.core.prefs b/com.minres.scviewer.e4.application/.settings/org.eclipse.jdt.core.prefs index f42de36..d17b672 100644 --- a/com.minres.scviewer.e4.application/.settings/org.eclipse.jdt.core.prefs +++ b/com.minres.scviewer.e4.application/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,12 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.7 diff --git a/com.minres.scviewer.e4.application/Application.e4xmi b/com.minres.scviewer.e4.application/Application.e4xmi index 2c5175a..ce8672d 100644 --- a/com.minres.scviewer.e4.application/Application.e4xmi +++ b/com.minres.scviewer.e4.application/Application.e4xmi @@ -4,29 +4,26 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -50,7 +47,7 @@ - + @@ -79,42 +76,48 @@ - - + + - + - + - + - + - + - + - + + + + + + + - + - + - + @@ -138,6 +141,7 @@ + @@ -156,15 +160,15 @@ - + - + - + @@ -199,7 +203,7 @@ - + @@ -214,7 +218,10 @@ - + + + + diff --git a/com.minres.scviewer.e4.application/icons/Minres_logo.png b/com.minres.scviewer.e4.application/icons/Minres_logo.png new file mode 100644 index 0000000..2d7a2ac Binary files /dev/null and b/com.minres.scviewer.e4.application/icons/Minres_logo.png differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer.icns b/com.minres.scviewer.e4.application/icons/SCViewer.icns deleted file mode 100644 index c4727f8..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer.icns and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer.ico b/com.minres.scviewer.e4.application/icons/SCViewer.ico deleted file mode 100644 index afd0d4f..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer.ico and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_128x32.png b/com.minres.scviewer.e4.application/icons/SCViewer_128x32.png deleted file mode 100644 index f7fb7fc..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer_128x32.png and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_16x32.png b/com.minres.scviewer.e4.application/icons/SCViewer_16x32.png deleted file mode 100644 index 0b790d9..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer_16x32.png and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_256x32.png b/com.minres.scviewer.e4.application/icons/SCViewer_256x32.png deleted file mode 100644 index 9cceaa6..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer_256x32.png and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_32x32.png b/com.minres.scviewer.e4.application/icons/SCViewer_32x32.png deleted file mode 100644 index 2ffbcb6..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer_32x32.png and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_48x32.png b/com.minres.scviewer.e4.application/icons/SCViewer_48x32.png deleted file mode 100644 index 3526a1e..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer_48x32.png and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_512.png b/com.minres.scviewer.e4.application/icons/SCViewer_512.png deleted file mode 100644 index ba03ec8..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer_512.png and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_64x32.png b/com.minres.scviewer.e4.application/icons/SCViewer_64x32.png deleted file mode 100644 index 304cd77..0000000 Binary files a/com.minres.scviewer.e4.application/icons/SCViewer_64x32.png and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/SCViewer_logo.png b/com.minres.scviewer.e4.application/icons/SCViewer_logo.png new file mode 100644 index 0000000..255cfbc Binary files /dev/null and b/com.minres.scviewer.e4.application/icons/SCViewer_logo.png differ diff --git a/com.minres.scviewer.e4.application/icons/empty.png b/com.minres.scviewer.e4.application/icons/empty.png new file mode 100644 index 0000000..cdba92a Binary files /dev/null and b/com.minres.scviewer.e4.application/icons/empty.png differ diff --git a/com.minres.scviewer.e4.application/icons/scviewer.gif b/com.minres.scviewer.e4.application/icons/scviewer.gif deleted file mode 100644 index 229a663..0000000 Binary files a/com.minres.scviewer.e4.application/icons/scviewer.gif and /dev/null differ diff --git a/com.minres.scviewer.e4.application/icons/tick.png b/com.minres.scviewer.e4.application/icons/tick.png new file mode 100644 index 0000000..a9925a0 Binary files /dev/null and b/com.minres.scviewer.e4.application/icons/tick.png differ diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/elements/NavigateContribution.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/elements/NavigateContribution.java new file mode 100644 index 0000000..5f6658e --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/elements/NavigateContribution.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ + +package com.minres.scviewer.e4.application.elements; + +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.ui.di.AboutToShow; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.commands.MCommand; +import org.eclipse.e4.ui.model.application.commands.MCommandParameter; +import org.eclipse.e4.ui.model.application.commands.MParameter; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; +import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +import com.minres.scviewer.database.RelationType; +import com.minres.scviewer.e4.application.parts.WaveformViewerPart; + +public class NavigateContribution { + @Inject EPartService partService; + + @AboutToShow + public void aboutToShow(List items, MApplication application, EModelService modelService) { +// modelService.getActivePerspective(window) +// modelService.findElements(application,"myID",MPart.class, EModelService.IN_ACTIVE_PERSPECTIVE); + // MDirectMenuItem dynamicItem = MMenuFactory.INSTANCE.createDirectMenuItem(); + MPart part = partService.getActivePart(); + if(part.getObject()instanceof WaveformViewerPart){ + WaveformViewerPart waveformViewerPart = (WaveformViewerPart) part.getObject(); + RelationType relationTypeFilter = waveformViewerPart.getRelationTypeFilter(); + MCommand command = modelService.findElements(application, + "com.minres.scviewer.e4.application.command.setrelationtype", MCommand.class, null).get(0); + MCommandParameter commandParameter = command.getParameters().get(0); + for(RelationType relationType:waveformViewerPart.getAllRelationTypes()){ +// MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class); +// +// dynamicItem.setLabel(relationType.getName()); +// dynamicItem.setIconURI(relationTypeFilter.equals(relationType)? +// "platform:/plugin/com.minres.scviewer.e4.application/icons/tick.png": +// "platform:/plugin/com.minres.scviewer.e4.application/icons/empty.png"); +// dynamicItem.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application"); +// dynamicItem.setContributionURI("bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.DirectMenuItem?blah=1"); +// items.add(dynamicItem); + MParameter parameter=modelService.createModelElement(MParameter.class); + parameter.setName(commandParameter.getElementId()); + parameter.setValue(relationType.getName()); + parameter.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application"); + MHandledMenuItem handledMenuItem= modelService.createModelElement(MHandledMenuItem.class); + handledMenuItem.setLabel(relationType.getName()); + if(relationTypeFilter.equals(relationType)){ + handledMenuItem.setEnabled(false); + handledMenuItem.setIconURI("platform:/plugin/com.minres.scviewer.e4.application/icons/tick.png"); + }else + handledMenuItem.setIconURI("platform:/plugin/com.minres.scviewer.e4.application/icons/empty.png"); + handledMenuItem.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application"); + handledMenuItem.setCommand(command); + handledMenuItem.getParameters().add(parameter); + items.add(handledMenuItem); + } + } + } + +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/elements/RelationTypeToolControl.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/elements/RelationTypeToolControl.java new file mode 100644 index 0000000..ad18b66 --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/elements/RelationTypeToolControl.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.elements; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + +import com.minres.scviewer.database.ITx; +import com.minres.scviewer.database.RelationType; +import com.minres.scviewer.e4.application.parts.PartListener; +import com.minres.scviewer.e4.application.parts.WaveformViewerPart; + +public class RelationTypeToolControl extends PartListener implements ISelectionChangedListener { + + EPartService partService; + + ComboViewer comboViewer; + + WaveformViewerPart waveformViewerPart; + + RelationType dummy = RelationType.create("------------"); + + @Inject + public RelationTypeToolControl(EPartService partService) { + this.partService=partService; + partService.addPartListener(this); + } + + @PostConstruct + public void createGui(Composite parent) { + comboViewer = new ComboViewer(parent, SWT.NONE); + Combo comboBox = comboViewer.getCombo(); + comboBox.setBounds(0, 0, 26, 22); + comboBox.setText("Select"); + comboViewer.setContentProvider(new ArrayContentProvider()); + comboViewer.setInput(new RelationType[] {dummy}); + comboViewer.setSelection(new StructuredSelection(dummy)); + comboViewer.addSelectionChangedListener(this); + } + + @Override + public void partActivated(MPart part) { + if(part.getObject() instanceof WaveformViewerPart){ + waveformViewerPart=(WaveformViewerPart) part.getObject(); + checkSelection(waveformViewerPart.getSelection()); + } else { + waveformViewerPart=null; + checkSelection(new StructuredSelection()); + } + } + + @Inject + public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){ + MPart part = partService.getActivePart(); + if(part!=null && part.getObject() instanceof WaveformViewerPart && comboViewer!=null){ + checkSelection(selection); + } + } + + protected void checkSelection(ISelection selection) { + 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; + } + } + comboViewer.getCombo().setEnabled(false); + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + MPart part = partService.getActivePart(); + if(part!=null && part.getObject() instanceof WaveformViewerPart && !event.getSelection().isEmpty()){ + WaveformViewerPart waveformViewerPart=(WaveformViewerPart) part.getObject(); + if(event.getSelection() instanceof IStructuredSelection){ + waveformViewerPart.setNavigationRelationType( + (RelationType)((IStructuredSelection)event.getSelection()).getFirstElement()); + } + } + } + +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java index d6bf717..4220ee4 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java @@ -12,11 +12,14 @@ package com.minres.scviewer.e4.application.handlers; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; +import com.minres.scviewer.e4.application.parts.AboutDialog; + public class AboutHandler { @Execute public void execute(Shell shell) { - MessageDialog.openInformation(shell, "About", "Eclipse 4 Application example."); + AboutDialog.open(shell, SWT.NONE); } } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java index b3aaf47..0e532cb 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java @@ -13,6 +13,7 @@ package com.minres.scviewer.e4.application.handlers; import java.util.List; +import javax.inject.Inject; import javax.inject.Named; import org.eclipse.e4.core.di.annotations.CanExecute; @@ -24,44 +25,46 @@ import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.jface.viewers.IStructuredSelection; import com.minres.scviewer.database.IWaveform; -import com.minres.scviewer.e4.application.parts.WaveformListPart; +import com.minres.scviewer.e4.application.parts.DesignBrowser; public class AddWaveformHandler { public final static String PARAM_WHERE_ID="com.minres.scviewer.e4.application.command.addwaveform.where"; public final static String PARAM_ALL_ID="com.minres.scviewer.e4.application.command.addwaveform.all"; - + + @Inject @Optional DesignBrowser designBrowser; + @CanExecute public boolean canExecute(@Named(PARAM_WHERE_ID) String where, @Named(PARAM_ALL_ID) String all, EPartService partService, @Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection) { - WaveformListPart listPart = getListPart( partService); - if(listPart==null || listPart.getActiveWaveformViewerPart()==null) return false; + if(designBrowser==null) designBrowser = getListPart( partService); + if(designBrowser==null || designBrowser.getActiveWaveformViewerPart()==null) return false; Boolean before = "before".equalsIgnoreCase(where); if("true".equalsIgnoreCase(all)) - return listPart.getFilteredChildren().length>0 && - (!before || ((IStructuredSelection)listPart.getActiveWaveformViewerPart().getSelection()).size()>0); + return designBrowser.getFilteredChildren().length>0 && + (!before || ((IStructuredSelection)designBrowser.getActiveWaveformViewerPart().getSelection()).size()>0); else return selection.size()>0 && - (!before || ((IStructuredSelection)listPart.getActiveWaveformViewerPart().getSelection()).size()>0); + (!before || ((IStructuredSelection)designBrowser.getActiveWaveformViewerPart().getSelection()).size()>0); } @Execute public void execute(@Named(PARAM_WHERE_ID) String where, @Named(PARAM_ALL_ID) String all, EPartService partService, @Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection) { - WaveformListPart listPart = getListPart( partService); - if(listPart!=null && selection.size()>0){ + if(designBrowser==null) designBrowser = getListPart( partService); + if(designBrowser!=null && selection.size()>0){ List sel=selection.toList(); - listPart.getActiveWaveformViewerPart().addStreamsToList(sel.toArray(new IWaveform[]{}), + designBrowser.getActiveWaveformViewerPart().addStreamsToList(sel.toArray(new IWaveform[]{}), "before".equalsIgnoreCase(where)); } } - protected WaveformListPart getListPart(EPartService partService){ + protected DesignBrowser getListPart(EPartService partService){ MPart part = partService.getActivePart(); - if(part.getObject() instanceof WaveformListPart) - return (WaveformListPart) part.getObject(); + if(part.getObject() instanceof DesignBrowser) + return (DesignBrowser) part.getObject(); else return null; } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SetRelationTypeHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SetRelationTypeHandler.java new file mode 100644 index 0000000..10c28c4 --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SetRelationTypeHandler.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ + +package com.minres.scviewer.e4.application.handlers; + +import javax.inject.Named; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +import com.minres.scviewer.e4.application.parts.WaveformViewerPart; + +public class SetRelationTypeHandler { + final static String PARAMTER_ID="com.minres.scviewer.e4.application.commandparameter.relationName"; + + @Execute + public void execute(@Named(PARAMTER_ID) String relationName, EPartService partService) { + MPart part = partService.getActivePart(); + Object obj = part.getObject(); + if(obj instanceof WaveformViewerPart){ + WaveformViewerPart waveformViewerPart = (WaveformViewerPart) obj; + waveformViewerPart.setNavigationRelationType(relationName); + } + } + +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java new file mode 100644 index 0000000..fc67b59 --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.parts; + +import java.awt.Desktop; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.wb.swt.ResourceManager; +import org.eclipse.wb.swt.SWTResourceManager; + +public class AboutDialog extends Dialog { + + protected int result; + protected Shell shell; + private Color white; + protected StyledText styledText; + /* + Eclipse IDE for Java Developers + +Version: Mars.1 Release (4.5.1) +Build id: 20150924-1200 +(c) Copyright Eclipse contributors and others 2000, 2015. All rights reserved. Eclipse and the Eclipse logo are trademarks of the Eclipse Foundation, Inc., https://www.eclipse.org/. The Eclipse logo cannot be altered without Eclipse's permission. Eclipse logos are provided for use under the Eclipse logo and trademark guidelines, https://www.eclipse.org/logotm/. Oracle and Java are trademarks or registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. + */ + private String productTitle= + "\nSCViewer - a SystemC waveform viewer\n\nVersion: 1.0\n"; + private String copyrightText="\nCopyright (c) 2015 MINRES Technologies GmbH and others.\n"+ + "\n"+ + "All rights reserved. MINRES and the MINRES logo are trademarks of MINRES Technologies GmbH, http://www.minres.com/ . "+ + "This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 "+ + "which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html\n"; + + /** + * Create the dialog. + * @param parent + * @param style + */ + public AboutDialog(Shell parent, int style) { + super(parent, style); + setText("SWT Dialog"); + white=SWTResourceManager.getColor(SWT.COLOR_WHITE); + } + + /** + * Open the dialog. + * @return the result + */ + public int open() { + createContents(); + shell.open(); + shell.layout(); + Display display = getParent().getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + return result; + } + + /** + * Create contents of the dialog. + */ + private void createContents() { + shell = new Shell(getParent(), getStyle()); + shell.setSize(600, 300); + shell.setText(getText()); + shell.setLayout(new GridLayout(2, false)); + final Image scviewerLogo=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/SCViewer_logo.png"); + final Image minresLogo=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/Minres_logo.png"); + + Canvas canvas = new Canvas(shell,SWT.NO_REDRAW_RESIZE); + GridData gd_canvas = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_canvas.widthHint = 200; + gd_canvas.heightHint =250; + canvas.setLayoutData(gd_canvas); + canvas.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + e.gc.setBackground(white); + e.gc.fillRectangle(e.x, e.y, e.width, e.height); + e.gc.drawImage(scviewerLogo,4,0); + e.gc.drawImage(minresLogo,0,200); + } + }); + + styledText = new StyledText(shell, SWT.BORDER); + styledText.setEditable(false); + GridData gd_styledText = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + styledText.setLayoutData(gd_styledText); + styledText.setText(productTitle+copyrightText); + styledText.setBackground(white); + styledText.setWordWrap(true); + styledText.setLeftMargin(5); + StyleRange styleRange = new StyleRange(); + styleRange.start = 0; + styleRange.length = productTitle.length(); + styleRange.fontStyle = SWT.BOLD; + styledText.setStyleRange(styleRange); + ///^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ + Pattern pattern = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w\\.-]*)*\\/?"); + // in case you would like to ignore case sensitivity, + // you could use this statement: + // Pattern pattern = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(productTitle+copyrightText); + // check all occurance + while (matcher.find()) { + styleRange = new StyleRange(); + styleRange.underline=true; + styleRange.underlineStyle = SWT.UNDERLINE_LINK; + styleRange.data = matcher.group(); + styleRange.start = matcher.start(); + styleRange.length = matcher.end()-matcher.start(); + styledText.setStyleRange(styleRange); + } + styledText.addListener(SWT.MouseDown, new Listener() { + @Override + public void handleEvent(Event event) { + // It is up to the application to determine when and how a link should be activated. + // links are activated on mouse down when the control key is held down +// if ((event.stateMask & SWT.MOD1) != 0) { + try { + int offset = styledText.getOffsetAtLocation(new Point (event.x, event.y)); + StyleRange style = styledText.getStyleRangeAtOffset(offset); + if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) { + Desktop.getDesktop().browse(new java.net.URI(style.data.toString())); + } + } catch (IOException | URISyntaxException | IllegalArgumentException e) {} +// } + } + }); + + styleRange.start = 0; + new Label(shell, SWT.NONE); + + Button okButton = new Button(shell, SWT.NONE); + okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + okButton.setBounds(0, 0, 94, 28); + okButton.setText("Close"); + okButton.setFocus(); + okButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if(!shell.isDisposed()) shell.dispose(); + } + }); + } + + public static boolean open(Shell parent, int style) { + AboutDialog dialog = new AboutDialog(parent, style | SWT.SHEET); + return dialog.open() == 0; + } +} diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/DesignBrowser.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/DesignBrowser.java index 137b970..2616263 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/DesignBrowser.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/DesignBrowser.java @@ -12,39 +12,97 @@ package com.minres.scviewer.e4.application.parts; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; +import javax.inject.Named; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.di.Focus; import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.services.EMenuService; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.wb.swt.ResourceManager; +import org.eclipse.wb.swt.SWTResourceManager; +import com.minres.scviewer.database.IHierNode; +import com.minres.scviewer.database.ITx; +import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformDb; +import com.minres.scviewer.e4.application.handlers.AddWaveformHandler; import com.minres.scviewer.e4.application.provider.TxDbContentProvider; import com.minres.scviewer.e4.application.provider.TxDbLabelProvider; -public class DesignBrowser implements ISelectionChangedListener { +public class DesignBrowser { + + private static final String POPUP_ID="com.minres.scviewer.e4.application.parts.DesignBrowser.popupmenu"; @Inject IEventBroker eventBroker; @Inject ESelectionService selectionService; + @Inject EMenuService menuService; + + @Inject IEclipseContext eclipseCtx; + + private SashForm sashForm; + + Composite top; + + private Composite bottom; + private TreeViewer treeViewer; + private Text nameFilter; - private PropertyChangeListener l = new PropertyChangeListener() { + private TableViewer txTableViewer; + + ToolItem appendItem, insertItem, insertAllItem, appendAllItem; + + WaveformAttributeFilter attributeFilter; + + int thisSelectionCount=0, otherSelectionCount=0; + + private PropertyChangeListener treeViewerPCL = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if("CHILDS".equals(evt.getPropertyName())){ @@ -58,46 +116,327 @@ public class DesignBrowser implements ISelectionChangedListener { } }; + private WaveformViewerPart waveformViewerPart; + + protected PaintListener sashPaintListener=new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + int size=Math.min(e.width, e.height)-1; + e.gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY)); + e.gc.setFillRule(SWT.FILL_EVEN_ODD); + if(e.width>e.height) + e.gc.drawArc(e.x+(e.width-size)/2, e.y, size, size, 0, 360); + else + e.gc.drawArc(e.x, e.y+(e.height-size)/2, size, size, 0, 360); + } + }; + @PostConstruct public void createComposite(Composite parent) { + sashForm = new SashForm(parent, SWT.BORDER | SWT.SMOOTH | SWT.VERTICAL); + + top = new Composite(sashForm, SWT.NONE); + createTreeViewerComposite(top); + bottom = new Composite(sashForm, SWT.NONE); + createTableComposite(bottom); + + sashForm.setWeights(new int[] {100, 100}); + sashForm.SASH_WIDTH=5; + top.addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + sashForm.getChildren()[2].addPaintListener(sashPaintListener); + top.removeControlListener(this); + } + }); + } + + public void createTreeViewerComposite(Composite parent) { parent.setLayout(new GridLayout(1, false)); treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - treeViewer.addSelectionChangedListener(this); treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); treeViewer.setContentProvider(new TxDbContentProvider()); treeViewer.setLabelProvider(new TxDbLabelProvider()); treeViewer.setUseHashlookup(true); treeViewer.setAutoExpandLevel(2); + treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + ISelection selection=event.getSelection(); + if( selection instanceof IStructuredSelection) { + Object object= ((IStructuredSelection)selection).getFirstElement(); + if(object instanceof IHierNode&& ((IHierNode)object).getChildNodes().size()!=0){ + txTableViewer.setInput(object); + updateButtons(); + } + } + } + }); + } + + public void createTableComposite(Composite parent) { + parent.setLayout(new GridLayout(1, false)); + + nameFilter = new Text(parent, SWT.BORDER); + nameFilter.setMessage("Enter text to filter waveforms"); + nameFilter.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + attributeFilter.setSearchText(((Text) e.widget).getText()); + updateButtons(); + txTableViewer.refresh(); + } + }); + nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + attributeFilter = new WaveformAttributeFilter(); + + txTableViewer = new TableViewer(parent); + txTableViewer.setContentProvider(new TxDbContentProvider(true)); + txTableViewer.setLabelProvider(new TxDbLabelProvider()); + txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); + txTableViewer.addFilter(attributeFilter); + txTableViewer.addDoubleClickListener(new IDoubleClickListener() { + @Override + public void doubleClick(DoubleClickEvent event) { + AddWaveformHandler myHandler = new AddWaveformHandler(); + Object result = runCommand(myHandler, CanExecute.class, "after", false); + if(result!=null && (Boolean)result) + ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); + } + }); + txTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + selectionService.setSelection(event.getSelection()); + updateButtons(); + } + }); + + menuService.registerContextMenu(txTableViewer.getControl(), POPUP_ID); + + ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT); + toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + toolBar.setBounds(0, 0, 87, 20); + + appendItem = new ToolItem(toolBar, SWT.NONE); + appendItem.setToolTipText("Append after"); + appendItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_wave.png")); + appendItem.setEnabled(false); + appendItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AddWaveformHandler myHandler = new AddWaveformHandler(); + Object result = runCommand(myHandler, CanExecute.class, "after", false); + if(result!=null && (Boolean)result) + ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); + } + + }); + + insertItem = new ToolItem(toolBar, SWT.NONE); + insertItem.setToolTipText("Insert before"); + insertItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_wave.png")); + insertItem.setEnabled(false); + insertItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AddWaveformHandler myHandler = new AddWaveformHandler(); + Object result = runCommand(myHandler, CanExecute.class, "before", false); + if(result!=null && (Boolean)result) + ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); + } + }); + new ToolItem(toolBar, SWT.SEPARATOR); + + appendAllItem = new ToolItem(toolBar, SWT.NONE); + appendAllItem.setToolTipText("Append all after"); + appendAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_all_waves.png")); + appendAllItem.setEnabled(false); + + new ToolItem(toolBar, SWT.SEPARATOR); + appendAllItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Object[] all = getFilteredChildren(txTableViewer); + if(all.length>0){ + Object oldSel=selectionService.getSelection(); + selectionService.setSelection(new StructuredSelection(all)); + AddWaveformHandler myHandler = new AddWaveformHandler(); + Object result = runCommand(myHandler, CanExecute.class, "after", false); + if(result!=null && (Boolean)result) + ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); + selectionService.setSelection(oldSel); + } + } + }); + insertAllItem = new ToolItem(toolBar, SWT.NONE); + insertAllItem.setToolTipText("Insert all before"); + insertAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_all_waves.png")); + insertAllItem.setEnabled(false); + insertAllItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Object[] all = getFilteredChildren(txTableViewer); + if(all.length>0){ + Object oldSel=selectionService.getSelection(); + selectionService.setSelection(new StructuredSelection(all)); + AddWaveformHandler myHandler = new AddWaveformHandler(); + Object result = runCommand(myHandler, CanExecute.class, "before", false); + if(result!=null && (Boolean)result) + ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); + selectionService.setSelection(oldSel); + } + } + }); } @Focus public void setFocus() { - treeViewer.getTree().setFocus(); - selectionService.setSelection(treeViewer.getSelection()); - } - - @Override - public void selectionChanged(SelectionChangedEvent event) { - selectionService.setSelection(event.getSelection()); + txTableViewer.getTable().setFocus(); + IStructuredSelection selection = (IStructuredSelection)txTableViewer.getSelection(); + if(selection.size()==0){ + appendItem.setEnabled(false); + } + selectionService.setSelection(selection); + thisSelectionCount=selection.toList().size(); + updateButtons(); } @SuppressWarnings("unchecked") @Inject @Optional public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_WAVEFORMVIEW) WaveformViewerPart waveformViewerPart) { + if(this.waveformViewerPart!=null) + this.waveformViewerPart.storeDesignBrowerState(new DBState()); + this.waveformViewerPart=waveformViewerPart; IWaveformDb database = waveformViewerPart.getDatabase(); Object input = treeViewer.getInput(); - if(input!=null && input instanceof List) - ((List)input).get(0).removePropertyChangeListener(l); + if(input!=null && input instanceof List){ + IWaveformDb db = ((List)input).get(0); + if(db==database) return; // do nothing if old and new daabase is the same + ((List)input).get(0).removePropertyChangeListener(treeViewerPCL); + } treeViewer.setInput(database.isLoaded()?Arrays.asList(new IWaveformDb[]{database}):null); + Object state=this.waveformViewerPart.retrieveDesignBrowerState(); + if(state!=null && state instanceof DBState) + ((DBState)state).apply(); + else + txTableViewer.setInput(null); // Set up the tree viewer - database.addPropertyChangeListener(l); + database.addPropertyChangeListener(treeViewerPCL); } -/* - * TODO: needs top be implemented - @Inject @Optional - public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_NODE_PATH) String path) { - + + @Inject + public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){ + MPart part = partService.getActivePart(); + if(part!=null && part.getObject() != this && selection!=null){ + if( selection instanceof IStructuredSelection) { + Object object= ((IStructuredSelection)selection).getFirstElement(); + if(object instanceof IHierNode&& ((IHierNode)object).getChildNodes().size()!=0) + txTableViewer.setInput(object); + otherSelectionCount = (object instanceof IWaveform || object instanceof ITx)?1:0; + } + } + updateButtons(); + } + + private void updateButtons() { + if(txTableViewer!=null && !insertItem.isDisposed() && !appendItem.isDisposed() && + !appendAllItem.isDisposed() && !insertAllItem.isDisposed()){ + AddWaveformHandler myHandler = new AddWaveformHandler(); + Object result = runCommand(myHandler, CanExecute.class, "after", false); + appendItem.setEnabled(result instanceof Boolean && (Boolean)result); + result = runCommand(myHandler, CanExecute.class, "after", true); + appendAllItem.setEnabled(result instanceof Boolean && (Boolean)result); + result = runCommand(myHandler, CanExecute.class, "before", false); + insertItem.setEnabled(result instanceof Boolean && (Boolean)result); + result = runCommand(myHandler, CanExecute.class, "before", true); + insertAllItem.setEnabled(result instanceof Boolean && (Boolean)result); + } + } + + public class WaveformAttributeFilter extends ViewerFilter { + + private String searchString; + + public void setSearchText(String s) { + this.searchString = ".*" + s + ".*"; + } + + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (searchString == null || searchString.length() == 0) { + return true; + } + IWaveform p = (IWaveform) element; + if (p.getName().matches(searchString)) { + return true; + } + return false; + } + } + + protected Object[] getFilteredChildren(TableViewer viewer){ + Object parent = viewer.getInput(); + if(parent==null) return new Object[0]; + Object[] result = null; + if (parent != null) { + IStructuredContentProvider cp = (IStructuredContentProvider) viewer.getContentProvider(); + if (cp != null) { + result = cp.getElements(parent); + if(result==null) return new Object[0]; + for (int i = 0, n = result.length; i < n; ++i) { + if(result[i]==null) return new Object[0]; + } + } + } + ViewerFilter[] filters = viewer.getFilters(); + if (filters != null) { + for (ViewerFilter f:filters) { + Object[] filteredResult = f.filter(viewer, parent, result); + result = filteredResult; + } + } + return result; + } + + protected Object runCommand(AddWaveformHandler handler, Class annotation, String where, Boolean all) { + ContextInjectionFactory.inject(handler, eclipseCtx); + eclipseCtx.set(AddWaveformHandler.PARAM_WHERE_ID, where); + eclipseCtx.set(AddWaveformHandler.PARAM_ALL_ID, all.toString()); + eclipseCtx.set(DesignBrowser.class, this); + eclipseCtx.set(WaveformViewerPart.class, waveformViewerPart); + Object result = ContextInjectionFactory.invoke(handler, annotation, eclipseCtx); + return result; + } + + public Object[] getFilteredChildren() { + return getFilteredChildren(txTableViewer); + } + + public WaveformViewerPart getActiveWaveformViewerPart() { + return waveformViewerPart; + } + + class DBState { + + public DBState() { + this.expandedElements=treeViewer.getExpandedElements(); + this.treeSelection=treeViewer.getSelection(); + this.tableSelection=txTableViewer.getSelection(); + } + + public void apply() { + treeViewer.setExpandedElements(expandedElements); + treeViewer.setSelection(treeSelection, true); + txTableViewer.setSelection(tableSelection, true); + + } + + private Object[] expandedElements; + private ISelection treeSelection; + private ISelection tableSelection; } -*/ }; \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformListPart.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformListPart.java deleted file mode 100644 index 912ee3a..0000000 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformListPart.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 MINRES Technologies GmbH and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * MINRES Technologies GmbH - initial API and implementation - *******************************************************************************/ -package com.minres.scviewer.e4.application.parts; - -import java.lang.annotation.Annotation; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; - -import org.eclipse.e4.core.contexts.ContextInjectionFactory; -import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.core.di.annotations.CanExecute; -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.core.di.annotations.Optional; -import org.eclipse.e4.core.services.events.IEventBroker; -import org.eclipse.e4.ui.di.Focus; -import org.eclipse.e4.ui.di.UIEventTopic; -import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.e4.ui.services.EMenuService; -import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.e4.ui.workbench.modeling.EPartService; -import org.eclipse.e4.ui.workbench.modeling.ESelectionService; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.wb.swt.ResourceManager; - -import com.minres.scviewer.database.IHierNode; -import com.minres.scviewer.database.ITx; -import com.minres.scviewer.database.IWaveform; -import com.minres.scviewer.e4.application.handlers.AddWaveformHandler; -import com.minres.scviewer.e4.application.provider.TxDbContentProvider; -import com.minres.scviewer.e4.application.provider.TxDbLabelProvider; - -public class WaveformListPart implements ISelectionChangedListener { - - private static final String POPUP_ID="com.minres.scviewer.e4.application.parts.WaveformList.popupmenu"; - - @Inject IEventBroker eventBroker; - - @Inject ESelectionService selectionService; - - @Inject EMenuService menuService; - - @Inject IEclipseContext eclipseCtx; - - - private Text nameFilter; - - private TableViewer txTableViewer; - - ToolItem appendItem, insertItem, insertAllItem, appendAllItem; - - WaveformAttributeFilter attributeFilter; - - int thisSelectionCount=0, otherSelectionCount=0; - - private WaveformViewerPart waveformViewerPart; - - @PostConstruct - public void createComposite(Composite parent) { - parent.setLayout(new GridLayout(1, false)); - - nameFilter = new Text(parent, SWT.BORDER); - nameFilter.setMessage("Enter text to filter waveforms"); - nameFilter.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - attributeFilter.setSearchText(((Text) e.widget).getText()); - updateButtons(); - txTableViewer.refresh(); - } - }); - nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - attributeFilter = new WaveformAttributeFilter(); - - txTableViewer = new TableViewer(parent); - txTableViewer.setContentProvider(new TxDbContentProvider(true)); - txTableViewer.setLabelProvider(new TxDbLabelProvider()); - txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); - txTableViewer.addSelectionChangedListener(this); - txTableViewer.addFilter(attributeFilter); - txTableViewer.addDoubleClickListener(new IDoubleClickListener() { - @Override - public void doubleClick(DoubleClickEvent event) { - AddWaveformHandler myHandler = new AddWaveformHandler(); - Object result = runCommand(myHandler, CanExecute.class, "after", false); - if(result!=null && (Boolean)result) - ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); - } - }); - menuService.registerContextMenu(txTableViewer.getControl(), POPUP_ID); - - ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT); - toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - toolBar.setBounds(0, 0, 87, 20); - - appendItem = new ToolItem(toolBar, SWT.NONE); - appendItem.setToolTipText("Append after"); - appendItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_wave.png")); - appendItem.setEnabled(false); - appendItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - /* - eventBroker.post(WaveformViewerPart.ADD_WAVEFORM, - ((IStructuredSelection)txTableViewer.getSelection()).toList()); - ECommandService commandService = eclipseCtx.get(ECommandService.class); - EHandlerService handlerService = eclipseCtx.get(EHandlerService.class); - HashMap param=new HashMap<>(); - param.clear(); - //param.put("where", "after"); - ParameterizedCommand myCommand = commandService.createCommand(COMMAND_ID, param); - if(myCommand!=null)handlerService.executeHandler(myCommand); - */ - AddWaveformHandler myHandler = new AddWaveformHandler(); - Object result = runCommand(myHandler, CanExecute.class, "after", false); - if(result!=null && (Boolean)result) - ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); - } - - }); - - insertItem = new ToolItem(toolBar, SWT.NONE); - insertItem.setToolTipText("Insert before"); - insertItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_wave.png")); - insertItem.setEnabled(false); - insertItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - AddWaveformHandler myHandler = new AddWaveformHandler(); - Object result = runCommand(myHandler, CanExecute.class, "before", false); - if(result!=null && (Boolean)result) - ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); - } - }); - new ToolItem(toolBar, SWT.SEPARATOR); - - appendAllItem = new ToolItem(toolBar, SWT.NONE); - appendAllItem.setToolTipText("Append all after"); - appendAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_all_waves.png")); - appendAllItem.setEnabled(false); - - new ToolItem(toolBar, SWT.SEPARATOR); - appendAllItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - Object[] all = getFilteredChildren(txTableViewer); - if(all.length>0){ - Object oldSel=selectionService.getSelection(); - selectionService.setSelection(new StructuredSelection(all)); - AddWaveformHandler myHandler = new AddWaveformHandler(); - Object result = runCommand(myHandler, CanExecute.class, "after", false); - if(result!=null && (Boolean)result) - ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); - selectionService.setSelection(oldSel); - } - } - }); - insertAllItem = new ToolItem(toolBar, SWT.NONE); - insertAllItem.setToolTipText("Insert all before"); - insertAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_all_waves.png")); - insertAllItem.setEnabled(false); - insertAllItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - Object[] all = getFilteredChildren(txTableViewer); - if(all.length>0){ - Object oldSel=selectionService.getSelection(); - selectionService.setSelection(new StructuredSelection(all)); - AddWaveformHandler myHandler = new AddWaveformHandler(); - Object result = runCommand(myHandler, CanExecute.class, "before", false); - if(result!=null && (Boolean)result) - ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); - selectionService.setSelection(oldSel); - } - } - }); - } - - @Focus - public void setFocus() { - txTableViewer.getTable().setFocus(); - setSelection(txTableViewer.getSelection()); - } - - @Inject @Optional - public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_WAVEFORMVIEW) WaveformViewerPart part) { - this.waveformViewerPart=part; - updateButtons(); - } - - @Override - public void selectionChanged(SelectionChangedEvent event) { - setSelection(event.getSelection()); - } - - protected void setSelection(ISelection iSelection) { - IStructuredSelection selection = (IStructuredSelection)iSelection; - if(selection.size()==0){ - appendItem.setEnabled(false); - } - selectionService.setSelection(selection); - thisSelectionCount=selection.toList().size(); - updateButtons(); - } - - @Inject - public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){ - MPart part = partService.getActivePart(); - if(part!=null && part.getObject() != this && selection!=null){ - if( selection instanceof IStructuredSelection) { - Object object= ((IStructuredSelection)selection).getFirstElement(); - if(object instanceof IHierNode&& ((IHierNode)object).getChildNodes().size()!=0) - txTableViewer.setInput(object); - otherSelectionCount = (object instanceof IWaveform || object instanceof ITx)?1:0; - } - } - updateButtons(); - } - - private void updateButtons() { - if(txTableViewer!=null && !insertItem.isDisposed() && !appendItem.isDisposed() && - !appendAllItem.isDisposed() && !insertAllItem.isDisposed()){ - AddWaveformHandler myHandler = new AddWaveformHandler(); - Object result = runCommand(myHandler, CanExecute.class, "after", false); - appendItem.setEnabled(result instanceof Boolean && (Boolean)result); - result = runCommand(myHandler, CanExecute.class, "after", true); - appendAllItem.setEnabled(result instanceof Boolean && (Boolean)result); - result = runCommand(myHandler, CanExecute.class, "before", false); - insertItem.setEnabled(result instanceof Boolean && (Boolean)result); - result = runCommand(myHandler, CanExecute.class, "before", true); - insertAllItem.setEnabled(result instanceof Boolean && (Boolean)result); - } - } - - public class WaveformAttributeFilter extends ViewerFilter { - - private String searchString; - - public void setSearchText(String s) { - this.searchString = ".*" + s + ".*"; - } - - @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { - if (searchString == null || searchString.length() == 0) { - return true; - } - IWaveform p = (IWaveform) element; - if (p.getName().matches(searchString)) { - return true; - } - return false; - } - } - - public Object[] getFilteredChildren(){ - return getFilteredChildren(txTableViewer); - } - - protected Object[] getFilteredChildren(TableViewer viewer){ - Object parent = viewer.getInput(); - if(parent==null) return new Object[0]; - Object[] result = null; - if (parent != null) { - IStructuredContentProvider cp = (IStructuredContentProvider) viewer.getContentProvider(); - if (cp != null) { - result = cp.getElements(parent); - if(result==null) return new Object[0]; - for (int i = 0, n = result.length; i < n; ++i) { - if(result[i]==null) return new Object[0]; - } - } - } - ViewerFilter[] filters = viewer.getFilters(); - if (filters != null) { - for (ViewerFilter f:filters) { - Object[] filteredResult = f.filter(viewer, parent, result); - result = filteredResult; - } - } - return result; - } - - public WaveformViewerPart getActiveWaveformViewerPart() { - return waveformViewerPart; - } - - protected Object runCommand(AddWaveformHandler myHandler, Class annotation, String where, Boolean all) { - ContextInjectionFactory.inject(myHandler, eclipseCtx); - eclipseCtx.set(AddWaveformHandler.PARAM_WHERE_ID, where); - eclipseCtx.set(AddWaveformHandler.PARAM_ALL_ID, all.toString()); - Object result = ContextInjectionFactory.invoke(myHandler, annotation, eclipseCtx); - return result; - } - -} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java index 3b8b78e..6355895 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java @@ -57,10 +57,12 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import com.minres.scviewer.database.ITx; +import com.minres.scviewer.database.ITxRelation; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDbFactory; import com.minres.scviewer.database.IWaveformEvent; +import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.swt.WaveformViewerFactory; import com.minres.scviewer.database.ui.GotoDirection; import com.minres.scviewer.database.ui.ICursor; @@ -87,7 +89,7 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang protected static final String ZOOM_LEVEL = "ZOOM_LEVEL"; protected static final long FILE_CHECK_INTERVAL = 60000; - + private String[] zoomLevel; public static final String ID = "com.minres.scviewer.ui.TxEditorPart"; //$NON-NLS-1$ @@ -126,6 +128,10 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang Map persistedState; + private Object browserState; + + private RelationType navigationRelationType=IWaveformViewer.NEXT_PREV_IN_STREAM ; + FileMonitor fileMonitor = new FileMonitor(); IModificationChecker fileChecker; @@ -487,11 +493,16 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang } public void moveSelected(int i) { - waveformPane.moveSelected(i); + waveformPane.moveSelectedTrack(i); } - public void moveSelection(GotoDirection direction) { - waveformPane.moveSelection(direction); + + public void moveSelection(GotoDirection direction ) { + moveSelection(direction, navigationRelationType); + } + + public void moveSelection(GotoDirection direction, RelationType relationType) { + waveformPane.moveSelection(direction, relationType); } public void moveCursor(GotoDirection direction) { @@ -528,4 +539,53 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang return waveformPane.getScaledTime(time); } + public void storeDesignBrowerState(Object browserState) { + this.browserState=browserState; + } + + public Object retrieveDesignBrowerState() { + return browserState; + } + + public List getAllRelationTypes() { + List res =new ArrayList<>(); + res.add(IWaveformViewer.NEXT_PREV_IN_STREAM); + res.addAll(database.getAllRelationTypes()); + return res; + } + + public List getSelectionRelationTypes() { + List res =new ArrayList<>(); + res.add(IWaveformViewer.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()); + } + } + } + return res; + } + + public RelationType getRelationTypeFilter() { + return navigationRelationType; + } + + public void setNavigationRelationType(String relationName) { + setNavigationRelationType(RelationType.create(relationName)); + } + + public void setNavigationRelationType(RelationType relationType) { + if(navigationRelationType!=relationType) waveformPane.setHighliteRelation(relationType); + navigationRelationType=relationType; + } + } \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java index f83e8cf..5fe7302 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java @@ -44,7 +44,8 @@ public class DefaultValuesInitializer extends AbstractPreferenceInitializer { colors[WaveformColors.CURSOR_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); colors[WaveformColors.MARKER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY); colors[WaveformColors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); - colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_YELLOW); + colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_MAGENTA); + colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()] = SWTResourceManager.getColor(255, 128, 255); } @Override diff --git a/com.minres.scviewer.e4.product/SCViewer (restart).launch b/com.minres.scviewer.e4.product/SCViewer (restart).launch index cc2c08f..723a487 100644 --- a/com.minres.scviewer.e4.product/SCViewer (restart).launch +++ b/com.minres.scviewer.e4.product/SCViewer (restart).launch @@ -23,7 +23,7 @@ - + diff --git a/com.minres.scviewer.e4.product/icons/SCViewer.png b/com.minres.scviewer.e4.product/icons/SCViewer.png index ba03ec8..cb5cbef 100644 Binary files a/com.minres.scviewer.e4.product/icons/SCViewer.png and b/com.minres.scviewer.e4.product/icons/SCViewer.png differ diff --git a/com.opcoach.e4.preferences/.classpath b/com.opcoach.e4.preferences/.classpath index ad32c83..e8ea977 100644 --- a/com.opcoach.e4.preferences/.classpath +++ b/com.opcoach.e4.preferences/.classpath @@ -1,7 +1,7 @@ - + diff --git a/com.opcoach.e4.preferences/.settings/org.eclipse.jdt.core.prefs b/com.opcoach.e4.preferences/.settings/org.eclipse.jdt.core.prefs index c537b63..d17b672 100644 --- a/com.opcoach.e4.preferences/.settings/org.eclipse.jdt.core.prefs +++ b/com.opcoach.e4.preferences/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,12 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/ScopedPreferenceStore.java b/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/ScopedPreferenceStore.java index 8916abb..3017845 100644 --- a/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/ScopedPreferenceStore.java +++ b/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/ScopedPreferenceStore.java @@ -79,7 +79,7 @@ public class ScopedPreferenceStore extends EventManager implements * The default context is the context where getDefault and setDefault * methods will search. This context is also used in the search. */ - private IScopeContext defaultContext = new DefaultScope(); + private IScopeContext defaultContext = DefaultScope.INSTANCE; /** * The nodeQualifer is the string used to look up the node in the contexts. diff --git a/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/internal/E4PreferenceRegistry.java b/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/internal/E4PreferenceRegistry.java index f1702fe..5623c9d 100644 --- a/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/internal/E4PreferenceRegistry.java +++ b/com.opcoach.e4.preferences/src/com/opcoach/e4/preferences/internal/E4PreferenceRegistry.java @@ -26,9 +26,7 @@ import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Creatable; import org.eclipse.e4.core.services.contributions.IContributionFactory; import org.eclipse.e4.core.services.log.Logger; -import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceNode; -import org.eclipse.jface.preference.IPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceManager; import org.eclipse.jface.preference.PreferenceNode; @@ -41,6 +39,7 @@ import org.eclipse.swt.widgets.Label; import com.opcoach.e4.preferences.IPreferenceStoreProvider; import com.opcoach.e4.preferences.ScopedPreferenceStore; +@SuppressWarnings("restriction") @Creatable public class E4PreferenceRegistry {