2015-10-22 00:25:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* 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
|
|
|
|
*******************************************************************************/
|
2015-10-22 00:05:29 +02:00
|
|
|
package com.minres.scviewer.e4.application.parts;
|
|
|
|
|
2019-03-15 08:31:13 +01:00
|
|
|
import java.util.ArrayList;
|
2020-06-11 10:51:59 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
2020-05-09 12:50:28 +02:00
|
|
|
import java.util.stream.Collectors;
|
2015-10-27 23:39:33 +01:00
|
|
|
|
2015-10-22 00:05:29 +02:00
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
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;
|
2015-10-27 23:39:33 +01:00
|
|
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
2020-02-28 21:19:40 +01:00
|
|
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
2015-10-22 00:05:29 +02:00
|
|
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
2020-02-28 21:19:40 +01:00
|
|
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
2015-10-22 00:05:29 +02:00
|
|
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
2015-10-27 23:39:33 +01:00
|
|
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
|
|
|
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
|
|
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
|
|
|
import org.eclipse.jface.viewers.ISelection;
|
|
|
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
2019-03-14 19:28:38 +01:00
|
|
|
import org.eclipse.jface.viewers.ITreeViewerListener;
|
2015-10-27 23:39:33 +01:00
|
|
|
import org.eclipse.jface.viewers.StructuredSelection;
|
2019-03-14 19:28:38 +01:00
|
|
|
import org.eclipse.jface.viewers.TreeExpansionEvent;
|
2020-06-11 10:51:59 +02:00
|
|
|
import org.eclipse.jface.viewers.TreePath;
|
2015-10-27 23:39:33 +01:00
|
|
|
import org.eclipse.jface.viewers.TreeViewer;
|
|
|
|
import org.eclipse.jface.viewers.TreeViewerColumn;
|
2015-10-22 00:05:29 +02:00
|
|
|
import org.eclipse.swt.SWT;
|
|
|
|
import org.eclipse.swt.events.ControlAdapter;
|
|
|
|
import org.eclipse.swt.events.ControlEvent;
|
|
|
|
import org.eclipse.swt.events.ModifyEvent;
|
|
|
|
import org.eclipse.swt.events.ModifyListener;
|
|
|
|
import org.eclipse.swt.events.SelectionAdapter;
|
|
|
|
import org.eclipse.swt.events.SelectionEvent;
|
|
|
|
import org.eclipse.swt.graphics.Point;
|
|
|
|
import org.eclipse.swt.graphics.Rectangle;
|
2020-11-27 08:53:34 +01:00
|
|
|
import org.eclipse.swt.layout.FillLayout;
|
2015-10-22 00:05:29 +02:00
|
|
|
import org.eclipse.swt.layout.GridData;
|
|
|
|
import org.eclipse.swt.layout.GridLayout;
|
|
|
|
import org.eclipse.swt.widgets.Composite;
|
2020-10-29 07:48:35 +01:00
|
|
|
import org.eclipse.swt.widgets.Control;
|
2015-10-22 00:05:29 +02:00
|
|
|
import org.eclipse.swt.widgets.Text;
|
2015-10-27 23:39:33 +01:00
|
|
|
import org.eclipse.swt.widgets.Tree;
|
2019-03-14 19:28:38 +01:00
|
|
|
import org.eclipse.swt.widgets.TreeItem;
|
2015-10-22 00:05:29 +02:00
|
|
|
|
|
|
|
import com.minres.scviewer.database.ITx;
|
2017-01-23 22:53:14 +01:00
|
|
|
import com.minres.scviewer.e4.application.Messages;
|
2020-11-01 17:42:16 +01:00
|
|
|
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;
|
2015-10-22 00:05:29 +02:00
|
|
|
import com.minres.scviewer.e4.application.provider.TxPropertiesLabelProvider;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* The Class TransactionDetails shows the details of a selected transaction.
|
|
|
|
*/
|
2015-10-22 00:05:29 +02:00
|
|
|
public class TransactionDetails {
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The Constant COLUMN_FIRST. */
|
2015-10-22 00:05:29 +02:00
|
|
|
// Column constants
|
|
|
|
public static final int COLUMN_FIRST = 0;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The Constant COLUMN_SECOND. */
|
2015-10-22 00:05:29 +02:00
|
|
|
public static final int COLUMN_SECOND = 1;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The Constant COLUMN_THIRD. */
|
2015-10-27 23:39:33 +01:00
|
|
|
public static final int COLUMN_THIRD = 2;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The event broker. */
|
2015-10-22 00:05:29 +02:00
|
|
|
@Inject IEventBroker eventBroker;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The selection service. */
|
2015-10-22 00:05:29 +02:00
|
|
|
@Inject ESelectionService selectionService;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The name filter. */
|
2015-10-22 00:05:29 +02:00
|
|
|
private Text nameFilter;
|
2015-10-27 23:39:33 +01:00
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The tree viewer. */
|
2015-10-27 23:39:33 +01:00
|
|
|
private TreeViewer treeViewer;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The col3. */
|
2015-10-27 23:39:33 +01:00
|
|
|
private TreeViewerColumn col1, col2, col3;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The attribute filter. */
|
2015-10-22 00:05:29 +02:00
|
|
|
TxAttributeFilter attributeFilter;
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The view sorter. */
|
2015-10-27 23:39:33 +01:00
|
|
|
TxAttributeViewerSorter viewSorter;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The waveform viewer part. */
|
|
|
|
private WaveformViewer waveformViewerPart;
|
2015-10-27 23:39:33 +01:00
|
|
|
|
2020-10-29 07:48:35 +01:00
|
|
|
private Composite top;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Creates the composite.
|
|
|
|
*
|
|
|
|
* @param parent the parent
|
|
|
|
*/
|
2015-10-22 00:05:29 +02:00
|
|
|
@PostConstruct
|
2020-10-17 12:44:33 +02:00
|
|
|
public void createComposite(final Composite parent, @Optional WaveformViewer waveformViewerPart) {
|
2020-11-27 08:53:34 +01:00
|
|
|
parent.setLayout(new FillLayout());
|
2020-10-17 12:44:33 +02:00
|
|
|
this.waveformViewerPart=waveformViewerPart;
|
|
|
|
|
2020-10-29 07:48:35 +01:00
|
|
|
top = new Composite(parent, SWT.NONE);
|
|
|
|
top.setLayout(new GridLayout(1, false));
|
2015-10-22 00:05:29 +02:00
|
|
|
|
2020-10-29 07:48:35 +01:00
|
|
|
nameFilter = new Text(top, SWT.BORDER);
|
2017-01-23 22:53:14 +01:00
|
|
|
nameFilter.setMessage(Messages.TransactionDetails_0);
|
2015-10-22 00:05:29 +02:00
|
|
|
nameFilter.addModifyListener(new ModifyListener() {
|
|
|
|
@Override
|
|
|
|
public void modifyText(ModifyEvent e) {
|
|
|
|
attributeFilter.setSearchText(((Text) e.widget).getText());
|
2015-10-27 23:39:33 +01:00
|
|
|
treeViewer.refresh();
|
2020-02-17 19:43:27 +01:00
|
|
|
treeViewer.expandAll(true);
|
2015-10-22 00:05:29 +02:00
|
|
|
}
|
|
|
|
});
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2015-10-22 00:05:29 +02:00
|
|
|
nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
|
|
|
|
|
|
attributeFilter = new TxAttributeFilter();
|
2015-10-27 23:39:33 +01:00
|
|
|
viewSorter = new TxAttributeViewerSorter();
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2020-10-29 07:48:35 +01:00
|
|
|
treeViewer = new TreeViewer(top);
|
2020-11-01 17:42:16 +01:00
|
|
|
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)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2015-10-27 23:39:33 +01:00
|
|
|
treeViewer.setLabelProvider(new TxPropertiesLabelProvider());
|
|
|
|
treeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
|
|
treeViewer.addFilter(attributeFilter);
|
2017-01-21 13:13:05 +01:00
|
|
|
treeViewer.setComparator(viewSorter);
|
2015-10-27 23:39:33 +01:00
|
|
|
treeViewer.setAutoExpandLevel(2);
|
2019-03-14 19:28:38 +01:00
|
|
|
treeViewer.addTreeListener(new ITreeViewerListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void treeCollapsed(TreeExpansionEvent event) {
|
|
|
|
treeViewer.getSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void treeExpanded(TreeExpansionEvent event) {
|
|
|
|
treeViewer.getSelection();
|
|
|
|
}
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2019-03-14 19:28:38 +01:00
|
|
|
});
|
2015-10-22 00:05:29 +02:00
|
|
|
// Set up the table
|
2015-10-27 23:39:33 +01:00
|
|
|
Tree tree = treeViewer.getTree();
|
|
|
|
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
|
|
// Add the name column
|
|
|
|
col1 = new TreeViewerColumn(treeViewer, SWT.NONE);
|
2017-01-23 22:53:14 +01:00
|
|
|
col1.getColumn().setText(Messages.TransactionDetails_1);
|
2015-10-27 23:39:33 +01:00
|
|
|
col1.getColumn().setResizable(true);
|
2020-11-01 17:42:16 +01:00
|
|
|
col1.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.NAME)));
|
2015-10-27 23:39:33 +01:00
|
|
|
col1.getColumn().addSelectionListener(new SelectionAdapter() {
|
2015-10-22 00:05:29 +02:00
|
|
|
public void widgetSelected(SelectionEvent event) {
|
2017-01-21 13:13:05 +01:00
|
|
|
((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_FIRST);
|
2015-10-27 23:39:33 +01:00
|
|
|
treeViewer.refresh();
|
2015-10-22 00:05:29 +02:00
|
|
|
}
|
|
|
|
});
|
2015-10-27 23:39:33 +01:00
|
|
|
// Add the type column
|
|
|
|
col2 = new TreeViewerColumn(treeViewer, SWT.NONE);
|
2017-01-23 22:53:14 +01:00
|
|
|
col2.getColumn().setText(Messages.TransactionDetails_2);
|
2015-10-27 23:39:33 +01:00
|
|
|
col2.getColumn().setResizable(true);
|
2020-11-01 17:42:16 +01:00
|
|
|
col2.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.TYPE)));
|
2015-10-27 23:39:33 +01:00
|
|
|
col2.getColumn().addSelectionListener(new SelectionAdapter() {
|
2015-10-22 00:05:29 +02:00
|
|
|
public void widgetSelected(SelectionEvent event) {
|
2017-01-21 13:13:05 +01:00
|
|
|
((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_SECOND);
|
2015-10-27 23:39:33 +01:00
|
|
|
treeViewer.refresh();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Add the value column
|
|
|
|
col3 = new TreeViewerColumn(treeViewer, SWT.NONE);
|
2017-01-23 22:53:14 +01:00
|
|
|
col3.getColumn().setText(Messages.TransactionDetails_3);
|
2015-10-27 23:39:33 +01:00
|
|
|
col3.getColumn().setResizable(true);
|
2020-11-01 17:42:16 +01:00
|
|
|
col3.setLabelProvider(new DelegatingStyledCellLabelProvider(new AttributeLabelProvider(waveformViewerPart, AttributeLabelProvider.VALUE)));
|
2015-10-27 23:39:33 +01:00
|
|
|
col3.getColumn().addSelectionListener(new SelectionAdapter() {
|
|
|
|
public void widgetSelected(SelectionEvent event) {
|
2017-01-21 13:13:05 +01:00
|
|
|
((TxAttributeViewerSorter) treeViewer.getComparator()).doSort(COLUMN_SECOND);
|
2015-10-27 23:39:33 +01:00
|
|
|
treeViewer.refresh();
|
2015-10-22 00:05:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Pack the columns
|
2020-03-21 06:28:28 +01:00
|
|
|
// for (int i = 0, n = table.getColumnCount(); i < n; i++) {
|
|
|
|
// table.getColumn(i).pack();
|
|
|
|
// }
|
2015-10-22 00:05:29 +02:00
|
|
|
|
|
|
|
// Turn on the header and the lines
|
2015-10-27 23:39:33 +01:00
|
|
|
tree.setHeaderVisible(true);
|
|
|
|
tree.setLinesVisible(true);
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2015-10-27 23:39:33 +01:00
|
|
|
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]));
|
2019-03-15 08:31:13 +01:00
|
|
|
setInput(selectedArray[2]);
|
2015-10-27 23:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2015-10-27 23:39:33 +01:00
|
|
|
});
|
2020-10-29 07:48:35 +01:00
|
|
|
top.addControlListener(new ControlAdapter() {
|
2015-10-22 00:05:29 +02:00
|
|
|
public void controlResized(ControlEvent e) {
|
2015-10-27 23:39:33 +01:00
|
|
|
Tree table = treeViewer.getTree();
|
2020-10-29 07:48:35 +01:00
|
|
|
Rectangle area = top.getClientArea();
|
2015-10-22 00:05:29 +02:00
|
|
|
Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
|
|
|
int width = area.width - 2*table.getBorderWidth();
|
|
|
|
if (preferredSize.y > area.height + table.getHeaderHeight()) {
|
|
|
|
// Subtract the scrollbar width from the total column width
|
|
|
|
// if a vertical scrollbar will be required
|
|
|
|
Point vBarSize = table.getVerticalBar().getSize();
|
|
|
|
width -= vBarSize.x;
|
|
|
|
}
|
|
|
|
Point oldSize = table.getSize();
|
|
|
|
if (oldSize.x > area.width) {
|
|
|
|
// table is getting smaller so make the columns
|
|
|
|
// smaller first and then resize the table to
|
|
|
|
// match the client area width
|
2015-10-27 23:39:33 +01:00
|
|
|
col1.getColumn().setWidth(width/3);
|
|
|
|
col2.getColumn().setWidth(width/4);
|
|
|
|
col3.getColumn().setWidth(width - col1.getColumn().getWidth());
|
2015-10-22 00:05:29 +02:00
|
|
|
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);
|
2015-10-27 23:39:33 +01:00
|
|
|
col1.getColumn().setWidth(width/3);
|
|
|
|
col2.getColumn().setWidth(width/4);
|
|
|
|
col3.getColumn().setWidth(width - col1.getColumn().getWidth()- col2.getColumn().getWidth());
|
2015-10-22 00:05:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-29 07:48:35 +01:00
|
|
|
public Control getControl() {
|
|
|
|
return top;
|
|
|
|
}
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Sets the focus.
|
|
|
|
*/
|
2015-10-22 00:05:29 +02:00
|
|
|
@Focus
|
|
|
|
public void setFocus() {
|
2020-10-04 16:20:16 +02:00
|
|
|
if(treeViewer!=null)
|
|
|
|
treeViewer.getTree().setFocus();
|
2015-10-27 23:39:33 +01:00
|
|
|
}
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Gets the status event.
|
|
|
|
*
|
|
|
|
* @param part the part
|
|
|
|
* @return the status event
|
|
|
|
*/
|
2015-10-27 23:39:33 +01:00
|
|
|
@Inject @Optional
|
2015-11-22 12:47:07 +01:00
|
|
|
public void getStatusEvent(@UIEventTopic(WaveformViewer.ACTIVE_WAVEFORMVIEW) WaveformViewer part) {
|
2015-10-27 23:39:33 +01:00
|
|
|
this.waveformViewerPart=part;
|
2015-10-22 00:05:29 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 10:51:59 +02:00
|
|
|
class ViewSettings {
|
|
|
|
public ViewSettings(List<String> names, TreePath[] paths) {
|
|
|
|
super();
|
|
|
|
this.names = names;
|
|
|
|
this.paths = paths;
|
|
|
|
}
|
|
|
|
public List<String> names;
|
|
|
|
public TreePath[] paths;
|
|
|
|
}
|
|
|
|
HashMap<Integer, ViewSettings> settings = new HashMap<>();
|
|
|
|
|
2019-03-14 19:28:38 +01:00
|
|
|
public void setInput(Object object) {
|
|
|
|
if(object instanceof ITx){
|
2020-06-11 10:51:59 +02:00
|
|
|
Object oldInput = treeViewer.getInput();
|
|
|
|
if(oldInput!=null) {
|
|
|
|
final Integer hash = getAttrNameHash(oldInput);
|
|
|
|
final List<String> names = getTopItemHier(treeViewer.getTree().getTopItem());
|
|
|
|
final TreePath[] paths = treeViewer.getInput()!=null?treeViewer.getExpandedTreePaths():null;
|
|
|
|
settings.put(hash, new ViewSettings(names, paths));
|
|
|
|
}
|
2019-03-14 19:28:38 +01:00
|
|
|
treeViewer.setInput(object);
|
2020-06-11 10:51:59 +02:00
|
|
|
final Integer newHash = getAttrNameHash(object);
|
|
|
|
final ViewSettings newSettings = settings.get(newHash);
|
|
|
|
if(newSettings!=null) {
|
|
|
|
setExpandedState(newSettings.paths);
|
|
|
|
setTopItemFromHier(newSettings.names, treeViewer.getTree().getItems());
|
|
|
|
} else
|
|
|
|
setExpandedState(null);
|
2019-03-14 19:28:38 +01:00
|
|
|
} else {
|
|
|
|
treeViewer.setInput(null);
|
|
|
|
}
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2019-03-14 19:28:38 +01:00
|
|
|
}
|
2019-03-15 08:31:13 +01:00
|
|
|
|
2020-06-11 10:51:59 +02:00
|
|
|
int getAttrNameHash(Object o) {
|
|
|
|
if(o instanceof ITx) {
|
|
|
|
ITx tx = (ITx) o;
|
|
|
|
List<String> attr_names = tx.getAttributes().stream().map(a -> a.getName()).collect(Collectors.toList());
|
|
|
|
return Objects.hash(attr_names);
|
|
|
|
} else
|
|
|
|
return o.hashCode();
|
2019-03-15 08:31:13 +01:00
|
|
|
|
|
|
|
}
|
2020-06-11 10:51:59 +02:00
|
|
|
|
|
|
|
private void setExpandedState(TreePath[] paths) {
|
|
|
|
if(paths==null)
|
|
|
|
treeViewer.setAutoExpandLevel(2);
|
|
|
|
else {
|
2020-11-01 17:42:16 +01:00
|
|
|
AbstractTransactionTreeContentProvider cp = (AbstractTransactionTreeContentProvider) treeViewer.getContentProvider();
|
2020-06-11 10:51:59 +02:00
|
|
|
Object[] elems = cp.getElements(treeViewer.getInput());
|
|
|
|
for(TreePath path: paths) {
|
2020-11-01 17:42:16 +01:00
|
|
|
TransactionTreeNode firstSeg = (TransactionTreeNode)path.getFirstSegment();
|
2020-06-11 10:51:59 +02:00
|
|
|
for(Object elem : elems) {
|
2020-11-01 17:42:16 +01:00
|
|
|
if(((TransactionTreeNode)elem).type == firstSeg.type) {
|
2020-06-11 10:51:59 +02:00
|
|
|
treeViewer.setExpandedState(elem, true);
|
2020-11-01 17:42:16 +01:00
|
|
|
if(firstSeg.type==TransactionTreeNodeType.ATTRS && path.getSegmentCount()>1)
|
|
|
|
expandSubNodes(path, 1, (TransactionTreeNode)elem);
|
2019-03-15 08:31:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-21 06:28:28 +01:00
|
|
|
|
2020-11-01 17:42:16 +01:00
|
|
|
private void expandSubNodes(TreePath path, int level, TransactionTreeNode elem) {
|
2020-06-11 10:51:59 +02:00
|
|
|
if(level==path.getSegmentCount()) return;
|
2020-11-01 17:42:16 +01:00
|
|
|
AbstractTransactionTreeContentProvider cp = (AbstractTransactionTreeContentProvider) treeViewer.getContentProvider();
|
2020-06-11 10:51:59 +02:00
|
|
|
Object[] childs = cp.getChildren(elem);
|
2020-11-01 17:42:16 +01:00
|
|
|
TransactionTreeNode nextSeg = (TransactionTreeNode)path.getSegment(level);
|
2020-06-11 10:51:59 +02:00
|
|
|
for(Object child:childs) {
|
2020-11-01 17:42:16 +01:00
|
|
|
if(child instanceof TransactionTreeNode) {
|
|
|
|
TransactionTreeNode node = (TransactionTreeNode) child;
|
2020-06-11 10:51:59 +02:00
|
|
|
if(nextSeg.toString().equals(node.toString())) {
|
|
|
|
treeViewer.setExpandedState(node, true);
|
|
|
|
expandSubNodes(path, level+1, node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> getTopItemHier(TreeItem node){
|
|
|
|
if(node == null) {
|
|
|
|
return new ArrayList<String>();
|
|
|
|
} else {
|
|
|
|
List<String> elems = getTopItemHier(node.getParentItem());
|
|
|
|
elems.add(node.getText(0));
|
|
|
|
return elems;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setTopItemFromHier(List<String> names, TreeItem [] items) {
|
2020-11-27 08:53:34 +01:00
|
|
|
if(names.size()==0) return;
|
2020-06-11 10:51:59 +02:00
|
|
|
for (TreeItem item : items) { // find item from category
|
2019-03-15 08:31:13 +01:00
|
|
|
if(item.getText(0).equals(names.get(0))) {
|
2020-06-11 10:51:59 +02:00
|
|
|
if(names.size()==1 || item.getItemCount()==0) {
|
|
|
|
treeViewer.getTree().setTopItem(item);
|
|
|
|
} else {
|
|
|
|
setTopItemFromHier(names.subList(1, names.size()), item.getItems());
|
2019-03-15 08:31:13 +01:00
|
|
|
}
|
2020-06-11 10:51:59 +02:00
|
|
|
return;
|
2019-03-15 08:31:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-11 10:51:59 +02:00
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Sets the selection.
|
|
|
|
*
|
|
|
|
* @param selection the new selection
|
|
|
|
*/
|
2015-10-22 00:05:29 +02:00
|
|
|
@Inject
|
2020-02-28 21:19:40 +01:00
|
|
|
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();
|
2020-11-01 17:42:16 +01:00
|
|
|
if( part == null || ! (part.getObject() instanceof WaveformViewer ) || part.getObject() != waveformViewerPart)
|
2020-02-28 21:19:40 +01:00
|
|
|
return;
|
2015-10-27 23:39:33 +01:00
|
|
|
if(treeViewer!=null && selection!=null && !treeViewer.getTree().isDisposed()){
|
2020-10-17 13:54:34 +02:00
|
|
|
if( selection instanceof IStructuredSelection && !selection.isEmpty()) {
|
2020-02-28 21:19:40 +01:00
|
|
|
setInput(((IStructuredSelection)selection).getFirstElement());
|
2015-10-22 00:05:29 +02:00
|
|
|
}
|
2015-10-27 23:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|