Search in sources :

Example 76 with NotConfigurableException

use of org.knime.core.node.NotConfigurableException in project knime-core by knime.

the class ColumnResorterNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    if (specs[0] == null || specs[0].getNumColumns() == 0) {
        throw new NotConfigurableException("No input table found or no columns found in input table! " + "Please connect the node first or check input table.");
    }
    try {
        List<DataColumnSpec> columnNames = new ArrayList<DataColumnSpec>();
        for (DataColumnSpec colSpec : specs[0]) {
            columnNames.add(colSpec);
        }
        m_columnNames = columnNames.toArray(new DataColumnSpec[] {});
        if (m_model.size() > 0) {
            m_model.removeAllElements();
        }
        m_order = settings.getStringArray(ColumnResorterNodeModel.CFG_NEW_ORDER);
        Set<String> alreadyInList = new HashSet<String>();
        if (m_order.length > 0) {
            for (String cur : m_order) {
                // is column in new spec?
                if (specs[0].containsName(cur)) {
                    alreadyInList.add(cur);
                    m_model.addElement(specs[0].getColumnSpec(cur));
                }
            }
            // add new columns at the end
            for (DataColumnSpec cur : specs[0]) {
                if (!alreadyInList.contains(cur.getName())) {
                    m_model.addElement(cur);
                }
            }
        } else {
            for (DataColumnSpec cur : m_columnNames) {
                m_model.addElement(cur);
            }
        }
    } catch (InvalidSettingsException is) {
    // do nothing here - its the dialog
    }
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 77 with NotConfigurableException

use of org.knime.core.node.NotConfigurableException in project knime-core by knime.

the class ScorerNodeDialog method loadSettingsFrom.

// ScorerNodeDialog(NodeModel)
/**
 * Fills the two combo boxes with all column names retrieved from the input
 * table spec. The second and last column will be selected by default unless
 * the settings object contains others.
 *
 * @see NodeDialogPane#loadSettingsFrom(NodeSettingsRO, DataTableSpec[])
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    assert (settings != null && specs != null);
    m_firstColumns.removeAllItems();
    m_secondColumns.removeAllItems();
    DataTableSpec spec = specs[ScorerNodeModel.INPORT];
    if ((spec == null) || (spec.getNumColumns() < 2)) {
        throw new NotConfigurableException("Scorer needs an input table " + "with at least two columns");
    }
    int numCols = spec.getNumColumns();
    for (int i = 0; i < numCols; i++) {
        String c = spec.getColumnSpec(i).getName();
        m_firstColumns.addItem(c);
        m_secondColumns.addItem(c);
    }
    // if at least two columns available
    String col2 = (numCols > 0) ? spec.getColumnSpec(numCols - 1).getName() : null;
    String col1 = (numCols > 1) ? spec.getColumnSpec(numCols - 2).getName() : col2;
    col1 = settings.getString(ScorerNodeModel.FIRST_COMP_ID, col1);
    col2 = settings.getString(ScorerNodeModel.SECOND_COMP_ID, col2);
    m_firstColumns.setSelectedItem(col1);
    m_secondColumns.setSelectedItem(col2);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec)

Example 78 with NotConfigurableException

use of org.knime.core.node.NotConfigurableException in project knime-core by knime.

the class JavaScriptingPanel method loadSettingsFrom.

/**
 * Load settings from arg.
 * @param s To load from.
 * @param spec The input spec.
 */
