use of org.knime.core.node.config.base.ConfigBaseRO in project knime-core by knime.
the class NodeMonitorView method updateSettingsTable.
/*
* Put info about node settings into table.
*/
private void updateSettingsTable(final NodeContainerUI nc, final boolean showAll) {
assert Display.getCurrent().getThread() == Thread.currentThread();
m_info.setText("Node Configuration");
// retrieve settings
ConfigBaseRO settings = nc.getNodeSettings();
// and put them into the table
m_table.removeAll();
for (TableColumn tc : m_table.getColumns()) {
tc.dispose();
}
String[] titles = { "Key", "Value" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(m_table, SWT.NONE);
column.setText(titles[i]);
}
// add information about plugin and version to list (in show all/expert mode only)
if (Wrapper.wraps(nc, NativeNodeContainer.class) && showAll) {
NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
TableItem item4 = new TableItem(m_table, SWT.NONE);
item4.setText(0, "Node's feature name");
item4.setText(1, nnc.getNodeAndBundleInformation().getFeatureName().orElse("?"));
TableItem item5 = new TableItem(m_table, SWT.NONE);
item5.setText(0, "Node's feature symbolic name");
item5.setText(1, nnc.getNodeAndBundleInformation().getFeatureSymbolicName().orElse("?"));
TableItem item6 = new TableItem(m_table, SWT.NONE);
item6.setText(0, "Node's feature version (last saved with)");
item6.setText(1, nnc.getNodeAndBundleInformation().getFeatureVersion().map(v -> v.toString()).orElse("?"));
TableItem item1 = new TableItem(m_table, SWT.NONE);
item1.setText(0, "Node's plug-in name");
item1.setText(1, nnc.getNodeAndBundleInformation().getBundleName().orElse("?"));
TableItem item2 = new TableItem(m_table, SWT.NONE);
item2.setText(0, "Node's plug-in symbolic name");
item2.setText(1, nnc.getNodeAndBundleInformation().getBundleSymbolicName().orElse("?"));
TableItem item3 = new TableItem(m_table, SWT.NONE);
item3.setText(0, "Node's plug-in version (last saved with)");
item3.setText(1, nnc.getNodeAndBundleInformation().getBundleVersion().map(v -> v.toString()).orElse("?"));
}
// add settings to table
Stack<Pair<Iterator<String>, ConfigBaseRO>> stack = new Stack<Pair<Iterator<String>, ConfigBaseRO>>();
Iterator<String> it = settings.keySet().iterator();
if (it.hasNext()) {
stack.push(new Pair<Iterator<String>, ConfigBaseRO>(it, settings));
}
while (!stack.isEmpty()) {
String key = stack.peek().getFirst().next();
int depth = stack.size();
boolean noexpertskip = (depth <= 1);
ConfigBaseRO second = stack.peek().getSecond();
ConfigBaseRO confBase = null;
try {
confBase = second.getConfigBase(key);
} catch (InvalidSettingsException e) {
// nothing to do here - then it's just null as handled below
}
if (!stack.peek().getFirst().hasNext()) {
stack.pop();
}
if (confBase != null) {
// it's another Config entry, push on stack!
String val = confBase.toString();
if ((!val.endsWith("_Internals")) || showAll) {
Iterator<String> it2 = confBase.iterator();
if (it2.hasNext()) {
stack.push(new Pair<Iterator<String>, ConfigBaseRO>(it2, confBase));
}
} else {
noexpertskip = true;
}
}
// in both cases, we report its value
if ((!noexpertskip) || showAll) {
// TODO little problem here: there is no way to turn the entry for a specific key in the config base into a string!
// Hence, we check for a implementation that allows to do that as workaround.
// Yet, it would be better to add, e.g., a #toStringValue(String key) method to the ConfigRO interface ...
// However, so far there isn't any other implementation than ConfigBase anyway ...
String value;
if (second instanceof ConfigBase) {
value = ((ConfigBase) second).getEntry(key).toStringValue();
} else {
throw new IllegalStateException("Sub type \"" + second.getClass() + "\" of ConfigBaseRO not supported.");
}
TableItem item = new TableItem(m_table, SWT.NONE);
char[] indent = new char[depth - 1];
Arrays.fill(indent, '_');
item.setText(0, new String(indent) + key);
item.setText(1, value != null ? value : "null");
}
}
for (int i = 0; i < m_table.getColumnCount(); i++) {
m_table.getColumn(i).pack();
}
}
Aggregations