Search in sources :

Example 1 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class StringManipulationVariableNodeModel method calculate.

/**
 * @throws CompilationFailedException
 * @throws InstantiationException
 * @throws Exception
 */
private void calculate() throws InvalidSettingsException, CompilationFailedException, InstantiationException {
    if (m_settings == null || m_settings.getExpression() == null) {
        throw new InvalidSettingsException("No expression has been set.");
    }
    JavaScriptingSettings settings = m_settings.createJavaScriptingSettings();
    settings.setInputAndCompile(new DataTableSpec());
    // calculate the result
    ColumnCalculator cc = new ColumnCalculator(settings, this);
    DataCell calculate = null;
    try {
        calculate = cc.calculate(new DefaultRow(new RowKey(""), new DataCell[] {}));
    } catch (NoSuchElementException e) {
        throw new InvalidSettingsException(e.getMessage());
    }
    String newVariableName;
    Map<String, FlowVariable> inputFlowVariables = getAvailableInputFlowVariables();
    if (m_settings.isReplace()) {
        newVariableName = m_settings.getColName();
        CheckUtils.checkSettingNotNull(inputFlowVariables.get(newVariableName), "Can't replace input variable '%s' -- it does not exist in the input", newVariableName);
    } else {
        newVariableName = new UniqueNameGenerator(inputFlowVariables.keySet()).newName(m_settings.getColName());
    }
    // convert and push result as flow variable
    CheckUtils.checkSetting(!calculate.isMissing(), "Calculation returned missing value");
    Class<? extends DataCell> cellType = calculate.getClass();
    if (cellType.equals(IntCell.class)) {
        pushFlowVariableInt(newVariableName, ((IntCell) calculate).getIntValue());
    } else if (cellType.equals(DoubleCell.class)) {
        pushFlowVariableDouble(newVariableName, ((DoubleCell) calculate).getDoubleValue());
    } else if (cellType.equals(StringCell.class)) {
        pushFlowVariableString(newVariableName, ((StringCell) calculate).getStringValue());
    } else {
        throw new RuntimeException("Invalid variable class: " + cellType);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ColumnCalculator(org.knime.ext.sun.nodes.script.calculator.ColumnCalculator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) NoSuchElementException(java.util.NoSuchElementException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 2 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class JavaScriptingNodeDialog method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    JavaScriptingSettings s = m_customizer.createSettings();
    // first save jar panel so that settings contain additional
    // libraries that may be required for test compilation
    m_jarPanel.saveSettingsTo(s);
    m_mainPanel.saveSettingsTo(s);
    s.saveSettingsTo(settings);
}
Also used : JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings)

Example 3 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class JavaIfSwitchNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    JavaScriptingSettings jsSettings = m_customizer.createSettings();
    jsSettings.loadSettingsInDialog(settings, JavaIfSwitchNodeModel.EMPTY_SPEC);
    m_panel.loadSettingsFrom(jsSettings, JavaIfSwitchNodeModel.EMPTY_SPEC);
}
Also used : JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings)

Example 4 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class JavaEditVariableNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    JavaScriptingSettings jsSettings = m_customizer.createSettings();
    jsSettings.loadSettingsInModel(settings);
    m_settings = jsSettings;
}
Also used : JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings)

Example 5 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class JavaScriptingNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    JavaScriptingSettings s = m_customizer.createSettings();
    s.loadSettingsInDialog(settings, specs[0]);
    m_mainPanel.loadSettingsFrom(s, specs[0]);
    m_jarPanel.loadSettingsFrom(s);
}
Also used : JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings)

Aggregations

JavaScriptingSettings (org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings)13 IOException (java.io.IOException)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 ColumnCalculator (org.knime.ext.sun.nodes.script.calculator.ColumnCalculator)2 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Path (org.eclipse.core.runtime.Path)1 Manipulator (org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)1 DataCell (org.knime.core.data.DataCell)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 RowKey (org.knime.core.data.RowKey)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 FlowVariable (org.knime.core.node.workflow.FlowVariable)1 UniqueNameGenerator (org.knime.core.util.UniqueNameGenerator)1