Search in sources :

Example 1 with ConfigBase

use of org.knime.core.node.config.base.ConfigBase in project knime-core by knime.

the class NodeOutputView method updateSettingsTable.

/*
     *  Put info about node settings into table.
     */
private void updateSettingsTable(final NodeContainer nc, final boolean showAll) {
    assert Display.getCurrent().getThread() == Thread.currentThread();
    // display swt table
    ((StackLayout) m_stackPanel.getLayout()).topControl = m_table;
    m_stackPanel.layout();
    m_info.setText("Node Configuration");
    // retrieve settings
    NodeSettings settings = new NodeSettings("");
    try {
        nc.getParent().saveNodeSettings(nc.getID(), settings);
    } catch (InvalidSettingsException ise) {
    // never happens.
    }
    // 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 ((nc instanceof NativeNodeContainer) && showAll) {
        NativeNodeContainer nnc = (NativeNodeContainer) nc;
        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>, ConfigBase>> stack = new Stack<Pair<Iterator<String>, ConfigBase>>();
    Iterator<String> it = settings.keySet().iterator();
    if (it.hasNext()) {
        stack.push(new Pair<Iterator<String>, ConfigBase>(it, settings));
    }
    while (!stack.isEmpty()) {
        String key = stack.peek().getFirst().next();
        int depth = stack.size();
        boolean noexpertskip = (depth <= 1);
        AbstractConfigEntry ace = stack.peek().getSecond().getEntry(key);
        if (!stack.peek().getFirst().hasNext()) {
            stack.pop();
        }
        if (ace.getType().equals(ConfigEntries.config)) {
            // it's another Config entry, push on stack!
            String val = ace.toStringValue();
            if ((!val.endsWith("_Internals")) || showAll) {
                Iterator<String> it2 = ((ConfigBase) ace).iterator();
                if (it2.hasNext()) {
                    stack.push(new Pair<Iterator<String>, ConfigBase>(it2, (ConfigBase) ace));
                }
            } else {
                noexpertskip = true;
            }
        }
        // in both cases, we report its value
        if ((!noexpertskip) || showAll) {
            String value = ace.toStringValue();
            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();
    }
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry) TableItem(org.eclipse.swt.widgets.TableItem) ConfigBase(org.knime.core.node.config.base.ConfigBase) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) Stack(java.util.Stack) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Iterator(java.util.Iterator) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) Pair(org.knime.core.util.Pair)

Example 2 with ConfigBase

use of org.knime.core.node.config.base.ConfigBase 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();
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ConfigBase(org.knime.core.node.config.base.ConfigBase) TableColumn(org.eclipse.swt.widgets.TableColumn) Stack(java.util.Stack) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) ConfigBaseRO(org.knime.core.node.config.base.ConfigBaseRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Iterator(java.util.Iterator) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) Pair(org.knime.core.util.Pair)

Aggregations

Iterator (java.util.Iterator)2 Stack (java.util.Stack)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 TableItem (org.eclipse.swt.widgets.TableItem)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 ConfigBase (org.knime.core.node.config.base.ConfigBase)2 FlowObjectStack (org.knime.core.node.workflow.FlowObjectStack)2 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)2 Pair (org.knime.core.util.Pair)2 Point (org.eclipse.swt.graphics.Point)1 NodeSettings (org.knime.core.node.NodeSettings)1 AbstractConfigEntry (org.knime.core.node.config.base.AbstractConfigEntry)1 ConfigBaseRO (org.knime.core.node.config.base.ConfigBaseRO)1