fix #27 'Add filter to hierarchy viewer'

This commit is contained in:
Eyck Jentzsch 2020-03-12 18:17:47 +01:00
parent f89471e14b
commit d73b01f77d
3 changed files with 51 additions and 15 deletions

View File

@ -9,6 +9,7 @@ public class Messages extends NLS {
public static String DesignBrowser_12; public static String DesignBrowser_12;
public static String DesignBrowser_16; public static String DesignBrowser_16;
public static String DesignBrowser_2; public static String DesignBrowser_2;
public static String DesignBrowser_3;
public static String DesignBrowser_4; public static String DesignBrowser_4;
public static String DesignBrowser_8; public static String DesignBrowser_8;
public static String LoadingWaveformDb_0; public static String LoadingWaveformDb_0;

View File

@ -3,6 +3,7 @@ AboutDialog_1=\nCopyright (c) 2015, 2019 MINRES Technologies GmbH and others.\n\
DesignBrowser_12=Append all after DesignBrowser_12=Append all after
DesignBrowser_16=Insert all before DesignBrowser_16=Insert all before
DesignBrowser_2=Enter text to filter waveforms DesignBrowser_2=Enter text to filter waveforms
DesignBrowser_3=Enter text to filter hierarchy
DesignBrowser_4=Append after DesignBrowser_4=Append after
DesignBrowser_8=Insert before DesignBrowser_8=Insert before
LoadingWaveformDb_0=Database loading... LoadingWaveformDb_0=Database loading...

View File

@ -68,6 +68,7 @@ import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.wb.swt.ResourceManager; import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.wb.swt.SWTResourceManager;
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IHierNode; import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
@ -110,8 +111,17 @@ public class DesignBrowser {
/** The tree viewer. */ /** The tree viewer. */
private TreeViewer treeViewer; private TreeViewer treeViewer;
/** The name filter of the design browser tree. */
private Text treeNameFilter;
/** The attribute filter. */
WaveformAttributeFilter treeAttributeFilter;
/** The name filter. */ /** The name filter. */
private Text nameFilter; private Text tableNameFilter;
/** The attribute filter. */
WaveformAttributeFilter tableAttributeFilter;
/** The tx table viewer. */ /** The tx table viewer. */
private TableViewer txTableViewer; private TableViewer txTableViewer;
@ -119,9 +129,6 @@ public class DesignBrowser {
/** The append all item. */ /** The append all item. */
ToolItem appendItem, insertItem, insertAllItem, appendAllItem; ToolItem appendItem, insertItem, insertAllItem, appendAllItem;
/** The attribute filter. */
WaveformAttributeFilter attributeFilter;
/** The other selection count. */ /** The other selection count. */
int thisSelectionCount=0, otherSelectionCount=0; int thisSelectionCount=0, otherSelectionCount=0;
@ -189,10 +196,25 @@ public class DesignBrowser {
*/ */
public void createTreeViewerComposite(Composite parent) { public void createTreeViewerComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false)); parent.setLayout(new GridLayout(1, false));
treeNameFilter = new Text(parent, SWT.BORDER);
treeNameFilter.setMessage(Messages.DesignBrowser_3);
treeNameFilter.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
treeAttributeFilter.setSearchText(((Text) e.widget).getText());
treeViewer.refresh();
}
});
treeNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
treeAttributeFilter = new WaveformAttributeFilter();
treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
treeViewer.setContentProvider(new TxDbContentProvider()); treeViewer.setContentProvider(new TxDbContentProvider());
treeViewer.setLabelProvider(new TxDbLabelProvider()); treeViewer.setLabelProvider(new TxDbLabelProvider());
treeViewer.addFilter(treeAttributeFilter);
treeViewer.setUseHashlookup(true); treeViewer.setUseHashlookup(true);
treeViewer.setAutoExpandLevel(2); treeViewer.setAutoExpandLevel(2);
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@ -223,25 +245,25 @@ public class DesignBrowser {
public void createTableComposite(Composite parent) { public void createTableComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false)); parent.setLayout(new GridLayout(1, false));
nameFilter = new Text(parent, SWT.BORDER); tableNameFilter = new Text(parent, SWT.BORDER);
nameFilter.setMessage(Messages.DesignBrowser_2); tableNameFilter.setMessage(Messages.DesignBrowser_2);
nameFilter.addModifyListener(new ModifyListener() { tableNameFilter.addModifyListener(new ModifyListener() {
@Override @Override
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
attributeFilter.setSearchText(((Text) e.widget).getText()); tableAttributeFilter.setSearchText(((Text) e.widget).getText());
updateButtons(); updateButtons();
txTableViewer.refresh(); txTableViewer.refresh();
} }
}); });
nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
attributeFilter = new WaveformAttributeFilter(); tableAttributeFilter = new WaveformAttributeFilter();
txTableViewer = new TableViewer(parent); txTableViewer = new TableViewer(parent);
txTableViewer.setContentProvider(new TxDbContentProvider(true)); txTableViewer.setContentProvider(new TxDbContentProvider(true));
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(attributeFilter); txTableViewer.addFilter(tableAttributeFilter);
txTableViewer.addDoubleClickListener(new IDoubleClickListener() { txTableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override @Override
public void doubleClick(DoubleClickEvent event) { public void doubleClick(DoubleClickEvent event) {
@ -469,6 +491,7 @@ public class DesignBrowser {
if (searchString == null || searchString.length() == 0) { if (searchString == null || searchString.length() == 0) {
return true; return true;
} }
if(element instanceof IWaveform) {
IWaveform p = (IWaveform) element; IWaveform p = (IWaveform) element;
try { try {
if (p.getName().matches(searchString)) if (p.getName().matches(searchString))
@ -476,6 +499,17 @@ public class DesignBrowser {
} catch (PatternSyntaxException e) { } catch (PatternSyntaxException e) {
return true; return true;
} }
} else if(element instanceof IWaveformDb) {
return true;
} else if(element instanceof HierNode) {
HierNode n = (HierNode) element;
try {
if (n.getFullName().matches(searchString))
return true;
} catch (PatternSyntaxException e) {
return true;
}
}
return false; return false;
} }
} }