show children of streams

This commit is contained in:
Eyck Jentzsch 2021-01-09 12:55:51 +01:00
parent eb64cc60c5
commit 9d2e2e7f64
2 changed files with 113 additions and 208 deletions

View File

@ -10,7 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.e4.application.parts; package com.minres.scviewer.e4.application.parts;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,7 +20,6 @@ import java.util.regex.PatternSyntaxException;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.contexts.IEclipseContext;
@ -31,21 +29,14 @@ import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.di.Focus; import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.EMenuService; import org.eclipse.e4.ui.services.EMenuService;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ITreePathContentProvider; import org.eclipse.jface.viewers.ITreePathContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreePath;
@ -56,11 +47,6 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
@ -79,7 +65,6 @@ import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IHierNode; import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.e4.application.Messages; import com.minres.scviewer.e4.application.Messages;
import com.minres.scviewer.e4.application.handlers.AddWaveformHandler; import com.minres.scviewer.e4.application.handlers.AddWaveformHandler;
import com.minres.scviewer.e4.application.provider.TxDbContentProvider; import com.minres.scviewer.e4.application.provider.TxDbContentProvider;
@ -112,9 +97,6 @@ public class DesignBrowser {
/** The top. */ /** The top. */
Composite top; Composite top;
/** The bottom. */
private Composite bottom;
/** The tree viewer. */ /** The tree viewer. */
private TreeViewer treeViewer; private TreeViewer treeViewer;
@ -140,9 +122,7 @@ public class DesignBrowser {
int thisSelectionCount=0, otherSelectionCount=0; int thisSelectionCount=0, otherSelectionCount=0;
/** The tree viewer pcl. */ /** The tree viewer pcl. */
private PropertyChangeListener treeViewerPCL = new PropertyChangeListener() { private PropertyChangeListener treeViewerPCL = evt -> {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if("CHILDS".equals(evt.getPropertyName())){ //$NON-NLS-1$ if("CHILDS".equals(evt.getPropertyName())){ //$NON-NLS-1$
treeViewer.getTree().getDisplay().asyncExec(new Runnable() { treeViewer.getTree().getDisplay().asyncExec(new Runnable() {
@Override @Override
@ -159,16 +139,13 @@ public class DesignBrowser {
} }
}); });
} }
}
}; };
/** The waveform viewer part. */ /** The waveform viewer part. */
private WaveformViewer waveformViewerPart; private WaveformViewer waveformViewerPart;
/** The sash paint listener. */ /** The sash paint listener. */
protected PaintListener sashPaintListener=new PaintListener() { protected PaintListener sashPaintListener= e -> {
@Override
public void paintControl(PaintEvent e) {
int size=Math.min(e.width, e.height)-1; int size=Math.min(e.width, e.height)-1;
e.gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY)); e.gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
e.gc.setFillRule(SWT.FILL_EVEN_ODD); e.gc.setFillRule(SWT.FILL_EVEN_ODD);
@ -176,7 +153,6 @@ public class DesignBrowser {
e.gc.drawArc(e.x+(e.width-size)/2, e.y, size, size, 0, 360); e.gc.drawArc(e.x+(e.width-size)/2, e.y, size, size, 0, 360);
else else
e.gc.drawArc(e.x, e.y+(e.height-size)/2, size, size, 0, 360); e.gc.drawArc(e.x, e.y+(e.height-size)/2, size, size, 0, 360);
}
}; };
@ -192,12 +168,13 @@ public class DesignBrowser {
top = new Composite(sashForm, SWT.NONE); top = new Composite(sashForm, SWT.NONE);
createTreeViewerComposite(top); createTreeViewerComposite(top);
bottom = new Composite(sashForm, SWT.NONE); Composite bottom = new Composite(sashForm, SWT.NONE);
createTableComposite(bottom); createTableComposite(bottom);
sashForm.setWeights(new int[] {100, 100}); sashForm.setWeights(new int[] {100, 100});
sashForm.SASH_WIDTH=5; sashForm.SASH_WIDTH=5;
top.addControlListener(new ControlAdapter() { top.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) { public void controlResized(ControlEvent e) {
sashForm.getChildren()[2].addPaintListener(sashPaintListener); sashForm.getChildren()[2].addPaintListener(sashPaintListener);
top.removeControlListener(this); top.removeControlListener(this);
@ -217,12 +194,9 @@ public class DesignBrowser {
treeNameFilter = new Text(parent, SWT.BORDER); treeNameFilter = new Text(parent, SWT.BORDER);
treeNameFilter.setMessage(Messages.DesignBrowser_3); treeNameFilter.setMessage(Messages.DesignBrowser_3);
treeNameFilter.addModifyListener(new ModifyListener() { treeNameFilter.addModifyListener( e -> {
@Override
public void modifyText(ModifyEvent e) {
treeAttributeFilter.setSearchText(((Text) e.widget).getText()); treeAttributeFilter.setSearchText(((Text) e.widget).getText());
treeViewer.refresh(); treeViewer.refresh();
}
}); });
treeNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); treeNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@ -235,14 +209,11 @@ public class DesignBrowser {
treeViewer.addFilter(treeAttributeFilter); treeViewer.addFilter(treeAttributeFilter);
treeViewer.setUseHashlookup(true); treeViewer.setUseHashlookup(true);
treeViewer.setAutoExpandLevel(2); treeViewer.setAutoExpandLevel(2);
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { treeViewer.addSelectionChangedListener(event -> {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection=event.getSelection(); ISelection selection=event.getSelection();
if( selection instanceof IStructuredSelection) { if( selection instanceof IStructuredSelection) {
Object object= ((IStructuredSelection)selection).getFirstElement(); Object object= ((IStructuredSelection)selection).getFirstElement();
if(object instanceof IHierNode && ((IHierNode)object).getChildNodes().size()!=0){ if(object instanceof IHierNode && !((IHierNode)object).getChildNodes().isEmpty()){
txTableViewer.setInput(object); txTableViewer.setInput(object);
updateButtons(); updateButtons();
} }
@ -251,7 +222,6 @@ public class DesignBrowser {
updateButtons(); updateButtons();
} }
} }
}
}); });
} }
@ -265,13 +235,10 @@ public class DesignBrowser {
tableNameFilter = new Text(parent, SWT.BORDER); tableNameFilter = new Text(parent, SWT.BORDER);
tableNameFilter.setMessage(Messages.DesignBrowser_2); tableNameFilter.setMessage(Messages.DesignBrowser_2);
tableNameFilter.addModifyListener(new ModifyListener() { tableNameFilter.addModifyListener(e -> {
@Override
public void modifyText(ModifyEvent e) {
tableAttributeFilter.setSearchText(((Text) e.widget).getText()); tableAttributeFilter.setSearchText(((Text) e.widget).getText());
updateButtons(); updateButtons();
txTableViewer.refresh(); txTableViewer.refresh();
}
}); });
tableNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@ -282,22 +249,15 @@ public class DesignBrowser {
txTableViewer.setLabelProvider(new TxDbLabelProvider()); txTableViewer.setLabelProvider(new TxDbLabelProvider());
txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
txTableViewer.addFilter(tableAttributeFilter); txTableViewer.addFilter(tableAttributeFilter);
txTableViewer.addDoubleClickListener(new IDoubleClickListener() { txTableViewer.addDoubleClickListener(event -> {
@Override
public void doubleClick(DoubleClickEvent event) {
AddWaveformHandler myHandler = new AddWaveformHandler(); AddWaveformHandler myHandler = new AddWaveformHandler();
Object result = runCommand(myHandler, CanExecute.class, "after", false); //$NON-NLS-1$ Object result = runCommand(myHandler, CanExecute.class, "after", false); //$NON-NLS-1$
if(result!=null && (Boolean)result) if(result!=null && (Boolean)result)
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx); ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
}
}); });
txTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { txTableViewer.addSelectionChangedListener(event -> {
@Override
public void selectionChanged(SelectionChangedEvent event) {
selectionService.setSelection(event.getSelection()); selectionService.setSelection(event.getSelection());
updateButtons(); updateButtons();
}
}); });
menuService.registerContextMenu(txTableViewer.getControl(), POPUP_ID); menuService.registerContextMenu(txTableViewer.getControl(), POPUP_ID);
@ -383,16 +343,13 @@ public class DesignBrowser {
if( this.waveformViewerPart == null || this.waveformViewerPart != waveformViewerPart ) { if( this.waveformViewerPart == null || this.waveformViewerPart != waveformViewerPart ) {
if(this.waveformViewerPart!=null) if(this.waveformViewerPart!=null)
this.waveformViewerPart.storeDesignBrowerState(new DBState()); this.waveformViewerPart.storeDesignBrowerState(new DBState());
waveformViewerPart.addDisposeListener( new DisposeListener() { waveformViewerPart.addDisposeListener( e -> {
@Override
public void widgetDisposed(DisposeEvent e) {
Control control = treeViewer.getControl(); Control control = treeViewer.getControl();
// check if widget is already disposed (f.ex. because of workbench closing) // check if widget is already disposed (f.ex. because of workbench closing)
if (control == null || control.isDisposed()) { //if so: do nothing if (control == null || control.isDisposed()) { //if so: do nothing
}else { //reset tree- and tableviewer }else { //reset tree- and tableviewer
resetTreeViewer(); resetTreeViewer();
} }
}
}); });
setWaveformViewer(waveformViewerPart); setWaveformViewer(waveformViewerPart);
} }
@ -403,14 +360,14 @@ public class DesignBrowser {
this.waveformViewerPart=waveformViewerPart; this.waveformViewerPart=waveformViewerPart;
IWaveformDb database = waveformViewerPart.getDatabase(); IWaveformDb database = waveformViewerPart.getDatabase();
Object input = treeViewer.getInput(); Object input = treeViewer.getInput();
if(input!=null && input instanceof List<?>){ if(input instanceof List<?>){
IWaveformDb db = ((List<IWaveformDb>)input).get(0); IWaveformDb db = ((List<IWaveformDb>)input).get(0);
if(db==database) return; // do nothing if old and new database is the same if(db==database) return; // do nothing if old and new database is the same
((List<IWaveformDb>)input).get(0).removePropertyChangeListener(treeViewerPCL); ((List<IWaveformDb>)input).get(0).removePropertyChangeListener(treeViewerPCL);
} }
treeViewer.setInput(Arrays.asList(database.isLoaded()?new IWaveformDb[]{database}:new IWaveformDb[]{new LoadingWaveformDb()})); treeViewer.setInput(Arrays.asList(database.isLoaded()?new IWaveformDb[]{database}:new IWaveformDb[]{new LoadingWaveformDb()}));
Object state=this.waveformViewerPart.retrieveDesignBrowerState(); Object state=this.waveformViewerPart.retrieveDesignBrowerState();
if(state!=null && state instanceof DBState) if(state instanceof DBState)
((DBState)state).apply(); ((DBState)state).apply();
else else
txTableViewer.setInput(null); txTableViewer.setInput(null);
@ -418,26 +375,6 @@ public class DesignBrowser {
database.addPropertyChangeListener(treeViewerPCL); database.addPropertyChangeListener(treeViewerPCL);
} }
/**
* Sets the selection.
*
* @param selection the selection
* @param partService the part service
*/
@Inject
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){
MPart part = partService.getActivePart();
if(part!=null && part.getObject() != this && selection!=null){
if( selection instanceof IStructuredSelection) {
Object object= ((IStructuredSelection)selection).getFirstElement();
if(object instanceof IHierNode&& ((IHierNode)object).getChildNodes().size()!=0)
txTableViewer.setInput(object);
otherSelectionCount = (object instanceof IWaveform || object instanceof ITx)?1:0;
}
}
updateButtons();
}
/** /**
* Update buttons. * Update buttons.
*/ */
@ -477,14 +414,9 @@ public class DesignBrowser {
*/ */
@Override @Override
public boolean select(Viewer viewer, Object parentElement, Object element) { public boolean select(Viewer viewer, Object parentElement, Object element) {
if (searchString == null || searchString.length() == 0) { return searchString == null ||
return true; searchString.length() == 0 ||
} (element instanceof IWaveform && pattern.matcher(((IWaveform) element).getName()).matches());
if(element instanceof IWaveform) {
if (pattern.matcher(((IWaveform) element).getName()).matches())
return true;
}
return false;
} }
} }
@ -529,12 +461,11 @@ public class DesignBrowser {
if (searchString == null || searchString.length() == 0) { if (searchString == null || searchString.length() == 0) {
return true; return true;
} }
TreeViewer treeViewer = (TreeViewer) viewer;
Boolean matchingResult = isMatchingOrNull(element); Boolean matchingResult = isMatchingOrNull(element);
if (matchingResult != null) { if (matchingResult != null) {
return matchingResult; return matchingResult;
} }
return hasUnfilteredChild(treeViewer, parentPath, element); return hasUnfilteredChild((TreeViewer)viewer, parentPath, element);
} }
Boolean isMatchingOrNull(Object element) { Boolean isMatchingOrNull(Object element) {
@ -587,7 +518,6 @@ public class DesignBrowser {
Object parent = viewer.getInput(); Object parent = viewer.getInput();
if(parent==null) return new Object[0]; if(parent==null) return new Object[0];
Object[] result = null; Object[] result = null;
if (parent != null) {
IStructuredContentProvider cp = (IStructuredContentProvider) viewer.getContentProvider(); IStructuredContentProvider cp = (IStructuredContentProvider) viewer.getContentProvider();
if (cp != null) { if (cp != null) {
result = cp.getElements(parent); result = cp.getElements(parent);
@ -596,7 +526,6 @@ public class DesignBrowser {
if(result[i]==null) return new Object[0]; if(result[i]==null) return new Object[0];
} }
} }
}
ViewerFilter[] filters = viewer.getFilters(); ViewerFilter[] filters = viewer.getFilters();
if (filters != null) { if (filters != null) {
for (ViewerFilter f:filters) { for (ViewerFilter f:filters) {
@ -622,8 +551,7 @@ public class DesignBrowser {
eclipseCtx.set(AddWaveformHandler.PARAM_ALL_ID, all.toString()); eclipseCtx.set(AddWaveformHandler.PARAM_ALL_ID, all.toString());
eclipseCtx.set(DesignBrowser.class, this); eclipseCtx.set(DesignBrowser.class, this);
eclipseCtx.set(WaveformViewer.class, waveformViewerPart); eclipseCtx.set(WaveformViewer.class, waveformViewerPart);
Object result = ContextInjectionFactory.invoke(handler, annotation, eclipseCtx); return ContextInjectionFactory.invoke(handler, annotation, eclipseCtx);
return result;
} }
/** /**
@ -677,4 +605,4 @@ public class DesignBrowser {
/** The table selection. */ /** The table selection. */
private ISelection tableSelection; private ISelection tableSelection;
} }
}; }

View File

@ -12,12 +12,10 @@ package com.minres.scviewer.e4.application.provider;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.minres.scviewer.database.IHierNode; import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
@ -28,15 +26,14 @@ import com.minres.scviewer.database.IWaveformDb;
public class TxDbContentProvider implements ITreeContentProvider { public class TxDbContentProvider implements ITreeContentProvider {
/** The show nodes. */ /** The show nodes. */
// private List<HierNode> nodes; private boolean tableEntries;
private boolean tabelEntries;
/** /**
* Instantiates a new tx db content provider. * Instantiates a new tx db content provider.
*/ */
public TxDbContentProvider() { public TxDbContentProvider() {
super(); super();
this.tabelEntries = false; this.tableEntries = false;
} }
/** /**
@ -46,20 +43,7 @@ public class TxDbContentProvider implements ITreeContentProvider {
*/ */
public TxDbContentProvider(boolean tableEntries) { public TxDbContentProvider(boolean tableEntries) {
super(); super();
this.tabelEntries = tableEntries; this.tableEntries = tableEntries;
}
/* (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) /* (non-Javadoc)
@ -67,24 +51,17 @@ public class TxDbContentProvider implements ITreeContentProvider {
*/ */
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
if(tabelEntries && inputElement instanceof IWaveformDb){ if(tableEntries && inputElement instanceof IWaveformDb){
return new Object[]{}; return new Object[]{};
}else if(inputElement instanceof IHierNode){ }else if(inputElement instanceof IHierNode){
Collection<IHierNode> res = Collections2.filter(((IHierNode)inputElement).getChildNodes(), new Predicate<IHierNode>(){ Collection<IHierNode> res = ((IHierNode)inputElement).getChildNodes().stream().filter(n ->
@Override tableEntries? n instanceof IWaveform : !n.getChildNodes().isEmpty()
public boolean apply(IHierNode arg0) { ).collect(Collectors.toList());
if(tabelEntries){
return arg0 instanceof IWaveform;
} else{
return arg0.getChildNodes().size()!=0;
}
}
});
return res.toArray(); return res.toArray();
}else if(inputElement instanceof List<?>){ }else if(inputElement instanceof List<?>){
return ((List<?>)inputElement).toArray(); return ((List<?>)inputElement).toArray();
} else } else
return null; return new Object[]{};
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -109,7 +86,7 @@ public class TxDbContentProvider implements ITreeContentProvider {
@Override @Override
public boolean hasChildren(Object element) { public boolean hasChildren(Object element) {
Object[] obj = getElements(element); Object[] obj = getElements(element);
return obj == null ? false : obj.length > 0; return obj.length > 0;
} }
} }