diff --git a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java index 85a4716..dea611a 100644 --- a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java +++ b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java @@ -188,6 +188,6 @@ public class Tx implements ITx { @Override public String toString() { - return "tx#"+getId()+"@"+getBeginTime()+"-@"+getEndTime(); + return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]"; } } diff --git a/com.minres.scviewer.database.swt/src/com/minres/scviewer/database/swt/TxDisplay.java b/com.minres.scviewer.database.swt/src/com/minres/scviewer/database/swt/TxDisplay.java index 907eb4f..19aa5fa 100644 --- a/com.minres.scviewer.database.swt/src/com/minres/scviewer/database/swt/TxDisplay.java +++ b/com.minres.scviewer.database.swt/src/com/minres/scviewer/database/swt/TxDisplay.java @@ -88,33 +88,43 @@ import com.minres.scviewer.database.swt.internal.WaveformCanvas; import swing2swt.layout.BorderLayout; public class TxDisplay implements PropertyChangeListener, ISelectionProvider { + private ListenerList selectionChangedListeners = new ListenerList(); + private PropertyChangeSupport pcs; public static final String CURSOR_PROPERTY = "cursor time"; private static final String SELECTION = "selection"; + private ITx currentTxSelection; + private IWaveform currentWaveformSelection; - private CursorPainter currentCursorSelection; private ScrolledComposite nameListScrolled; + private ScrolledComposite valueListScrolled; private Canvas nameList; + private Canvas valueList; + WaveformCanvas waveformList; private Composite top; protected ObservableList> streams; + Vector cursorPainters; private Composite trackPane; + private int trackVerticalHeight; + private TreeMap> trackVerticalOffset; + private HashMap, String> actualValues; - // private long maxTime=0; + private Font nameFont, nameFontB; protected MouseListener nameValueMouseListener = new MouseAdapter() { @@ -389,10 +399,12 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider { actualValues.clear(); waveformList.clearAllWavefromPainter(); boolean even = true; + boolean clearSelection = true; TextLayout tl = new TextLayout(waveformList.getDisplay()); tl.setFont(nameFontB); for (IWaveform waveform : streams) { int height = waveformList.getTrackHeight(); + clearSelection &= (waveform != currentWaveformSelection); if (waveform instanceof ITxStream) { ITxStream stream = (ITxStream) waveform; height *= stream.getMaxConcurrency(); @@ -421,7 +433,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider { Point o = waveformList.getOrigin(); waveformList.setOrigin(o.x, o.y - (previousHeight - trackVerticalOffset.lastKey())); } - setSelection(new StructuredSelection()); + if(clearSelection) setSelection(new StructuredSelection()); /* System.out.println("updateTracklist() state:"); for(Entry> entry: trackVerticalOffset.entrySet()){ System.out.println(" "+entry.getKey()+": " +entry.getValue().getFullName()); @@ -514,42 +526,44 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider { @Override public ISelection getSelection() { - if(currentCursorSelection != null){ - return new StructuredSelection(currentCursorSelection); - }else if (currentTxSelection != null) + if (currentTxSelection != null) return new StructuredSelection(currentTxSelection); else if (currentWaveformSelection != null) return new StructuredSelection(currentWaveformSelection); else - return null; + return new StructuredSelection(); } - @SuppressWarnings("unchecked") @Override public void setSelection(ISelection selection) { + setSelection(selection, false); + } + + @SuppressWarnings("unchecked") + public void setSelection(ISelection selection, boolean addIfNeeded) { boolean selectionChanged = false; if (selection instanceof IStructuredSelection) { if(((IStructuredSelection) selection).size()==0){ selectionChanged = currentTxSelection!=null||currentWaveformSelection!=null; currentTxSelection = null; currentWaveformSelection = null; - currentCursorSelection=null; } else { for(Object sel:((IStructuredSelection) selection).toArray()){ - if (sel instanceof ITx && currentTxSelection != sel && streams.contains(((ITx)sel).getStream())) { - currentTxSelection = (ITx) sel; - currentWaveformSelection = currentTxSelection.getStream(); - currentCursorSelection=null; - selectionChanged = true; + if (sel instanceof ITx && currentTxSelection != sel){ + ITx txSel = (ITx) sel; + if (streams.contains(((ITx)sel).getStream())) { + currentTxSelection = txSel; + currentWaveformSelection = txSel.getStream(); + selectionChanged = true; + } else if(addIfNeeded){ + streams.add(txSel.getStream()); + currentTxSelection = txSel; + currentWaveformSelection = txSel.getStream(); + selectionChanged = true; + } } else if (sel instanceof IWaveform && currentWaveformSelection != sel&& streams.contains(sel)) { currentTxSelection = null; currentWaveformSelection = (IWaveform) sel; - currentCursorSelection=null; - selectionChanged = true; - } else if (sel instanceof CursorPainter && currentCursorSelection != sel){ - currentTxSelection = null; - currentWaveformSelection = null; - currentCursorSelection=(CursorPainter) sel; selectionChanged = true; } } @@ -559,7 +573,6 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider { selectionChanged = true; currentTxSelection = null; currentWaveformSelection = null; - currentCursorSelection=null; } if (selectionChanged) { waveformList.setSelected(currentTxSelection, currentWaveformSelection); @@ -823,6 +836,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider { Point dropPoint = ((Canvas) tgt.getControl()).toControl(event.x, event.y); Object target = trackVerticalOffset.floorEntry(dropPoint.y).getValue(); if(source instanceof IWaveform && target instanceof IWaveform){ + IWaveform srcWave=(IWaveform) source; // int srcIdx=streams.indexOf(source); // int tgtIdx=streams.indexOf(target); // if(srcIdxtgtIdx?tgtIdx:tgtIdx+1, (IWaveform) source); + if(srcIdx<=tgtIdx) tgtIdx++; + if(tgtIdx>=streams.size()) + streams.add(srcWave); + else + streams.add(tgtIdx, srcWave); + currentWaveformSelection=srcWave; updateTracklist(); } else if(source instanceof CursorPainter){ ((CursorPainter)source).setTime(0); @@ -954,4 +973,9 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider { return this.pcs.hasListeners(propertyName); } + public String getScaledTime(Long time) { + StringBuilder sb = new StringBuilder(); + return sb.append(time/waveformList.getScaleFactor()).append(waveformList.getUnitStr()).toString(); + } + } diff --git a/com.minres.scviewer.database.test/build.properties b/com.minres.scviewer.database.test/build.properties index e310bbc..7c01bfb 100644 --- a/com.minres.scviewer.database.test/build.properties +++ b/com.minres.scviewer.database.test/build.properties @@ -1,4 +1,4 @@ bin.includes = META-INF/,\ .,\ - OSGI-INF/component.xml + OSGI-INF/ source.. = src/ diff --git a/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/Tx.groovy b/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/Tx.groovy index 931d7ed..4442146 100644 --- a/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/Tx.groovy +++ b/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/Tx.groovy @@ -59,4 +59,9 @@ class Tx implements ITx { return id.compareTo(o.id) } + @Override + public String toString() { + return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]"; + } + } 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 3799af0..6694d38 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 @@ -24,6 +24,8 @@ public interface IWaveformDb extends IHierNode { public boolean load(File inp) throws Exception; + public boolean isLoaded(); + public void clear(); } 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 a426a35..812a082 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 @@ -27,4 +27,7 @@ public class RelationType { this.name = name; } + public String toString(){ + return name; + } } 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 b77f7af..10fe6a2 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 @@ -34,6 +34,8 @@ public class WaveformDb extends HierNode implements IWaveformDb { private static List loaders=new LinkedList(); + private boolean loaded; + private List childNodes; private Map> waveforms; @@ -89,6 +91,7 @@ public class WaveformDb extends HierNode implements IWaveformDb { buildHierarchyNodes() ; pcs.firePropertyChange("WAVEFORMS", null, waveforms); pcs.firePropertyChange("CHILDS", null, childNodes); + loaded = true; return true; } } @@ -108,6 +111,11 @@ public class WaveformDb extends HierNode implements IWaveformDb { public void clear() { waveforms.clear(); childNodes.clear(); + loaded=false; + } + + public boolean isLoaded() { + return loaded; } private void buildHierarchyNodes() throws InputFormatException{ diff --git a/com.minres.scviewer.e4.application/.settings/org.eclipse.ltk.core.refactoring.prefs b/com.minres.scviewer.e4.application/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 0000000..b196c64 --- /dev/null +++ b/com.minres.scviewer.e4.application/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/com.minres.scviewer.e4.application/Application.e4xmi b/com.minres.scviewer.e4.application/Application.e4xmi index b06a5d1..6abd75c 100644 --- a/com.minres.scviewer.e4.application/Application.e4xmi +++ b/com.minres.scviewer.e4.application/Application.e4xmi @@ -1,16 +1,36 @@ - + - + + + + + + + + + + + + + + + + + + + + + - - + + @@ -101,7 +121,9 @@ stretch - + + Draggable + Draggable @@ -131,31 +153,43 @@ + + - + + + + + + + + + + - + + @@ -178,6 +212,10 @@ + + + + diff --git a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index 43bab36..503032b 100644 --- a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -1,9 +1,9 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Application +Bundle-Name: %Bundle-Name Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true Bundle-Version: 1.0.0.qualifier -Bundle-Vendor: MINRES Technologies GmbH +Bundle-Vendor: %Bundle-Vendor Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.core.runtime;bundle-version="3.11.1", org.eclipse.swt;bundle-version="3.104.1", @@ -24,7 +24,9 @@ Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.core.jobs, org.eclipse.osgi, com.google.guava, - org.eclipse.equinox.preferences + org.eclipse.equinox.preferences, + org.eclipse.core.expressions, + org.eclipse.e4.core.commands;bundle-version="0.11.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: com.minres.scviewer.database, javax.inject;version="1.0.0" diff --git a/com.minres.scviewer.e4.application/OSGI-INF/l10n/bundle.properties b/com.minres.scviewer.e4.application/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..fc0409e --- /dev/null +++ b/com.minres.scviewer.e4.application/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,5 @@ +#Properties file for com.minres.scviewer.e4.application +Bundle-Vendor = MINRES Technologies GmbH +Bundle-Name = Application +product.description = SystemC Transaction and Waveform Viewer +product.name = SCViewer \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/build.properties b/com.minres.scviewer.e4.application/build.properties index d21f19d..d93eaca 100644 --- a/com.minres.scviewer.e4.application/build.properties +++ b/com.minres.scviewer.e4.application/build.properties @@ -5,5 +5,6 @@ bin.includes = META-INF/,\ plugin.xml,\ Application.e4xmi,\ icons/,\ - css/default.css + css/default.css,\ + OSGI-INF/l10n/bundle.properties source.. = src/ diff --git a/com.minres.scviewer.e4.application/icons/append_all_waves.png b/com.minres.scviewer.e4.application/icons/append_all_waves.png index 8a4698d..780ed3a 100644 Binary files a/com.minres.scviewer.e4.application/icons/append_all_waves.png and b/com.minres.scviewer.e4.application/icons/append_all_waves.png differ diff --git a/com.minres.scviewer.e4.application/icons/append_wave.png b/com.minres.scviewer.e4.application/icons/append_wave.png index cea9636..092eae2 100644 Binary files a/com.minres.scviewer.e4.application/icons/append_wave.png and b/com.minres.scviewer.e4.application/icons/append_wave.png differ diff --git a/com.minres.scviewer.e4.application/icons/insert_all_waves.png b/com.minres.scviewer.e4.application/icons/insert_all_waves.png index 70950db..d6064fd 100644 Binary files a/com.minres.scviewer.e4.application/icons/insert_all_waves.png and b/com.minres.scviewer.e4.application/icons/insert_all_waves.png differ diff --git a/com.minres.scviewer.e4.application/icons/insert_wave.png b/com.minres.scviewer.e4.application/icons/insert_wave.png index aa3efdc..1988499 100644 Binary files a/com.minres.scviewer.e4.application/icons/insert_wave.png and b/com.minres.scviewer.e4.application/icons/insert_wave.png differ diff --git a/com.minres.scviewer.e4.application/plugin.xml b/com.minres.scviewer.e4.application/plugin.xml index 6d64b40..3ba19b3 100644 --- a/com.minres.scviewer.e4.application/plugin.xml +++ b/com.minres.scviewer.e4.application/plugin.xml @@ -6,8 +6,8 @@ point="org.eclipse.core.runtime.products"> + description="%product.description" + name="%product.name"> @@ -22,5 +22,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java index 39db037..e8c0efb 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java @@ -10,11 +10,28 @@ *******************************************************************************/ package com.minres.scviewer.e4.application; +import java.io.File; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; +import org.eclipse.e4.ui.workbench.UIEvents; import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate; import org.eclipse.e4.ui.workbench.lifecycle.PreSave; import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions; import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; +import org.eclipse.equinox.app.IApplicationContext; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; /** * This is a stub implementation containing e4 LifeCycle annotated methods.
@@ -25,10 +42,30 @@ import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals; @SuppressWarnings("restriction") public class E4LifeCycle { - @PostContextCreate - void postContextCreate(IEclipseContext workbenchContext) { + @PostConstruct + private static void postConstruct(final IEventBroker eventBroker) { } + @PostContextCreate + void postContextCreate(IApplicationContext appContext, final IEventBroker eventBroker) { + final String[] args = (String[])appContext.getArguments().get(IApplicationContext.APPLICATION_ARGS); + // react on the first view being created, at that time the UI is available + eventBroker.subscribe(UIEvents.UILifeCycle.ACTIVATE, new EventHandler() { + @Override + public void handleEvent(Event event) { + MPart part = (MPart) event.getProperty("ChangedElement"); + if(part!=null){ + IEclipseContext ctx = part.getContext(); + OpenViewHandler openViewHandler= new OpenViewHandler(); + ContextInjectionFactory.inject(openViewHandler, ctx); + eventBroker.unsubscribe(this); + for(String name:args){ + if(new File(name).exists()) openViewHandler.openViewForFile(name); + } + } + } + }); + } @PreSave void preSave(IEclipseContext workbenchContext) { } @@ -40,4 +77,31 @@ public class E4LifeCycle { @ProcessRemovals void processRemovals(IEclipseContext workbenchContext) { } + + String join(String[] tokens){ + StringBuilder sb = new StringBuilder(); + boolean first=true; + for(String token:tokens){ + if(!first) sb.append(","); + sb.append(token); + first=false; + } + return sb.toString(); + } + + private class OpenViewHandler { + @Inject MApplication app; + @Inject EModelService modelService; + @Inject EPartService partService; + public void openViewForFile(String name){ + MPart part = partService.createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); + part.setLabel(name); + MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); + partStack.getChildren().add(part); + partService.showPart(part, PartState.ACTIVATE); + IEclipseContext ctx=part.getContext(); + ctx.modify("input", new File(name)); + ctx.declareModifiable("input"); + } + } } 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 new file mode 100644 index 0000000..01aa29f --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java @@ -0,0 +1,58 @@ + +package com.minres.scviewer.e4.application.handlers; + +import java.util.List; + +import javax.inject.Named; + +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.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.IStructuredSelection; + +import com.minres.scviewer.database.IWaveform; +import com.minres.scviewer.e4.application.parts.WaveformListPart; + +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"; + + @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; + Boolean before = "before".equalsIgnoreCase(where); + if("true".equalsIgnoreCase(all)) + return listPart.getFilteredChildren().length>0 && + (!before || ((IStructuredSelection)listPart.getActiveWaveformViewerPart().getSelection()).size()>0); + else + return selection.size()>0 && + (!before || ((IStructuredSelection)listPart.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){ + List sel=selection.toList(); + listPart.getActiveWaveformViewerPart().addStreamsToList(sel.toArray(new IWaveform[]{}), + "before".equalsIgnoreCase(where)); + } + } + + protected WaveformListPart getListPart(EPartService partService){ + MPart part = partService.getActivePart(); + if(part.getObject() instanceof WaveformListPart) + return (WaveformListPart) part.getObject(); + else + return null; + } +} diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/DeleteWaveformHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/DeleteWaveformHandler.java index 2df86d2..5c407ac 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/DeleteWaveformHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/DeleteWaveformHandler.java @@ -15,6 +15,7 @@ import org.eclipse.e4.core.di.annotations.CanExecute; 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.ESelectionService; +import org.eclipse.jface.viewers.IStructuredSelection; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.e4.application.parts.WaveformViewerPart; @@ -24,16 +25,15 @@ public class DeleteWaveformHandler { @CanExecute public Boolean canExecute(ESelectionService selectionService){ Object o = selectionService.getSelection(); - return o instanceof IWaveform; + return o instanceof IStructuredSelection && ((IStructuredSelection)o).getFirstElement() instanceof IWaveform; } @Execute public void execute(ESelectionService selectionService, MPart activePart) { Object o = activePart.getObject(); Object sel = selectionService.getSelection(); - if(o instanceof WaveformViewerPart && sel instanceof IWaveform){ - ((WaveformViewerPart)o).removeStreamFromList((IWaveform) sel); + if(o instanceof WaveformViewerPart && ((IStructuredSelection)sel).getFirstElement() instanceof IWaveform){ + ((WaveformViewerPart)o).removeStreamFromList((IWaveform) ((IStructuredSelection)sel).getFirstElement()); } - } - + } } \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/MoveWaveformHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/MoveWaveformHandler.java index df737ec..efb262a 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/MoveWaveformHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/MoveWaveformHandler.java @@ -18,6 +18,7 @@ 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 org.eclipse.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.jface.viewers.IStructuredSelection; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.IWaveform; @@ -29,8 +30,12 @@ public class MoveWaveformHandler { @CanExecute public Boolean canExecute(ESelectionService selectionService){ - Object o = selectionService.getSelection(); - return o instanceof IWaveform || o instanceof ITx; + Object sel = selectionService.getSelection(); + if( sel instanceof IStructuredSelection) { + Object o= ((IStructuredSelection)sel).getFirstElement(); + return o instanceof IWaveform || o instanceof ITx; + } + return false; } @Execute diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateEvent.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateEvent.java index 03da19a..1e19253 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateEvent.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateEvent.java @@ -18,6 +18,7 @@ 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 org.eclipse.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.jface.viewers.IStructuredSelection; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.IWaveform; @@ -30,8 +31,12 @@ public class NavigateEvent { @CanExecute public Boolean canExecute(ESelectionService selectionService){ - Object o = selectionService.getSelection(); - return o instanceof IWaveform || o instanceof ITx; + Object sel = selectionService.getSelection(); + if( sel instanceof IStructuredSelection) { + Object o= ((IStructuredSelection)sel).getFirstElement(); + return o instanceof IWaveform || o instanceof ITx; + } + return false; } @Execute diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateTrans.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateTrans.java index 1ca30d1..e6e5341 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateTrans.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/NavigateTrans.java @@ -18,6 +18,7 @@ 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 org.eclipse.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.jface.viewers.IStructuredSelection; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.swt.GotoDirection; @@ -29,8 +30,12 @@ public class NavigateTrans { @CanExecute public Boolean canExecute(ESelectionService selectionService){ - Object o = selectionService.getSelection(); - return o instanceof ITx; + Object sel = selectionService.getSelection(); + if( sel instanceof IStructuredSelection) { + Object o= ((IStructuredSelection)sel).getFirstElement(); + return o instanceof ITx; + } + return false; } @Execute diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/WaveStatusBarControl.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/WaveStatusBarControl.java index 344b5df..0f1e1d4 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/WaveStatusBarControl.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/WaveStatusBarControl.java @@ -10,8 +10,6 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.internal; -import java.util.List; - import javax.inject.Inject; import javax.inject.Named; @@ -22,6 +20,7 @@ import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.action.StatusLineManager; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.layout.GridData; @@ -87,13 +86,19 @@ public class WaveStatusBarControl extends StatusBarControl { } @Inject - public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION)@Optional Object obj){ - // if(status!=null ) status.setText(obj==null?"":obj.toString()); - if(manager!=null ){ - if(obj instanceof List){ - manager.setMessage(""+((List)obj).size()+" Elements"); - } else - manager.setMessage(obj==null?"":obj.getClass().getSimpleName()+" selected"); + public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION)@Optional IStructuredSelection selection){ + if(manager!=null && selection!=null){ + switch(selection.size()){ + case 0: + manager.setMessage(""); + break; + case 1: + manager.setMessage(selection.getFirstElement().getClass().getSimpleName()+" selected"); + break; + default: + manager.setMessage(""+selection.size()+" Elements"); + break; + } } } 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 7de1f9e..27826df 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 @@ -23,9 +23,7 @@ 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.workbench.modeling.ESelectionService; -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.TreeViewer; import org.eclipse.swt.SWT; @@ -45,6 +43,7 @@ public class DesignBrowser implements ISelectionChangedListener { private TreeViewer contentOutlineViewer; + private PropertyChangeListener l = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -58,6 +57,7 @@ public class DesignBrowser implements ISelectionChangedListener { } } }; + @PostConstruct public void createComposite(Composite parent) { @@ -73,38 +73,22 @@ public class DesignBrowser implements ISelectionChangedListener { @Focus public void setFocus() { contentOutlineViewer.getTree().setFocus(); - setSelection(contentOutlineViewer.getSelection()); + selectionService.setSelection(contentOutlineViewer.getSelection()); } @Override public void selectionChanged(SelectionChangedEvent event) { - setSelection(event.getSelection()); - } - - protected void setSelection(ISelection iSelection) { - IStructuredSelection selection = (IStructuredSelection)iSelection; - switch(selection.size()){ - case 0: - eventBroker.post(WaveformViewerPart.ACTIVE_NODE, null); - break; - case 1: - eventBroker.post(WaveformViewerPart.ACTIVE_NODE, selection.getFirstElement()); - selectionService.setSelection(selection.getFirstElement()); - break; - default: - eventBroker.post(WaveformViewerPart.ACTIVE_NODE, selection.getFirstElement()); - selectionService.setSelection(selection.toList()); - break; - } + selectionService.setSelection(event.getSelection()); } @SuppressWarnings("unchecked") @Inject @Optional - public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_DATABASE) IWaveformDb database) { + public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_WAVEFORMVIEW) WaveformViewerPart waveformViewerPart) { + IWaveformDb database = waveformViewerPart.getDatabase(); Object input = contentOutlineViewer.getInput(); if(input!=null && input instanceof List) ((List)input).get(0).removePropertyChangeListener(l); - contentOutlineViewer.setInput(Arrays.asList(new IWaveformDb[]{database})); + contentOutlineViewer.setInput(database.isLoaded()?Arrays.asList(new IWaveformDb[]{database}):null); // Set up the tree viewer database.addPropertyChangeListener(l); } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java index 01bec4f..2351c34 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java @@ -10,6 +10,8 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.parts; +import java.util.Vector; + import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Named; @@ -17,9 +19,21 @@ import javax.inject.Named; 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.services.IServiceConstants; import org.eclipse.e4.ui.workbench.modeling.ESelectionService; -import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jface.viewers.ViewerSorter; @@ -35,13 +49,12 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITxAttribute; -import com.minres.scviewer.e4.application.provider.TxPropertiesContentProvider; +import com.minres.scviewer.database.ITxRelation; import com.minres.scviewer.e4.application.provider.TxPropertiesLabelProvider; public class TransactionDetails { @@ -51,16 +64,25 @@ public class TransactionDetails { public static final int COLUMN_SECOND = 1; + public static final int COLUMN_THIRD = 2; + @Inject IEventBroker eventBroker; @Inject ESelectionService selectionService; private Text nameFilter; - private TableViewer txTableViewer; - private TableColumn col1, col2; + + private TreeViewer treeViewer; + + private TreeViewerColumn col1, col2, col3; + TxAttributeFilter attributeFilter; - + TxAttributeViewerSorter viewSorter; + + private WaveformViewerPart waveformViewerPart; + + @PostConstruct public void createComposite(final Composite parent) { parent.setLayout(new GridLayout(1, false)); @@ -71,57 +93,89 @@ public class TransactionDetails { @Override public void modifyText(ModifyEvent e) { attributeFilter.setSearchText(((Text) e.widget).getText()); - txTableViewer.refresh(); + treeViewer.refresh(); } }); nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); attributeFilter = new TxAttributeFilter(); + viewSorter = new TxAttributeViewerSorter(); - txTableViewer = new TableViewer(parent); - txTableViewer.setContentProvider(new TxPropertiesContentProvider()); - txTableViewer.setLabelProvider(new TxPropertiesLabelProvider()); - txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); - txTableViewer.addFilter(attributeFilter); - + treeViewer = new TreeViewer(parent); + treeViewer.setContentProvider(new TransactionTreeContentProvider()); + treeViewer.setLabelProvider(new TxPropertiesLabelProvider()); + treeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); + treeViewer.addFilter(attributeFilter); + treeViewer.setSorter(viewSorter); + treeViewer.setAutoExpandLevel(2); + // Set up the table - Table table = txTableViewer.getTable(); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - - // Add the first name column - col1 = new TableColumn(table, SWT.LEFT); - col1.setText("Name"); - col1.setResizable(true); - col1.addSelectionListener(new SelectionAdapter() { + Tree tree = treeViewer.getTree(); + tree.setLayoutData(new GridData(GridData.FILL_BOTH)); + // Add the name column + col1 = new TreeViewerColumn(treeViewer, SWT.NONE); + col1.getColumn().setText("Name"); + col1.getColumn().setResizable(true); + col1.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(AttributeLabelProvider.NAME))); + col1.getColumn().addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - ((TxAttributeViewerSorter) txTableViewer.getSorter()).doSort(COLUMN_FIRST); - txTableViewer.refresh(); + ((TxAttributeViewerSorter) treeViewer.getSorter()).doSort(COLUMN_FIRST); + treeViewer.refresh(); } }); - - // Add the last name column - col2 = new TableColumn(table, SWT.LEFT); - col2.setText("Value"); - col2.setResizable(true); - col2.addSelectionListener(new SelectionAdapter() { + // Add the type column + col2 = new TreeViewerColumn(treeViewer, SWT.NONE); + col2.getColumn().setText("Type"); + col2.getColumn().setResizable(true); + col2.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(AttributeLabelProvider.TYPE))); + col2.getColumn().addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - ((TxAttributeViewerSorter) txTableViewer.getSorter()).doSort(COLUMN_SECOND); - txTableViewer.refresh(); + ((TxAttributeViewerSorter) treeViewer.getSorter()).doSort(COLUMN_SECOND); + treeViewer.refresh(); + } + }); + // Add the value column + col3 = new TreeViewerColumn(treeViewer, SWT.NONE); + col3.getColumn().setText("Value"); + col3.getColumn().setResizable(true); + col3.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(AttributeLabelProvider.VALUE))); + col3.getColumn().addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + ((TxAttributeViewerSorter) treeViewer.getSorter()).doSort(COLUMN_SECOND); + treeViewer.refresh(); } }); - // Pack the columns - for (int i = 0, n = table.getColumnCount(); i < n; i++) { - table.getColumn(i).pack(); - } +// for (int i = 0, n = table.getColumnCount(); i < n; i++) { +// table.getColumn(i).pack(); +// } // Turn on the header and the lines - table.setHeaderVisible(true); - table.setLinesVisible(true); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + treeViewer.addDoubleClickListener(new IDoubleClickListener(){ + + @Override + public void doubleClick(DoubleClickEvent event) { + ISelection selection = treeViewer.getSelection(); + if(selection instanceof IStructuredSelection){ + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + Object selected = structuredSelection.getFirstElement(); + if(selected instanceof Object[]){ + Object[] selectedArray = (Object[]) selected; + if(selectedArray.length==3 && selectedArray[2] instanceof ITx){ + waveformViewerPart.setSelection(new StructuredSelection(selectedArray[2])); + treeViewer.setInput(selectedArray[2]); + } + } + } + } + + }); parent.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { - Table table = txTableViewer.getTable(); + Tree table = treeViewer.getTree(); Rectangle area = parent.getClientArea(); Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); int width = area.width - 2*table.getBorderWidth(); @@ -136,16 +190,18 @@ public class TransactionDetails { // table is getting smaller so make the columns // smaller first and then resize the table to // match the client area width - col1.setWidth(width/3); - col2.setWidth(width - col1.getWidth()); + col1.getColumn().setWidth(width/3); + col2.getColumn().setWidth(width/4); + col3.getColumn().setWidth(width - col1.getColumn().getWidth()); table.setSize(area.width, area.height); } else { // table is getting bigger so make the table // bigger first and then make the columns wider // to match the client area width table.setSize(area.width, area.height); - col1.setWidth(width/3); - col2.setWidth(width - col1.getWidth()); + col1.getColumn().setWidth(width/3); + col2.getColumn().setWidth(width/4); + col3.getColumn().setWidth(width - col1.getColumn().getWidth()- col2.getColumn().getWidth()); } } }); @@ -153,19 +209,39 @@ public class TransactionDetails { @Focus public void setFocus() { - txTableViewer.getTable().setFocus(); + treeViewer.getTree().setFocus(); + } + + @Inject @Optional + public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_WAVEFORMVIEW) WaveformViewerPart part) { + this.waveformViewerPart=part; } @Inject - public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional Object object){ - if(txTableViewer!=null && !txTableViewer.getTable().isDisposed()) - if(object instanceof ITx){ - txTableViewer.setInput(object); - } else { - txTableViewer.setInput(null); + public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection){ + if(treeViewer!=null && selection!=null && !treeViewer.getTree().isDisposed()){ + if( selection instanceof IStructuredSelection) { + Object object= ((IStructuredSelection)selection).getFirstElement(); + if(object instanceof ITx){ + treeViewer.setInput(object); + } else { + treeViewer.setInput(null); + } } + } } + String timeToString(Long time){ + return waveformViewerPart.getScaledTime(time); + } + + String txToString(ITx tx){ + StringBuilder sb = new StringBuilder(); + sb.append("tx#").append(tx.getId()).append("[").append(timeToString(tx.getBeginTime())). + append(" - ").append(timeToString(tx.getEndTime())).append("]"); + return sb.toString(); + } + class TxAttributeViewerSorter extends ViewerSorter { private static final int ASCENDING = 0; @@ -199,45 +275,182 @@ public class TransactionDetails { @SuppressWarnings("unchecked") public int compare(Viewer viewer, Object e1, Object e2) { int rc = 0; - ITxAttribute p1 = (ITxAttribute) e1; - ITxAttribute p2 = (ITxAttribute) e2; - - // Determine which column and do the appropriate sort - switch (column) { - case COLUMN_FIRST: - rc = getComparator().compare(p1.getName(), p2.getName()); - break; - case COLUMN_SECOND: - rc = getComparator().compare(p1.getValue(), p2.getValue()); - break; + if(e1 instanceof ITxAttribute && e2 instanceof ITxAttribute){ + ITxAttribute p1 = (ITxAttribute) e1; + ITxAttribute p2 = (ITxAttribute) e2; + // Determine which column and do the appropriate sort + switch (column) { + case COLUMN_FIRST: + rc = getComparator().compare(p1.getName(), p2.getName()); + break; + case COLUMN_SECOND: + rc = getComparator().compare(p1.getDataType().name(), p2.getDataType().name()); + break; + case COLUMN_THIRD: + rc = getComparator().compare(p1.getValue(), p2.getValue()); + break; + } + // If descending order, flip the direction + if (direction == DESCENDING) rc = -rc; } - - // If descending order, flip the direction - if (direction == DESCENDING) - rc = -rc; - return rc; } } - public class TxAttributeFilter extends ViewerFilter { + class TxAttributeFilter extends ViewerFilter { - private String searchString; + 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; - } - ITxAttribute p = (ITxAttribute) element; - if (p.getName().matches(searchString)) { - return true; - } - return false; - } + public void setSearchText(String s) { + this.searchString = ".*" + s + ".*"; } -} \ No newline at end of file + + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (searchString == null || searchString.length() == 0) { + return true; + } + if(element instanceof ITxAttribute){ + ITxAttribute p = (ITxAttribute) element; + if (p.getName().matches(searchString)) { + return true; + } + } else if(element instanceof TreeNode) + return true; + return false; + } + } + + enum Type {TIMES, PROPS, IN_REL, OUT_REL} + + class TreeNode{ + public Type type; + public ITx element; + + public TreeNode(ITx element, Type type){ + this.element=element; + this.type=type; + } + + public String toString(){ + switch(type){ + case TIMES: return "Times"; + case PROPS: return "Attributes"; + case IN_REL: return "Incoming relations"; + case OUT_REL: return "Outgoing relations"; + } + return ""; + } + } + + class TransactionTreeContentProvider implements ITreeContentProvider { + + @Override + public void dispose() { } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + @Override + public Object[] getElements(Object element) { + return new Object[]{ + new TreeNode((ITx)element, Type.TIMES), + new TreeNode((ITx)element, Type.PROPS), + new TreeNode((ITx)element, Type.IN_REL), + new TreeNode((ITx)element, Type.OUT_REL) + }; + } + + @Override + public Object[] getChildren(Object element) { + if(element instanceof TreeNode){ + TreeNode propertyHolder=(TreeNode) element; + if(propertyHolder.type == Type.TIMES) + return new Object[][]{ + {"Start time", "", timeToString(propertyHolder.element.getBeginTime())}, + {"End time", "", timeToString(propertyHolder.element.getEndTime())}}; + else if(propertyHolder.type == Type.PROPS) + return propertyHolder.element.getAttributes().toArray(); + else if(propertyHolder.type == Type.IN_REL){ + Vector res = new Vector<>(); + for(ITxRelation rel:propertyHolder.element.getIncomingRelations()){ + res.add(new Object[]{ + rel.getRelationType(), + rel.getSource().getGenerator().getName(), + txToString(rel.getSource())}); + } + return res.toArray(); + } else if(propertyHolder.type == Type.OUT_REL){ + Vector res = new Vector<>(); + for(ITxRelation rel:propertyHolder.element.getOutgoingRelations()){ + res.add(new Object[]{ + rel.getRelationType(), + rel.getTarget().getGenerator().getName(), + txToString(rel.getTarget())}); + } + return res.toArray(); + } + } + return null; + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public boolean hasChildren(Object element) { + return getChildren(element)!=null; + } + + } + + class AttributeLabelProvider extends LabelProvider implements IStyledLabelProvider { + final int field; + public static final int NAME=0; + public static final int TYPE=1; + public static final int VALUE=2; + + public AttributeLabelProvider(int field) { + this.field=field; + } + + @Override + public StyledString getStyledText(Object element) { + switch(field){ + case NAME: + if (element instanceof ITxAttribute) { + ITxAttribute attribute = (ITxAttribute) element; + return new StyledString(attribute.getName()); + }else if (element instanceof ITxRelation) { + return new StyledString("Relation"); + }else if(element instanceof Object[]){ + Object[] elements = (Object[]) element; + return new StyledString(elements[field].toString()); + } else + return new StyledString(element.toString()); + case TYPE: + if (element instanceof ITxAttribute) { + ITxAttribute attribute = (ITxAttribute) element; + return new StyledString(attribute.getDataType().toString()); + }else if(element instanceof Object[]){ + Object[] elements = (Object[]) element; + return new StyledString(elements[field].toString()); + }else + return new StyledString(""); + default: + if (element instanceof ITxAttribute) { + ITxAttribute attribute = (ITxAttribute) element; + return new StyledString(attribute.getValue().toString()); + }else if(element instanceof Object[]){ + Object[] elements = (Object[]) element; + return new StyledString(elements[field].toString()); + }else + return new StyledString(""); + } + } + } +} + 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 index 429d713..fb5e56c 100644 --- 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 @@ -10,25 +10,33 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.parts; -import java.util.Arrays; +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; @@ -45,23 +53,38 @@ 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)); @@ -86,40 +109,64 @@ public class WaveformListPart implements ISelectionChangedListener { 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 selected"); + 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 selected"); + 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) { - eventBroker.post(WaveformViewerPart.ADD_WAVEFORM, - ((IStructuredSelection)txTableViewer.getSelection()).toList()); - + 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"); + appendAllItem.setToolTipText("Append all after"); appendAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_all_waves.png")); appendAllItem.setEnabled(false); @@ -128,22 +175,34 @@ public class WaveformListPart implements ISelectionChangedListener { @Override public void widgetSelected(SelectionEvent e) { Object[] all = getFilteredChildren(txTableViewer); - if(all.length>0) - eventBroker.post(WaveformViewerPart.ADD_WAVEFORM, Arrays.asList(all)); - + 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"); + 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) - eventBroker.post(WaveformViewerPart.ADD_WAVEFORM, Arrays.asList(all)); - + 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); + } } }); } @@ -155,8 +214,8 @@ public class WaveformListPart implements ISelectionChangedListener { } @Inject @Optional - public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_NODE) Object o) { - txTableViewer.setInput(o); + public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_WAVEFORMVIEW) WaveformViewerPart part) { + this.waveformViewerPart=part; updateButtons(); } @@ -167,37 +226,40 @@ public class WaveformListPart implements ISelectionChangedListener { protected void setSelection(ISelection iSelection) { IStructuredSelection selection = (IStructuredSelection)iSelection; - switch(selection.size()){ - case 0: + if(selection.size()==0){ appendItem.setEnabled(false); - break; - case 1: - selectionService.setSelection(selection.getFirstElement()); - break; - default: - selectionService.setSelection(selection.toList()); - break; } + selectionService.setSelection(selection); thisSelectionCount=selection.toList().size(); updateButtons(); } @Inject - public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional Object object, EPartService partService){ + public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){ MPart part = partService.getActivePart(); - if(part!=null && part.getObject() != this) - otherSelectionCount = (object instanceof IWaveform || object instanceof ITx)?1:0; + if(part!=null && part.getObject() != this && selection!=null){ + if( selection instanceof IStructuredSelection) { + Object object= ((IStructuredSelection)selection).getFirstElement(); + if(object instanceof IHierNode&& !(object instanceof IWaveform)) + 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()){ - Object[] all = getFilteredChildren(txTableViewer); - appendItem.setEnabled(thisSelectionCount>0); - appendAllItem.setEnabled(all.length>0); - insertItem.setEnabled(thisSelectionCount>0 && otherSelectionCount>0); - insertAllItem.setEnabled(all.length>0 && otherSelectionCount>0); + 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); } } @@ -222,6 +284,10 @@ public class WaveformListPart implements ISelectionChangedListener { } } + public Object[] getFilteredChildren(){ + return getFilteredChildren(txTableViewer); + } + protected Object[] getFilteredChildren(TableViewer viewer){ Object parent = viewer.getInput(); if(parent==null) return new Object[0]; @@ -245,4 +311,17 @@ public class WaveformListPart implements ISelectionChangedListener { } 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 9059647..a821e0d 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 @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -42,12 +41,12 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.services.EMenuService; import org.eclipse.e4.ui.workbench.modeling.ESelectionService; import org.eclipse.jface.dialogs.MessageDialog; +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.swt.widgets.Composite; -import com.minres.scviewer.database.IHierNode; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformDb; @@ -59,9 +58,7 @@ import com.minres.scviewer.e4.application.internal.StatusBarControl; public class WaveformViewerPart { - public static final String ACTIVE_DATABASE="Active_Database"; - public static final String ACTIVE_NODE="ActiveNode"; - public static final String ACTIVE_NODE_PATH="ActiveNodePath"; + public static final String ACTIVE_WAVEFORMVIEW="Active_Waveform_View"; public static final String ADD_WAVEFORM="AddWaveform"; protected static final String DATABASE_FILE = "DATABASE_FILE"; @@ -83,12 +80,10 @@ public class WaveformViewerPart { @Inject private IEventBroker eventBroker; @Inject EMenuService menuService; - - @Inject ESelectionService selectionService; - - private IWaveformDb database; - private IHierNode activeNode; + @Inject ESelectionService selectionService; + + private IWaveformDb database; private Composite myParent; @@ -128,12 +123,7 @@ public class WaveformViewerPart { @Override public void selectionChanged(SelectionChangedEvent event) { if(event.getSelection() instanceof IStructuredSelection) - for(Object o:((IStructuredSelection)event.getSelection()).toList()){ - if(o instanceof ITx || o instanceof IWaveform){ - selectionService.setSelection(o); - return; - } - } + selectionService.setSelection(event.getSelection()); } }); filesToLoad=new ArrayList(); @@ -159,7 +149,7 @@ public class WaveformViewerPart { subMonitor.setTaskName("Loading database"); try { for(File file: filesToLoad){ - TimeUnit.SECONDS.sleep(2); + //TimeUnit.SECONDS.sleep(2); database.load(file); database.addPropertyChangeListener(txDisplay); subMonitor.worked(1); @@ -237,8 +227,6 @@ public class WaveformViewerPart { persistedState.put(DATABASE_FILE+index, file.getAbsolutePath()); index++; } - if(activeNode!=null) - persistedState.put(ACTIVE_NODE_PATH, activeNode.getFullName()); persistedState.put(SHOWN_WAVEFORM+"S", Integer.toString(txDisplay.getStreamList().size())); index=0; for(IWaveform waveform:txDisplay.getStreamList()){ @@ -249,8 +237,6 @@ public class WaveformViewerPart { protected void restoreState() { updateAll(); - String hierName = persistedState.get(ACTIVE_NODE_PATH); - if(hierName!=null) eventBroker.post(ACTIVE_NODE_PATH, hierName); Integer waves = persistedState.containsKey(SHOWN_WAVEFORM+"S")?Integer.parseInt(persistedState.get(SHOWN_WAVEFORM+"S")):0; List> res = new LinkedList<>(); for(int i=0; i0) txDisplay.getStreamList().addAll(res); } - + private void updateAll() { - eventBroker.post(ACTIVE_DATABASE, database); + eventBroker.post(ACTIVE_WAVEFORMVIEW, this); eventBroker.post(StatusBarControl.ZOOM_LEVEL, zoomLevel[txDisplay.getZoomLevel()]); eventBroker.post(StatusBarControl.CURSOR_TIME, Long.toString(txDisplay.getCursorTime()/1000000)+"ns"); } - @Inject @Optional - public void getActiveNodeEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_NODE) Object o, MPart activePart) { - if(o instanceof IHierNode){ - activeNode=(IHierNode) o; - } - } - @Inject @Optional public void getAddWaveformEvent(@UIEventTopic(WaveformViewerPart.ADD_WAVEFORM) Object o) { Object sel = o==null?selectionService.getSelection():o; - if(sel instanceof List) - for(Object el:((List)sel)){ + if(sel instanceof IStructuredSelection) + for(Object el:((IStructuredSelection)sel).toArray()){ if(el instanceof IWaveform) - addStreamToList((IWaveform) el); + addStreamToList((IWaveform) el, false); } - else if(sel instanceof IWaveform ) - addStreamToList((IWaveform) sel); } -/* + /* @Inject public void setWaveform(@Optional @Named( IServiceConstants.ACTIVE_SELECTION) IWaveform waveform, @Optional @Named( IServiceConstants.ACTIVE_PART) MPart part) { @@ -293,7 +270,7 @@ public class WaveformViewerPart { txDisplay.setSelection(waveform==null?new StructuredSelection():new StructuredSelection(waveform)); } } -*/ + */ protected boolean askIfToLoad(File txFile) { if(txFile.exists() && MessageDialog.openQuestion(myParent.getDisplay().getActiveShell(), "Database open", @@ -326,17 +303,29 @@ public class WaveformViewerPart { public IWaveformDb getModel() { return database; } + public IWaveformDb getDatabase() { return database; } - public void addStreamToList(IWaveform obj){ - txDisplay.getStreamList().add(obj); + public void addStreamToList(IWaveform obj, boolean insert){ + addStreamsToList(new IWaveform[]{obj}, insert); } - public void addStreamsToList(IWaveform[] iWaveforms){ + public void addStreamsToList(IWaveform[] iWaveforms, boolean insert){ + List> streams= new LinkedList<>(); for(IWaveform stream:iWaveforms) - addStreamToList(stream); + streams.add(stream); + IStructuredSelection selection = (IStructuredSelection) txDisplay.getSelection(); + if(selection.size()==0) + txDisplay.getStreamList().addAll(streams); + else { + IWaveform selectedStream = (selection.getFirstElement() instanceof ITx)? + ((ITx)selection.getFirstElement()).getStream():(IWaveform)selection.getFirstElement(); + int index = txDisplay.getStreamList().indexOf(selectedStream); + if(!insert) index++; + txDisplay.getStreamList().addAll(index, streams); + } } public void removeStreamFromList(IWaveform obj){ @@ -355,7 +344,7 @@ public class WaveformViewerPart { public void moveSelected(int i) { txDisplay.moveSelected(i); } - + public void moveSelection(GotoDirection direction) { txDisplay.moveSelection(direction); } @@ -379,5 +368,15 @@ public class WaveformViewerPart { return txDisplay.getZoomLevel(); } + public ISelection getSelection() { + return txDisplay.getSelection(); + } + + public void setSelection(IStructuredSelection structuredSelection) { + txDisplay.setSelection(structuredSelection, true); + } + + public String getScaledTime(Long time) { + return txDisplay.getScaledTime(time); + } } - \ No newline at end of file diff --git a/com.minres.scviewer.e4.product/SCViewer.launch b/com.minres.scviewer.e4.product/SCViewer.launch index 7320b34..950fc88 100644 --- a/com.minres.scviewer.e4.product/SCViewer.launch +++ b/com.minres.scviewer.e4.product/SCViewer.launch @@ -16,13 +16,13 @@ - + - +