Search in sources :

Example 1 with AbstractConfigEntry

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

the class NodeContainerProperties method setPropertyValue.

/**
 * {@inheritDoc}
 */
@Override
public void setPropertyValue(final Object id, final Object value) {
    if ((id instanceof String) && (value instanceof String)) {
        String strVal = (String) value;
        String strID = (String) id;
        if (strID.startsWith(m_prefix)) {
            String[] hierarchy = strID.split(CONFIG_SEPARATOR);
            String key = hierarchy[hierarchy.length - 1];
            // apply it to the node's settings:
            NodeContainer node = getNode();
            if (node == null) {
                return;
            }
            WorkflowManager wfm = node.getParent();
            NodeSettings nodeSettings = new NodeSettings("Transfer");
            NodeSettings settings;
            try {
                wfm.saveNodeSettings(node.getID(), nodeSettings);
                // overwrite our config in the settings
                settings = nodeSettings.getNodeSettings("model");
                if (hierarchy.length > 1) {
                    for (int i = 0; i < hierarchy.length - 1; i++) {
                        settings = settings.getNodeSettings(hierarchy[i]);
                        if (settings == null) {
                            return;
                        }
                    }
                }
            } catch (InvalidSettingsException e) {
                // somehow node is not able to save its settings anymore
                return;
            }
            AbstractConfigEntry entry = settings.getEntry(key);
            if (entry == null || entry instanceof Config) {
                // settings are not complete or correct anymore
                return;
            }
            switch(entry.getType()) {
                case xboolean:
                    settings.addBoolean(key, Boolean.parseBoolean(strVal));
                    break;
                case xbyte:
                    settings.addByte(key, Byte.parseByte(strVal));
                    break;
                case xchar:
                    String decoded = TokenizerSettings.unescapeString(strVal);
                    settings.addChar(key, decoded.charAt(0));
                    break;
                case xdouble:
                    settings.addDouble(key, Double.parseDouble(strVal));
                    break;
                case xfloat:
                    settings.addFloat(key, Float.parseFloat(strVal));
                    break;
                case xint:
                    settings.addInt(key, Integer.parseInt(strVal));
                    break;
                case xlong:
                    settings.addLong(key, Long.parseLong(strVal));
                    break;
                case xshort:
                    settings.addShort(key, Short.parseShort(strVal));
                    break;
                case xstring:
                    String dec = TokenizerSettings.unescapeString(strVal);
                    settings.addString(key, dec);
                    break;
                default:
                    // ignore the new value
                    return;
            }
            try {
                wfm.loadNodeSettings(node.getID(), nodeSettings);
            } catch (Exception ex) {
                LOGGER.error("Invalid Value (" + strVal + "): " + ex.getMessage(), ex);
                return;
            }
            return;
        }
    }
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry) NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 2 with AbstractConfigEntry

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

the class ConfigEditTreeModel method recursiveAdd.

/**
 * Recursive construction of tree.
 */
private static void recursiveAdd(final ConfigEditTreeNode treeNode, final ConfigBase configValue) {
    assert (configValue == treeNode.getUserObject().m_configEntry);
    for (String s : configValue.keySet()) {
        AbstractConfigEntry childValue = configValue.getEntry(s);
        ConfigEditTreeNode childTreeNode = new ConfigEditTreeNode(childValue);
        if (childValue.getType().equals(ConfigEntries.config)) {
            recursiveAdd(childTreeNode, (ConfigBase) childValue);
        }
        treeNode.add(childTreeNode);
    }
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry)

Example 3 with AbstractConfigEntry

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

the class ConfigEditTreeNodePanel method setTreeNode.

/**
 * Set a new tree node to display.
 *
 * @param treeNode the new node to represent (may be null).
 */
