From 6be1f018b1b5b19f625f36746afe216f7dd7c1be Mon Sep 17 00:00:00 2001 From: eyck Date: Thu, 29 Oct 2020 07:48:35 +0100 Subject: [PATCH 1/3] add search dialog and pane --- .../ui/swt/internal/WaveformView.java | 19 +- .../eclipse/wb/swt/SWTResourceManager.java | 20 +- .../Application.e4xmi | 9 + .../icons/find.png | Bin 0 -> 659 bytes .../application/handlers/SearchHandler.java | 63 ++++++ .../e4/application/parts/SearchTxDialog.java | 185 ++++++++++++++++++ .../application/parts/TransactionDetails.java | 18 +- .../e4/application/parts/WaveformViewer.java | 32 ++- .../org/eclipse/wb/swt/ResourceManager.java | 171 +++++++++------- 9 files changed, 412 insertions(+), 105 deletions(-) create mode 100755 plugins/com.minres.scviewer.e4.application/icons/find.png create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/SearchTxDialog.java diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java index 08e8c76..aac936a 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java @@ -140,7 +140,8 @@ public class WaveformView implements IWaveformView { public void mouseDown(MouseEvent e) { if (e.button == 1) { Entry entry = trackVerticalOffset.floorEntry(e.y); - entry.getValue().selected=true; + if(entry!=null) + entry.getValue().selected=true; } else if (e.button == 3) { Menu topMenu= top.getMenu(); if(topMenu!=null) topMenu.setVisible(true); @@ -191,7 +192,7 @@ public class WaveformView implements IWaveformView { down=false; if(start==null) return; if((e.stateMask&SWT.MODIFIER_MASK&~SWT.SHIFT)!=0) return; //don't react on modifier except shift - if(!start.equals(end)){ + if(e.button == 1 && Math.abs(e.x-start.x)>3){ asyncUpdate(e.widget); long startTime = waveformCanvas.getTimeForOffset(start.x); long endTime = waveformCanvas.getTimeForOffset(end.x); @@ -287,9 +288,9 @@ public class WaveformView implements IWaveformView { case SWT.MouseDown: start=new Point(e.x, e.y); end=new Point(e.x, e.y); - down=true; if((e.stateMask&SWT.MODIFIER_MASK)!=0) return; //don't react on modifier if (e.button == 1) { + down=true; initialSelected = waveformCanvas.getElementsAt(start); } else if (e.button == 3) { Menu topMenu= top.getMenu(); @@ -680,15 +681,13 @@ public class WaveformView implements IWaveformView { */ @Override public ISelection getSelection() { + ArrayList sel = new ArrayList<>(); if (currentTxSelection != null) { - ArrayList sel = new ArrayList<>(); sel.add(currentTxSelection); - sel.addAll(currentWaveformSelection.stream().map(e -> e.waveform).collect(Collectors.toList())); - return new StructuredSelection(sel.toArray()); - } else if (currentWaveformSelection.size()>0) { - return new StructuredSelection(currentWaveformSelection.toArray()); - } else - return new StructuredSelection(); + } + // sel.addAll(currentWaveformSelection.stream().map(e -> e.waveform).collect(Collectors.toList())); + sel.addAll(currentWaveformSelection); + return new StructuredSelection(sel.toArray()); } /* (non-Javadoc) diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java b/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java index 20a9264..d8a2858 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java @@ -1,13 +1,13 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc. + * 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: + * Google, Inc. - initial API and implementation + *******************************************************************************/ package org.eclipse.wb.swt; import java.io.FileInputStream; diff --git a/plugins/com.minres.scviewer.e4.application/Application.e4xmi b/plugins/com.minres.scviewer.e4.application/Application.e4xmi index 0822bbe..baa15c1 100644 --- a/plugins/com.minres.scviewer.e4.application/Application.e4xmi +++ b/plugins/com.minres.scviewer.e4.application/Application.e4xmi @@ -136,6 +136,7 @@ + type:user @@ -200,6 +201,10 @@ + + + + @@ -226,6 +231,9 @@ + + + @@ -268,6 +276,7 @@ + diff --git a/plugins/com.minres.scviewer.e4.application/icons/find.png b/plugins/com.minres.scviewer.e4.application/icons/find.png new file mode 100755 index 0000000000000000000000000000000000000000..1547479646722bda4647df52cf3e8bc9b77428c6 GIT binary patch literal 659 zcmV;E0&M+>P)IO9T&v~?D!=C@G6X*U1@h2}>2WE%HrrsjTfQsh6N9%SR25A5rkWp0g zzi;-6|3HJE;58sAyX1e@^d7EwiKQLb00%dp|5+t<{|l;G!D3eSuFDma zRCxr2MVY_`ELgLXqo}ssqp5E;*r|opZT~&|!~VN?1^mw`Yxp0VmiIp*r|Ey~#AW|W zTBd;IxVd?%*x1<_!3Ip2yP9Rn!u1aqt=siKx4a3At0%7dKV|u@|9wlg|7x7R;eT!K z{QuFp&Huxb3&AdAW?^~2z`(!^HUQ{cR*=op7H|BYU0VMi3A-|5H&#ol!zs_8lnTU stream; + + private ConcurrentHashMap propNames=new ConcurrentHashMap(); + + /** + * Create the dialog. + * @param parentShell + * @param iTxStream + */ + public SearchTxDialog(Shell parentShell, ITxStream iTxStream) { + super(parentShell); + setShellStyle(SWT.BORDER | SWT.RESIZE | SWT.TITLE | SWT.APPLICATION_MODAL); + stream=iTxStream; + new Thread() { + public void run() { + stream.getEvents().values().parallelStream().forEach(evtLst -> { + evtLst.forEach(evt -> { + evt.getTransaction().getAttributes().stream().forEach(attr -> { + propNames.put(attr.getName(), attr.getDataType()); + }); + }); + }); + parentShell.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (propNameComboViewer!=null) { + propNameComboViewer.setInput(getEntries()); + propNameComboViewer.setSelection(new StructuredSelection(propNameComboViewer.getElementAt(0))); + } + } + }); + } + }.run(); + } + + /** + * Create contents of the dialog. + * @param parent + */ + @Override + protected Control createDialogArea(Composite parent) { + setMessage("Specify property name and value to search for"); + setTitleImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/Minres_logo.png")); + setTitle("Search Tx in stream"); + final Composite area = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = (GridLayout) area.getLayout(); + gridLayout.marginTop = 10; + gridLayout.marginBottom = 10; + final Composite container = new Composite(area, SWT.NONE); + final GridLayout gl_container = new GridLayout(2, false); + gl_container.horizontalSpacing = 2; + container.setLayout(gl_container); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + + final Label header = new Label(container, SWT.CENTER | SWT.WRAP); + GridData gd_header = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1); + gd_header.verticalIndent = 10; + header.setLayoutData(gd_header); + header.setText("Stream: "+stream.getName()); + + final Label propNameLabel = new Label(container, SWT.NONE); + propNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + propNameLabel.setText("Property Name:"); + + propNameComboViewer = new ComboViewer(container, SWT.NONE); + propNameComboViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + propNameComboViewer.setContentProvider(ArrayContentProvider.getInstance()); + propNameComboViewer.setLabelProvider(new LabelProvider() { + @SuppressWarnings("unchecked") + @Override + public String getText(Object element) { + Map.Entry e = (Map.Entry)element; + return e.getKey()+" ("+e.getValue().name()+")"; + } + + }); + propNameComboViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @SuppressWarnings("unchecked") + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection sel = event.getStructuredSelection(); + Map.Entry e = (Map.Entry)sel.getFirstElement(); + propName=e.getKey(); + propType=e.getValue(); + } + }); + propNameComboViewer.setInput(getEntries()); + propNameComboViewer.setSelection(new StructuredSelection(propNameComboViewer.getElementAt(0))); + + final Label propValueLabel = new Label(container, SWT.NONE); + propValueLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + propValueLabel.setText("Property Value:"); + + propValueText = new Text(container, SWT.BORDER); + propValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + return area; + } + + private List> getEntries() { + return propNames.entrySet().stream().sorted((e1,e2)->e1.getKey().compareTo(e2.getKey())).collect(Collectors.toList()); + } + + /** + * Create contents of the button bar. + * @param parent + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + final Button okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + okButton.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/tick.png")); + final Button cancelButton = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + cancelButton.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/cross.png")); + } + + protected void constrainShellSize() { + super.constrainShellSize(); + getShell().setMinimumSize(getShell().computeSize(-1, -1)); + + } + + @Override + protected void okPressed() { + //propName=propNameCombo.getItem(propNameCombo.getSelectionIndex()); + propValue=propValueText.getText(); + super.okPressed(); + } + + public String getPropName() { + return propName; + } + + public DataType getPropType() { + return propType; + } + + public String getPropValue() { + return propValue; + } +} diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java index f4d3b1c..acd8d35 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java @@ -63,6 +63,7 @@ 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.Control; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; @@ -113,7 +114,8 @@ public class TransactionDetails { /** The waveform viewer part. */ private WaveformViewer waveformViewerPart; - + private Composite top; + /** * Creates the composite. * @@ -123,9 +125,10 @@ public class TransactionDetails { public void createComposite(final Composite parent, @Optional WaveformViewer waveformViewerPart) { this.waveformViewerPart=waveformViewerPart; - parent.setLayout(new GridLayout(1, false)); + top = new Composite(parent, SWT.NONE); + top.setLayout(new GridLayout(1, false)); - nameFilter = new Text(parent, SWT.BORDER); + nameFilter = new Text(top, SWT.BORDER); nameFilter.setMessage(Messages.TransactionDetails_0); nameFilter.addModifyListener(new ModifyListener() { @Override @@ -141,7 +144,7 @@ public class TransactionDetails { attributeFilter = new TxAttributeFilter(); viewSorter = new TxAttributeViewerSorter(); - treeViewer = new TreeViewer(parent); + treeViewer = new TreeViewer(top); treeViewer.setContentProvider(new TransactionTreeContentProvider()); treeViewer.setLabelProvider(new TxPropertiesLabelProvider()); treeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); @@ -225,10 +228,10 @@ public class TransactionDetails { } }); - parent.addControlListener(new ControlAdapter() { + top.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { Tree table = treeViewer.getTree(); - Rectangle area = parent.getClientArea(); + Rectangle area = top.getClientArea(); Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); int width = area.width - 2*table.getBorderWidth(); if (preferredSize.y > area.height + table.getHeaderHeight()) { @@ -259,6 +262,9 @@ public class TransactionDetails { }); } + public Control getControl() { + return top; + } /** * Sets the focus. */ diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index 0c42fb8..4a1efbc 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -61,7 +61,10 @@ 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.jface.viewers.TableViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; @@ -287,14 +290,28 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis sashFormTop.setWeights(new int[] {25, 75}); Composite rightTop = new Composite(sashFormRight, SWT.NONE); - Composite rightBottom = new Composite(sashFormRight, SWT.NONE); - sashFormRight.setWeights(new int[] {80, 20}); - + waveformPane = factory.createPanel(rightTop); - ctx.set(Composite.class, rightBottom); - detailsView = ContextInjectionFactory.make(TransactionDetails.class, ctx); + CTabFolder tabFolder = new CTabFolder(sashFormRight, SWT.BORDER); + tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT)); + CTabItem tbtmDetails = new CTabItem(tabFolder, SWT.NONE); + tbtmDetails.setText("Transaction Details"); + + ctx.set(Composite.class, tabFolder); + detailsView = ContextInjectionFactory.make(TransactionDetails.class, ctx); + tbtmDetails.setControl(detailsView.getControl()); + + CTabItem tbtmSearchResults = new CTabItem(tabFolder, SWT.NONE); + tbtmSearchResults.setText("Search Results"); + + TableViewer tableViewer = new TableViewer(tabFolder, SWT.BORDER | SWT.FULL_SELECTION); + Table table = tableViewer.getTable(); + tbtmSearchResults.setControl(table); + + sashFormRight.setWeights(new int[] {75, 25}); + tabFolder.setSelection(0); waveformPane.setMaxTime(0); setupColors(); @@ -1294,4 +1311,9 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis eventBroker.post(WaveStatusBarControl.MARKER_DIFF, null); } } + + public void search(String propName, DataType type, String propValue) { + // TODO Auto-generated method stub + + } } \ No newline at end of file diff --git a/plugins/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java b/plugins/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java index 98642cf..56f340d 100644 --- a/plugins/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java +++ b/plugins/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java @@ -1,13 +1,14 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc. 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: + * Google, Inc. - initial API and implementation + * Wim Jongman - 1.8 and higher compliance + *******************************************************************************/ package org.eclipse.wb.swt; import java.io.File; @@ -24,51 +25,61 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.CompositeImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.ImageDataProvider; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; -import org.osgi.framework.Bundle; - +import org.osgi.framework.Bundle; + import com.minres.scviewer.e4.application.Messages; /** - * Utility class for managing OS resources associated with SWT/JFace controls such as colors, fonts, images, - * etc. + * Utility class for managing OS resources associated with SWT/JFace controls + * such as colors, fonts, images, etc. * - * !!! IMPORTANT !!! Application code must explicitly invoke the dispose() method to release the - * operating system resources managed by cached objects when those objects and OS resources are no longer - * needed (e.g. on application shutdown) + * This class is created automatically when you fiddle around with images and + * colors in WB. You might want to prevent your application from using this + * class and provide your own more effective means of resource caching. + * + * Even though this class can be used to manage these resources, if they are + * here for the duration of the application and not used then you still have an + * effective resource leak. + * + * Application code must explicitly invoke the dispose() method to + * release the operating system resources managed by cached objects when those + * objects and OS resources are no longer needed. * * This class may be freely distributed as part of any application or plugin. *

* * @author scheglov_ke * @author Dan Rubel + * @author Wim Jongman */ public class ResourceManager extends SWTResourceManager { - //////////////////////////////////////////////////////////////////////////// - // - // Image - // - //////////////////////////////////////////////////////////////////////////// - private static Map m_descriptorImageMap = new HashMap(); + /** - * Returns an {@link ImageDescriptor} stored in the file at the specified path relative to the specified - * class. + * The map where we store our images. + */ + private static Map m_descriptorImageMap = new HashMap(); + + /** + * Returns an {@link ImageDescriptor} stored in the file at the specified path + * relative to the specified class. * - * @param clazz - * the {@link Class} relative to which to find the image descriptor. - * @param path - * the path to the image file. + * @param clazz the {@link Class} relative to which to find the image + * descriptor. + * @param path the path to the image file. * @return the {@link ImageDescriptor} stored in the file at the specified path. */ public static ImageDescriptor getImageDescriptor(Class clazz, String path) { return ImageDescriptor.createFromFile(clazz, path); } + /** * Returns an {@link ImageDescriptor} stored in the file at the specified path. * - * @param path - * the path to the image file. + * @param path the path to the image file. * @return the {@link ImageDescriptor} stored in the file at the specified path. */ public static ImageDescriptor getImageDescriptor(String path) { @@ -78,11 +89,11 @@ public class ResourceManager extends SWTResourceManager { return null; } } + /** * Returns an {@link Image} based on the specified {@link ImageDescriptor}. * - * @param descriptor - * the {@link ImageDescriptor} for the {@link Image}. + * @param descriptor the {@link ImageDescriptor} for the {@link Image}. * @return the {@link Image} based on the specified {@link ImageDescriptor}. */ public static Image getImage(ImageDescriptor descriptor) { @@ -96,23 +107,24 @@ public class ResourceManager extends SWTResourceManager { } return image; } + /** * Maps images to decorated images. */ @SuppressWarnings("unchecked") private static Map>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; + /** * Returns an {@link Image} composed of a base image decorated by another image. * - * @param baseImage - * the base {@link Image} that should be decorated. - * @param decorator - * the {@link Image} to decorate the base image. + * @param baseImage the base {@link Image} that should be decorated. + * @param decorator the {@link Image} to decorate the base image. * @return {@link Image} The resulting decorated image. */ public static Image decorateImage(Image baseImage, Image decorator) { return decorateImage(baseImage, decorator, BOTTOM_RIGHT); } + /** * Returns an {@link Image} composed of a base image decorated by another image. * @@ -149,13 +161,13 @@ public class ResourceManager extends SWTResourceManager { protected void drawCompositeImage(int width, int height) { drawImage(createCachedImageDataProvider(baseImage), 0, 0); if (corner == TOP_LEFT) { - drawImage(createCachedImageDataProvider(decorator), 0, 0); + drawImage(getUnzoomedImageDataProvider(decorator.getImageData()) , 0, 0); } else if (corner == TOP_RIGHT) { - drawImage(createCachedImageDataProvider(decorator), bib.width - dib.width, 0); + drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, 0); } else if (corner == BOTTOM_LEFT) { - drawImage(createCachedImageDataProvider(decorator), 0, bib.height - dib.height); + drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), 0, bib.height - dib.height); } else if (corner == BOTTOM_RIGHT) { - drawImage(createCachedImageDataProvider(decorator), bib.width - dib.width, bib.height - dib.height); + drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, bib.height - dib.height); } } @Override @@ -169,6 +181,12 @@ public class ResourceManager extends SWTResourceManager { } return result; } + + private static ImageDataProvider getUnzoomedImageDataProvider(ImageData imageData) { + return zoom -> zoom == 100 ? imageData : null; + } + + /** * Dispose all of the cached images. */ @@ -202,6 +220,7 @@ public class ResourceManager extends SWTResourceManager { m_URLImageMap.clear(); } } + //////////////////////////////////////////////////////////////////////////// // // Plugin images support @@ -211,23 +230,25 @@ public class ResourceManager extends SWTResourceManager { * Maps URL to images. */ private static Map m_URLImageMap = new HashMap(); + /** * Provider for plugin resources, used by WindowBuilder at design time. */ public interface PluginResourceProvider { URL getEntry(String symbolicName, String path); } + /** - * Instance of {@link PluginResourceProvider}, used by WindowBuilder at design time. + * Instance of {@link PluginResourceProvider}, used by WindowBuilder at design + * time. */ private static PluginResourceProvider m_designTimePluginResourceProvider = null; + /** * Returns an {@link Image} based on a plugin and file path. * - * @param plugin - * the plugin {@link Object} containing the image - * @param name - * the path to the image within the plugin + * @param plugin the plugin {@link Object} containing the image + * @param name the path to the image within the plugin * @return the {@link Image} stored in the file at the specified path * * @deprecated Use {@link #getPluginImage(String, String)} instead. @@ -244,13 +265,12 @@ public class ResourceManager extends SWTResourceManager { } return null; } + /** * Returns an {@link Image} based on a {@link Bundle} and resource entry path. * - * @param symbolicName - * the symbolic name of the {@link Bundle}. - * @param path - * the path of the resource entry. + * @param symbolicName the symbolic name of the {@link Bundle}. + * @param path the path of the resource entry. * @return the {@link Image} stored in the file at the specified path. */ public static Image getPluginImage(String symbolicName, String path) { @@ -264,6 +284,7 @@ public class ResourceManager extends SWTResourceManager { } return null; } + /** * Returns an {@link Image} based on given {@link URL}. */ @@ -290,13 +311,12 @@ public class ResourceManager extends SWTResourceManager { } return null; } + /** * Returns an {@link ImageDescriptor} based on a plugin and file path. * - * @param plugin - * the plugin {@link Object} containing the image. - * @param name - * the path to th eimage within the plugin. + * @param plugin the plugin {@link Object} containing the image. + * @param name the path to th eimage within the plugin. * @return the {@link ImageDescriptor} stored in the file at the specified path. * * @deprecated Use {@link #getPluginImageDescriptor(String, String)} instead. @@ -315,14 +335,15 @@ public class ResourceManager extends SWTResourceManager { } return null; } + /** - * Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource entry path. + * Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource + * entry path. * - * @param symbolicName - * the symbolic name of the {@link Bundle}. - * @param path - * the path of the resource entry. - * @return the {@link ImageDescriptor} based on a {@link Bundle} and resource entry path. + * @param symbolicName the symbolic name of the {@link Bundle}. + * @param path the path of the resource entry. + * @return the {@link ImageDescriptor} based on a {@link Bundle} and resource + * entry path. */ public static ImageDescriptor getPluginImageDescriptor(String symbolicName, String path) { try { @@ -335,6 +356,7 @@ public class ResourceManager extends SWTResourceManager { } return null; } + /** * Returns an {@link URL} based on a {@link Bundle} and resource entry path. */ @@ -353,13 +375,12 @@ public class ResourceManager extends SWTResourceManager { // no such resource return null; } + /** * Returns an {@link URL} based on a plugin and file path. * - * @param plugin - * the plugin {@link Object} containing the file path. - * @param name - * the file path. + * @param plugin the plugin {@link Object} containing the file path. + * @param name the file path. * @return the {@link URL} representing the file at the specified path. * @throws Exception */ @@ -373,13 +394,13 @@ public class ResourceManager extends SWTResourceManager { Object bundle = getBundleMethod.invoke(plugin, new Object[0]); // Class PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ - Constructor pathConstructor = PathClass.getConstructor(new Class[]{String.class}); - Object path = pathConstructor.newInstance(new Object[]{name}); + Constructor pathConstructor = PathClass.getConstructor(new Class[] { String.class }); + Object path = pathConstructor.newInstance(new Object[] { name }); // Class IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ Class PlatformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$ - Method findMethod = PlatformClass.getMethod("find", new Class[]{BundleClass, IPathClass}); //$NON-NLS-1$ - return (URL) findMethod.invoke(null, new Object[]{bundle, path}); + Method findMethod = PlatformClass.getMethod("find", new Class[] { BundleClass, IPathClass }); //$NON-NLS-1$ + return (URL) findMethod.invoke(null, new Object[] { bundle, path }); } } catch (Throwable e) { // Ignore any exceptions @@ -390,24 +411,26 @@ public class ResourceManager extends SWTResourceManager { if (PluginClass.isAssignableFrom(plugin.getClass())) { // Class PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ - Constructor pathConstructor = PathClass.getConstructor(new Class[]{String.class}); - Object path = pathConstructor.newInstance(new Object[]{name}); + Constructor pathConstructor = PathClass.getConstructor(new Class[] { String.class }); + Object path = pathConstructor.newInstance(new Object[] { name }); // Class IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ - Method findMethod = PluginClass.getMethod("find", new Class[]{IPathClass}); //$NON-NLS-1$ - return (URL) findMethod.invoke(plugin, new Object[]{path}); + Method findMethod = PluginClass.getMethod("find", new Class[] { IPathClass }); //$NON-NLS-1$ + return (URL) findMethod.invoke(plugin, new Object[] { path }); } } return null; } + //////////////////////////////////////////////////////////////////////////// // // General // //////////////////////////////////////////////////////////////////////////// /** - * Dispose of cached objects and their underlying OS resources. This should only be called when the cached - * objects are no longer needed (e.g. on application shutdown). + * Dispose of cached objects and their underlying OS resources. This should only + * be called when the cached objects are no longer needed (e.g. on application + * shutdown). */ public static void dispose() { disposeColors(); From 5746b9f75875333e3537b45194e41cd5e2cf36ef Mon Sep 17 00:00:00 2001 From: eyck Date: Sun, 1 Nov 2020 17:42:16 +0100 Subject: [PATCH 2/3] add initial version of search list --- .../ui/swt/internal/WaveformView.java | 2 +- .../META-INF/MANIFEST.MF | 4 +- .../scviewer/e4/application/E4LifeCycle.java | 6 - .../application/handlers/SearchHandler.java | 17 +- .../e4/application/parts/SearchTxDialog.java | 4 - .../application/parts/TransactionDetails.java | 463 ++---------------- .../e4/application/parts/TransactionList.java | 286 +++++++++++ .../parts/TransactionListView.java | 84 ++++ .../e4/application/parts/WaveformViewer.java | 28 +- ...bstractTransactionTreeContentProvider.java | 102 ++++ .../txTableTree/AttributeLabelProvider.java | 160 ++++++ .../txTableTree/TransactionTreeNode.java | 95 ++++ .../txTableTree/TransactionTreeNodeType.java | 12 + .../parts/txTableTree/TxAttributeFilter.java | 55 +++ .../txTableTree/TxAttributeViewerSorter.java | 73 +++ .../parts/txTableTree/TxFilter.java | 92 ++++ 16 files changed, 1022 insertions(+), 461 deletions(-) create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionListView.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/AbstractTransactionTreeContentProvider.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/AttributeLabelProvider.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNode.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNodeType.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeFilter.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeViewerSorter.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxFilter.java diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java index aac936a..d7a90cd 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java @@ -164,8 +164,8 @@ public class WaveformView implements IWaveformView { } else { setSelection(new StructuredSelection(entry.getValue()), (e.stateMask & SWT.CTRL) !=0 , false); } + lastClickedEntry = entry.getValue(); } - lastClickedEntry = entry.getValue(); } } }; diff --git a/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index 8d335f5..a380eac 100644 --- a/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -29,7 +29,9 @@ Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.e4.core.di.extensions, org.eclipse.e4.ui.css.swt.theme;bundle-version="0.10.0", org.eclipse.core.resources;bundle-version="3.13.0", - javax.annotation;bundle-version="1.2.0" + javax.annotation;bundle-version="1.2.0", + org.eclipse.core.databinding, + org.eclipse.jface.databinding Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Import-Package: com.minres.scviewer.database, javax.inject;version="1.0.0" diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java index 6f91a1d..054b8be 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java @@ -10,17 +10,11 @@ *******************************************************************************/ package com.minres.scviewer.e4.application; -import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import javax.annotation.PostConstruct; -import javax.inject.Inject; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener; -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; diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java index 9c45219..858d2e7 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java @@ -15,11 +15,9 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import com.minres.scviewer.database.ui.TrackEntry; -import com.minres.scviewer.e4.application.parts.SearchTxDialog; import com.minres.scviewer.e4.application.parts.WaveformViewer; public class SearchHandler { @@ -44,13 +42,14 @@ public class SearchHandler { Object obj = activePart.getObject(); if(obj instanceof WaveformViewer){ WaveformViewer wfv = (WaveformViewer)obj; - ISelection sel = wfv.getSelection(); - if(sel instanceof StructuredSelection) { - TrackEntry e = findTrackEntry(((StructuredSelection)sel).toArray()); - SearchTxDialog dlg = new SearchTxDialog(shell, e.getStream()); - if (dlg.open() != Window.OK) return; - wfv.search(dlg.getPropName(), dlg.getPropType(), dlg.getPropValue()); - } + wfv.showSearch(); +// ISelection sel = wfv.getSelection(); +// if(sel instanceof StructuredSelection) { +// TrackEntry e = findTrackEntry(((StructuredSelection)sel).toArray()); +// SearchTxDialog dlg = new SearchTxDialog(shell, e.getStream()); +// if (dlg.open() != Window.OK) return; +// wfv.search(dlg.getPropName(), dlg.getPropType(), dlg.getPropValue()); +// } } } diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/SearchTxDialog.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/SearchTxDialog.java index 3dddefd..e73870a 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/SearchTxDialog.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/SearchTxDialog.java @@ -1,6 +1,5 @@ package com.minres.scviewer.e4.application.parts; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -17,11 +16,9 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; -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.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -166,7 +163,6 @@ public class SearchTxDialog extends TitleAreaDialog { @Override protected void okPressed() { - //propName=propNameCombo.getItem(propNameCombo.getSelectionIndex()); propValue=propValueText.getText(); super.okPressed(); } diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java index acd8d35..9d1c81f 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java @@ -10,15 +10,10 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.parts; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.TreeMap; -import java.util.Vector; -import java.util.regex.PatternSyntaxException; import java.util.stream.Collectors; import javax.annotation.PostConstruct; @@ -34,23 +29,16 @@ 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.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.ITreeViewerListener; -import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; @@ -68,11 +56,14 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; -import com.minres.scviewer.database.DataType; import com.minres.scviewer.database.ITx; -import com.minres.scviewer.database.ITxAttribute; -import com.minres.scviewer.database.ITxRelation; import com.minres.scviewer.e4.application.Messages; +import com.minres.scviewer.e4.application.parts.txTableTree.AttributeLabelProvider; +import com.minres.scviewer.e4.application.parts.txTableTree.AbstractTransactionTreeContentProvider; +import com.minres.scviewer.e4.application.parts.txTableTree.TransactionTreeNode; +import com.minres.scviewer.e4.application.parts.txTableTree.TransactionTreeNodeType; +import com.minres.scviewer.e4.application.parts.txTableTree.TxAttributeFilter; +import com.minres.scviewer.e4.application.parts.txTableTree.TxAttributeViewerSorter; import com.minres.scviewer.e4.application.provider.TxPropertiesLabelProvider; /** @@ -145,7 +136,18 @@ public class TransactionDetails { viewSorter = new TxAttributeViewerSorter(); treeViewer = new TreeViewer(top); - treeViewer.setContentProvider(new TransactionTreeContentProvider()); + treeViewer.setContentProvider(new AbstractTransactionTreeContentProvider(waveformViewerPart) { + + @Override + public Object[] getElements(Object element) { + return new Object[]{ + new TransactionTreeNode((ITx)element, TransactionTreeNodeType.PROPS), + new TransactionTreeNode((ITx)element, TransactionTreeNodeType.ATTRS), + new TransactionTreeNode((ITx)element, TransactionTreeNodeType.IN_REL), + new TransactionTreeNode((ITx)element, TransactionTreeNodeType.OUT_REL) + }; + } + }); treeViewer.setLabelProvider(new TxPropertiesLabelProvider()); treeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); treeViewer.addFilter(attributeFilter); @@ -171,7 +173,7 @@ public class TransactionDetails { col1 = new TreeViewerColumn(treeViewer, SWT.NONE); col1.getColumn().setText(Messages.TransactionDetails_1); col1.getColumn().setResizable(true); - col1.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(AttributeLabelProvider.NAME))); + col1.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.NAME))); col1.getColumn().addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_FIRST); @@ -182,7 +184,7 @@ public class TransactionDetails { col2 = new TreeViewerColumn(treeViewer, SWT.NONE); col2.getColumn().setText(Messages.TransactionDetails_2); col2.getColumn().setResizable(true); - col2.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(AttributeLabelProvider.TYPE))); + col2.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.TYPE))); col2.getColumn().addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_SECOND); @@ -193,7 +195,7 @@ public class TransactionDetails { col3 = new TreeViewerColumn(treeViewer, SWT.NONE); col3.getColumn().setText(Messages.TransactionDetails_3); col3.getColumn().setResizable(true); - col3.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(AttributeLabelProvider.VALUE))); + col3.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.VALUE))); col3.getColumn().addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_SECOND); @@ -333,15 +335,15 @@ public class TransactionDetails { if(paths==null) treeViewer.setAutoExpandLevel(2); else { - TransactionTreeContentProvider cp = (TransactionTreeContentProvider) treeViewer.getContentProvider(); + AbstractTransactionTreeContentProvider cp = (AbstractTransactionTreeContentProvider) treeViewer.getContentProvider(); Object[] elems = cp.getElements(treeViewer.getInput()); for(TreePath path: paths) { - TreeNode firstSeg = (TreeNode)path.getFirstSegment(); + TransactionTreeNode firstSeg = (TransactionTreeNode)path.getFirstSegment(); for(Object elem : elems) { - if(((TreeNode)elem).type == firstSeg.type) { + if(((TransactionTreeNode)elem).type == firstSeg.type) { treeViewer.setExpandedState(elem, true); - if(firstSeg.type==TransactionDetails.Type.ATTRS && path.getSegmentCount()>1) - expandSubNodes(path, 1, (TreeNode)elem); + if(firstSeg.type==TransactionTreeNodeType.ATTRS && path.getSegmentCount()>1) + expandSubNodes(path, 1, (TransactionTreeNode)elem); break; } } @@ -349,14 +351,14 @@ public class TransactionDetails { } } - private void expandSubNodes(TreePath path, int level, TreeNode elem) { + private void expandSubNodes(TreePath path, int level, TransactionTreeNode elem) { if(level==path.getSegmentCount()) return; - TransactionTreeContentProvider cp = (TransactionTreeContentProvider) treeViewer.getContentProvider(); + AbstractTransactionTreeContentProvider cp = (AbstractTransactionTreeContentProvider) treeViewer.getContentProvider(); Object[] childs = cp.getChildren(elem); - TreeNode nextSeg = (TreeNode)path.getSegment(level); + TransactionTreeNode nextSeg = (TransactionTreeNode)path.getSegment(level); for(Object child:childs) { - if(child instanceof TreeNode) { - TreeNode node = (TreeNode) child; + if(child instanceof TransactionTreeNode) { + TransactionTreeNode node = (TransactionTreeNode) child; if(nextSeg.toString().equals(node.toString())) { treeViewer.setExpandedState(node, true); expandSubNodes(path, level+1, node); @@ -398,7 +400,7 @@ public class TransactionDetails { public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){ // only react if selection is actually from the WaveformViewer and nothing else MPart part = partService.getActivePart(); - if( part == null || ! (part.getObject() instanceof WaveformViewer ) ) + if( part == null || ! (part.getObject() instanceof WaveformViewer ) || part.getObject() != waveformViewerPart) return; if(treeViewer!=null && selection!=null && !treeViewer.getTree().isDisposed()){ if( selection instanceof IStructuredSelection && !selection.isEmpty()) { @@ -406,406 +408,5 @@ public class TransactionDetails { } } } - - /** - * Time to string. - * - * @param time the time - * @return the string - */ - String timeToString(Long time){ - return waveformViewerPart.getScaledTime(time); - } - - /** - * Tx to string. - * - * @param tx the tx - * @return the string - */ - String txToString(ITx tx){ - StringBuilder sb = new StringBuilder(); - sb.append("tx#").append(tx.getId()).append("[").append(timeToString(tx.getBeginTime())); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append(" - ").append(timeToString(tx.getEndTime())).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ - return sb.toString(); - } - - /** - * The Class TxAttributeViewerSorter. - */ - class TxAttributeViewerSorter extends ViewerComparator { - - /** The Constant ASCENDING. */ - private static final int ASCENDING = 0; - - /** The Constant DESCENDING. */ - private static final int DESCENDING = 1; - - /** The column. */ - private int column; - - /** The direction. */ - private int direction; - - /** - * Does the sort. If it's a different column from the previous sort, do an - * ascending sort. If it's the same column as the last sort, toggle the sort - * direction. - * - * @param column the column - */ - public void doSort(int column) { - if (column == this.column) { - // Same column as last sort; toggle the direction - direction = 1 - direction; - } else { - // New column; do an ascending sort - this.column = column; - direction = ASCENDING; - } - } - - /** - * Compares the object for sorting. - * - * @param viewer the viewer - * @param e1 the e1 - * @param e2 the e2 - * @return the int - */ - public int compare(Viewer viewer, Object e1, Object e2) { - int rc = 0; - 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().toString(), p2.getValue().toString()); - break; - } - // If descending order, flip the direction - if (direction == DESCENDING) rc = -rc; - } - return rc; - } - } - - /** - * The Class TxAttributeFilter. - */ - class TxAttributeFilter extends ViewerFilter { - - /** The search string. */ - private String searchString; - - /** - * Sets the search text. - * - * @param s the new search text - */ - public void setSearchText(String s) { - this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) - */ - @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { - - if (searchString == null || searchString.length() == 0) { - return true; - } - if(element instanceof TreeNode) { - return true; - } - if(element instanceof ITxAttribute){ - try { - return (((ITxAttribute) element).getName().toLowerCase().matches(searchString.toLowerCase())); - } catch (PatternSyntaxException e) { - return true; - } - } - if(element instanceof Object[]) { - try { - return (((Object[])element)[0]).toString().toLowerCase().matches(searchString.toLowerCase()); - } catch (PatternSyntaxException e) { - return true; - } - } - return false; - } - } - - /** - * The Enum Type. - */ - enum Type { - PROPS, /** The props. */ - ATTRS, /** The attrs. */ - IN_REL, /** The in rel. */ - OUT_REL,/** The out rel. */ - HIER - } - - /** - * The Class TreeNode. - */ - class TreeNode implements Comparable{ - - /** The type. */ - public Type type; - - /** The element. */ - public ITx element; - - private String hier_path; - /** - * Instantiates a new tree node. - * - * @param element the element - * @param type the type - */ - public TreeNode(ITx element, Type type){ - this.element=element; - this.type=type; - this.hier_path=""; - } - - public TreeNode(ITx element, String path){ - this.element=element; - this.type=Type.HIER; - this.hier_path=path; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString(){ - switch(type){ - case PROPS: return Messages.TransactionDetails_10; - case ATTRS: return Messages.TransactionDetails_11; - case IN_REL: return Messages.TransactionDetails_12; - case OUT_REL: return Messages.TransactionDetails_13; - case HIER:{ - String[] tokens = hier_path.split("\\."); - return tokens[tokens.length-1]; - } - } - return ""; //$NON-NLS-1$ - } - - public Object[] getAttributeListForHier() { - if(childs==null) { - Map res = element.getAttributes().stream() - .filter(txAttr -> txAttr.getName().startsWith(hier_path)) - .map(txAttr -> { - String target = hier_path.length()==0?txAttr.getName():txAttr.getName().replace(hier_path+'.', ""); - String[] tokens = target.split("\\."); - if(tokens.length==1) - return new AbstractMap.SimpleEntry<>(tokens[0], txAttr); - else - return new AbstractMap.SimpleEntry<>(tokens[0], new TreeNode(element, hier_path.length()>0?hier_path+"."+tokens[0]:tokens[0])); - }) - .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue(), (first, second) -> first)); - childs = new TreeMap(res).values().toArray(); - } - return childs; - } - - private Object[] childs=null; - - @Override - public boolean equals(Object o) { - if(o instanceof TreeNode) { - TreeNode t = (TreeNode) o; - return type==t.type && hier_path.equals(t.hier_path); - } - return false; - } - - @Override - public int compareTo(TreeNode o) { - int res1 = type.compareTo(o.type); - if(res1==0) { - return hier_path.compareTo(o.hier_path); - } else - return res1; - } - } - - /** - * The Class TransactionTreeContentProvider. - */ - class TransactionTreeContentProvider implements ITreeContentProvider { - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - @Override - public void dispose() { } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) - */ - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) - */ - @Override - public Object[] getElements(Object element) { - return new Object[]{ - new TreeNode((ITx)element, Type.PROPS), - new TreeNode((ITx)element, Type.ATTRS), - new TreeNode((ITx)element, Type.IN_REL), - new TreeNode((ITx)element, Type.OUT_REL) - }; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) - */ - @Override - public Object[] getChildren(Object element) { - if(element instanceof TreeNode){ - TreeNode propertyHolder=(TreeNode) element; - if(propertyHolder.type == Type.PROPS){ - return new Object[][]{ - {Messages.TransactionDetails_1, Messages.TransactionDetails_16, propertyHolder.element.getStream().getFullName()}, - {Messages.TransactionDetails_2, Messages.TransactionDetails_16, propertyHolder.element.getGenerator().getName()}, - {Messages.TransactionDetails_19, Messages.TransactionDetails_20, timeToString(propertyHolder.element.getBeginTime())}, - {Messages.TransactionDetails_21, Messages.TransactionDetails_20, timeToString(propertyHolder.element.getEndTime())} - }; - }else if(propertyHolder.type == Type.ATTRS || propertyHolder.type == Type.HIER) - return propertyHolder.getAttributeListForHier(); - 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(), - 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(), - rel.getTarget()}); - } - return res.toArray(); - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) - */ - @Override - public Object getParent(Object element) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) - */ - @Override - public boolean hasChildren(Object element) { - return getChildren(element)!=null; - } - - } - - /** - * The Class AttributeLabelProvider. - */ - class AttributeLabelProvider extends LabelProvider implements IStyledLabelProvider { - - /** The field. */ - final int field; - - /** The Constant NAME. */ - public static final int NAME=0; - - /** The Constant TYPE. */ - public static final int TYPE=1; - - /** The Constant VALUE. */ - public static final int VALUE=2; - - /** - * Instantiates a new attribute label provider. - * - * @param field the field - */ - public AttributeLabelProvider(int field) { - this.field=field; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) - */ - @Override - public StyledString getStyledText(Object element) { - switch(field){ - case NAME: - if (element instanceof ITxAttribute) { - ITxAttribute attribute = (ITxAttribute) element; - String[] tokens = attribute.getName().split("\\."); - return new StyledString(tokens[tokens.length-1]); - }else if (element instanceof ITxRelation) { - return new StyledString(Messages.TransactionDetails_4); - }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(""); //$NON-NLS-1$ - default: - if (element instanceof ITxAttribute) { - ITxAttribute attribute = (ITxAttribute) element; - String value = attribute.getValue().toString(); - if((DataType.UNSIGNED == attribute.getDataType() || DataType.INTEGER==attribute.getDataType()) && !"0".equals(value)) { - try { - value += " [0x"+Long.toHexString(Long.parseLong(attribute.getValue().toString()))+"]"; - } catch(NumberFormatException e) { } - } - return new StyledString(value); - }else if(element instanceof Object[]){ - Object[] elements = (Object[]) element; - Object o = elements[field]; - if(o instanceof ITx) { - ITx tx = (ITx)o; - return new StyledString(txToString(tx)+" ("+tx.getStream().getFullName()+")"); - } else - return new StyledString(o.toString()); - } else if(element instanceof ITx){ - return new StyledString(txToString((ITx) element)); - }else - return new StyledString(""); //$NON-NLS-1$ - } - } - } } diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java new file mode 100644 index 0000000..cae3de4 --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java @@ -0,0 +1,286 @@ +package com.minres.scviewer.e4.application.parts; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +import org.eclipse.core.databinding.observable.list.ObservableList; +import org.eclipse.core.databinding.observable.list.WritableList; +import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; + +import com.minres.scviewer.database.DataType; +import com.minres.scviewer.database.ITx; +import com.minres.scviewer.database.ITxAttribute; +import com.minres.scviewer.database.ITxEvent; +import com.minres.scviewer.database.ITxEvent.Type; +import com.minres.scviewer.database.ITxStream; +import com.minres.scviewer.database.ui.TrackEntry; +import com.minres.scviewer.e4.application.parts.txTableTree.AbstractTransactionTreeContentProvider; +import com.minres.scviewer.e4.application.parts.txTableTree.AttributeLabelProvider; +import com.minres.scviewer.e4.application.parts.txTableTree.TxFilter; + +public class TransactionList extends Composite { + public class AttributeNameBean { + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public DataType getType() { + return type; + } + public void setType(DataType type) { + this.type = type; + } + public AttributeNameBean(String name, DataType type) { + super(); + this.name = name; + this.type = type; + } + String name; + DataType type; + + } + + private ComboViewer searchPropComboViewer = null; + + private ComboViewer viewPropComboViewer = null; + + private Text searchPropValue; + + private TreeViewer treeViewer = null; + + private TreeColumn valueColumn = null; + + private AttributeLabelProvider nameLabelProvider = null; + + private ITxStream stream; + + private ObservableList attrNames = new WritableList(); + + private List eventList = new ArrayList(); + + private List emptyList = new ArrayList(); + + TxFilter txFilter; + + /** + * Create the composite. + * @param parent + * @param style + */ + public TransactionList(Composite parent, int style, WaveformViewer waveformViewer) { + super(parent, style); + setLayout(new GridLayout(3, false)); + txFilter = new TxFilter(); + + searchPropComboViewer = new ComboViewer(this, SWT.NONE); + searchPropComboViewer.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + AttributeNameBean entry = (AttributeNameBean) element; + return entry.getName()+" ["+entry.getType().toString()+"]"; + } + }); + searchPropComboViewer.setContentProvider(new ObservableListContentProvider()); + searchPropComboViewer.setInput(attrNames); + Combo searchPropCombo = searchPropComboViewer.getCombo(); + searchPropCombo.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); + searchPropCombo.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + int idx = searchPropCombo.getSelectionIndex(); + AttributeNameBean sel = attrNames.get(idx); + txFilter.setSearchProp(sel.getName(), sel.getType()); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + int idx = searchPropCombo.getSelectionIndex(); + AttributeNameBean sel = attrNames.get(idx); + txFilter.setSearchProp(sel.getName(), sel.getType()); + } + }); + + searchPropValue = new Text(this, SWT.BORDER); + searchPropValue.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + searchPropValue.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + txFilter.setSearchValue(((Text) e.widget).getText()); + treeViewer.refresh(); + //treeViewer.expandAll(false); + } + }); + + viewPropComboViewer = new ComboViewer(this, SWT.NONE); + viewPropComboViewer.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + AttributeNameBean entry = (AttributeNameBean) element; + return entry.getName()+" ["+entry.getType().toString()+"]"; + } + }); + viewPropComboViewer.setContentProvider(new ObservableListContentProvider()); + viewPropComboViewer.setInput(attrNames); + Combo viewPropCombo = viewPropComboViewer.getCombo(); + viewPropCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + viewPropCombo.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + int idx = viewPropCombo.getSelectionIndex(); + AttributeNameBean sel = attrNames.get(idx); + nameLabelProvider.setShowProp(sel.getName()); + treeViewer.refresh(true); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { } + }); + + treeViewer = new TreeViewer(this, SWT.BORDER); + treeViewer.setContentProvider(new AbstractTransactionTreeContentProvider(waveformViewer) { + + @SuppressWarnings("rawtypes") + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Object[]) { + return (Object[]) inputElement; + } + if (inputElement instanceof Collection) { + return ((Collection) inputElement).toArray(); + } + return new Object[0]; + } + }); + treeViewer.addFilter(txFilter); + treeViewer.addDoubleClickListener(new IDoubleClickListener() { + @Override + public void doubleClick(DoubleClickEvent event) { + ITreeSelection treeSelection = treeViewer.getStructuredSelection(); + Object selected = treeSelection.getFirstElement(); + if(selected instanceof ITx){ + waveformViewer.setSelection(new StructuredSelection(selected)); + } + } + }); + + Tree tree = treeViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + + TreeViewerColumn nameColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE); + TreeColumn nameColumn = nameColumnViewer.getColumn(); + nameColumn.setWidth(200); + nameColumn.setText("Tx ID"); + nameColumn.setResizable(true); + nameColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.NAME))); + + TreeViewerColumn timeColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE); + TreeColumn timeColumn = timeColumnViewer.getColumn(); + timeColumn.setAlignment(SWT.RIGHT); + timeColumn.setWidth(150); + timeColumn.setText("Start time"); + timeColumn.setResizable(true); + timeColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.TX_TIME))); + + TreeViewerColumn typeColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE); + TreeColumn typeColumn = typeColumnViewer.getColumn(); + typeColumn.setAlignment(SWT.RIGHT); + typeColumn.setWidth(150); + typeColumn.setText("Type"); + typeColumn.setResizable(true); + typeColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.TYPE))); + + TreeViewerColumn valueColumnViewer = new TreeViewerColumn(treeViewer, SWT.NONE); + valueColumn = valueColumnViewer.getColumn(); + valueColumn.setWidth(150); + valueColumn.setText("Value"); + valueColumn.setResizable(true); + nameLabelProvider= new AttributeLabelProvider(waveformViewer, AttributeLabelProvider.VALUE); + valueColumnViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(nameLabelProvider)); + + // Turn on the header and the lines + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + } + + public void setInput(TrackEntry trackEntry) { + if(trackEntry==null || !trackEntry.isStream()) { + attrNames.clear(); + treeViewer.setInput(emptyList); + } else { + stream=trackEntry.getStream(); + treeViewer.setInput(emptyList); + new Thread() { + private ConcurrentHashMap propNames=new ConcurrentHashMap(); + + private List getEntries() { + return propNames.entrySet().stream() + .sorted((e1,e2)->e1.getKey().compareTo(e2.getKey())) + .map(e -> new AttributeNameBean(e.getKey(), e.getValue())) + .collect(Collectors.toList()); + } + + public void run() { + stream.getEvents().values().parallelStream().forEach(evtLst -> { + evtLst.forEach(evt -> { + if(evt.getType()==Type.BEGIN) { + eventList.add(evt.getTransaction()); + for(ITxAttribute attr: evt.getTransaction().getAttributes()) { + propNames.put(attr.getName(), attr.getDataType()); + } + } + }); + }); + eventList = eventList.parallelStream().sorted((t1, t2)-> t1.getBeginTime().compareTo(t2.getBeginTime())).collect(Collectors.toList()); + getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + treeViewer.setInput(eventList); + attrNames.clear(); + attrNames.addAll(getEntries()); + searchPropComboViewer.getCombo().select(0); + txFilter.setSearchProp(attrNames.get(0).getName(), attrNames.get(0).getType()); + if (searchPropComboViewer!=null) { + searchPropComboViewer.setInput(attrNames); + searchPropComboViewer.setSelection(new StructuredSelection(searchPropComboViewer.getElementAt(0))); + } + } + }); + } + }.run(); + } + } + + public void setSearchProps(String propName, DataType type, String propValue) { + for(int i=0; i res = new Vector<>(); + for(ITxRelation rel:propertyHolder.element.getIncomingRelations()){ + res.add(new Object[]{ + rel.getRelationType(), + rel.getSource().getGenerator().getName(), + rel.getSource()}); + } + return res.toArray(); + } else if(propertyHolder.type == TransactionTreeNodeType.OUT_REL){ + Vector res = new Vector<>(); + for(ITxRelation rel:propertyHolder.element.getOutgoingRelations()){ + res.add(new Object[]{ + rel.getRelationType(), + rel.getTarget().getGenerator().getName(), + rel.getTarget()}); + } + return res.toArray(); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + @Override + public Object getParent(Object element) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + @Override + public boolean hasChildren(Object element) { + return getChildren(element)!=null; + } + +} \ No newline at end of file diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/AttributeLabelProvider.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/AttributeLabelProvider.java new file mode 100644 index 0000000..0579cac --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/AttributeLabelProvider.java @@ -0,0 +1,160 @@ +package com.minres.scviewer.e4.application.parts.txTableTree; + +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; + +import com.minres.scviewer.database.DataType; +import com.minres.scviewer.database.ITx; +import com.minres.scviewer.database.ITxAttribute; +import com.minres.scviewer.database.ITxRelation; +import com.minres.scviewer.e4.application.Messages; +import com.minres.scviewer.e4.application.parts.WaveformViewer; + +/** + * The Class AttributeLabelProvider. + */ +public class AttributeLabelProvider extends LabelProvider implements IStyledLabelProvider { + + /** + * + */ + private final WaveformViewer waveformViewerPart; + + /** The field. */ + final int field; + + /** The Constant NAME. */ + public static final int NAME=0; + + /** The Constant TYPE. */ + public static final int TYPE=1; + + /** The Constant VALUE. */ + public static final int VALUE=2; + + /** The Constant VALUE. */ + public static final int TX_TIME=3; + + String showProp; + + public String getShowProp() { + return showProp; + } + + public void setShowProp(String showProp) { + this.showProp = showProp; + } + + /** + * Instantiates a new attribute label provider. + * + * @param field the field + * @param transactionDetails TODO + */ + public AttributeLabelProvider(WaveformViewer waveformViewerPart, int field) { + this.waveformViewerPart = waveformViewerPart; + this.field=field; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) + */ + @Override + public StyledString getStyledText(Object element) { + if(element instanceof ITx) { + ITx iTx = (ITx) element; + switch(field){ + case NAME: + return new StyledString(iTx.getId().toString()); + case TX_TIME: + return new StyledString(waveformViewerPart.getScaledTime(iTx.getBeginTime())); + case VALUE: + if(showProp!=null){ + List res = iTx.getAttributes().stream().filter(a -> showProp.equals(a.getName())).collect(Collectors.toList()); + if(res.size()==1) + return getAttrValueAsStyledString(res.get(0)); + } + return new StyledString(""); + } + } else { + switch(field){ + case NAME: + if (element instanceof ITxAttribute) { + ITxAttribute attribute = (ITxAttribute) element; + String[] tokens = attribute.getName().split("\\."); + return new StyledString(tokens[tokens.length-1]); + }else if (element instanceof ITxRelation) { + return new StyledString(Messages.TransactionDetails_4); + }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(""); //$NON-NLS-1$ + case TX_TIME: + return new StyledString(""); //$NON-NLS-1$ + default: + if (element instanceof ITxAttribute) { + ITxAttribute attribute = (ITxAttribute) element; + return getAttrValueAsStyledString(attribute); + }else if(element instanceof Object[]){ + Object[] elements = (Object[]) element; + Object o = elements[field]; + if(o instanceof ITx) { + ITx tx = (ITx)o; + return new StyledString(this.txToString(tx)+" ("+tx.getStream().getFullName()+")"); + } else + return new StyledString(o.toString()); + } else if(element instanceof ITx){ + return new StyledString(this.txToString((ITx) element)); + } + } + } + return new StyledString(""); //$NON-NLS-1$ + } + + public StyledString getAttrValueAsStyledString(ITxAttribute attribute) { + String value = attribute.getValue().toString(); + if((DataType.UNSIGNED == attribute.getDataType() || DataType.INTEGER==attribute.getDataType()) && !"0".equals(value)) { + try { + value += " [0x"+Long.toHexString(Long.parseLong(attribute.getValue().toString()))+"]"; + } catch(NumberFormatException e) { } + } + return new StyledString(value); + } + /** + * Tx to string. + * + * @param tx the tx + * @return the string + */ + String txToString(ITx tx){ + StringBuilder sb = new StringBuilder(); + sb.append("tx#").append(tx.getId()).append("[").append(timeToString(tx.getBeginTime())); //$NON-NLS-1$ //$NON-NLS-2$ + sb.append(" - ").append(timeToString(tx.getEndTime())).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ + return sb.toString(); + } + + /** + * Time to string. + * + * @param time the time + * @return the string + */ + String timeToString(Long time){ + return waveformViewerPart.getScaledTime(time); + } + +} \ No newline at end of file diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNode.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNode.java new file mode 100644 index 0000000..e8ccf00 --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNode.java @@ -0,0 +1,95 @@ +package com.minres.scviewer.e4.application.parts.txTableTree; + +import java.util.AbstractMap; +import java.util.Map; +import java.util.TreeMap; +import java.util.stream.Collectors; + +import com.minres.scviewer.database.ITx; +import com.minres.scviewer.e4.application.Messages; + +/** + * The Class TreeNode. + */ +public class TransactionTreeNode implements Comparable{ + + /** The type. */ + public TransactionTreeNodeType type; + + /** The element. */ + public ITx element; + + private String hier_path; + /** + * Instantiates a new tree node. + * + * @param element the element + * @param type the type + */ + public TransactionTreeNode(ITx element, TransactionTreeNodeType type){ + this.element=element; + this.type=type; + this.hier_path=""; + } + + public TransactionTreeNode(ITx element, String path){ + this.element=element; + this.type=TransactionTreeNodeType.HIER; + this.hier_path=path; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString(){ + switch(type){ + case PROPS: return Messages.TransactionDetails_10; + case ATTRS: return Messages.TransactionDetails_11; + case IN_REL: return Messages.TransactionDetails_12; + case OUT_REL: return Messages.TransactionDetails_13; + case HIER:{ + String[] tokens = hier_path.split("\\."); + return tokens[tokens.length-1]; + } + } + return ""; //$NON-NLS-1$ + } + + public Object[] getAttributeListForHier() { + if(childs==null) { + Map res = element.getAttributes().stream() + .filter(txAttr -> txAttr.getName().startsWith(hier_path)) + .map(txAttr -> { + String target = hier_path.length()==0?txAttr.getName():txAttr.getName().replace(hier_path+'.', ""); + String[] tokens = target.split("\\."); + if(tokens.length==1) + return new AbstractMap.SimpleEntry<>(tokens[0], txAttr); + else + return new AbstractMap.SimpleEntry<>(tokens[0], new TransactionTreeNode(element, hier_path.length()>0?hier_path+"."+tokens[0]:tokens[0])); + }) + .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue(), (first, second) -> first)); + childs = new TreeMap(res).values().toArray(); + } + return childs; + } + + private Object[] childs=null; + + @Override + public boolean equals(Object o) { + if(o instanceof TransactionTreeNode) { + TransactionTreeNode t = (TransactionTreeNode) o; + return type==t.type && hier_path.equals(t.hier_path); + } + return false; + } + + @Override + public int compareTo(TransactionTreeNode o) { + int res1 = type.compareTo(o.type); + if(res1==0) { + return hier_path.compareTo(o.hier_path); + } else + return res1; + } +} \ No newline at end of file diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNodeType.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNodeType.java new file mode 100644 index 0000000..93003ca --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TransactionTreeNodeType.java @@ -0,0 +1,12 @@ +package com.minres.scviewer.e4.application.parts.txTableTree; + +/** + * The Enum Type. + */ +public enum TransactionTreeNodeType { + PROPS, /** The props. */ + ATTRS, /** The attrs. */ + IN_REL, /** The in rel. */ + OUT_REL,/** The out rel. */ + HIER + } \ No newline at end of file diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeFilter.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeFilter.java new file mode 100644 index 0000000..f91b0d3 --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeFilter.java @@ -0,0 +1,55 @@ +package com.minres.scviewer.e4.application.parts.txTableTree; + +import java.util.regex.PatternSyntaxException; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +import com.minres.scviewer.database.ITxAttribute; + +/** + * The Class TxAttributeFilter. + */ +public class TxAttributeFilter extends ViewerFilter { + + /** The search string. */ + private String searchString; + + /** + * Sets the search text. + * + * @param s the new search text + */ + public void setSearchText(String s) { + this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + + if (searchString == null || searchString.length() == 0) { + return true; + } + if(element instanceof TransactionTreeNode) { + return true; + } + if(element instanceof ITxAttribute){ + try { + return (((ITxAttribute) element).getName().toLowerCase().matches(searchString.toLowerCase())); + } catch (PatternSyntaxException e) { + return true; + } + } + if(element instanceof Object[]) { + try { + return (((Object[])element)[0]).toString().toLowerCase().matches(searchString.toLowerCase()); + } catch (PatternSyntaxException e) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeViewerSorter.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeViewerSorter.java new file mode 100644 index 0000000..1b1dc4d --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxAttributeViewerSorter.java @@ -0,0 +1,73 @@ +package com.minres.scviewer.e4.application.parts.txTableTree; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; + +import com.minres.scviewer.database.ITxAttribute; + +/** + * The Class TxAttributeViewerSorter. + */ +public class TxAttributeViewerSorter extends ViewerComparator { + + /** The Constant ASCENDING. */ + private static final int ASCENDING = 0; + + /** The Constant DESCENDING. */ + private static final int DESCENDING = 1; + + /** The column. */ + private int column; + + /** The direction. */ + private int direction; + + /** + * Does the sort. If it's a different column from the previous sort, do an + * ascending sort. If it's the same column as the last sort, toggle the sort + * direction. + * + * @param column the column + */ + public void doSort(int column) { + if (column == this.column) { + // Same column as last sort; toggle the direction + direction = 1 - direction; + } else { + // New column; do an ascending sort + this.column = column; + direction = ASCENDING; + } + } + + /** + * Compares the object for sorting. + * + * @param viewer the viewer + * @param e1 the e1 + * @param e2 the e2 + * @return the int + */ + public int compare(Viewer viewer, Object e1, Object e2) { + int rc = 0; + 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 0: + rc = getComparator().compare(p1.getName(), p2.getName()); + break; + case 1: + rc = getComparator().compare(p1.getDataType().name(), p2.getDataType().name()); + break; + case 2: + rc = getComparator().compare(p1.getValue().toString(), p2.getValue().toString()); + break; + } + // If descending order, flip the direction + if (direction == DESCENDING) rc = -rc; + } + return rc; + } +} \ No newline at end of file diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxFilter.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxFilter.java new file mode 100644 index 0000000..2efa00a --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/txTableTree/TxFilter.java @@ -0,0 +1,92 @@ +package com.minres.scviewer.e4.application.parts.txTableTree; + +import java.math.BigInteger; +import java.util.List; +import java.util.regex.PatternSyntaxException; +import java.util.stream.Collectors; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +import com.minres.scviewer.database.DataType; +import com.minres.scviewer.database.ITx; +import com.minres.scviewer.database.ITxAttribute; + +/** + * The Class TxAttributeFilter. + */ +public class TxFilter extends ViewerFilter { + + /** The search string. */ + private String searchProp; + /** The search type. */ + private DataType searchType; + /** The search string. */ + private String searchValue; + + /** + * Sets the search text. + * + * @param s the new search text + * @param dataType + */ + public void setSearchProp(String s, DataType type) { + this.searchProp = s; + this.searchType = type; + } + /** + * Sets the search text. + * + * @param s the new search text + */ + public void setSearchValue(String s) { + this.searchValue = s; //$NON-NLS-1$ //$NON-NLS-2$ + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (searchValue == null || searchValue.length() == 0) + return true; + if(element instanceof ITx) { + ITx iTx = (ITx) element; + List res = iTx.getAttributes().stream().filter(a -> searchProp.equals(a.getName())).collect(Collectors.toList()); + if(res.size()==1) { + try { + ITxAttribute attr =res.get(0); + switch(searchType) { + case BOOLEAN: // bool + case ENUMERATION: + return searchValue.equalsIgnoreCase((String) attr.getValue()); + case INTEGER: + case UNSIGNED: + BigInteger lval = new BigInteger(attr.getValue().toString()); + BigInteger sval = parseBigInteger(searchValue); + return lval.equals(sval); + case STRING: + try { + return (((ITxAttribute) element).getName().toLowerCase().matches(searchValue.toLowerCase())); + } catch (PatternSyntaxException e) { + return true; + } + default: + break; + } + } catch(RuntimeException ex) { + return false; + } + } + return true; + } + return false; + } + + private BigInteger parseBigInteger(String value) { + if(value.startsWith("0x") || value.startsWith("0X")) + return new BigInteger(value.substring(2), 16); + else + return new BigInteger(value); + } +} \ No newline at end of file From 2a09fc7e6fa46b59daf21d59ab15eb1664625e14 Mon Sep 17 00:00:00 2001 From: eyck Date: Sun, 1 Nov 2020 18:29:29 +0100 Subject: [PATCH 3/3] update version numbers --- plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF | 2 +- plugins/com.minres.scviewer.e4.application/pom.xml | 2 +- products/com.minres.scviewer.e4.product/pom.xml | 2 +- products/com.minres.scviewer.e4.product/scviewer.product | 2 +- products/com.minres.scviewer.e4.product_slim/pom.xml | 2 +- products/com.minres.scviewer.e4.product_slim/scviewer.product | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index a380eac..b169c00 100644 --- a/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/plugins/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true -Bundle-Version: 2.8.1.qualifier +Bundle-Version: 2.9.0.qualifier Bundle-Vendor: %Bundle-Vendor Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.core.runtime;bundle-version="3.11.1", diff --git a/plugins/com.minres.scviewer.e4.application/pom.xml b/plugins/com.minres.scviewer.e4.application/pom.xml index 2852ace..b0d565a 100644 --- a/plugins/com.minres.scviewer.e4.application/pom.xml +++ b/plugins/com.minres.scviewer.e4.application/pom.xml @@ -1,7 +1,7 @@ 4.0.0 com.minres.scviewer.e4.application - 2.8.1-SNAPSHOT + 2.9.0-SNAPSHOT com.minres.scviewer com.minres.scviewer.parent diff --git a/products/com.minres.scviewer.e4.product/pom.xml b/products/com.minres.scviewer.e4.product/pom.xml index 376bce9..a05337a 100644 --- a/products/com.minres.scviewer.e4.product/pom.xml +++ b/products/com.minres.scviewer.e4.product/pom.xml @@ -10,7 +10,7 @@ ../.. com.minres.scviewer.e4.product - 2.8.1-SNAPSHOT + 2.9.0-SNAPSHOT eclipse-repository com.minres.scviewer diff --git a/products/com.minres.scviewer.e4.product/scviewer.product b/products/com.minres.scviewer.e4.product/scviewer.product index a53ab58..48c1d72 100644 --- a/products/com.minres.scviewer.e4.product/scviewer.product +++ b/products/com.minres.scviewer.e4.product/scviewer.product @@ -1,7 +1,7 @@ - + diff --git a/products/com.minres.scviewer.e4.product_slim/pom.xml b/products/com.minres.scviewer.e4.product_slim/pom.xml index 8315906..8239d01 100644 --- a/products/com.minres.scviewer.e4.product_slim/pom.xml +++ b/products/com.minres.scviewer.e4.product_slim/pom.xml @@ -10,7 +10,7 @@ ../.. com.minres.scviewer.e4.product_slim - 2.8.1-SNAPSHOT + 2.9.0-SNAPSHOT eclipse-repository com.minres.scviewer diff --git a/products/com.minres.scviewer.e4.product_slim/scviewer.product b/products/com.minres.scviewer.e4.product_slim/scviewer.product index 768da21..aac5cbd 100644 --- a/products/com.minres.scviewer.e4.product_slim/scviewer.product +++ b/products/com.minres.scviewer.e4.product_slim/scviewer.product @@ -1,7 +1,7 @@ - +