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

View File

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