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;
@ -96,7 +81,7 @@ public class DesignBrowser {
/** The event broker. */ /** The event broker. */
@Inject IEventBroker eventBroker; @Inject IEventBroker eventBroker;
/** The selection service. */ /** The selection service. */
@Inject ESelectionService selectionService; @Inject ESelectionService selectionService;
@ -105,16 +90,13 @@ public class DesignBrowser {
/** The eclipse ctx. */ /** The eclipse ctx. */
@Inject IEclipseContext eclipseCtx; @Inject IEclipseContext eclipseCtx;
/** The sash form. */ /** The sash form. */
private SashForm sashForm; private SashForm sashForm;
/** 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,25 +122,22 @@ 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 if("CHILDS".equals(evt.getPropertyName())){ //$NON-NLS-1$
public void propertyChange(PropertyChangeEvent evt) { treeViewer.getTree().getDisplay().asyncExec(new Runnable() {
if("CHILDS".equals(evt.getPropertyName())){ //$NON-NLS-1$ @Override
treeViewer.getTree().getDisplay().asyncExec(new Runnable() { public void run() {
@Override treeViewer.refresh();
public void run() { }
treeViewer.refresh(); });
} } else if("WAVEFORMS".equals(evt.getPropertyName())) {
}); treeViewer.getTree().getDisplay().asyncExec(new Runnable() {
} else if("WAVEFORMS".equals(evt.getPropertyName())) { @Override
treeViewer.getTree().getDisplay().asyncExec(new Runnable() { public void run() {
@Override IWaveformDb database = waveformViewerPart.getDatabase();
public void run() { treeViewer.setInput(Arrays.asList(database.isLoaded()?new IWaveformDb[]{database}:new IWaveformDb[]{new LoadingWaveformDb()}));
IWaveformDb database = waveformViewerPart.getDatabase(); }
treeViewer.setInput(Arrays.asList(database.isLoaded()?new IWaveformDb[]{database}:new IWaveformDb[]{new LoadingWaveformDb()})); });
}
});
}
} }
}; };
@ -166,20 +145,17 @@ public class DesignBrowser {
private WaveformViewer waveformViewerPart; private WaveformViewer waveformViewerPart;
/** The sash paint listener. */ /** The sash paint listener. */
protected PaintListener sashPaintListener=new PaintListener() { protected PaintListener sashPaintListener= e -> {
@Override int size=Math.min(e.width, e.height)-1;
public void paintControl(PaintEvent e) { e.gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
int size=Math.min(e.width, e.height)-1; e.gc.setFillRule(SWT.FILL_EVEN_ODD);
e.gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY)); if(e.width>e.height)
e.gc.setFillRule(SWT.FILL_EVEN_ODD); e.gc.drawArc(e.x+(e.width-size)/2, e.y, size, size, 0, 360);
if(e.width>e.height) else
e.gc.drawArc(e.x+(e.width-size)/2, e.y, size, size, 0, 360); e.gc.drawArc(e.x, e.y+(e.height-size)/2, size, size, 0, 360);
else
e.gc.drawArc(e.x, e.y+(e.height-size)/2, size, size, 0, 360);
}
}; };
/** /**
* Creates the composite. * Creates the composite.
* *
@ -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);
@ -206,7 +183,7 @@ public class DesignBrowser {
if(waveformViewerPart!=null) if(waveformViewerPart!=null)
setWaveformViewer(waveformViewerPart); setWaveformViewer(waveformViewerPart);
} }
/** /**
* Creates the tree viewer composite. * Creates the tree viewer composite.
* *
@ -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 treeAttributeFilter.setSearchText(((Text) e.widget).getText());
public void modifyText(ModifyEvent e) { treeViewer.refresh();
treeAttributeFilter.setSearchText(((Text) e.widget).getText());
treeViewer.refresh();
}
}); });
treeNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); treeNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@ -235,21 +209,17 @@ 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 -> {
ISelection selection=event.getSelection();
@Override if( selection instanceof IStructuredSelection) {
public void selectionChanged(SelectionChangedEvent event) { Object object= ((IStructuredSelection)selection).getFirstElement();
ISelection selection=event.getSelection(); if(object instanceof IHierNode && !((IHierNode)object).getChildNodes().isEmpty()){
if( selection instanceof IStructuredSelection) { txTableViewer.setInput(object);
Object object= ((IStructuredSelection)selection).getFirstElement(); updateButtons();
if(object instanceof IHierNode && ((IHierNode)object).getChildNodes().size()!=0){ }
txTableViewer.setInput(object); else { //if selection is changed but empty
updateButtons(); txTableViewer.setInput(null);
} updateButtons();
else { //if selection is changed but empty
txTableViewer.setInput(null);
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 tableAttributeFilter.setSearchText(((Text) e.widget).getText());
public void modifyText(ModifyEvent e) { updateButtons();
tableAttributeFilter.setSearchText(((Text) e.widget).getText()); txTableViewer.refresh();
updateButtons();
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 AddWaveformHandler myHandler = new AddWaveformHandler();
public void doubleClick(DoubleClickEvent event) { Object result = runCommand(myHandler, CanExecute.class, "after", false); //$NON-NLS-1$
AddWaveformHandler myHandler = new AddWaveformHandler(); if(result!=null && (Boolean)result)
Object result = runCommand(myHandler, CanExecute.class, "after", false); //$NON-NLS-1$ ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
if(result!=null && (Boolean)result)
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
}
}); });
txTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { txTableViewer.addSelectionChangedListener(event -> {
selectionService.setSelection(event.getSelection());
@Override updateButtons();
public void selectionChanged(SelectionChangedEvent event) {
selectionService.setSelection(event.getSelection());
updateButtons();
}
}); });
menuService.registerContextMenu(txTableViewer.getControl(), POPUP_ID); menuService.registerContextMenu(txTableViewer.getControl(), POPUP_ID);
@ -351,7 +311,7 @@ public class DesignBrowser {
} }
updateButtons(); updateButtons();
} }
/** /**
* reset tree viewer and tableviewer after every closed tab * reset tree viewer and tableviewer after every closed tab
*/ */
@ -371,7 +331,7 @@ public class DesignBrowser {
StructuredSelection sel = new StructuredSelection(list); StructuredSelection sel = new StructuredSelection(list);
txTableViewer.setSelection(sel); txTableViewer.setSelection(sel);
} }
/** /**
* Gets the status event. * Gets the status event.
* *
@ -383,17 +343,14 @@ 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 Control control = treeViewer.getControl();
public void widgetDisposed(DisposeEvent e) { // check if widget is already disposed (f.ex. because of workbench closing)
Control control = treeViewer.getControl(); if (control == null || control.isDisposed()) { //if so: do nothing
// check if widget is already disposed (f.ex. because of workbench closing) }else { //reset tree- and tableviewer
if (control == null || control.isDisposed()) { //if so: do nothing resetTreeViewer();
}else { //reset tree- and tableviewer
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.
*/ */
@ -467,8 +404,8 @@ public class DesignBrowser {
*/ */
public void setSearchText(String s) { public void setSearchText(String s) {
try { try {
pattern = Pattern.compile(".*" + s + ".*"); //$NON-NLS-1$ //$NON-NLS-2$ pattern = Pattern.compile(".*" + s + ".*"); //$NON-NLS-1$ //$NON-NLS-2$
this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$ this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$
} catch (PatternSyntaxException e) {} } catch (PatternSyntaxException e) {}
} }
@ -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;
} }
} }
@ -501,8 +433,8 @@ public class DesignBrowser {
*/ */
public void setSearchText(String s) { public void setSearchText(String s) {
try { try {
pattern = Pattern.compile(".*" + s + ".*"); pattern = Pattern.compile(".*" + s + ".*");
this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$ this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$
} catch (PatternSyntaxException e) {} } catch (PatternSyntaxException e) {}
} }
@ -514,7 +446,7 @@ public class DesignBrowser {
public boolean select(Viewer viewer, Object parentElement, Object element) { public boolean select(Viewer viewer, Object parentElement, Object element) {
return selectTreePath(viewer, new TreePath(new Object[] { parentElement }), element); return selectTreePath(viewer, new TreePath(new Object[] { parentElement }), element);
} }
private boolean selectTreePath(Viewer viewer, TreePath parentPath, Object element) { private boolean selectTreePath(Viewer viewer, TreePath parentPath, Object element) {
// Cut off children of elements that are shown repeatedly. // Cut off children of elements that are shown repeatedly.
for (int i = 0; i < parentPath.getSegmentCount() - 1; i++) { for (int i = 0; i < parentPath.getSegmentCount() - 1; i++) {
@ -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) {
@ -563,18 +494,18 @@ public class DesignBrowser {
IContentProvider contentProvider = viewer.getContentProvider(); IContentProvider contentProvider = viewer.getContentProvider();
Object[] children = contentProvider instanceof ITreePathContentProvider Object[] children = contentProvider instanceof ITreePathContentProvider
? ((ITreePathContentProvider) contentProvider).getChildren(elementPath) ? ((ITreePathContentProvider) contentProvider).getChildren(elementPath)
: ((ITreeContentProvider) contentProvider).getChildren(element); : ((ITreeContentProvider) contentProvider).getChildren(element);
/* avoid NPE + guard close */ /* avoid NPE + guard close */
if (children == null || children.length == 0) { if (children == null || children.length == 0) {
return false; return false;
} }
for (int i = 0; i < children.length; i++) { for (int i = 0; i < children.length; i++) {
if (selectTreePath(viewer, elementPath, children[i])) { if (selectTreePath(viewer, elementPath, children[i])) {
return true; return true;
} }
} }
return false; return false;
} }
} }
/** /**
@ -587,14 +518,12 @@ 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); if(result==null) return new Object[0];
if(result==null) return new Object[0]; for (int i = 0, n = result.length; i < n; ++i) {
for (int i = 0, n = result.length; i < n; ++i) { if(result[i]==null) return new Object[0];
if(result[i]==null) return new Object[0];
}
} }
} }
ViewerFilter[] filters = viewer.getFilters(); ViewerFilter[] filters = viewer.getFilters();
@ -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;
} }
/** /**
@ -643,12 +571,12 @@ public class DesignBrowser {
public WaveformViewer getActiveWaveformViewerPart() { public WaveformViewer getActiveWaveformViewerPart() {
return waveformViewerPart; return waveformViewerPart;
} }
/** /**
* The Class DBState. * The Class DBState.
*/ */
class DBState { class DBState {
/** /**
* Instantiates a new DB state. * Instantiates a new DB state.
*/ */
@ -657,7 +585,7 @@ public class DesignBrowser {
this.treeSelection=treeViewer.getSelection(); this.treeSelection=treeViewer.getSelection();
this.tableSelection=txTableViewer.getSelection(); this.tableSelection=txTableViewer.getSelection();
} }
/** /**
* Apply. * Apply.
*/ */
@ -665,16 +593,16 @@ public class DesignBrowser {
treeViewer.setExpandedElements(expandedElements); treeViewer.setExpandedElements(expandedElements);
treeViewer.setSelection(treeSelection, true); treeViewer.setSelection(treeSelection, true);
txTableViewer.setSelection(tableSelection, true); txTableViewer.setSelection(tableSelection, true);
} }
/** The expanded elements. */ /** The expanded elements. */
private Object[] expandedElements; private Object[] expandedElements;
/** The tree selection. */ /** The tree selection. */
private ISelection treeSelection; private ISelection treeSelection;
/** 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;
} }
} }