public void loadSettingsFrom(final JavaScriptingSettings s, final DataTableSpec spec) {
    String exp = s.getExpression();
    String header = s.getHeader();
    String rType = s.getReturnType().getName();
    boolean isArrayReturn = s.isArrayReturn();
    String defaultNewName = m_customizer.getOutputIsVariable() ? "new variable" : "new column";
    String newName = s.getColName();
    boolean isReplace = s.isReplace();
    boolean isTestCompilation = s.isTestCompilationOnDialogClose();
    boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
    m_currentVersion = s.getExpressionVersion();
    m_newNameField.setText("");
    // will select newColName only if it is in the spec list
    try {
        m_replaceColumnCombo.update(spec, newName);
    } catch (NotConfigurableException e1) {
        NodeLogger.getLogger(getClass()).coding("Combo box throws " + "exception although content is not required", e1);
    }
    DefaultComboBoxModel cmbModel = (DefaultComboBoxModel) m_replaceVariableCombo.getModel();
    cmbModel.removeAllElements();
    final Map<String, FlowVariable> availableFlowVariables = m_varProvider.getAvailableFlowVariables();
    for (FlowVariable v : availableFlowVariables.values()) {
        switch(v.getScope()) {
            case Flow:
                cmbModel.addElement(v);
                break;
            default:
        }
    }
    if (isReplace && availableFlowVariables.containsKey(newName)) {
        m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
    }
    m_currentSpec = spec;
    // whether there are variables or columns available
    // -- which of two depends on the customizer
    boolean fieldsAvailable;
    if (m_customizer.getOutputIsVariable()) {
        fieldsAvailable = m_replaceVariableCombo.getModel().getSize() > 0;
    } else {
        fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
    }
    if (isReplace && fieldsAvailable) {
        m_replaceRadio.doClick();
    } else {
        m_appendRadio.doClick();
        String newNameString = (newName != null ? newName : defaultNewName);
        m_newNameField.setText(newNameString);
    }
    m_replaceRadio.setEnabled(fieldsAvailable);
    m_headerEdit.setText(header);
    m_expEdit.setText(exp);
    m_expEdit.requestFocus();
    ButtonModel firstButton = null;
    for (Enumeration<?> e = m_returnTypeButtonGroup.getElements(); e.hasMoreElements(); ) {
        AbstractButton b = (AbstractButton) e.nextElement();
        if (firstButton == null) {
            firstButton = b.getModel();
        }
        if (b.getActionCommand().equals(rType)) {
            m_returnTypeButtonGroup.setSelected(b.getModel(), true);
        }
    }
    if (m_returnTypeButtonGroup.getSelection() == null) {
        m_returnTypeButtonGroup.setSelected(firstButton, true);
    }
    m_isArrayReturnChecker.setSelected(isArrayReturn);
    DefaultListModel listModel = (DefaultListModel) m_colList.getModel();
    listModel.removeAllElements();
    if (m_currentVersion == Expression.VERSION_1X) {
        listModel.addElement(Expression.ROWKEY);
        listModel.addElement(Expression.ROWNUMBER);
    } else {
        listModel.addElement(Expression.ROWID);
        listModel.addElement(Expression.ROWINDEX);
        listModel.addElement(Expression.ROWCOUNT);
    }
    for (int i = 0; i < spec.getNumColumns(); i++) {
        DataColumnSpec colSpec = spec.getColumnSpec(i);
        listModel.addElement(colSpec);
    }
    DefaultListModel fvListModel = (DefaultListModel) m_flowVarsList.getModel();
    fvListModel.removeAllElements();
    for (FlowVariable v : availableFlowVariables.values()) {
        fvListModel.addElement(v);
    }
    m_compileOnCloseChecker.setSelected(isTestCompilation);
    m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) AbstractButton(javax.swing.AbstractButton) DataColumnSpec(org.knime.core.data.DataColumnSpec) DefaultListModel(javax.swing.DefaultListModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ButtonModel(javax.swing.ButtonModel) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 79 with NotConfigurableException

use of org.knime.core.node.NotConfigurableException in project knime-core by knime.

the class DialogComponentColumnSelection method loadSettingsFrom.

/**
 * Reads values for this dialog component from configuration object.
 *
 * @param settings the <code>NodeSettings</code> to read from
 * @param specs the input specs
 * @throws InvalidSettingsException if the settings could not be read
 * @throws NotConfigurableException If the spec does not contain at least
 * one column which is compatible to the value list as given in the
 * constructor.
 */
@Override
public void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws InvalidSettingsException, NotConfigurableException {
    String classCol = "** Unknown column **";
    try {
        classCol = settings.getString(m_configName);
    } catch (Exception e) {
    // do nothing here, since its the dialog
    // catch it that the DefaultNodeDialogPane doesn't
    // interrupt the for loop (loadSettings)
    } finally {
        // update JComboBox with list of column names
        DataTableSpec spec = specs[m_specIndex];
        m_chooser.update(spec, classCol);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

NotConfigurableException (org.knime.core.node.NotConfigurableException)79 DataColumnSpec (org.knime.core.data.DataColumnSpec)35 DataTableSpec (org.knime.core.data.DataTableSpec)35 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)31 DataColumnSpecFilterConfiguration (org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration)8 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)5 DataType (org.knime.core.data.DataType)5 NominalValue (org.knime.core.data.NominalValue)5 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)5 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 Container (java.awt.Container)3 Frame (java.awt.Frame)3 GridBagConstraints (java.awt.GridBagConstraints)3 ActionListener (java.awt.event.ActionListener)3 ItemListener (java.awt.event.ItemListener)3 AbstractButton (javax.swing.AbstractButton)3 DefaultListModel (javax.swing.DefaultListModel)3 LinkedHashMap (java.util.LinkedHashMap)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2