public void setTreeNode(final ConfigEditTreeNode treeNode) {
    m_treeNode = treeNode;
    final boolean isEditable = (m_treeNode != null) && m_treeNode.isLeaf();
    String usedVariable;
    m_valueComboBox.setEnabled(isEditable);
    VariableType<?> selType = null;
    final Collection<FlowVariable> suitableVariables = new ArrayList<>();
    if (m_treeNode != null) {
        final AbstractConfigEntry entry = m_treeNode.getConfigEntry();
        selType = fillSuitableVariablesNew(suitableVariables);
        if (selType == null) {
            selType = StringType.INSTANCE;
            m_keyIcon = ICON_UNKNOWN;
        } else {
            m_keyIcon = selType.getIcon();
        }
        m_keyLabel.setText(displayTextForString(entry.getKey()));
        m_keyLabel.setToolTipText(entry.getKey());
        usedVariable = m_treeNode.getUseVariableName();
        final String exposeVariable = m_treeNode.getExposeVariableName();
        m_exposeAsVariableField.setText(exposeVariable);
    } else {
        selType = StringType.INSTANCE;
        m_keyLabel.setText("");
        m_keyLabel.setToolTipText(null);
        m_keyIcon = ICON_UNKNOWN;
        m_exposeAsVariableField.setText("");
        usedVariable = null;
    }
    m_keyLabel.setMinimumSize(LABEL_MINIMUM_SIZE);
    m_valueComboBoxModel.removeAllElements();
    m_valueComboBoxModel.addElement(EMPTY_COMBOBOX_ELEMENT);
    ComboBoxElement match = null;
    for (final FlowVariable v : suitableVariables) {
        final ComboBoxElement cbe = new ComboBoxElement(v);
        m_valueComboBoxModel.addElement(cbe);
        if (v.getName().equals(usedVariable)) {
            match = cbe;
        }
    }
    m_valueComboBox.setSize(VALUE_INPUTS_SIZE);
    m_valueComboBox.setMaximumSize(m_valueComboBox.getPreferredSize());
    if ((match == null) && (m_flowObjectStack != null)) {
        final Map<String, FlowVariable> allVars = m_flowObjectStack.getAllAvailableFlowVariables();
        if (allVars.containsKey(usedVariable)) {
            final FlowVariable v = allVars.get(usedVariable);
            final String error = "Variable \"" + usedVariable + "\" has wrong type (" + v.getVariableType() + "), expected " + selType;
            final ComboBoxElement cbe = new ComboBoxElement(v, error);
            m_valueComboBoxModel.addElement(cbe);
            match = cbe;
        }
    }
    if (match != null) {
        m_valueComboBox.setSelectedItem(match);
    } else if (usedVariable != null) {
        addPlaceholderForInvalidVariable(usedVariable, selType);
    }
    m_valueComboBox.setEnabled(m_valueComboBoxModel.getSize() > 1);
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry) ArrayList(java.util.ArrayList) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 4 with AbstractConfigEntry

use of org.knime.core.node.config.base.AbstractConfigEntry 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 5 with AbstractConfigEntry

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

the class NodeContainerProperties method getDescriptors.

/**
 * @return see {@link #getPropertyDescriptors()}
 */
protected IPropertyDescriptor[] getDescriptors() {
    ArrayList<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>();
    // iterate through all settings in the config
    for (Enumeration<TreeNode> it = m_settings.children(); it.hasMoreElements(); ) {
        AbstractConfigEntry prop = (AbstractConfigEntry) it.nextElement();
        // the id should be globally unique
        String hierID = m_prefix.isEmpty() ? prop.getKey() : m_prefix + CONFIG_SEPARATOR + prop.getKey();
        if (prop instanceof Config) {
            // sub-config
            descriptors.add(new PropertyDescriptor(hierID, prop.getKey()));
        } else {
            // all settings are displayed as string
            String typeName = prop.getType().name().substring(1);
            // we don't have a label yet
            String label = prop.getKey() + " (" + typeName + ")";
            switch(prop.getType()) {
                // if cases are changed here, setPropertyValue must be adapted
                case xboolean:
                case xbyte:
                case xchar:
                case xdouble:
                case xfloat:
                case xint:
                case xlong:
                case xshort:
                case xstring:
                    // editable types
                    descriptors.add(new TextPropertyDescriptor(hierID, label));
                    break;
                default:
                    descriptors.add(new PropertyDescriptor(hierID, label));
                    break;
            }
        }
    }
    return descriptors.toArray(new IPropertyDescriptor[descriptors.size()]);
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) TreeNode(javax.swing.tree.TreeNode) Config(org.knime.core.node.config.Config) ArrayList(java.util.ArrayList) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor)

Aggregations

AbstractConfigEntry (org.knime.core.node.config.base.AbstractConfigEntry)8 Config (org.knime.core.node.config.Config)3 ArrayList (java.util.ArrayList)2 TreeNode (javax.swing.tree.TreeNode)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 NodeSettings (org.knime.core.node.NodeSettings)2 ConfigBase (org.knime.core.node.config.base.ConfigBase)2 Iterator (java.util.Iterator)1 Stack (java.util.Stack)1 Point (org.eclipse.swt.graphics.Point)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 TableItem (org.eclipse.swt.widgets.TableItem)1 IPropertyDescriptor (org.eclipse.ui.views.properties.IPropertyDescriptor)1 PropertyDescriptor (org.eclipse.ui.views.properties.PropertyDescriptor)1 TextPropertyDescriptor (org.eclipse.ui.views.properties.TextPropertyDescriptor)1 ConfigEditTreeNode (org.knime.core.node.config.ConfigEditTreeModel.ConfigEditTreeNode)1 FlowObjectStack (org.knime.core.node.workflow.FlowObjectStack)1 FlowVariable (org.knime.core.node.workflow.FlowVariable)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1 NodeContainer (org.knime.core.node.workflow.NodeContainer)1